-
Notifications
You must be signed in to change notification settings - Fork 96
/
Jakefile.js
54 lines (43 loc) · 1.35 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
46
47
48
49
50
51
52
53
54
/*
Turns CommonJS package into a browser file and minifies.
uses node-jake http://github.com/mde/node-jake
install jake with `npm install jake -g`
run with `jake [build|minify|clean]`
*/
var fs = require("fs"),
path = require("path"),
browserify = require("browserify");
var pkg = JSON.parse(fs.readFileSync("package.json"));
var prefix = pkg.name + "-" + pkg.version;
task('build', [], function (dest) {
console.log("building...");
dest = dest || prefix + ".js";
var source = browserify.bundle({
name: "convert",
main: path.join(__dirname, pkg.main),
shim: false
});
source = "var colorConvert = (function() {" + source + " return require('convert')})();"
fs.writeFileSync(dest, source);
console.log("> " + 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");
console.log("> " + 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);
}