@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.cjs
CHANGED
|
@@ -2808,6 +2808,7 @@ function setup(opts = {}) {
|
|
|
2808
2808
|
const partialContext = {
|
|
2809
2809
|
emitter: new import_events.EventEmitter(),
|
|
2810
2810
|
isStop: () => false,
|
|
2811
|
+
isKill: () => false,
|
|
2811
2812
|
cleanupFunctions: [],
|
|
2812
2813
|
registerCleanup: (fn) => {
|
|
2813
2814
|
partialContext.cleanupFunctions.push(fn);
|
|
@@ -2829,6 +2830,7 @@ function setup(opts = {}) {
|
|
|
2829
2830
|
logger,
|
|
2830
2831
|
emitter: partialContext.emitter,
|
|
2831
2832
|
isStop: partialContext.isStop,
|
|
2833
|
+
isKill: partialContext.isKill,
|
|
2832
2834
|
cleanupFunctions: partialContext.cleanupFunctions,
|
|
2833
2835
|
registerCleanup: partialContext.registerCleanup,
|
|
2834
2836
|
// For long-running scripts (servers): with --showUsedParams=top, print
|
|
@@ -2878,6 +2880,7 @@ function printAllParameters(context) {
|
|
|
2878
2880
|
}
|
|
2879
2881
|
async function init(flow, opts = {}) {
|
|
2880
2882
|
let stop = false;
|
|
2883
|
+
let kill = false;
|
|
2881
2884
|
let context = null;
|
|
2882
2885
|
let cleanupRan = false;
|
|
2883
2886
|
const runRegisteredCleanups = async (ctx) => {
|
|
@@ -2907,6 +2910,7 @@ async function init(flow, opts = {}) {
|
|
|
2907
2910
|
}
|
|
2908
2911
|
context = setup(opts);
|
|
2909
2912
|
context.isStop = () => stop;
|
|
2913
|
+
context.isKill = () => kill;
|
|
2910
2914
|
context = await setupModules(context, opts);
|
|
2911
2915
|
const stopAfter = context.args.get("stopAfter");
|
|
2912
2916
|
const stopAllowanceSec = Number(context.params.get("stopAllowance", "number default 60"));
|
|
@@ -2945,6 +2949,14 @@ async function init(flow, opts = {}) {
|
|
|
2945
2949
|
);
|
|
2946
2950
|
context.emitter.emit("stop", stopAllowanceMs);
|
|
2947
2951
|
});
|
|
2952
|
+
process.on("SIGUSR2", () => {
|
|
2953
|
+
if (!context || kill) return;
|
|
2954
|
+
kill = true;
|
|
2955
|
+
stop = true;
|
|
2956
|
+
context.logger.warn(">> SIGUSR2: emitting kill (urgent stop)");
|
|
2957
|
+
context.emitter.emit("kill");
|
|
2958
|
+
context.emitter.emit("stop", stopAllowanceMs);
|
|
2959
|
+
});
|
|
2948
2960
|
await flow(context);
|
|
2949
2961
|
} catch (error) {
|
|
2950
2962
|
const errorLocation = error instanceof Error && error.stack ? error.stack.split("\n")[1]?.trim() || "Unknown location" : "Unknown location";
|
|
@@ -2971,7 +2983,7 @@ async function init(flow, opts = {}) {
|
|
|
2971
2983
|
}
|
|
2972
2984
|
if (process.exitCode && process.exitCode !== 0) {
|
|
2973
2985
|
process.exit(process.exitCode);
|
|
2974
|
-
} else if (stop) {
|
|
2986
|
+
} else if (stop || kill) {
|
|
2975
2987
|
process.exit(0);
|
|
2976
2988
|
}
|
|
2977
2989
|
}
|