diff options
author | Mihai Bazon <mihai@bazon.net> | 2012-08-21 12:55:56 +0300 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2012-08-21 13:53:16 +0300 |
commit | 7ae1c600a24e2f43feb839c5fd1625f6261751b5 (patch) | |
tree | abe06f041accc5dc0a4d277ae29612f2ee5af080 /tools/node.js | |
parent | 92bd53b513c6cf030d96ed627efc50dd1875ba85 (diff) | |
download | tracifyjs-7ae1c600a24e2f43feb839c5fd1625f6261751b5.tar.gz tracifyjs-7ae1c600a24e2f43feb839c5fd1625f6261751b5.zip |
some reorganization
(moved pretty much everything that relates to scope in scope.js, added a
module for NodeJS that can be used with require() and exports everything.)
Diffstat (limited to 'tools/node.js')
-rw-r--r-- | tools/node.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tools/node.js b/tools/node.js new file mode 100644 index 00000000..bb8ed7ae --- /dev/null +++ b/tools/node.js @@ -0,0 +1,37 @@ +var fs = require("fs"); +var vm = require("vm"); +var sys = require("util"); +var path = require("path"); + +var UglifyJS = vm.createContext({}); + +function load_global(file) { + file = path.resolve(path.dirname(module.filename), file); + try { + var code = fs.readFileSync(file, "utf8"); + return vm.runInContext(code, UglifyJS, file); + } catch(ex) { + // XXX: in case of a syntax error, the message is kinda + // useless. (no location information). + sys.debug("ERROR in file: " + file + " / " + ex); + process.exit(1); + } +}; + +load_global("../lib/utils.js"); +load_global("../lib/ast.js"); +load_global("../lib/parse.js"); +load_global("../lib/scope.js"); +load_global("../lib/output.js"); +load_global("../lib/compress.js"); + +UglifyJS.AST_Node.warn_function = function(txt) { + sys.debug(txt); +}; + +// XXX: perhaps we shouldn't export everything but heck, I'm lazy. +for (var i in UglifyJS) { + if (UglifyJS.hasOwnProperty(i)) { + exports[i] = UglifyJS[i]; + } +} |