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,43 +156,45 @@ 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(
} fileURLToPath(new URL('./backend.js', import.meta.url)),
); {
else { cwd: process.cwd(),
stdio: ['inherit', 'pipe', 'pipe', 'ipc'],
detached: true,
}
);
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());
tempServer.kill();
process.exitCode = 1;
});
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( 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
cwd: process.cwd(), // why this works for Windows when the start command's version does not.
stdio: ['inherit', 'pipe', 'pipe', 'ipc'], { cwd: process.cwd(), stdio: 'ignore', detached: true }
detached: true,
}
); );
server.stderr.on('data', (stderr) => {
console.error(stderr.toString());
if (stderr.toString().indexOf('DeprecationWarning') + 1) return;
server.stderr.destroy();
process.exitCode = 1;
});
server.stdout.on('data', () => {
server.kill();
const server2 = fork(
fileURLToPath(new URL('./backend.js', import.meta.url)),
{ 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.
} }