fix: forward exit codes

This commit is contained in:
cha0s 2021-03-29 13:58:34 -05:00
parent 67e8aef8a3
commit 1d69fe6c78

View File

@ -21,6 +21,15 @@ const localConfig = (filename) => {
return configFile;
};
const forwardProcessCode = (child) => new Promise((resolve, reject) => {
child.on('error', reject);
child.on('exit', (code) => {
child.off('error', reject);
process.exitCode = code;
resolve();
});
});
const build = async (args = []) => {
const {production} = program.opts();
const babelConfigFile = localConfig('.babelrc.js');
@ -53,13 +62,7 @@ const build = async (args = []) => {
stdio: 'inherit',
},
);
return new Promise((resolve, reject) => {
child.on('error', reject);
child.on('exit', (code) => {
child.off('error', reject);
resolve(code);
});
});
return forwardProcessCode(child);
};
program
@ -106,13 +109,7 @@ const unpublish = async () => {
stdio: 'inherit',
},
);
return new Promise((resolve, reject) => {
child.on('error', reject);
child.on('exit', (code) => {
child.off('error', reject);
resolve(code);
});
});
return forwardProcessCode(child);
};
const publish = async () => {
@ -125,13 +122,7 @@ const publish = async () => {
stdio: 'inherit',
},
);
return new Promise((resolve, reject) => {
child.on('error', reject);
child.on('exit', (code) => {
child.off('error', reject);
resolve(code);
});
});
return forwardProcessCode(child);
};
program
@ -145,7 +136,7 @@ program
const lint = () => {
const configFile = localConfig('.eslintrc.js');
spawn(
const child = spawn(
'eslint',
[
'--config',
@ -164,6 +155,7 @@ const lint = () => {
stdio: 'inherit',
},
);
return forwardProcessCode(child);
};
program
@ -178,7 +170,7 @@ const test = async () => {
process.argv.splice(watchIndex, 1);
}
await build(['--display', 'none']);
spawn(
const child = spawn(
'mocha',
(-1 === watchIndex ? [] : ['--watch'])
.concat([
@ -193,6 +185,7 @@ const test = async () => {
stdio: 'inherit',
},
);
return forwardProcessCode(child);
};
program