benchmark | ||
demo | ||
src | ||
tests | ||
.gitignore | ||
CHANGELOG.md | ||
LICENSE | ||
README.md | ||
Setup.hs | ||
SJW.cabal |
SJW
The Simple Javascript Wrench is a tool made to compile a set of independant Javascript modules into a single executable javascript file as expected by a web browser. It allows you to write (relatively) clean Javascript and to package it into one single script that will run once the page loading it is loaded.
How to install
SJW can be compiled and installed from a version of this repository by issueing the following commands
$ cabal new-update
$ cabal new-build
$ cabal new-install sjw
Using it
Invocation
SJW is a sort of compiler that expects the path to a source directory as argument and will output (on stdout
or at the path given with the usual -o
option) a script containing all the code required by the Main
module.
The demo/
directory is a simple example of this mechanism (I even committed the output main.js
by accident but it's actually useful because you can try and generate it locally and check that you get exactly the same result). Run the following from this directory (if you're not used to haskell projects handled with cabal, make sure you have ~/.cabal/bin
in your $PATH
variable) :
$ sjw demo/src -o demo/main.js
Ask sjw --help
to read more about available options or to print the version of SJW you're using.
Everyday usage
SJW is simple enough that you don't need special commands to list, install or uninstall packages. All those vital needs are achieved by the usual commands your shell provides : ls
, cp
or rm
.
The default location for the package store is a directory called .sjw
located directly in your home (as set in your variable $HOME
or, if unset, the home directory for your user as recorded by the system). This can be overriden by setting the variable $SJW_PACKAGE_DB
in your environment (for instance by defining it in your shell's profile).
A package is «installed» by creating a directory there.
$ cp -R myPackage/src ~/.sjw/myPackage
The module tree starts directly under this directory. So, if myPackage
exposes three modules Huey
, Dewey
and Louie
:
$ ls myPackage/src
Huey.js Dewey.js Louie.js
Then, after the previous cp
command, you can use in your code
import Huey;
import Dewey;
import Louie;
and compile it with sjw -I myPackage
. That's it. So, of course you can list all installed packages with :
$ ls ~/.sjw
And remove any package with :
$ rm -r ~/.sjw/myPackage