Add new scripts to package.json and handle rpm/rph conflict
Keep Running / Build (push) Failing after 2m51s
Details
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:
parent
8e80da343b
commit
99cc6708c6
|
@ -5,7 +5,9 @@
|
||||||
"bin": "src/index.js",
|
"bin": "src/index.js",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"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": {
|
"pkg": {
|
||||||
"scripts": "src/**/*.js",
|
"scripts": "src/**/*.js",
|
||||||
|
|
14
src/index.js
14
src/index.js
|
@ -20,7 +20,6 @@ const yargs = Yargs(process.argv.splice(2))
|
||||||
description: 'Time in seconds we want to delay the restart with.',
|
description: 'Time in seconds we want to delay the restart with.',
|
||||||
type: 'number'
|
type: 'number'
|
||||||
})
|
})
|
||||||
.conflicts('_rpm', '_rph')
|
|
||||||
|
|
||||||
const { _ = [], _rpm: rpm, _rph: rph, _delay: delay } = yargs.argv;
|
const { _ = [], _rpm: rpm, _rph: rph, _delay: delay } = yargs.argv;
|
||||||
const [command, ...args ] = _;
|
const [command, ...args ] = _;
|
||||||
|
@ -36,7 +35,9 @@ let historyMax = 4;
|
||||||
let seconds = SECONDS_IN_A_MINUTE;
|
let seconds = SECONDS_IN_A_MINUTE;
|
||||||
let restartName = '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
|
historyMax = rpm
|
||||||
} else if (rph) {
|
} else if (rph) {
|
||||||
historyMax = rph
|
historyMax = rph
|
||||||
|
@ -64,8 +65,15 @@ const checkHistory = () => Object.keys(history).length <= historyMax;
|
||||||
|
|
||||||
const restart = () => setTimeout(() => runCommand(delay), delay * 1000);
|
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 runCommand = () => {
|
||||||
const runner = spawn(command, args);
|
const runner = spawnCommand();
|
||||||
|
|
||||||
const commandLogs = [];
|
const commandLogs = [];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue