1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.commonTags = exports.crossEnv = exports.open = exports.mkdirp = exports.copy = exports.ifNotWindows = exports.ifWindows = exports.rimraf = exports.runInNewWindow = exports.series = exports.concurrent = undefined;
|
7 |
|
8 | var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
9 |
|
10 | var _path = require('path');
|
11 |
|
12 | var _path2 = _interopRequireDefault(_path);
|
13 |
|
14 | var _commonTags = require('common-tags');
|
15 |
|
16 | var commonTags = _interopRequireWildcard(_commonTags);
|
17 |
|
18 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
19 |
|
20 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
21 |
|
22 | function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
23 |
|
24 | var defaultColors = ['bgBlue.bold', 'bgMagenta.bold', 'bgGreen.bold', 'bgBlack.bold', 'bgCyan.bold', 'bgRed.bold', 'bgWhite.bold', 'bgYellow.bold'];
|
25 |
|
26 | exports.concurrent = concurrent;
|
27 | exports.series = series;
|
28 | exports.runInNewWindow = runInNewWindow;
|
29 | exports.rimraf = rimraf;
|
30 | exports.ifWindows = ifWindows;
|
31 | exports.ifNotWindows = ifNotWindows;
|
32 | exports.copy = copy;
|
33 | exports.mkdirp = mkdirp;
|
34 | exports.open = open;
|
35 | exports.crossEnv = crossEnv;
|
36 | exports.commonTags = commonTags;
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | function series() {
|
49 | for (var _len = arguments.length, scripts = Array(_len), _key = 0; _key < _len; _key++) {
|
50 | scripts[_key] = arguments[_key];
|
51 | }
|
52 |
|
53 | return scripts.filter(Boolean).join(' && ');
|
54 | }
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | series.nps = function seriesNPS() {
|
66 | for (var _len2 = arguments.length, scriptNames = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
67 | scriptNames[_key2] = arguments[_key2];
|
68 | }
|
69 |
|
70 | return series.apply(undefined, _toConsumableArray(scriptNames.filter(Boolean).map(function (scriptName) {
|
71 | return scriptName.trim();
|
72 | }).filter(Boolean).map(function (scriptName) {
|
73 | return `nps ${quoteScript(scriptName)}`;
|
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 | function concurrent(scripts) {
|
114 | var _Object$keys$reduce = Object.keys(scripts).reduce(reduceScripts, {
|
115 | colors: [],
|
116 | scripts: [],
|
117 | names: []
|
118 | }),
|
119 | colors = _Object$keys$reduce.colors,
|
120 | quotedScripts = _Object$keys$reduce.scripts,
|
121 | names = _Object$keys$reduce.names;
|
122 |
|
123 | var flags = ['--kill-others-on-fail', `--prefix-colors "${colors.join(',')}"`, '--prefix "[{name}]"', `--names "${names.join(',')}"`, shellEscape(quotedScripts)];
|
124 | var concurrently = getBin('concurrently');
|
125 | return `${concurrently} ${flags.join(' ')}`;
|
126 |
|
127 | function reduceScripts(accumulator, scriptName, index) {
|
128 | var scriptObj = scripts[scriptName];
|
129 | if (!scriptObj) {
|
130 | return accumulator;
|
131 | } else if (typeof scriptObj === 'string') {
|
132 | scriptObj = { script: scriptObj };
|
133 | }
|
134 | var _scriptObj = scriptObj,
|
135 | script = _scriptObj.script,
|
136 | _scriptObj$color = _scriptObj.color,
|
137 | color = _scriptObj$color === undefined ? defaultColors[index % defaultColors.length] : _scriptObj$color;
|
138 |
|
139 | if (!script) {
|
140 | return accumulator;
|
141 | }
|
142 | accumulator.names.push(scriptName);
|
143 | accumulator.colors.push(color);
|
144 | accumulator.scripts.push(script);
|
145 | return accumulator;
|
146 | }
|
147 | }
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 | concurrent.nps = function concurrentNPS() {
|
162 | for (var _len3 = arguments.length, scriptNames = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
163 | scriptNames[_key3] = arguments[_key3];
|
164 | }
|
165 |
|
166 | return concurrent(scriptNames.map(mapNPSScripts).reduce(reduceNPSScripts, {}));
|
167 |
|
168 | function mapNPSScripts(scriptName, index) {
|
169 | var color = defaultColors[index];
|
170 | if (!Boolean(scriptName)) {
|
171 | return undefined;
|
172 | } else if (typeof scriptName === 'string') {
|
173 | return { script: scriptName, color };
|
174 | } else {
|
175 | return Object.assign({ color }, scriptName);
|
176 | }
|
177 | }
|
178 |
|
179 | function reduceNPSScripts(scripts, scriptObj) {
|
180 | if (!scriptObj) {
|
181 | return scripts;
|
182 | }
|
183 | var color = scriptObj.color,
|
184 | script = scriptObj.script;
|
185 |
|
186 | var _script$split = script.split(' '),
|
187 | _script$split2 = _slicedToArray(_script$split, 1),
|
188 | name = _script$split2[0];
|
189 |
|
190 | scripts[name] = {
|
191 | script: `nps ${quoteScript(script.trim())}`,
|
192 | color
|
193 | };
|
194 | return scripts;
|
195 | }
|
196 | };
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 | function runInNewWindow(command) {
|
210 | return isWindows() ? `start cmd /k "cd ${process.cwd()} && ${command}"` : commonTags.oneLine`
|
211 | osascript
|
212 | -e 'tell application "Terminal"'
|
213 | -e 'tell application "System Events"
|
214 | to keystroke "t" using {command down}'
|
215 | -e 'do script "cd ${process.cwd()} && ${command}" in front window'
|
216 | -e 'end tell'
|
217 | `;
|
218 | }
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 | runInNewWindow.nps = function runInNewWindowNPS(scriptName) {
|
233 | var escaped = true;
|
234 | return runInNewWindow(`node node_modules/.bin/nps ${quoteScript(scriptName, escaped)}`);
|
235 | };
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 | function rimraf(args) {
|
246 | return `${getBin('rimraf')} ${args}`;
|
247 | }
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 | function ifWindows(script, altScript) {
|
258 | return isWindows() ? script : altScript;
|
259 | }
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 | function ifNotWindows(script, altScript) {
|
268 | return ifWindows(altScript, script);
|
269 | }
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 | function copy(args) {
|
280 | return `${getBin('cpy-cli', 'cpy')} ${args}`;
|
281 | }
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 | function mkdirp(args) {
|
292 | return `${getBin('mkdirp')} ${args}`;
|
293 | }
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 | function open(args) {
|
304 | return `${getBin('opn-cli', 'opn')} ${args}`;
|
305 | }
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 | function crossEnv(args) {
|
316 | return `${getBin('cross-env')} ${args}`;
|
317 | }
|
318 |
|
319 |
|
320 |
|
321 | function quoteScript(script, escaped) {
|
322 | var quote = escaped ? '\\"' : '"';
|
323 | var shouldQuote = script.indexOf(' ') !== -1;
|
324 | return shouldQuote ? `${quote}${script}${quote}` : script;
|
325 | }
|
326 |
|
327 | function getBin(packageName) {
|
328 | var binName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : packageName;
|
329 |
|
330 | var packagePath = require.resolve(`${packageName}/package.json`);
|
331 | var concurrentlyDir = _path2.default.dirname(packagePath);
|
332 |
|
333 | var _require = require(packagePath),
|
334 | binRelativeToPackage = _require.bin;
|
335 |
|
336 | if (typeof binRelativeToPackage === 'object') {
|
337 | binRelativeToPackage = binRelativeToPackage[binName];
|
338 | }
|
339 | var fullBinPath = _path2.default.join(concurrentlyDir, binRelativeToPackage);
|
340 | var relativeBinPath = _path2.default.relative(process.cwd(), fullBinPath);
|
341 | return `node ${relativeBinPath}`;
|
342 | }
|
343 |
|
344 | function isWindows() {
|
345 |
|
346 | return require('is-windows')();
|
347 | }
|
348 |
|
349 | function shellEscape() {
|
350 |
|
351 | return require('any-shell-escape').apply(undefined, arguments);
|
352 | }
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
\ | No newline at end of file |