Clean Javascript modules for front-end development
Find a file
2020-05-21 16:54:57 +02:00
demo Fix indentation typo 2020-01-01 19:46:32 +01:00
src Separate the sjw executable from a Haskell library used to write it and that can be re-used by other Haskell programs to assemble JS code directly from a Haskell program 2020-05-17 16:30:56 +02:00
tests Add static test directories 2020-01-10 18:44:24 +01:00
.gitignore First draft defining the structure of the program, needs to implement «imports» and the actual compilation 2019-12-30 12:16:05 +01:00
CHANGELOG.md Separate the sjw executable from a Haskell library used to write it and that can be re-used by other Haskell programs to assemble JS code directly from a Haskell program 2020-05-17 16:30:56 +02:00
LICENSE First draft defining the structure of the program, needs to implement «imports» and the actual compilation 2019-12-30 12:16:05 +01:00
README.md Add usage explanations 2020-05-17 17:09:15 +02:00
Setup.hs First draft defining the structure of the program, needs to implement «imports» and the actual compilation 2019-12-30 12:16:05 +01:00
SJW.cabal Separate the sjw executable from a Haskell library used to write it and that can be re-used by other Haskell programs to assemble JS code directly from a Haskell program 2020-05-17 16:30:56 +02:00

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