-
Notifications
You must be signed in to change notification settings - Fork 8
/
GruntParser.js
48 lines (48 loc) · 1.45 KB
/
GruntParser.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
define(function(require, exports, module){
function noop() {}
function parse(gruntfileText) {
var targets = [],
module = {},
config;
// Yes, we're just going to eval the entire Gruntfile.
// Get over it.
eval(gruntfileText);
var gruntShim = {
initConfig: function(_config) {
config = _config;
},
registerTask: function(_name) {
if (_name !== "default") {
targets.push(_name);
}
},
registerMultiTask: noop,
renameTask: noop,
loadTasks: noop,
loadNpmTasks: noop,
warn: noop,
fatal: noop
};
// After eval'ing the Gruntfile text, module.exports should be a function
// that takes a 'grunt' argument
try {
module.exports(gruntShim);
}
catch (exception) {
// It's likely going to fail,
// but should have done enough...
}
if (!config) {
console.log("Failed to parse grunt config");
return null;
}
for (var task in config) {
targets.push(task);
for (var subTask in config[task]) {
targets.push(task + ":" + subTask);
}
}
return targets;
}
exports.parse = parse;
});