-
-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathexec.js
51 lines (40 loc) · 969 Bytes
/
exec.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
const execSync = require('child_process').execSync;
const vxPath = require('./vxPath');
const logger = require('vx/logger');
const joinTruthy = require('vx/util/joinTruthy');
function exec(
command,
{
exitOnFailure = true,
throwOnFailure = false,
silent = false,
raw = false,
} = {},
) {
const cmd = joinTruthy(command?.flat?.() ?? command, ' ');
if (!raw && !silent) {
logger.info(`🎬 Executing command: "${cmd}"`);
}
execCommand(cmd, { exitOnFailure, silent, throwOnFailure });
}
module.exports = exec;
function execCommand(command, { silent, throwOnFailure, exitOnFailure }) {
try {
run(command, silent);
} catch (err) {
if (throwOnFailure) {
throw err;
}
logger.error(err.message);
if (exitOnFailure) exit();
}
}
function run(command, silent) {
execSync(command, {
cwd: vxPath.VX_ROOT_PATH,
stdio: silent ? 'ignore' : 'inherit',
});
}
function exit() {
process.exit(1);
}