-
-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy pathrun.js
More file actions
49 lines (43 loc) · 1.06 KB
/
run.js
File metadata and controls
49 lines (43 loc) · 1.06 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
const { spawnSync } = require("child_process");
const runSync = (cmd, args, options = {}) => {
const result = spawnSync(cmd, args, {
stdio: ["inherit", "inherit", "inherit"],
windowsHide: true,
shell: process.platform === "win32",
...options,
env: {
...process.env,
// YARN_SILENT: "1",
npm_config_loglevel: "silent",
...options.env,
},
});
const { error, status, signal, stderr, stdout } = result;
if (error) {
throw error;
}
if (status || signal) {
if (stdout) {
console.log(stdout.toString("utf8"));
}
if (stderr) {
console.error(stderr.toString("utf8"));
}
if (status) {
process.exitCode = status;
throw new Error(
`Process exited with status '${status}' (running '${cmd} ${
args ? args.join(" ") : ""
}')`
);
} else {
throw new Error(
`Process exited due to signal '${signal}' (running '${cmd} ${
args ? args.join(" ") : null
}')`
);
}
}
return result;
};
exports.runSync = runSync;