-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
74 lines (63 loc) · 1.98 KB
/
index.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
'use strict';
var util = require('util');
var gutil = require('gulp-util');
var Orchestrator = require('orchestrator');
var buildCommand = require('./lib/buildCommand');
var npmTaskRun = require('./lib/exec');
var justExec = require('./lib/justExec');
function JsRun() {
Orchestrator.call(this);
}
util.inherits(JsRun, Orchestrator);
JsRun.prototype.task = JsRun.prototype.add;
JsRun.prototype.just = function just() {
var NAME = '[run-script]';
if (arguments.length < 2) {
var invalidArgsErr = new Error(
'Invalid argument for just task\n' +
'args: ' + JSON.stringify(arguments, null, 2)
);
throw invalidArgsErr;
}
var runArgs = arguments[arguments.length - 1];
if (!Array.isArray(runArgs)) {
var invalidCommandTreeErr = new Error(
'Invalid argument for just task\n' +
'args: ' + JSON.stringify(arguments, null, 2) +
'\ncommandTree: ' + JSON.stringify(runArgs, null, 2)
);
throw invalidCommandTreeErr;
}
var options = arguments[arguments.length - 2];
var hasOptions = options &&
typeof options === 'object' &&
!Array.isArray(options);
var skipRun = hasOptions ? !!options.skipRun : false;
var cwd = (hasOptions ? options.cwd : null) || process.cwd();
var command = buildCommand.apply(buildCommand, runArgs);
function runScript(cb) {
gutil.log(NAME, command);
if (skipRun) {
return cb();
}
return npmTaskRun(command, {cwd: cwd}, function callback(err) {
if (err) {
var cmdErr = new gutil.PluginError(
NAME,
'Command failed: ' + command
);
cmdErr.code = err.code;
return cb(cmdErr);
}
return cb();
});
}
var args = Array.prototype.slice.call(arguments);
var sliceLength = args.length - (hasOptions ? 2 : 1);
var addTaskArgs = args.slice(0, sliceLength).concat([runScript]);
this.add.apply(this, addTaskArgs);
};
JsRun.prototype.justExec = justExec;
JsRun.prototype.JsRun = JsRun;
var inst = new JsRun();
module.exports = inst;