Skip to content

Commit

Permalink
using node install script in case uglify is not installed in node_mod…
Browse files Browse the repository at this point in the history
…uels
  • Loading branch information
jstewmon committed Feb 27, 2012
1 parent a6966a8 commit 7d04cf1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 1 addition & 2 deletions Makefile
Expand Up @@ -2,7 +2,6 @@ PACKAGE = asyncjs
NODEJS = $(if $(shell test -f /usr/bin/nodejs && echo "true"),nodejs,node)
CWD := $(shell pwd)
WITH_NODEUNIT = PATH=$(CWD)/node_modules/nodeunit/bin:$(PATH)
WITH_UGLIFY = PATH=$(CWD)/node_modules/uglify-js/bin:$(PATH)
WITH_NODELINT = PATH=$(CWD)/node_modules/nodelint/bin:$(PATH)

BUILDDIR = dist
Expand All @@ -11,7 +10,7 @@ all: clean test build

build: $(wildcard lib/*.js)
mkdir -p $(BUILDDIR)
$(WITH_UGLIFY) uglifyjs lib/async.js > $(BUILDDIR)/async.min.js
node install.js

test:
$(WITH_NODEUNIT) nodeunit test
Expand Down
11 changes: 11 additions & 0 deletions install.js
@@ -0,0 +1,11 @@
var fs = require('fs');
var path = require('path');
var jsp = require("uglify-js").parser;
var pro = require("uglify-js").uglify;

var orig_code = fs.readFileSync(path.join(__dirname, './lib/async.js'), 'utf8');
var ast = jsp.parse(orig_code); // parse code and get the initial AST
ast = pro.ast_mangle(ast); // get a new AST with mangled names
ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
var final_code = pro.gen_code(ast); // compressed code here
fs.writeFileSync(path.join(__dirname, './dist/async.min.js'), final_code, 'utf8');

0 comments on commit 7d04cf1

Please sign in to comment.