0.0.1 • Published 4 months ago
simple-run-scripts-cycle v0.0.1
simple-run-scripts-cycle
Js and shell scripts cyclic runner with interval. Usable for replacing cron, or making processes from scripts.
Package contains cli tools and exports runner class.
CLI
Run bash script
For example we have bash script in root dir ./test.sh
# ./test.sh file
echo "Hello from sh!"
Next npm script will run it cyclic with 2 secs interval
npm run simple-run-script-cycle --script ./test.sh --delayMs 2000 --maxDurationMs 5000 --pathStrategy fromClosestPackageJsonFile
(You may try to use it with npx or add this script to scripts
section of your package.json)
Run node script
For example we have js script ./js/test/test.js
//./js/test/test.js
console.log("Hello from js script!");
Next npm script will run it cyclic with 2 secs interval
npm run simple-run-js-cycle --script ./js/test/test.js --delayMs 2000 --maxDurationMs 5000 --pathStrategy fromClosestPackageJsonFile
CLI params
- {name: "script", type: String, multiple: true, reuqired: true} - absolute or relative path to script
- {name: "delayMs", type: Number} - min delay between execuitions in milliseconds
- {name: "maxDurationMs", type: Number} - max available duration of every script execution before cold reset
- {name: "pathStrategy", type: String} - one of available path strategies (more next..)
- {name: "console", type: String} - path to js file, exports only one function type of
(...s) => void
for logging. Default will use console.log.
Path strategies
Available 3 strategies to resolve relative paths:
- none - don't process relative paths (default option)
- fromScriptRoot - resolve relative paths from parent running scripts root
- fromClosestPackageJsonFile - found parent running scripts root and moving top by directories before found
package.json
file. Using this directory as a root.
Runner class
export type SimpleRunScriptsCycleConfig = {
scriptsAndOpts: string[];
delayMs: number;
maxDurationMs: number;
relativePathStrategy: PathProcessStrategy;
};
export declare class SimpleRunScriptsCycle {
config: SimpleRunScriptsCycleConfig;
constructor(config: SimpleRunScriptsCycleConfig, logFn?: ((...a: any[]) => void) | null);
run(): void;
stop(): void;
}
Author
Anatoly Starodubtsev tostar74@mail.ru https://t.me/pantagruel74
LICENSE
MIT
0.0.1
4 months ago