onilabs / stratifiedjs

Oni StratifiedJS (previously Apollo)
http://onilabs.com/stratifiedjs
Other
231 stars 22 forks source link

A way to compile sjs codes? #13

Closed kevyworks closed 10 years ago

kevyworks commented 10 years ago

Hi, Is there a way I can obfuscate / compile SJS scripts? I am embedding this to a node-webkit application and when the application runs, it extracts the .nw files to temp and all sources are available.

timbertson commented 10 years ago

The compiled (to JavaScript) sources are not terribly readable, although obviously these are not going to prevent a dedicated snooper.

We expose the compiler as a module at sjs:compile/sjs, which is also runnable from the command line:

$ sjs sjs:compile/sjs module.sjs

This will print out the compiled JS code. This might not work too well with the module system though (since it's no longer associated with a module). A better bet is probably to use sjs:bundle, which will compile a module and all of its dependencies into a single .js file which you just need to include with a <script> tag (you still need to include stratified.js). Unlike the straight-to-js compilation method, this bundle file hooks into the module system so it should be transparent to your code.

$ sjs sjs:bundle --compile --output bundle.js --resource ./=/ <main-module.sjs>

See sjs sjs:bundle --help for the available command-line options.

You could always try running a regular JS obfuscator over the generated bundle.js if you want to, but see if the existing output is obtuse enough first (a buggy obfuscator could break compiled JS code).