The Simple Javascript Wrench is a very simple tool to pack several JS «modules» into a single script.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Tissevert 5a5f9b7f96 Support base as old as 4.9 3 weeks ago
demo Fix indentation typo 6 months ago
src Support base as old as 4.9 3 weeks ago
.gitignore First draft defining the structure of the program, needs to implement «imports» and the actual compilation 6 months ago
CHANGELOG.md Fix bug in loop reporting causing in some cases the display of an inaccurate loop instead of the one actually detected 1 month ago
LICENSE First draft defining the structure of the program, needs to implement «imports» and the actual compilation 6 months ago
README.md Add usage explanations 1 month ago
SJW.cabal Support base as old as 4.9 3 weeks ago
Setup.hs First draft defining the structure of the program, needs to implement «imports» and the actual compilation 6 months ago

README.md

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