-
Notifications
You must be signed in to change notification settings - Fork 5
/
danf.js
83 lines (71 loc) · 2.05 KB
/
danf.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict';
require('./lib/common/init');
var spawn = require('child_process').spawn,
path = require('path'),
fs = require('fs'),
os = require('os')
;
// Retrieve gulp command path.
var gulpCommandPath = path.join(
__dirname,
-1 === os.platform().indexOf('win')
? 'node_modules/.bin/gulp'
: 'node_modules/.bin/gulp.cmd'
)
;
try {
fs.statSync(gulpCommandPath);
} catch (error) {
// Handle not existing modules folder.
if (!(error.code in {'ENOENT': true, 'ENOTDIR': true})) {
throw error;
}
gulpCommandPath = path.join(
__dirname,
-1 === os.platform().indexOf('win')
? '../../node_modules/.bin/gulp'
: '../../node_modules/.bin/gulp.cmd'
);
}
// Handle "&&" separated commands.
var commands = process.argv.slice(2).join(' ').split('&&');
for (var i = 0; i < commands.length; i++) {
var command = commands[i],
commandParts = command.split(' '),
task = commandParts[0]
;
if (task in {'execute-cmd': true, '$': true}) {
command = '{0} --cmd {1} {2}'.format(
commandParts.shift(),
commandParts.shift(),
commandParts.join(' ')
);
}
var args = process.argv.slice(2, 3).concat(['--colors']).concat(process.argv.slice(3));
for (var j = 1; j < args.length; j++) {
// Escape value parameter to avoid being interpreted as a task by gulp.
if (/^[^-"]/.test(args[j])) {
args[j] = '---{0}'.format(args[j]);
}
}
// Forward the task execution to gulp.
var child = spawn(
gulpCommandPath,
args,
{
cwd: path.dirname(require.main.filename)
}
),
errored = false;
;
child.stdout.on('data', function(data) {
process.stdout.write(data);
});
child.stderr.on('data', function(data) {
errored = true;
process.stderr.write(data);
});
child.on('close', function(data) {
process.exit(errored ? 1 : 0);
});
}