forked from javanto/jquery-fileinput
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jakefile
62 lines (56 loc) · 2.17 KB
/
Jakefile
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
58
59
60
61
62
desc("This is the default task.");
task("default", function (params) {
var fs = require("node-fs");
var dot = require("dot");
var uglify = require("uglify-js");
package(function(pkg) {
console.log("Building " + pkg.title + " " + pkg.version);
fs.readFile("./jquery.fileinput.js", "utf8", function(err, data) {
if (err) throw err;
var cmp = dot.template(data, {evaluate: /\{\{([\s\S]+?)\}\}/g,
interpolate: /\{\{=([\s\S]+?)\}\}/g,
encode: /\{\{!([\s\S]+?)\}\}/g,
use: /\{\{#([\s\S]+?)\}\}/g, //compile time evaluation
define: /\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g, //compile time defs
strip: false,
varname: "it"})(pkg);
var ast = uglify.parse(cmp);
ast.figure_out_scope();
ast = ast.transform(uglify.Compressor());
// need to figure out scope again so mangler works optimally
ast.figure_out_scope();
ast.compute_char_frequency();
ast.mangle_names();
var min = ast.print_to_string({ comments: true });
var buildDirectory = pkg.build.directory? dot.template(pkg.build.directory)(pkg) : "dist";
try {
fs.rmdirSync("./" + buildDirectory);
} catch (e) {
}
fs.mkdirSync("./" + buildDirectory, 0777, true);
console.log("Writing to " + buildDirectory);
var buildFinalName = pkg.build.final_name ? dot.template(pkg.build.final_name)(pkg) : pkg.name + "-" + pkg.version;
fs.writeFileSync("./" + buildDirectory + "/" + buildFinalName + ".min.js", min);
fs.writeFileSync("./" + buildDirectory + "/" + buildFinalName + ".js", cmp);
complete();
});
});
}, true);
task("publish", ["default"], function (params) {
var gits = require("gits");
package(function(pkg) {
var tagName = pkg.version;
gits.git(".", ["tag", "-a", "-m", "Publishing new version", tagName], function() {
gits.git(".", ["push", "upstream", "--tags"], function() {
console.log("Created remote tag " + tagName);
});
});
});
});
function package(callback) {
var fs = require("node-fs");
fs.readFile("./fileinput.jquery.json", "utf8", function(err, data) {
if (err) throw err;
callback(JSON.parse(data));
});
}