This repository has been archived by the owner on Apr 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrunt.js
52 lines (47 loc) · 1.45 KB
/
grunt.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
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
concat : {
js : {
src : "engine.js",
dest : "dist/engine.js"
}
},
lint : {
beforeExclude : "engine.js",
afterExclude : "dist/engine.js"
},
min : {
"dist/engine.min.js" : "dist/engine.js"
}
});
grunt.registerTask("default", "lint:beforeExclude concat min");
grunt.registerHelper("removeSection", function (script, secNameStart, secNameEnd, all) {
var regEscape = /[-/\\^$*+?.()|[\]{}]/g,
flag = all
? "g"
: "";
//comment out special RegExp characters in secNameStart and secNameEnd
secNameStart = secNameStart.replace(regEscape, "\\$&");
secNameEnd = secNameEnd.replace(regEscape, "\\$&");
return script.replace(
new RegExp("/\\*" + secNameStart + "\\*/[\\s\\S]*?/\\*" + secNameEnd + "\\*/", flag),
""
);
});
grunt.registerTask("exclude", function () {
grunt.task.run("lint:afterExclude");
this.requires("concat");
this.requiresConfig("concat.js.dest");
var l,
src = grunt.file.read(grunt.config("concat").js.dest);
[].slice.call(arguments).forEach(function(section) {
l = src.length;
src = grunt.helper("removeSection", src, section + "_start", section + "_end", true);
if (src.length == l) {
grunt.log.writeln(("Could not find section \"" + section + "\"").yellow);
}
});
grunt.file.write(grunt.config("concat").js.dest, src);
});
};