@flowscripter/dynamic-cli-framework 7.0.11 → 7.1.1
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/src/cli/BaseCLI.d.ts.map +1 -1
- package/dist/src/cli/BaseCLI.js +7 -1
- package/dist/src/cli/BaseCLIFeatureOptions.d.ts +5 -0
- package/dist/src/cli/BaseCLIFeatureOptions.d.ts.map +1 -1
- package/dist/src/cli/DefaultRuntimeCLI.js +1 -1
- package/dist/src/runtime/runner.d.ts +10 -1
- package/dist/src/runtime/runner.d.ts.map +1 -1
- package/dist/src/runtime/runner.js +7 -1
- package/dist/src/service/completion/command/CompletionCompleteSubCommand.d.ts.map +1 -1
- package/dist/src/service/completion/command/CompletionIntegrationSubCommand.d.ts.map +1 -1
- package/dist/src/service/configuration/DefaultKeyValueService.d.ts +9 -1
- package/dist/src/service/configuration/DefaultKeyValueService.d.ts.map +1 -1
- package/dist/src/service/configuration/DefaultKeyValueService.js +16 -1
- package/dist/src/service/configuration/KeyValueServiceProvider.d.ts.map +1 -1
- package/dist/src/service/configuration/KeyValueServiceProvider.js +13 -6
- package/dist/src/service/prompter/DefaultPrompterService.d.ts +2 -1
- package/dist/src/service/prompter/DefaultPrompterService.d.ts.map +1 -1
- package/dist/src/service/prompter/DefaultPrompterService.js +3 -0
- package/dist/src/service/prompter/PrompterServiceProvider.d.ts +2 -3
- package/dist/src/service/prompter/PrompterServiceProvider.d.ts.map +1 -1
- package/dist/src/service/prompter/PrompterServiceProvider.js +5 -1
- package/dist/src/service/prompter/prompt/PromptContext.d.ts +4 -1
- package/dist/src/service/prompter/prompt/PromptContext.d.ts.map +1 -1
- package/dist/src/service/prompter/prompt/PromptContext.js +10 -0
- package/dist/src/service/prompter/prompt/promptMultiSelect.d.ts.map +1 -1
- package/dist/src/service/prompter/prompt/promptMultiSelect.js +2 -3
- package/dist/src/service/prompter/prompt/promptOpenUrl.d.ts +2 -1
- package/dist/src/service/prompter/prompt/promptOpenUrl.d.ts.map +1 -1
- package/dist/src/service/prompter/prompt/promptOpenUrl.js +14 -10
- package/dist/src/service/prompter/prompt/promptSingleSelect.d.ts.map +1 -1
- package/dist/src/service/prompter/prompt/promptSingleSelect.js +2 -3
- package/dist/src/service/prompter/prompt/promptText.d.ts.map +1 -1
- package/dist/src/service/prompter/prompt/promptText.js +2 -3
- package/dist/src/service/shutdown/DefaultShutdownService.d.ts +3 -0
- package/dist/src/service/shutdown/DefaultShutdownService.d.ts.map +1 -1
- package/dist/src/service/shutdown/DefaultShutdownService.js +7 -0
- package/dist/src/service/shutdown/ShutdownServiceProvider.js +4 -4
- package/dist/src/service/spawn/DefaultSpawnService.d.ts.map +1 -1
- package/dist/src/service/spawn/DefaultSpawnService.js +1 -0
- package/dist/src/service/upgrade/DefaultUpgradeService.d.ts +30 -2
- package/dist/src/service/upgrade/DefaultUpgradeService.d.ts.map +1 -1
- package/dist/src/service/upgrade/DefaultUpgradeService.js +99 -6
- package/dist/src/service/upgrade/UpgradeServiceProvider.d.ts +19 -4
- package/dist/src/service/upgrade/UpgradeServiceProvider.d.ts.map +1 -1
- package/dist/src/service/upgrade/UpgradeServiceProvider.js +51 -12
- package/dist/src/startup/banner/bannerStartupTask.d.ts.map +1 -1
- package/dist/src/startup/banner/bannerStartupTask.js +9 -5
- package/package.json +2 -2
- package/src/cli/BaseCLI.ts +7 -0
- package/src/cli/BaseCLIFeatureOptions.ts +5 -0
- package/src/cli/DefaultRuntimeCLI.ts +1 -1
- package/src/runtime/runner.ts +17 -2
- package/src/service/completion/command/CompletionCompleteSubCommand.ts +2 -4
- package/src/service/completion/command/CompletionIntegrationSubCommand.ts +2 -4
- package/src/service/configuration/DefaultKeyValueService.ts +22 -1
- package/src/service/configuration/KeyValueServiceProvider.ts +18 -6
- package/src/service/prompter/DefaultPrompterService.ts +6 -2
- package/src/service/prompter/PrompterServiceProvider.ts +6 -3
- package/src/service/prompter/prompt/PromptContext.ts +19 -1
- package/src/service/prompter/prompt/promptMultiSelect.ts +2 -3
- package/src/service/prompter/prompt/promptOpenUrl.ts +18 -11
- package/src/service/prompter/prompt/promptSingleSelect.ts +2 -3
- package/src/service/prompter/prompt/promptText.ts +2 -3
- package/src/service/shutdown/DefaultShutdownService.ts +10 -0
- package/src/service/shutdown/ShutdownServiceProvider.ts +4 -4
- package/src/service/spawn/DefaultSpawnService.ts +1 -0
- package/src/service/upgrade/DefaultUpgradeService.ts +112 -5
- package/src/service/upgrade/UpgradeServiceProvider.ts +77 -19
- package/src/service/upgrade/command/UpgradeSubCommand.ts +2 -2
- package/src/startup/banner/bannerStartupTask.ts +11 -5
|
@@ -1,10 +1,22 @@
|
|
|
1
|
-
import type { CLIConfig, Context, UpgradeCheckResult, UpgradeResult } from "@flowscripter/dynamic-cli-framework-api";
|
|
2
|
-
import { InstallMethod, SupportedArch, SupportedOs, type UpgradeService } from "@flowscripter/dynamic-cli-framework-api";
|
|
1
|
+
import type { CLIConfig, Context, SpawnResult, UpgradeCheckResult, UpgradeResult } from "@flowscripter/dynamic-cli-framework-api";
|
|
2
|
+
import { InstallMethod, RunState, SupportedArch, SupportedOs, type UpgradeService } from "@flowscripter/dynamic-cli-framework-api";
|
|
3
3
|
import type { UpgradeLocationsConfig } from "./UpgradeLocationsConfig.ts";
|
|
4
4
|
export declare const UPGRADE_CHECK_CACHE_KEY = "upgrade-check-result";
|
|
5
5
|
export declare function describeUpgradeCheckResult(result: UpgradeCheckResult): string;
|
|
6
|
+
/**
|
|
7
|
+
* Map the result of spawning a restarted CLI to the {@link RunState} it ended with.
|
|
8
|
+
*
|
|
9
|
+
* The child is the same framework CLI, so it normally exits with a {@link RunState} value, which is
|
|
10
|
+
* returned as is (this includes 130 for SIGINT and 143 for SIGTERM). Termination by any other
|
|
11
|
+
* signal, or a timeout, maps to {@link RunState.TERMINATED}, and any other exit code to
|
|
12
|
+
* {@link RunState.RUNTIME_ERROR}.
|
|
13
|
+
*
|
|
14
|
+
* @return the {@link RunState}, or `undefined` if the child could not be started.
|
|
15
|
+
*/
|
|
16
|
+
export declare function toRunState(result: SpawnResult): RunState | undefined;
|
|
6
17
|
export default class DefaultUpgradeService implements UpgradeService {
|
|
7
18
|
#private;
|
|
19
|
+
readonly restartedFromVersion: string | undefined;
|
|
8
20
|
constructor(config: UpgradeLocationsConfig, cliConfig: CLIConfig);
|
|
9
21
|
setContext(context: Context): void;
|
|
10
22
|
getUpgradeCheckResult(): Promise<UpgradeCheckResult>;
|
|
@@ -19,6 +31,22 @@ export default class DefaultUpgradeService implements UpgradeService {
|
|
|
19
31
|
* Returns `undefined` if nothing has been persisted yet or no KeyValueService is available.
|
|
20
32
|
*/
|
|
21
33
|
getCachedUpgradeCheckResult(): Promise<UpgradeCheckResult | undefined>;
|
|
34
|
+
/**
|
|
35
|
+
* Resolve the executable to restart into after a successful upgrade via `installMethod`.
|
|
36
|
+
*
|
|
37
|
+
* @return the executable path, or `undefined` if it cannot be resolved (e.g. for winget, or a
|
|
38
|
+
* homebrew install whose `opt` link is missing).
|
|
39
|
+
*/
|
|
40
|
+
resolveUpgradedExecutable(installMethod: InstallMethod): string | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Run `executable` with `args` in place of this process, with terminal input and output
|
|
43
|
+
* inherited, and wait for it to exit. The child process sees the current version as its
|
|
44
|
+
* {@link restartedFromVersion}.
|
|
45
|
+
*
|
|
46
|
+
* @return the {@link RunState} the child ended with (see {@link toRunState}), or `undefined` if
|
|
47
|
+
* it could not be started.
|
|
48
|
+
*/
|
|
49
|
+
restart(executable: string, args: ReadonlyArray<string>): Promise<RunState | undefined>;
|
|
22
50
|
detectOs(): SupportedOs | undefined;
|
|
23
51
|
detectArch(): SupportedArch | undefined;
|
|
24
52
|
detectInstallMethod(os: SupportedOs): Promise<InstallMethod | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultUpgradeService.d.ts","sourceRoot":"","sources":["../../../../src/service/upgrade/DefaultUpgradeService.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,SAAS,EACT,OAAO,
|
|
1
|
+
{"version":3,"file":"DefaultUpgradeService.d.ts","sourceRoot":"","sources":["../../../../src/service/upgrade/DefaultUpgradeService.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,SAAS,EACT,OAAO,EAKP,WAAW,EAEX,kBAAkB,EAClB,aAAa,EAEd,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAEL,aAAa,EAGb,QAAQ,EAER,aAAa,EACb,WAAW,EACX,KAAK,cAAc,EACpB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAwC1E,eAAO,MAAM,uBAAuB,yBAAyB,CAAC;AAY9D,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAI7E;AAaD;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,SAAS,CAiBpE;AAQD,MAAM,CAAC,OAAO,OAAO,qBAAsB,YAAW,cAAc;;IAKlE,SAAgB,oBAAoB,EAAE,MAAM,GAAG,SAAS,CAAC;IAEzD,YAAmB,MAAM,EAAE,sBAAsB,EAAE,SAAS,EAAE,SAAS,EAItE;IAEM,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAExC;IA4DM,qBAAqB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAe1D;IAED;;;;OAIG;IACU,wBAAwB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CASnE;IAED;;;OAGG;IACU,2BAA2B,IAAI,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAWlF;IAED;;;;;OAKG;IACI,yBAAyB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS,CAUjF;IAoBD;;;;;;;OAOG;IACU,OAAO,CAClB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,GAC1B,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAY/B;IAEM,QAAQ,IAAI,WAAW,GAAG,SAAS,CAWzC;IAEM,UAAU,IAAI,aAAa,GAAG,SAAS,CAS7C;IAEY,mBAAmB,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAsCpF;IA2CY,eAAe,CAC1B,UAAU,CAAC,EAAE,WAAW,EACxB,YAAY,CAAC,EAAE,aAAa,EAC5B,qBAAqB,CAAC,EAAE,aAAa,GACpC,OAAO,CAAC,kBAAkB,CAAC,CAsC7B;IAEY,OAAO,CAClB,UAAU,CAAC,EAAE,WAAW,EACxB,YAAY,CAAC,EAAE,aAAa,EAC5B,qBAAqB,CAAC,EAAE,aAAa,GACpC,OAAO,CAAC,aAAa,CAAC,CAkDxB;CA2TF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
|
-
import { realpathSync } from "node:fs";
|
|
2
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
3
3
|
import { mkdtemp, rename, rm } from "node:fs/promises";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
|
-
import { dirname, join } from "node:path";
|
|
6
|
-
import { FETCH_SERVICE_ID, InstallMethod, KEY_VALUE_SERVICE_ID, PRINTER_SERVICE_ID, SPAWN_SERVICE_ID, SupportedArch, SupportedOs, } from "@flowscripter/dynamic-cli-framework-api";
|
|
5
|
+
import { basename, dirname, join } from "node:path";
|
|
6
|
+
import { FETCH_SERVICE_ID, InstallMethod, KEY_VALUE_SERVICE_ID, PRINTER_SERVICE_ID, RunState, SPAWN_SERVICE_ID, SupportedArch, SupportedOs, } from "@flowscripter/dynamic-cli-framework-api";
|
|
7
7
|
import semver from "semver";
|
|
8
8
|
import getLogger from "../../util/logger.js";
|
|
9
9
|
const logger = getLogger("DefaultUpgradeService");
|
|
@@ -38,6 +38,40 @@ export function describeUpgradeCheckResult(result) {
|
|
|
38
38
|
? `Upgrade check result: failed - ${result.error.message}`
|
|
39
39
|
: `Upgrade check result: ${JSON.stringify(result)}`;
|
|
40
40
|
}
|
|
41
|
+
// Environment variable set on a process restarted after an automatic upgrade, holding the version
|
|
42
|
+
// which restarted it (see DefaultUpgradeService.restart() and restartedFromVersion).
|
|
43
|
+
const RESTARTED_FROM_VERSION_ENV_VAR = "DYNAMIC_CLI_FRAMEWORK_REEXEC_FROM";
|
|
44
|
+
// Exit codes from 129 upwards are reported for a child terminated by a signal (128 + signal number).
|
|
45
|
+
const SIGNAL_EXIT_CODE_BASE = 128;
|
|
46
|
+
const RUN_STATE_VALUES = new Set(Object.values(RunState).filter((value) => typeof value === "number"));
|
|
47
|
+
/**
|
|
48
|
+
* Map the result of spawning a restarted CLI to the {@link RunState} it ended with.
|
|
49
|
+
*
|
|
50
|
+
* The child is the same framework CLI, so it normally exits with a {@link RunState} value, which is
|
|
51
|
+
* returned as is (this includes 130 for SIGINT and 143 for SIGTERM). Termination by any other
|
|
52
|
+
* signal, or a timeout, maps to {@link RunState.TERMINATED}, and any other exit code to
|
|
53
|
+
* {@link RunState.RUNTIME_ERROR}.
|
|
54
|
+
*
|
|
55
|
+
* @return the {@link RunState}, or `undefined` if the child could not be started.
|
|
56
|
+
*/
|
|
57
|
+
export function toRunState(result) {
|
|
58
|
+
if (result.ok) {
|
|
59
|
+
return RunState.SUCCESS;
|
|
60
|
+
}
|
|
61
|
+
if ("timedOut" in result) {
|
|
62
|
+
return RunState.TERMINATED;
|
|
63
|
+
}
|
|
64
|
+
if (result.exitCode === undefined) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
if (RUN_STATE_VALUES.has(result.exitCode)) {
|
|
68
|
+
return result.exitCode;
|
|
69
|
+
}
|
|
70
|
+
if (result.exitCode > SIGNAL_EXIT_CODE_BASE) {
|
|
71
|
+
return RunState.TERMINATED;
|
|
72
|
+
}
|
|
73
|
+
return RunState.RUNTIME_ERROR;
|
|
74
|
+
}
|
|
41
75
|
const OS_LABELS = {
|
|
42
76
|
[SupportedOs.LINUX]: "Linux",
|
|
43
77
|
[SupportedOs.MACOS]: "MacOS",
|
|
@@ -48,9 +82,11 @@ export default class DefaultUpgradeService {
|
|
|
48
82
|
#upgradeCheckPromise;
|
|
49
83
|
#config;
|
|
50
84
|
#cliConfig;
|
|
85
|
+
restartedFromVersion;
|
|
51
86
|
constructor(config, cliConfig) {
|
|
52
87
|
this.#config = config;
|
|
53
88
|
this.#cliConfig = cliConfig;
|
|
89
|
+
this.restartedFromVersion = process.env[RESTARTED_FROM_VERSION_ENV_VAR] || undefined;
|
|
54
90
|
}
|
|
55
91
|
setContext(context) {
|
|
56
92
|
this.#context = context;
|
|
@@ -150,6 +186,61 @@ export default class DefaultUpgradeService {
|
|
|
150
186
|
const cached = await this.#safeKeyValueCall(() => keyValueService.get(UPGRADE_CHECK_CACHE_KEY));
|
|
151
187
|
return cached;
|
|
152
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Resolve the executable to restart into after a successful upgrade via `installMethod`.
|
|
191
|
+
*
|
|
192
|
+
* @return the executable path, or `undefined` if it cannot be resolved (e.g. for winget, or a
|
|
193
|
+
* homebrew install whose `opt` link is missing).
|
|
194
|
+
*/
|
|
195
|
+
resolveUpgradedExecutable(installMethod) {
|
|
196
|
+
switch (installMethod) {
|
|
197
|
+
case InstallMethod.GITHUB_RELEASE:
|
|
198
|
+
case InstallMethod.LINUX_SCRIPT:
|
|
199
|
+
return process.execPath;
|
|
200
|
+
case InstallMethod.HOMEBREW:
|
|
201
|
+
return this.#resolveHomebrewOptExecutable();
|
|
202
|
+
case InstallMethod.WINGET:
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// The running executable lives in a version-specific Cellar directory, e.g.
|
|
207
|
+
// "<prefix>/Cellar/<formula>/<version>/bin/<exe>", while "<prefix>/opt/<formula>" links to the
|
|
208
|
+
// installed version, so the upgraded executable is "<prefix>/opt/<formula>/bin/<exe>".
|
|
209
|
+
#resolveHomebrewOptExecutable() {
|
|
210
|
+
if (!this.#config.homebrew) {
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
const { formula } = this.#config.homebrew;
|
|
214
|
+
const realExecutable = this.#resolveRealExecutable();
|
|
215
|
+
const cellarIndex = realExecutable.indexOf(`/Cellar/${formula}/`);
|
|
216
|
+
if (cellarIndex === -1) {
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
const prefix = realExecutable.slice(0, cellarIndex);
|
|
220
|
+
const executable = join(prefix, "opt", formula, "bin", basename(realExecutable));
|
|
221
|
+
return existsSync(executable) ? executable : undefined;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Run `executable` with `args` in place of this process, with terminal input and output
|
|
225
|
+
* inherited, and wait for it to exit. The child process sees the current version as its
|
|
226
|
+
* {@link restartedFromVersion}.
|
|
227
|
+
*
|
|
228
|
+
* @return the {@link RunState} the child ended with (see {@link toRunState}), or `undefined` if
|
|
229
|
+
* it could not be started.
|
|
230
|
+
*/
|
|
231
|
+
async restart(executable, args) {
|
|
232
|
+
const spawnService = this.#spawnService;
|
|
233
|
+
if (!spawnService) {
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
const result = await spawnService.spawn([executable, ...args], {
|
|
237
|
+
mode: "inherit",
|
|
238
|
+
// Ctrl-C reaches the child directly from the terminal, so this process only notes it
|
|
239
|
+
longRunning: true,
|
|
240
|
+
env: { [RESTARTED_FROM_VERSION_ENV_VAR]: this.#cliConfig.version },
|
|
241
|
+
});
|
|
242
|
+
return toRunState(result);
|
|
243
|
+
}
|
|
153
244
|
detectOs() {
|
|
154
245
|
switch (process.platform) {
|
|
155
246
|
case "linux":
|
|
@@ -331,15 +422,17 @@ export default class DefaultUpgradeService {
|
|
|
331
422
|
// `brew`, which has a slow cold start - avoiding it keeps the background upgrade-check
|
|
332
423
|
// StartupTask (see UpgradeServiceProvider) fast even though it runs to completion.
|
|
333
424
|
#isRunningFromHomebrewCellar(formula) {
|
|
334
|
-
|
|
425
|
+
return this.#resolveRealExecutable().includes(`/Cellar/${formula}/`);
|
|
426
|
+
}
|
|
427
|
+
#resolveRealExecutable() {
|
|
335
428
|
try {
|
|
336
|
-
|
|
429
|
+
return realpathSync(process.execPath);
|
|
337
430
|
}
|
|
338
431
|
catch {
|
|
339
432
|
// process.execPath may not resolve on disk (e.g. a fabricated path in tests) - fall back to
|
|
340
433
|
// the unresolved path rather than treating that as "not installed".
|
|
434
|
+
return process.execPath;
|
|
341
435
|
}
|
|
342
|
-
return realExecutable.includes(`/Cellar/${formula}/`);
|
|
343
436
|
}
|
|
344
437
|
async #isHomebrewInstalled() {
|
|
345
438
|
if (!this.#spawnService || !this.#config.homebrew) {
|
|
@@ -3,7 +3,7 @@ import type { Context } from "@flowscripter/dynamic-cli-framework-api";
|
|
|
3
3
|
import type { CLIConfig } from "@flowscripter/dynamic-cli-framework-api";
|
|
4
4
|
import DefaultUpgradeService from "./DefaultUpgradeService.ts";
|
|
5
5
|
import type { UpgradeLocationsConfig } from "./UpgradeLocationsConfig.ts";
|
|
6
|
-
import type { StartupTask } from "@flowscripter/dynamic-cli-framework-api";
|
|
6
|
+
import type { StartupTask, StartupTaskOutcome } from "@flowscripter/dynamic-cli-framework-api";
|
|
7
7
|
/**
|
|
8
8
|
* Build the background {@link StartupTask} which opportunistically refreshes the upgrade-check
|
|
9
9
|
* cache (see {@link DefaultUpgradeService.refreshUpgradeCheckCache}) that the banner task reads
|
|
@@ -13,7 +13,7 @@ import type { StartupTask } from "@flowscripter/dynamic-cli-framework-api";
|
|
|
13
13
|
export declare function createUpgradeCheckStartupTask(upgradeService: DefaultUpgradeService, priority: number): StartupTask;
|
|
14
14
|
/**
|
|
15
15
|
* Build the blocking {@link StartupTask} which offers to enable automatic upgrades and, when they
|
|
16
|
-
* are enabled, checks for and installs a newer version (see
|
|
16
|
+
* are enabled, checks for and installs a newer version, optionally restarting into it (see
|
|
17
17
|
* {@link UpgradeServiceProvider.runAutoUpgrade}). It is registered separately from the provider's
|
|
18
18
|
* own init task so it can run at a lower priority, after consumer startup tasks such as the banner.
|
|
19
19
|
*/
|
|
@@ -22,7 +22,18 @@ export default class UpgradeServiceProvider implements ServiceProvider {
|
|
|
22
22
|
#private;
|
|
23
23
|
readonly serviceId: string;
|
|
24
24
|
readonly servicePriority: number;
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* @param servicePriority the priority of the service.
|
|
27
|
+
* @param config the upgrade locations.
|
|
28
|
+
* @param restartAfterAutoUpgrade whether to run the upgraded executable, with the arguments from
|
|
29
|
+
* {@link setRestartArgs}, after a successful automatic upgrade and end the run with its result.
|
|
30
|
+
*/
|
|
31
|
+
constructor(servicePriority: number, config: UpgradeLocationsConfig, restartAfterAutoUpgrade?: boolean);
|
|
32
|
+
/**
|
|
33
|
+
* Set the CLI arguments to run the upgraded executable with when restarting after an automatic
|
|
34
|
+
* upgrade. These are kept internal to the framework and never exposed to startup tasks.
|
|
35
|
+
*/
|
|
36
|
+
setRestartArgs(args: ReadonlyArray<string>): void;
|
|
26
37
|
get upgradeService(): DefaultUpgradeService | undefined;
|
|
27
38
|
getServiceInfo(cliConfig: CLIConfig): Promise<ServiceInfo>;
|
|
28
39
|
initService(context: Context): Promise<void>;
|
|
@@ -31,8 +42,12 @@ export default class UpgradeServiceProvider implements ServiceProvider {
|
|
|
31
42
|
* service's scope) and, when they are enabled, check for and install a newer version. Must be
|
|
32
43
|
* called after {@link initService}.
|
|
33
44
|
*
|
|
45
|
+
* After a successful upgrade, when restarting is enabled, the upgraded executable is run with the
|
|
46
|
+
* arguments from {@link setRestartArgs} and its result is returned as an `exitRequest`. Does
|
|
47
|
+
* nothing in a process which was itself started by such a restart.
|
|
48
|
+
*
|
|
34
49
|
* @param context the startup task's context, used to look up the Prompter and Printer services.
|
|
35
50
|
*/
|
|
36
|
-
runAutoUpgrade(context: Context): Promise<void>;
|
|
51
|
+
runAutoUpgrade(context: Context): Promise<void | StartupTaskOutcome>;
|
|
37
52
|
}
|
|
38
53
|
//# sourceMappingURL=UpgradeServiceProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UpgradeServiceProvider.d.ts","sourceRoot":"","sources":["../../../../src/service/upgrade/UpgradeServiceProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC5F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAYzE,OAAO,qBAAqB,MAAM,4BAA4B,CAAC;AAE/D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAE1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"UpgradeServiceProvider.d.ts","sourceRoot":"","sources":["../../../../src/service/upgrade/UpgradeServiceProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC5F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAYzE,OAAO,qBAAqB,MAAM,4BAA4B,CAAC;AAE/D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAE1E,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAI/F;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,cAAc,EAAE,qBAAqB,EACrC,QAAQ,EAAE,MAAM,GACf,WAAW,CASb;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,sBAAsB,EAChC,QAAQ,EAAE,MAAM,GACf,WAAW,CAOb;AAED,MAAM,CAAC,OAAO,OAAO,sBAAuB,YAAW,eAAe;;IACpE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAsB;IAChD,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAQjC;;;;;OAKG;IACH,YACE,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,sBAAsB,EAC9B,uBAAuB,UAAQ,EAKhC;IAED;;;OAGG;IACI,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,IAAI,CAEvD;IAED,IAAW,cAAc,IAAI,qBAAqB,GAAG,SAAS,CAE7D;IAEM,cAAc,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAOhE;IAEM,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBlD;IAED;;;;;;;;;;OAUG;IACU,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,GAAG,kBAAkB,CAAC,CA4EhF;CA8DF"}
|
|
@@ -26,7 +26,7 @@ export function createUpgradeCheckStartupTask(upgradeService, priority) {
|
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Build the blocking {@link StartupTask} which offers to enable automatic upgrades and, when they
|
|
29
|
-
* are enabled, checks for and installs a newer version (see
|
|
29
|
+
* are enabled, checks for and installs a newer version, optionally restarting into it (see
|
|
30
30
|
* {@link UpgradeServiceProvider.runAutoUpgrade}). It is registered separately from the provider's
|
|
31
31
|
* own init task so it can run at a lower priority, after consumer startup tasks such as the banner.
|
|
32
32
|
*/
|
|
@@ -45,9 +45,25 @@ export default class UpgradeServiceProvider {
|
|
|
45
45
|
#upgradeService;
|
|
46
46
|
#cliConfig;
|
|
47
47
|
#keyValueService;
|
|
48
|
-
|
|
48
|
+
#restartAfterAutoUpgrade;
|
|
49
|
+
#restartArgs = [];
|
|
50
|
+
/**
|
|
51
|
+
* @param servicePriority the priority of the service.
|
|
52
|
+
* @param config the upgrade locations.
|
|
53
|
+
* @param restartAfterAutoUpgrade whether to run the upgraded executable, with the arguments from
|
|
54
|
+
* {@link setRestartArgs}, after a successful automatic upgrade and end the run with its result.
|
|
55
|
+
*/
|
|
56
|
+
constructor(servicePriority, config, restartAfterAutoUpgrade = false) {
|
|
49
57
|
this.servicePriority = servicePriority;
|
|
50
58
|
this.#config = config;
|
|
59
|
+
this.#restartAfterAutoUpgrade = restartAfterAutoUpgrade;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Set the CLI arguments to run the upgraded executable with when restarting after an automatic
|
|
63
|
+
* upgrade. These are kept internal to the framework and never exposed to startup tasks.
|
|
64
|
+
*/
|
|
65
|
+
setRestartArgs(args) {
|
|
66
|
+
this.#restartArgs = args;
|
|
51
67
|
}
|
|
52
68
|
get upgradeService() {
|
|
53
69
|
return this.#upgradeService;
|
|
@@ -87,12 +103,20 @@ export default class UpgradeServiceProvider {
|
|
|
87
103
|
* service's scope) and, when they are enabled, check for and install a newer version. Must be
|
|
88
104
|
* called after {@link initService}.
|
|
89
105
|
*
|
|
106
|
+
* After a successful upgrade, when restarting is enabled, the upgraded executable is run with the
|
|
107
|
+
* arguments from {@link setRestartArgs} and its result is returned as an `exitRequest`. Does
|
|
108
|
+
* nothing in a process which was itself started by such a restart.
|
|
109
|
+
*
|
|
90
110
|
* @param context the startup task's context, used to look up the Prompter and Printer services.
|
|
91
111
|
*/
|
|
92
112
|
async runAutoUpgrade(context) {
|
|
93
113
|
const upgradeService = this.#upgradeService;
|
|
94
114
|
const cliConfig = this.#cliConfig;
|
|
95
115
|
const keyValueService = this.#keyValueService;
|
|
116
|
+
if (upgradeService.restartedFromVersion !== undefined) {
|
|
117
|
+
logger.debug(() => `Restarted from version ${upgradeService.restartedFromVersion}, skipping auto-upgrade`);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
96
120
|
if (!context.doesServiceExist(PROMPTER_SERVICE_ID)) {
|
|
97
121
|
logger.debug(() => "PrompterService not available, skipping auto-upgrade");
|
|
98
122
|
return;
|
|
@@ -108,8 +132,7 @@ export default class UpgradeServiceProvider {
|
|
|
108
132
|
return;
|
|
109
133
|
}
|
|
110
134
|
if (status === "enabled") {
|
|
111
|
-
|
|
112
|
-
return;
|
|
135
|
+
return this.#checkAndUpgrade(context, upgradeService, cliConfig, keyValueService);
|
|
113
136
|
}
|
|
114
137
|
}
|
|
115
138
|
const prompterService = context.getServiceById(PROMPTER_SERVICE_ID);
|
|
@@ -150,9 +173,9 @@ export default class UpgradeServiceProvider {
|
|
|
150
173
|
return;
|
|
151
174
|
}
|
|
152
175
|
await keyValueService.set("upgrade-status", "enabled");
|
|
153
|
-
|
|
176
|
+
return this.#checkAndUpgrade(context, upgradeService, cliConfig, keyValueService);
|
|
154
177
|
}
|
|
155
|
-
async #checkAndUpgrade(context, upgradeService, cliConfig) {
|
|
178
|
+
async #checkAndUpgrade(context, upgradeService, cliConfig, keyValueService) {
|
|
156
179
|
try {
|
|
157
180
|
const checkResult = await upgradeService.getUpgradeCheckResult();
|
|
158
181
|
if (checkResult.status === "failed") {
|
|
@@ -163,16 +186,32 @@ export default class UpgradeServiceProvider {
|
|
|
163
186
|
return;
|
|
164
187
|
}
|
|
165
188
|
const upgradeResult = await upgradeService.upgrade();
|
|
166
|
-
|
|
189
|
+
const printerService = context.doesServiceExist(PRINTER_SERVICE_ID)
|
|
190
|
+
? context.getServiceById(PRINTER_SERVICE_ID)
|
|
191
|
+
: undefined;
|
|
192
|
+
if (!upgradeResult.ok) {
|
|
193
|
+
await printerService?.error(`Auto-upgrade failed: ${upgradeResult.error?.message ?? "unknown error"}\n`, Icon.FAILURE);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
await printerService?.info(`${cliConfig.name} upgraded (${upgradeResult.oldVersion} -> ${upgradeResult.newVersion})\n`, Icon.SUCCESS);
|
|
197
|
+
if (!this.#restartAfterAutoUpgrade) {
|
|
167
198
|
return;
|
|
168
199
|
}
|
|
169
|
-
const
|
|
170
|
-
if (
|
|
171
|
-
await printerService
|
|
200
|
+
const executable = upgradeService.resolveUpgradedExecutable(checkResult.installMethod);
|
|
201
|
+
if (executable === undefined) {
|
|
202
|
+
await printerService?.info(`Restart ${cliConfig.name} to use ${upgradeResult.newVersion}\n`, Icon.INFORMATION);
|
|
203
|
+
return;
|
|
172
204
|
}
|
|
173
|
-
|
|
174
|
-
|
|
205
|
+
// the cache write from the background upgrade check lands before the flush, so the shutdown
|
|
206
|
+
// flush has nothing left to write over the restarted process's configuration
|
|
207
|
+
await upgradeService.refreshUpgradeCheckCache();
|
|
208
|
+
// written now so the restarted process sees the stored upgrade-status
|
|
209
|
+
await keyValueService.flush();
|
|
210
|
+
const runState = await upgradeService.restart(executable, this.#restartArgs);
|
|
211
|
+
if (runState !== undefined) {
|
|
212
|
+
return { exitRequest: { runState } };
|
|
175
213
|
}
|
|
214
|
+
await printerService?.warn(`${cliConfig.name} upgraded to ${upgradeResult.newVersion}; restart it to use the new version\n`, Icon.ALERT);
|
|
176
215
|
}
|
|
177
216
|
catch (error) {
|
|
178
217
|
logger.debug(() => `Auto-upgrade check failed: ${error}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bannerStartupTask.d.ts","sourceRoot":"","sources":["../../../../src/startup/banner/bannerStartupTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA2B,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAYpG,eAAO,MAAM,sBAAsB,4DAA4D,CAAC;AAEhG;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAC7C,QAAQ,EAAE,MAAM,EAChB,QAAQ,SAAa,GACpB,WAAW,
|
|
1
|
+
{"version":3,"file":"bannerStartupTask.d.ts","sourceRoot":"","sources":["../../../../src/startup/banner/bannerStartupTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA2B,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAYpG,eAAO,MAAM,sBAAsB,4DAA4D,CAAC;AAEhG;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAC7C,QAAQ,EAAE,MAAM,EAChB,QAAQ,SAAa,GACpB,WAAW,CAqEb"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ASCII_BANNER_GENERATOR_SERVICE_ID, CONFIGURATION_SERVICE_ID, PRINTER_SERVICE_ID, UPGRADE_SERVICE_ID, } from "@flowscripter/dynamic-cli-framework-api";
|
|
2
|
-
import DefaultUpgradeService from "../../service/upgrade/DefaultUpgradeService.js";
|
|
3
2
|
import NoBannerCommand, {} from "./command/NoBannerCommand.js";
|
|
4
3
|
export const BANNER_STARTUP_TASK_ID = "@flowscripter/dynamic-cli-framework/banner-startup-task";
|
|
5
4
|
/**
|
|
@@ -26,6 +25,14 @@ export default function createBannerStartupTask(priority, fontName = "standard")
|
|
|
26
25
|
if (!state.printBanner) {
|
|
27
26
|
return;
|
|
28
27
|
}
|
|
28
|
+
const upgradeService = context.doesServiceExist(UPGRADE_SERVICE_ID)
|
|
29
|
+
? context.getServiceById(UPGRADE_SERVICE_ID)
|
|
30
|
+
: undefined;
|
|
31
|
+
// a process restarted after an automatic upgrade follows the banner already printed by the
|
|
32
|
+
// process which restarted it
|
|
33
|
+
if (upgradeService?.restartedFromVersion !== undefined) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
29
36
|
const printerService = context.getServiceById(PRINTER_SERVICE_ID);
|
|
30
37
|
const asciiBannerGeneratorService = context.getServiceById(ASCII_BANNER_GENERATOR_SERVICE_ID);
|
|
31
38
|
const { cliConfig } = context;
|
|
@@ -44,10 +51,7 @@ export default function createBannerStartupTask(priority, fontName = "standard")
|
|
|
44
51
|
// result yet) shows no upgrade-available suffix. The cached result is read through the
|
|
45
52
|
// upgrade service because it is stored in that service's own KeyValueService scope, and
|
|
46
53
|
// it is ignored if it was recorded by a different version (e.g. before an upgrade).
|
|
47
|
-
|
|
48
|
-
? context.getServiceById(UPGRADE_SERVICE_ID)
|
|
49
|
-
: undefined;
|
|
50
|
-
if (upgradeService instanceof DefaultUpgradeService) {
|
|
54
|
+
if (upgradeService) {
|
|
51
55
|
const result = await upgradeService.getCachedUpgradeCheckResult();
|
|
52
56
|
if (result?.status === "checked" &&
|
|
53
57
|
result.updateAvailable &&
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowscripter/dynamic-cli-framework",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.1",
|
|
4
4
|
"description": "A framework for developing CLI applications which supports dynamic discovery and installation of new commands",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"build": "tsc -p tsconfig.build.json"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@flowscripter/dynamic-cli-framework-api": "^4.0
|
|
51
|
+
"@flowscripter/dynamic-cli-framework-api": "^4.2.0",
|
|
52
52
|
"@flowscripter/dynamic-plugin-framework": "^2.2.14",
|
|
53
53
|
"emphasize": "^7.0.0",
|
|
54
54
|
"fastest-levenshtein": "^1.0.16",
|
package/src/cli/BaseCLI.ts
CHANGED
|
@@ -171,6 +171,7 @@ export default class BaseCLI implements CLI {
|
|
|
171
171
|
fetchServiceEnabled: false,
|
|
172
172
|
upgradeServiceEnabled: false,
|
|
173
173
|
upgradeLocationsConfig: { supportedPlatforms: [] },
|
|
174
|
+
restartAfterAutoUpgrade: false,
|
|
174
175
|
pluginServiceEnabled: false,
|
|
175
176
|
pluginServiceRemoteConfig: { name: "", registryUrl: "", packageJsonNamespace: "" },
|
|
176
177
|
pluginServiceLocalConfig: { nodeModulesPath: "", packageJsonNamespace: "" },
|
|
@@ -356,7 +357,9 @@ export default class BaseCLI implements CLI {
|
|
|
356
357
|
upgradeServiceProvider = new UpgradeServiceProvider(
|
|
357
358
|
UPGRADE_SERVICE_PRIORITY,
|
|
358
359
|
this.#options.upgradeLocationsConfig,
|
|
360
|
+
this.#options.restartAfterAutoUpgrade,
|
|
359
361
|
);
|
|
362
|
+
upgradeServiceProvider.setRestartArgs(args);
|
|
360
363
|
this.addServiceProvider(upgradeServiceProvider);
|
|
361
364
|
}
|
|
362
365
|
|
|
@@ -474,6 +477,10 @@ export default class BaseCLI implements CLI {
|
|
|
474
477
|
defaultCommand,
|
|
475
478
|
this.#startupServiceProvider.startupService,
|
|
476
479
|
);
|
|
480
|
+
// a startup task ended the run, having already handled its outcome itself
|
|
481
|
+
if (runResult.exitRequested) {
|
|
482
|
+
return { runState: runResult.runState };
|
|
483
|
+
}
|
|
477
484
|
// then handle the result...
|
|
478
485
|
if (runResult.runState === RunState.NO_COMMAND) {
|
|
479
486
|
// print usage
|
|
@@ -16,6 +16,11 @@ export default interface BaseCLIFeatureOptions {
|
|
|
16
16
|
readonly fetchServiceEnabled?: boolean;
|
|
17
17
|
readonly upgradeServiceEnabled?: boolean;
|
|
18
18
|
readonly upgradeLocationsConfig?: UpgradeLocationsConfig;
|
|
19
|
+
/**
|
|
20
|
+
* When an automatic upgrade on startup succeeds, run the upgraded executable with the same
|
|
21
|
+
* arguments and end this run with its result, rather than continuing on the old version.
|
|
22
|
+
*/
|
|
23
|
+
readonly restartAfterAutoUpgrade?: boolean;
|
|
19
24
|
readonly pluginServiceEnabled?: boolean;
|
|
20
25
|
readonly pluginServiceRemoteConfig?: NpmjsPluginRepositoryConfig;
|
|
21
26
|
readonly pluginServiceLocalConfig?: NpmPluginRepositoryConfig;
|
|
@@ -72,7 +72,7 @@ export default class DefaultRuntimeCLI extends BaseCLI {
|
|
|
72
72
|
stderrTerminal,
|
|
73
73
|
new TtyStyler(colorLevel, supportsHyperlinks(process.stderr)),
|
|
74
74
|
keyReader,
|
|
75
|
-
{ promptingEnabled, ...options },
|
|
75
|
+
{ promptingEnabled, restartAfterAutoUpgrade: true, ...options },
|
|
76
76
|
);
|
|
77
77
|
}
|
|
78
78
|
|
package/src/runtime/runner.ts
CHANGED
|
@@ -36,6 +36,12 @@ import { sortByPriority } from "./lifecycle/PriorityTaskList.ts";
|
|
|
36
36
|
|
|
37
37
|
const logger = getLogger("runner");
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* The {@link RunResult} returned by {@link run}, with `exitRequested` set when a startup task ended
|
|
41
|
+
* the run early by returning an `exitRequest`.
|
|
42
|
+
*/
|
|
43
|
+
export type RunnerResult = RunResult & { readonly exitRequested?: true };
|
|
44
|
+
|
|
39
45
|
/**
|
|
40
46
|
* Wrap a {@link ServiceProvider}'s `initService()` call as a {@link StartupTask} so it can be
|
|
41
47
|
* merged with directly-registered {@link StartupTask}s (e.g. the banner task) into a single
|
|
@@ -560,6 +566,8 @@ async function findAndExecuteDefaultNonModifierCommand(
|
|
|
560
566
|
* - Run the task: awaited before continuing if its mode is "blocking" (the default, and how
|
|
561
567
|
* every ServiceProvider's initService() behaves); fired without awaiting if "background"
|
|
562
568
|
* (errors logged, not propagated).
|
|
569
|
+
* - Return immediately if a "blocking" task returned an exitRequest, using its runState and
|
|
570
|
+
* skipping the remaining tasks and the command.
|
|
563
571
|
* 2. Scan arguments for any GlobalModifierCommand clauses not provided by a StartupTask
|
|
564
572
|
* - For each discovered clause:
|
|
565
573
|
* - Set any argument defaults from ConfigurationServiceProvider
|
|
@@ -615,7 +623,7 @@ export async function run(
|
|
|
615
623
|
context: Context,
|
|
616
624
|
defaultCommand?: Command,
|
|
617
625
|
startupService?: DefaultStartupService,
|
|
618
|
-
): Promise<
|
|
626
|
+
): Promise<RunnerResult> {
|
|
619
627
|
if (defaultCommand && !isSubCommand(defaultCommand) && !isGlobalCommand(defaultCommand)) {
|
|
620
628
|
throw new Error(
|
|
621
629
|
"If a default command is provided, if must be a global command or sub-command!",
|
|
@@ -681,7 +689,14 @@ export async function run(
|
|
|
681
689
|
: context;
|
|
682
690
|
|
|
683
691
|
if ((task.mode ?? "blocking") === "blocking") {
|
|
684
|
-
await task.run(taskContext);
|
|
692
|
+
const outcome = await task.run(taskContext);
|
|
693
|
+
if (outcome?.exitRequest) {
|
|
694
|
+
logger.debug(
|
|
695
|
+
() =>
|
|
696
|
+
`Startup task '${task.id}' requested exit with run state ${outcome.exitRequest.runState}`,
|
|
697
|
+
);
|
|
698
|
+
return { runState: outcome.exitRequest.runState, exitRequested: true };
|
|
699
|
+
}
|
|
685
700
|
} else {
|
|
686
701
|
void task.run(taskContext).catch((error: unknown) => {
|
|
687
702
|
logger.debug(() => `Background startup task '${task.id}' failed: ${error}`);
|
|
@@ -4,7 +4,7 @@ import type { Positional } from "@flowscripter/dynamic-cli-framework-api";
|
|
|
4
4
|
import type { Context } from "@flowscripter/dynamic-cli-framework-api";
|
|
5
5
|
import { type Values, ValueTypeName } from "@flowscripter/dynamic-cli-framework-api";
|
|
6
6
|
import { COMPLETION_SERVICE_ID, ShellType } from "@flowscripter/dynamic-cli-framework-api";
|
|
7
|
-
import type
|
|
7
|
+
import type { CompletionService } from "@flowscripter/dynamic-cli-framework-api";
|
|
8
8
|
import { PRINTER_SERVICE_ID } from "@flowscripter/dynamic-cli-framework-api";
|
|
9
9
|
import type { PrinterService } from "@flowscripter/dynamic-cli-framework-api";
|
|
10
10
|
|
|
@@ -33,9 +33,7 @@ export class CompletionCompleteSubCommand implements SubCommand {
|
|
|
33
33
|
];
|
|
34
34
|
|
|
35
35
|
async execute(context: Context, argumentValues: Values): Promise<void> {
|
|
36
|
-
const completionService = context.getServiceById(
|
|
37
|
-
COMPLETION_SERVICE_ID,
|
|
38
|
-
) as DefaultCompletionService;
|
|
36
|
+
const completionService = context.getServiceById(COMPLETION_SERVICE_ID) as CompletionService;
|
|
39
37
|
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
40
38
|
|
|
41
39
|
const shellType = argumentValues.shell as ShellType;
|
|
@@ -5,7 +5,7 @@ import type { Positional } from "@flowscripter/dynamic-cli-framework-api";
|
|
|
5
5
|
import type { Context } from "@flowscripter/dynamic-cli-framework-api";
|
|
6
6
|
import { type Values, ValueTypeName } from "@flowscripter/dynamic-cli-framework-api";
|
|
7
7
|
import { COMPLETION_SERVICE_ID, ShellType } from "@flowscripter/dynamic-cli-framework-api";
|
|
8
|
-
import type
|
|
8
|
+
import type { CompletionService } from "@flowscripter/dynamic-cli-framework-api";
|
|
9
9
|
import { Icon, PRINTER_SERVICE_ID } from "@flowscripter/dynamic-cli-framework-api";
|
|
10
10
|
import type { PrinterService } from "@flowscripter/dynamic-cli-framework-api";
|
|
11
11
|
|
|
@@ -33,9 +33,7 @@ export class CompletionIntegrationSubCommand implements SubCommand {
|
|
|
33
33
|
];
|
|
34
34
|
|
|
35
35
|
async execute(context: Context, argumentValues: Values): Promise<void> {
|
|
36
|
-
const completionService = context.getServiceById(
|
|
37
|
-
COMPLETION_SERVICE_ID,
|
|
38
|
-
) as DefaultCompletionService;
|
|
36
|
+
const completionService = context.getServiceById(COMPLETION_SERVICE_ID) as CompletionService;
|
|
39
37
|
const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
|
|
40
38
|
|
|
41
39
|
const shellType = argumentValues.shell as ShellType;
|
|
@@ -16,16 +16,37 @@ export default class DefaultKeyValueService implements KeyValueService {
|
|
|
16
16
|
readonly #keyValueData: Map<string, ValueNode>;
|
|
17
17
|
#dirty = false;
|
|
18
18
|
readonly #secretService: DefaultSecretService | undefined;
|
|
19
|
+
readonly #flushToStorage: (() => Promise<void>) | undefined;
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
/**
|
|
22
|
+
* @param keyValueData the scope's data.
|
|
23
|
+
* @param secretService optional secret service for {@link Secret} values.
|
|
24
|
+
* @param flushToStorage optional callback which writes every scope's pending changes to storage
|
|
25
|
+
* and marks them clean, invoked by {@link flush}.
|
|
26
|
+
*/
|
|
27
|
+
constructor(
|
|
28
|
+
keyValueData: Map<string, ValueNode>,
|
|
29
|
+
secretService?: DefaultSecretService,
|
|
30
|
+
flushToStorage?: () => Promise<void>,
|
|
31
|
+
) {
|
|
21
32
|
this.#keyValueData = keyValueData;
|
|
22
33
|
this.#secretService = secretService;
|
|
34
|
+
this.#flushToStorage = flushToStorage;
|
|
23
35
|
}
|
|
24
36
|
|
|
25
37
|
public isDirty(): boolean {
|
|
26
38
|
return this.#dirty;
|
|
27
39
|
}
|
|
28
40
|
|
|
41
|
+
public markClean(): void {
|
|
42
|
+
this.#dirty = false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public async flush(): Promise<void> {
|
|
46
|
+
await this.#flushToStorage?.();
|
|
47
|
+
this.#dirty = false;
|
|
48
|
+
}
|
|
49
|
+
|
|
29
50
|
public async get<T extends ValueNode = ValueNode>(key: string): Promise<T> {
|
|
30
51
|
const value = this.#keyValueData.get(key);
|
|
31
52
|
if (value === undefined) {
|