Skip to content

Commit 0b2ad5d

Browse files
authored
fix: exit generate-clients if child process errors or fails (#1498)
1 parent 9fb8850 commit 0b2ad5d

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed
Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
// @ts-check
22
const { spawn } = require("child_process");
33

4-
const spawnProcess = (command, args = [], options = {}) =>
5-
new Promise((resolve, reject) => {
6-
try {
7-
const ls = spawn(command, args, options);
8-
ls.stdout.on("data", (data) => {
9-
console.log(data.toString());
10-
});
11-
ls.stderr.on("data", (data) => {
12-
console.error(`stderr: ${data.toString()}`);
13-
});
4+
const spawnProcess = async (command, args = [], options = {}) => {
5+
const childProcess = spawn(command, args, options);
146

15-
ls.on("close", (code) => {
16-
console.log(`child process exited with code ${code}`);
17-
resolve();
18-
});
19-
} catch (e) {
20-
reject(e);
21-
}
7+
childProcess.stdout.pipe(process.stdout);
8+
childProcess.stderr.pipe(process.stderr);
9+
10+
return new Promise((resolve, reject) => {
11+
childProcess.on("error", reject);
12+
childProcess.on("exit", (code, signal) =>
13+
code === 0 ? resolve() : reject(`${command} failed with { code: ${code}, signal: ${signal} }`)
14+
);
2215
});
16+
};
2317

2418
module.exports = { spawnProcess };

0 commit comments

Comments
 (0)