-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.js
29 lines (23 loc) · 910 Bytes
/
utils.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
const CONCURRENT = 'concurrent';
const SERIES = 'series';
const NORMAL = 'normal';
module.exports.runType = cmd => {
if (cmd.includes('&&')) return SERIES;
if (cmd.includes('&')) return CONCURRENT;
return NORMAL;
}
module.exports.isEnvVar = bit => bit.includes('=') && !bit.split('=')[0].match(/[a-z]/g);
module.exports.removeEnvVars = cmd => cmd.split(' ').filter(bit => !module.exports.isEnvVar(bit)).join(' ');
module.exports.getEnvVars = cmd => cmd.split(' ').filter(module.exports.isEnvVar).reduce((obj, env) => ({ [env.split('=')[0]]: env.split('=')[1] }), {})
module.exports.splitCmds = cmd => {
// first try and split && cmds
// or & cmds
const cmds = cmd.split(/\s?&&?\s+/g);
return cmds;
//cmd.split(' ').concat(args.length ? ['--', ...args].join(' ') : []).filter(e => !removeEnvVars(e));
}
module.exports.constants = {
CONCURRENT,
SERIES,
NORMAL
}