You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.6 KiB
58 lines
1.6 KiB
import { exec } from "../lib/builderator.js";
|
|
|
|
|
|
export const description = "Runs various services needed for development";
|
|
|
|
export const options = [
|
|
['--stop', `Stop the ${process.platform} OS services.`],
|
|
['--start', `Start the ${process.platform} OS services (the default).`],
|
|
['--noexit', `When used in other commands, don't call process.exit.`],
|
|
['--os', 'Force the process.platform to specific one']
|
|
]
|
|
|
|
const windows = (opts) => {
|
|
if(opts.stop) {
|
|
console.log("Stopping redis...");
|
|
exec("wsl -u root /etc/init.d/redis-server stop");
|
|
} else {
|
|
console.log("Starting redis...")
|
|
exec("wsl -u root /etc/init.d/redis-server start");
|
|
}
|
|
}
|
|
|
|
const linux = (opts) => {
|
|
console.error("ERROR: linux isn't supported yet. Sorry!");
|
|
}
|
|
|
|
const darwin = (opts) => {
|
|
if(opts.stop) {
|
|
console.log("Stopping pm2...");
|
|
exec("npx pm2 stop scripts/osx.config.cjs");
|
|
} else {
|
|
console.log("Starting pm2...")
|
|
exec("npx pm2 start scripts/osx.config.cjs");
|
|
console.log("Use npx pm2 for more options.");
|
|
}
|
|
}
|
|
|
|
export const main = (opts) => {
|
|
const platform = opts.os ? opts.os : process.platform;
|
|
|
|
if(process.platform === "win32") {
|
|
windows(opts);
|
|
} else if(process.platform === "linux") {
|
|
linux(opts);
|
|
} else if(process.platform === "darwin") {
|
|
darwin(opts);
|
|
} else {
|
|
console.error(`ERROR: invalid OS ${platform} given, must be win32, linux, or darwin`);
|
|
|
|
if(opts.noexit) {
|
|
throw new Error("invalid OS error.");
|
|
} else {
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
if(!opts.noexit) process.exit(0); // for some reason exec hangs on windows
|
|
}
|
|
|