@nmakarov/cli-toolkit 0.72.0 → 0.75.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli-runner.cjs +243 -4
- package/dist/cli-runner.cjs.map +1 -1
- package/dist/cli-runner.js +243 -4
- package/dist/cli-runner.js.map +1 -1
- package/dist/index.cjs +242 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +238 -3
- package/dist/index.js.map +1 -1
- package/dist/init.cjs +13 -1
- package/dist/init.cjs.map +1 -1
- package/dist/init.js +13 -1
- package/dist/init.js.map +1 -1
- package/dist/tasks.cjs +240 -3
- package/dist/tasks.cjs.map +1 -1
- package/dist/tasks.js +236 -3
- package/dist/tasks.js.map +1 -1
- package/package.json +1 -1
package/dist/init.js
CHANGED
|
@@ -2783,6 +2783,7 @@ function setup(opts = {}) {
|
|
|
2783
2783
|
const partialContext = {
|
|
2784
2784
|
emitter: new EventEmitter(),
|
|
2785
2785
|
isStop: () => false,
|
|
2786
|
+
isKill: () => false,
|
|
2786
2787
|
cleanupFunctions: [],
|
|
2787
2788
|
registerCleanup: (fn) => {
|
|
2788
2789
|
partialContext.cleanupFunctions.push(fn);
|
|
@@ -2804,6 +2805,7 @@ function setup(opts = {}) {
|
|
|
2804
2805
|
logger,
|
|
2805
2806
|
emitter: partialContext.emitter,
|
|
2806
2807
|
isStop: partialContext.isStop,
|
|
2808
|
+
isKill: partialContext.isKill,
|
|
2807
2809
|
cleanupFunctions: partialContext.cleanupFunctions,
|
|
2808
2810
|
registerCleanup: partialContext.registerCleanup,
|
|
2809
2811
|
// For long-running scripts (servers): with --showUsedParams=top, print
|
|
@@ -2853,6 +2855,7 @@ function printAllParameters(context) {
|
|
|
2853
2855
|
}
|
|
2854
2856
|
async function init(flow, opts = {}) {
|
|
2855
2857
|
let stop = false;
|
|
2858
|
+
let kill = false;
|
|
2856
2859
|
let context = null;
|
|
2857
2860
|
let cleanupRan = false;
|
|
2858
2861
|
const runRegisteredCleanups = async (ctx) => {
|
|
@@ -2882,6 +2885,7 @@ async function init(flow, opts = {}) {
|
|
|
2882
2885
|
}
|
|
2883
2886
|
context = setup(opts);
|
|
2884
2887
|
context.isStop = () => stop;
|
|
2888
|
+
context.isKill = () => kill;
|
|
2885
2889
|
context = await setupModules(context, opts);
|
|
2886
2890
|
const stopAfter = context.args.get("stopAfter");
|
|
2887
2891
|
const stopAllowanceSec = Number(context.params.get("stopAllowance", "number default 60"));
|
|
@@ -2920,6 +2924,14 @@ async function init(flow, opts = {}) {
|
|
|
2920
2924
|
);
|
|
2921
2925
|
context.emitter.emit("stop", stopAllowanceMs);
|
|
2922
2926
|
});
|
|
2927
|
+
process.on("SIGUSR2", () => {
|
|
2928
|
+
if (!context || kill) return;
|
|
2929
|
+
kill = true;
|
|
2930
|
+
stop = true;
|
|
2931
|
+
context.logger.warn(">> SIGUSR2: emitting kill (urgent stop)");
|
|
2932
|
+
context.emitter.emit("kill");
|
|
2933
|
+
context.emitter.emit("stop", stopAllowanceMs);
|
|
2934
|
+
});
|
|
2923
2935
|
await flow(context);
|
|
2924
2936
|
} catch (error) {
|
|
2925
2937
|
const errorLocation = error instanceof Error && error.stack ? error.stack.split("\n")[1]?.trim() || "Unknown location" : "Unknown location";
|
|
@@ -2946,7 +2958,7 @@ async function init(flow, opts = {}) {
|
|
|
2946
2958
|
}
|
|
2947
2959
|
if (process.exitCode && process.exitCode !== 0) {
|
|
2948
2960
|
process.exit(process.exitCode);
|
|
2949
|
-
} else if (stop) {
|
|
2961
|
+
} else if (stop || kill) {
|
|
2950
2962
|
process.exit(0);
|
|
2951
2963
|
}
|
|
2952
2964
|
}
|