-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.js
49 lines (41 loc) · 1.46 KB
/
run.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
// @flow
const utils = require('./utils');
const proc = require('child_process')
const chalk = require('chalk');
const bprom = require('bluebird');
const exec = command => {
const cmd = utils.removeEnvVars(command).split(' ');
return new Promise(function (resolve, reject) {
console.log(chalk.dim(`Running "${cmd.join(' ')}"`));
const npm = proc.spawn(
cmd[0],
cmd.slice(1),
{
stdio: 'inherit',
cwd: process.cwd(),
env: Object.assign(process.env, utils.getEnvVars(command))
},
err => {
console.log(err);
err ? reject(err) : resolve('doneee')
});
npm.on('stdout', console.log.bind(console));
npm.on('stderr', console.error.bind(console));
npm.on('close', code => code == 0 ? resolve() : reject(new Error(`${command} exited with code: ${code}`)));
})
};
function runner (command) {
// find out how to run the command(s)
const runType = utils.runType(command);
if (runType === utils.constants.NORMAL) {
return exec(command);
}
if (runType === utils.constants.SERIES) {
return bprom.mapSeries(utils.splitCmds(command), exec);
}
if (runType === utils.constants.CONCURRENT) {
return bprom.map(utils.splitCmds(command), cmd => exec(cmd));
}
return exec(command);
}
module.exports = runner;