1 | 'use strict';
|
2 |
|
3 | require('./lib/common/init');
|
4 |
|
5 | var spawn = require('child_process').spawn,
|
6 | path = require('path'),
|
7 | fs = require('fs'),
|
8 | os = require('os')
|
9 | ;
|
10 |
|
11 |
|
12 | var gulpCommandPath = path.join(
|
13 | __dirname,
|
14 | -1 === os.platform().indexOf('win')
|
15 | ? 'node_modules/.bin/gulp'
|
16 | : 'node_modules/.bin/gulp.cmd'
|
17 | )
|
18 | ;
|
19 |
|
20 | try {
|
21 | fs.statSync(gulpCommandPath);
|
22 | } catch (error) {
|
23 |
|
24 | if (!(error.code in {'ENOENT': true, 'ENOTDIR': true})) {
|
25 | throw error;
|
26 | }
|
27 |
|
28 | gulpCommandPath = path.join(
|
29 | __dirname,
|
30 | -1 === os.platform().indexOf('win')
|
31 | ? '../../node_modules/.bin/gulp'
|
32 | : '../../node_modules/.bin/gulp.cmd'
|
33 | );
|
34 | }
|
35 |
|
36 |
|
37 | var commands = process.argv.slice(2).join(' ').split('&&');
|
38 |
|
39 | for (var i = 0; i < commands.length; i++) {
|
40 | var command = commands[i],
|
41 | commandParts = command.split(' '),
|
42 | task = commandParts[0]
|
43 | ;
|
44 |
|
45 | if (task in {'execute-cmd': true, '$': true}) {
|
46 | command = '{0} --cmd {1} {2}'.format(
|
47 | commandParts.shift(),
|
48 | commandParts.shift(),
|
49 | commandParts.join(' ')
|
50 | );
|
51 | }
|
52 |
|
53 | var args = process.argv.slice(2, 3).concat(['--colors']).concat(process.argv.slice(3));
|
54 |
|
55 | for (var j = 1; j < args.length; j++) {
|
56 |
|
57 | if (/^[^-"]/.test(args[j])) {
|
58 | args[j] = '---{0}'.format(args[j]);
|
59 | }
|
60 | }
|
61 |
|
62 |
|
63 | var child = spawn(
|
64 | gulpCommandPath,
|
65 | args,
|
66 | {
|
67 | cwd: path.dirname(require.main.filename)
|
68 | }
|
69 | ),
|
70 | errored = false;
|
71 | ;
|
72 |
|
73 | child.stdout.on('data', function(data) {
|
74 | process.stdout.write(data);
|
75 | });
|
76 | child.stderr.on('data', function(data) {
|
77 | errored = true;
|
78 | process.stderr.write(data);
|
79 | });
|
80 | child.on('close', function(data) {
|
81 | process.exit(errored ? 1 : 0);
|
82 | });
|
83 | } |
\ | No newline at end of file |