forked from shelljs/shelljs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.js
48 lines (40 loc) · 1009 Bytes
/
make.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
require('./global');
config.fatal = true;
global.target = {};
// This ensures we only execute the script targets after the entire script has
// been evaluated
var args = process.argv.slice(2);
setTimeout(function() {
var t;
if (args.length === 1 && args[0] === '--help') {
console.log('Available targets:');
for (t in target)
console.log(' ' + t);
return;
}
// Wrap targets to prevent duplicate execution
for (t in target) {
(function(t, oldTarget){
// Wrap it
target[t] = function(force) {
if (oldTarget.done && !force)
return;
oldTarget.done = true;
return oldTarget.apply(oldTarget, arguments);
};
})(t, target[t]);
}
// Execute desired targets
if (args.length > 0) {
args.forEach(function(arg) {
if (arg in target)
target[arg]();
else {
console.log('no such target: ' + arg);
exit(1);
}
});
} else if ('all' in target) {
target.all();
}
}, 0);