Skip to content

Commit

Permalink
Simplify npm scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
00Fjongl committed Aug 8, 2024
1 parent 976513b commit 5b7e418
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
"restart": "node run-command.mjs stop start",
"stop": "node run-command.mjs stop",
"test": "npm run proxy-validator",
"pm2-start": "npx pm2 start ecosystem.config.js --env production --watch false",
"pm2-stop": "npx pm2 stop ecosystem.config.js",
"pm2-monit": "npx pm2 monit",
"pm2-nuke": "npx pm2 delete ecosystem.config.js",
"manual-start": "node run-command.mjs start",
"kill": "node run-command.mjs stop kill",
"build": "node run-command.mjs build && cd lib/rammerhead && npm install && npm run build",
Expand Down
18 changes: 10 additions & 8 deletions run-command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ for (let i = 2; i < process.argv.length; i++)
// config file.
case "start":
if (config.production)
exec("npm run pm2-start", (error, stdout) => {
exec("npx pm2 start ecosystem.config.js --env production --watch false",
(error, stdout) => {
if (error) throw error;
console.log(stdout);
});
}
);
// Handle setup on Windows differently from platforms with POSIX-compliant shells.
// This should run the server as a background process.
else if (process.platform === "win32")
Expand Down Expand Up @@ -73,7 +75,7 @@ for (let i = 2; i < process.argv.length; i++)
await unlink(shutdown);
}
if (config.production && !process.argv.slice(i + 1).includes("kill"))
exec("npm run pm2-stop", (error, stdout) => {
exec("npx pm2 stop ecosystem.config.js", (error, stdout) => {
if (error) throw error;
console.log(stdout);
});
Expand All @@ -99,13 +101,13 @@ for (let i = 2; i < process.argv.length; i++)
break;
}

// Kill all node processes and fully reset PM2. To be used for debugging. The
// npm run pm2-nuke is built into the command because, if handled in Node, it
// will not wait for PM2 to actually finish resetting before it closes itself.
// Kill all node processes and fully reset PM2. To be used for debugging.
// Using npx pm2 monit, or npx pm2 list in the terminal will also bring up
// more PM2 debugging tools.
case "kill":
if (process.platform === "win32")
exec("npm run pm2-nuke ; taskkill /F /IM node*", (error, stdout) => {console.log(stdout)});
else exec("npm run pm2-nuke ; pkill node", (error, stdout) => {console.log(stdout)});
exec("( npx pm2 delete ecosystem.config.js ) ; taskkill /F /IM node*", (error, stdout) => {console.log(stdout)});
else exec("npx pm2 delete ecosystem.config.js; pkill node", (error, stdout) => {console.log(stdout)});
break;

// No default case.
Expand Down

0 comments on commit 5b7e418

Please sign in to comment.