diff --git a/.gitignore b/.gitignore index e3fbd98..e6b6cf5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ build node_modules + +# downloaded by minification build +tools/compiler.jar diff --git a/Makefile b/Makefile index 9dfb2f8..9b0da39 100644 --- a/Makefile +++ b/Makefile @@ -17,10 +17,11 @@ src_tests := index.js $(shell find "$(path_test)" -name test-* \ path_doc := ./doc -combine=${path_tools}/combine +combine := $(path_tools)/combine +compiler := $(path_tools)/compiler.jar -.PHONY: combine min doc test test-combine +.PHONY: combine min doc test test-combine clean distclean default: combine min @@ -55,10 +56,15 @@ perf: default $(perf_tests) perf-%.js: default @node $@ -min: build/ease.min.js build/ease-full.min.js $(path_build)/browser-test-min.html -build/%.min.js: build/%.js +# minificatino process uses Google Closure compiler +min: build/ease.min.js build/ease-full.min.js $(path_build)/browser-test-min.html \ + | combine +$(compiler): + wget -O- http://closure-compiler.googlecode.com/files/compiler-latest.tar.gz \ + | tar -C $(path_tools) -xzv compiler.jar +build/%.min.js: build/%.js $(compiler) cat $(path_tools)/license.tpl > $@ - node $(path_tools)/minify.js < $< > $@ + java -jar $(compiler) --js $< >> $@ || rm $@ install: doc-info [ -d $(path_info_install) ] || mkdir -p $(path_info_install) @@ -72,3 +78,6 @@ clean: $(MAKE) -C $(path_doc) clean rm -rf "${path_build}" +distclean: clean + rm $(compiler) + diff --git a/tools/minify.js b/tools/minify.js deleted file mode 100644 index 14794d0..0000000 --- a/tools/minify.js +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Minification script - * - * Takes input from stdin, mangles and minifies it, then outputs to stdout. - * ex: $ node minify.js < source.js > source.min.js - */ - -// uses UglifyJS -var uglify, - FILE_ROOT = '../build/'; - -try -{ - // attempt to load UglifyJS - var uglify = require( 'uglify-js' ); -} -catch ( e ) -{ - // if there's a problem loading it, let the user know what they probably - // need to do - process.stderr.write( - "Unable to located UglifyJS. Please run:\n\n" + - " $ npm install uglify-js\n\n" + - "and then try again.\n" - ); - - process.exit( 1 ); -} - -var parser = uglify.parser, - uglify = uglify.uglify; - -// we should receive the file via stdin -var data = ''; -process.stdin - .on( 'data', function( chunk ) - { - data += chunk; - } ) - .on( 'end', function() - { - minify(); - } ) -; - -// stdin is paused by default, so we have to unpause it to read -process.stdin.setEncoding( 'utf8' ) -process.stdin.resume() - - -/** - * Minifies and outputs the code - * - * The process involves mangling the code and minifying it. - */ -function minify() -{ - var ast = parser.parse( data ); - - // mange and minify - ast = uglify.ast_squeeze( ast ); - - // output final, compressed code - process.stdout.write( uglify.gen_code( ast ) ); -} -