-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
134 lines (115 loc) · 3.1 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
"use strict";
var gutil = require("gulp-util"),
through = require("through2"),
exec = require("child_process").exec,
shallowCopy = require("util")._extend;
var defaultOpts = {
nologo: false,
silent: false,
teamcity: false,
wait: false,
failOnError: false,
debug: false,
trace: false,
openInBrowser: void(0),
parallelism: void(0),
vsoutput: false,
coverage: false,
showFailureReport: false,
settingsFileEnvironment: "",
junit: "",
lcov: "",
trx: "",
nunit2: "",
coveragehtml: ""
};
var getCombinedOpts = function(baseOpts, userSuppliedOpts) {
if (!userSuppliedOpts) {
return baseOpts;
}
for (var key in userSuppliedOpts) {
if (isValidProperty(baseOpts, userSuppliedOpts, key)) {
baseOpts[key] = userSuppliedOpts[key];
}
}
return baseOpts;
};
var isValidProperty = function(baseOpts, userOpts, propertyName) {
return (
baseOpts.hasOwnProperty(propertyName) &&
userOpts.hasOwnProperty(propertyName) &&
(typeof baseOpts[propertyName] === typeof userOpts[propertyName] ||
typeof baseOpts[propertyName] === "undefined")
);
};
var getCommandLineOptionArgString = function(opts, files, isSettingsFile) {
var arg = "";
files = files || [];
if(isSettingsFile) {
validateSettingsFile(files);
return ' ' + files[0];
}
for (var key in opts) {
if (!opts.hasOwnProperty(key))
continue;
if (typeof opts[key] === "boolean")
arg += opts[key] ? " /" + key : "";
else if (typeof opts[key] === "string")
arg += opts[key].length ? " /" + key + " " + opts[key] : "";
else if (typeof opts[key] === "number")
arg += " /" + key + " " + opts[key];
}
files.forEach(function(file) {
arg += ' /path "' + file + '"';
});
return arg;
};
var validateSettingsFile = function(files) {
if (files.length !== 1 || !files[0].endsWith(".json")) {
throw new gutil.PluginError({
plugin: "gulp-chutzpah",
message:
"gulp-chutzpah: invalid chutzpah.json settings file specified in the source stream."
});
}
};
var getExecOptions = function (execOpts) {
return execOpts || {};
}
var chutzpahRunner = function(userOpts, execOpts) {
if (
!userOpts ||
typeof userOpts["executable"] !== "string" ||
userOpts["executable"].length === 0
) {
throw new gutil.PluginError({
plugin: "gulp-chutzpah",
message:
"gulp-chutzpah: path to chutzpah runner must be specified using the property named 'executable'."
});
}
var files = [];
var opts = shallowCopy({}, defaultOpts);
opts = getCombinedOpts(opts, userOpts);
return through.obj(
function(file, encoding, callback) {
if (!file.isNull()) {
files.push(file.path);
}
callback(null, file);
},
function(callback) {
var args = getCommandLineOptionArgString(
opts,
files,
userOpts.isSettingsFile
);
exec(userOpts.executable + args, getExecOptions(execOpts), function(err, stdout, stderr) {
console.log(stdout);
console.error(stderr);
callback(err);
});
}
);
};
module.exports = chutzpahRunner;