Permalink
Browse files

Ditching cake for jake and added templating for distribution output.

Using new UglifyJS2 fixes #69
  • Loading branch information...
1 parent 2c5075f commit 9191e875a49bf09f9e07390b7ddea23c1a2379e4 @digitalBush committed Jan 17, 2013
Showing with 330 additions and 333 deletions.
  1. +0 −36 Cakefile
  2. +31 −0 Jakefile
  3. +290 −297 src/jquery.maskedinput.js
  4. +9 −0 templates/jquery.maskedinput.template
View
@@ -1,36 +0,0 @@
-sys = require 'sys'
-fs = require 'fs'
-path = require 'path'
-uglify = require 'uglify-js'
-distPath='dist/'
-
-plugin = JSON.parse(fs.readFileSync('plugin.json','utf8'))
-plugin.Year=new Date().getFullYear()
-
-
-task 'clean','clean dist/', ->
- fs.rmdir distPath
-
-
-minify = (js)->
- uglify = require 'uglify-js'
- ast = uglify.parser.parse(js)
- process = uglify.uglify
- ast = process.ast_mangle(ast)
- ast = process.ast_squeeze(ast)
- comment = uglify.parser.tokenizer(js)().comments_before[0].value;
- '/*'+comment+'*/\n'+process.gen_code(ast)
-
-replaceTokens = (js,tokens)->
- js.replace(
- /@(\w+)/g,
- (match,p)-> tokens[p]
- )
-
-task 'compress', 'compress javascript', ->
- invoke 'clean'
- fs.mkdir(distPath,0755)
- compressed = minify(fs.readFileSync('src/jquery.maskedinput.js','utf8'))
- final=replaceTokens(compressed,plugin)
- fs.writeFileSync(path.join(distPath,'jquery.maskedinput.min.js'), final)
-
View
@@ -0,0 +1,31 @@
+var Handlebars=require("handlebars"),
+ fs = require("fs"),
+ path = require ("path"),
+ UglifyJS = require("uglify-js"),
+ distPath='dist/';
+
+Handlebars.registerHelper('include', function(context) {
+ return fs.readFileSync(context,'utf8');
+});
+
+function keepComment(node,comment){
+ return comment.type === "comment2";
+}
+
+task('clean',function(){
+ fs.rmdir(distPath)
+});
+
+task('default',['clean'], function (params) {
+ fs.mkdir(distPath,0755);
+
+ var options = JSON.parse(fs.readFileSync('plugin.json','utf8'))
+ options.Year=new Date().getFullYear()
+
+ var template = Handlebars.compile(fs.readFileSync('templates/jquery.maskedinput.template','utf8'));
+ var debugFile = path.join(distPath,'jquery.maskedinput.js');
+ fs.writeFileSync(debugFile,template(options));
+
+ compressed = UglifyJS.minify(debugFile,{output:{comments:keepComment}});
+ fs.writeFileSync(path.join(distPath,'jquery.maskedinput.min.js'), compressed.code);
+});
Oops, something went wrong. Retry.

0 comments on commit 9191e87

Please sign in to comment.