-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathcli.js
64 lines (54 loc) · 1.43 KB
/
cli.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
#!/usr/bin/env node
/**
* js-builder CLI.
* Installed as command "jjsbuilder".
*/
// Prepend the local node_modules to NODE_PATH so as to
// pick up peer deps. Will not work otherwise.
const path = require('path');
process.env.NODE_PATH='./node_modules' + path.delimiter + process.env.NODE_PATH;
var args = require('./internal/args');
var fs = require('fs');
var cwd = process.cwd();
var GulpRunner = require('gulp-runner');
var gulpfilePath;
if (fs.existsSync('gulpfile.js')) {
gulpfilePath = 'gulpfile.js';
} else {
gulpfilePath = __dirname + '/res/cli-gulpfile.js';
}
var gulp = new GulpRunner(gulpfilePath);
var tasks = args.argvValue('--tasks');
if (tasks) {
tasks = tasks.split(',');
} else {
tasks = 'default';
}
gulp.on('log', function(data) {
process.stdout.write(data);
});
gulp.on('error', function(err) {
process.stderr.write(err);
});
// Lets pass on the options supplied, stripping off the
// leading '--'.
var options = {};
var lastOpt;
for (var i = 0; i < process.argv.length; i++) {
var opt = process.argv[i];
if (opt.indexOf('--') === 0) {
opt = opt.substring(2);
options[opt] = true;
lastOpt = opt;
} else if (lastOpt) {
options[lastOpt] = opt;
lastOpt = undefined; // clear it so we don't assign again.
}
}
delete options.tasks;
options.cwd = cwd;
gulp.run(tasks, options, function(error) {
if (error) {
process.exitCode = 1;
}
});