Add new scripts to package.json and handle rpm/rph conflict
Keep Running / Build (push) Failing after 2m51s Details

Updated the package.json with two new scripts: copy-local and build-local. This allows for easier local testing by building and copying the program to a local directory. In index.js, handled the situation where both rpm and rph options are provided by the user, which was causing conflicts. This is resolved by adding explicit handling which returns an error and asks the user to choose only one.
This commit is contained in:
Ian Wijma 2023-11-19 16:19:24 +11:00
parent 8e80da343b
commit 99cc6708c6
2 changed files with 14 additions and 4 deletions

View File

@ -5,7 +5,9 @@
"bin": "src/index.js",
"main": "src/index.js",
"scripts": {
"build": "pkg package.json"
"build": "pkg package.json",
"copy-local": "cp -f out/kr-linux ~/bin/kr",
"build-local": "npm run build && npm run copy-local"
},
"pkg": {
"scripts": "src/**/*.js",

View File

@ -20,7 +20,6 @@ const yargs = Yargs(process.argv.splice(2))
description: 'Time in seconds we want to delay the restart with.',
type: 'number'
})
.conflicts('_rpm', '_rph')
const { _ = [], _rpm: rpm, _rph: rph, _delay: delay } = yargs.argv;
const [command, ...args ] = _;
@ -36,7 +35,9 @@ let historyMax = 4;
let seconds = SECONDS_IN_A_MINUTE;
let restartName = 'minute';
if (rpm) {
if (rpm && rph) {
return console.error('Currently, can not define both --rpm and --rph, please choose only one.');
} else if (rpm) {
historyMax = rpm
} else if (rph) {
historyMax = rph
@ -64,8 +65,15 @@ const checkHistory = () => Object.keys(history).length <= historyMax;
const restart = () => setTimeout(() => runCommand(delay), delay * 1000);
const spawnCommand = () => {
const [ spawnCommand, ...cmdArgs ] = command.split(' ');
const spawnArgs = [...cmdArgs, ...args];
return spawn(spawnCommand, spawnArgs);
}
const runCommand = () => {
const runner = spawn(command, args);
const runner = spawnCommand();
const commandLogs = [];