-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (45 loc) · 1.48 KB
/
index.js
File metadata and controls
59 lines (45 loc) · 1.48 KB
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
'use strict';
const chalk = require('chalk');
const cp = require('child_process');
const emoji = require('node-emoji');
module.exports = (flags, options) => {
const breakpoint = !!process.execArgv.filter(arg => /\-\-(harmony[\w\-]*)/.test(arg)).length;
if (!Array.isArray) {
Array.isArray = function (arg) {
return Object.prototype.toString.call(arg) === '[object Array]';
};
}
if (!options && !Array.isArray(flags)) {
if (typeof flags === 'object') {
options = flags;
flags = null;
}
else if (flags) {
throw new Error(`harmonica's first parameter must be either an Array containing flags or options Object`);
}
}
options = options || {};
flags = flags || ['harmony']; // all the things by default
flags = Array.from(new Set(flags)); // force uniqueness
flags = flags.map((f) => '--' + f); // prepend --
if (breakpoint) {
return;
}
let command = process.argv[0],
script = process.argv.slice(1),
params = flags.concat(script),
app;
if (!options.silent) {
let pad = (new Array(15).join(' ')),
list = chalk.dim(flags.join(`\n${pad}`)),
message = `${emoji.get('sparkles')} harmonica: ${list}`;
process.stdout.write(`\n${message}\n\n`);
}
app = cp.spawn(command, params, { stdio: 'inherit' });
app.on('close', (code) => {
process.exit(code);
});
// Interrupt process flow in the parent
process.once('uncaughtException', (e) => {});
throw new Error('harmony');
};