forked from DmitryBaranovskiy/raphael
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake
executable file
·57 lines (51 loc) · 1.89 KB
/
make
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
55
56
57
#!/usr/bin/env node
/*
To use this script, must have:
- uglify.js (npm install uglify)
- eve/eve.js (get it from https://github.com/DmitryBaranovskiy/eve)
*/
var setup = {
input: {
core: "raphael.core.js",
svg: "raphael.svg.js",
vml: "raphael.vml.js",
eve: "eve.js",
copy: "copy.js",
fakeDefine: "fakedefine.js"
},
output: {
"raphael-min.js": function () {
return this.copy + "\n" + minify(this.fakeDefine + "\n\n" + this.eve + this.core + this.svg + this.vml);
},
"raphael.js": function () {
return this.copy + "\n" + this.fakeDefine + "\n\n" + this.eve + "\n\n" + this.core + "\n\n" + this.svg + "\n\n" + this.vml;
},
"raphael.pro-min.js": function () {
return this.copy + "\n" + minify(this.fakeDefine + "\n\n" + this.eve + this.core + this.svg);
},
"raphael.pro.js": function () {
return this.copy + "\n" + this.fakeDefine + "\n\n" + this.eve + "\n\n" + this.core + "\n\n" + this.svg ;
}
}
},
ujs = require("uglify-js"),
jsp = ujs.parser,
pro = ujs.uglify,
fs = require("fs"),
rxdr = /\/\*\\[\s\S]+?\\\*\//g;
function minify(code) {
return pro.gen_code(pro.ast_squeeze(pro.ast_mangle(jsp.parse(code))));
}
var files = {};
for (var file in setup.input) {
files[file] = String(fs.readFileSync(setup.input[file], "utf8")).replace(rxdr, "").replace(/^define\(/m, "define('" + setup.input[file].replace('.js', '') + "', ");
}
for (file in setup.output) {
var before = "(function () {\n\n";
var after = "\n\n}());";
(function (file) {
fs.writeFile(file, before + setup.output[file].call(files) + after, function () {
console.log("Saved to \033[32m" + file + "\033[0m\n");
});
})(file);
}