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; break;
case 'workflow': /* Make a temporary server solely to test startup errors. The server will
if (config.production) * stop the command if there is an error, and restart itself otherwise.
exec( * This uses the same command for both Windows and other platforms, but
'npx pm2 start ecosystem.config.js --env production', * consequently forces the server to stay completely silent after startup.
(error, stdout) => { */
if (error) throw error; case 'workflow': {
console.log(stdout); const tempServer = fork(
}
);
else {
const server = fork(
fileURLToPath(new URL('./backend.js', import.meta.url)), fileURLToPath(new URL('./backend.js', import.meta.url)),
{ {
cwd: process.cwd(), cwd: process.cwd(),
@ -174,25 +170,31 @@ commands: for (let i = 2; i < process.argv.length; i++)
detached: true, 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()); console.error(stderr.toString());
if (stderr.toString().indexOf('DeprecationWarning') + 1) return; tempServer.kill();
server.stderr.destroy();
process.exitCode = 1; process.exitCode = 1;
}); });
server.stdout.on('data', () => { tempServer.stdout.on('data', () => {
server.kill(); // Kill the server and start a new one if there were no startup errors.
const server2 = fork( // Restarting is necessary to prevent the workflow check from hanging.
tempServer.kill();
const server = fork(
fileURLToPath(new URL('./backend.js', import.meta.url)), 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 } { cwd: process.cwd(), stdio: 'ignore', detached: true }
); );
server2.unref();
server2.disconnect();
});
server.unref(); server.unref();
server.disconnect(); server.disconnect();
} });
tempServer.unref();
tempServer.disconnect();
break; break;
}
// No default case. // No default case.
} }