forked from digitalBush/jquery.maskedinput
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCakefile
38 lines (29 loc) · 920 Bytes
/
Cakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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)
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)