Simplify and comment workflow test command

This commit is contained in:
00Fjongl 2024-08-09 08:37:15 -05:00
parent ecfa6cc0da
commit cb33731bc9

View file

@ -156,17 +156,13 @@ commands: for (let i = 2; i < process.argv.length; i++)
);
break;
case 'workflow':
if (config.production)
exec(
'npx pm2 start ecosystem.config.js --env production',
(error, stdout) => {
if (error) throw error;
console.log(stdout);
}
);
else {
const server = fork(
/* Make a temporary server solely to test startup errors. The server will
* stop the command if there is an error, and restart itself otherwise.
* This uses the same command for both Windows and other platforms, but
* consequently forces the server to stay completely silent after startup.
*/
case 'workflow': {
const tempServer = fork(
fileURLToPath(new URL('./backend.js', import.meta.url)),
{
cwd: process.cwd(),
@ -174,25 +170,31 @@ commands: for (let i = 2; i < process.argv.length; i++)
detached: true,
}
);
server.stderr.on('data', (stderr) => {
tempServer.stderr.on('data', (stderr) => {
// The temporary server will print startup errors that aren't deprecation
// warnings; stop the process and return an error exit code upon doing so.
if (stderr.toString().indexOf('DeprecationWarning') >= 0) return;
console.error(stderr.toString());
if (stderr.toString().indexOf('DeprecationWarning') + 1) return;
server.stderr.destroy();
tempServer.kill();
process.exitCode = 1;
});
server.stdout.on('data', () => {
server.kill();
const server2 = fork(
tempServer.stdout.on('data', () => {
// Kill the server and start a new one if there were no startup errors.
// Restarting is necessary to prevent the workflow check from hanging.
tempServer.kill();
const server = fork(
fileURLToPath(new URL('./backend.js', import.meta.url)),
// The stdio: 'ignore' makes the server completely silent, yet it is also
// why this works for Windows when the start command's version does not.
{ cwd: process.cwd(), stdio: 'ignore', detached: true }
);
server2.unref();
server2.disconnect();
});
server.unref();
server.disconnect();
}
});
tempServer.unref();
tempServer.disconnect();
break;
}
// No default case.
}