forked from harthur/brain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jakefile.js
45 lines (37 loc) · 1.1 KB
/
Jakefile.js
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
38
39
40
41
42
43
44
45
/*
Turns CommonJS package into a browser file and minifies.
uses node-jake http://github.com/mde/node-jake
run with 'jake [build|minify|clean]'
*/
var fs = require("fs"),
path = require("path"),
util = require('util')
build = require("./build");
var pkg = JSON.parse(fs.readFileSync("package.json"));
var prefix = pkg.name + "-" + pkg.version;
task('build', [], function (dest) {
util.puts("building...");
dest = dest || prefix + ".js";
build.build(dest);
util.puts("> " + dest);
});
task('minify', [], function (file, dest) {
file = file || prefix + ".js";
dest = dest || prefix + ".min.js";
var minified = minify(fs.readFileSync(file, "utf-8"));
fs.writeFileSync(dest, minified, "utf-8");
util.puts("> " + dest)
});
task('clean', [], function () {
fs.unlink(prefix + ".js");
fs.unlink(prefix + ".min.js");
});
function minify(code) {
var uglifyjs = require("uglify-js"),
parser = uglifyjs.parser,
uglify = uglifyjs.uglify;
var ast = parser.parse(code);
ast = uglify.ast_mangle(ast);
ast = uglify.ast_squeeze(ast);
return uglify.gen_code(ast);
}