@flowscripter/dynamic-cli-framework 3.0.2 → 5.0.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.
Files changed (60) hide show
  1. package/dist/index.d.ts +2 -3
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +2 -3
  4. package/dist/src/cli/BaseCLI.d.ts +1 -0
  5. package/dist/src/cli/BaseCLI.d.ts.map +1 -1
  6. package/dist/src/cli/BaseCLI.js +8 -0
  7. package/dist/src/cli/BaseCLIFeatureOptions.d.ts +4 -0
  8. package/dist/src/cli/BaseCLIFeatureOptions.d.ts.map +1 -1
  9. package/dist/src/command/VersionCommand.js +2 -2
  10. package/dist/src/launcher.d.ts +0 -2
  11. package/dist/src/launcher.d.ts.map +1 -1
  12. package/dist/src/launcher.js +0 -20
  13. package/dist/src/service/banner/BannerServiceProvider.js +2 -2
  14. package/dist/src/service/completion/CompletionServiceProvider.js +4 -4
  15. package/dist/src/service/configuration/ConfigurationServiceProvider.d.ts +19 -8
  16. package/dist/src/service/configuration/ConfigurationServiceProvider.d.ts.map +1 -1
  17. package/dist/src/service/configuration/ConfigurationServiceProvider.js +26 -33
  18. package/dist/src/service/configuration/DefaultKeyValueService.d.ts +6 -6
  19. package/dist/src/service/configuration/DefaultKeyValueService.d.ts.map +1 -1
  20. package/dist/src/service/configuration/DefaultKeyValueService.js +60 -19
  21. package/dist/src/service/configuration/resolveSecrets.d.ts +11 -0
  22. package/dist/src/service/configuration/resolveSecrets.d.ts.map +1 -0
  23. package/dist/src/service/configuration/resolveSecrets.js +31 -0
  24. package/dist/src/service/plugin/DefaultPluginService.d.ts +5 -2
  25. package/dist/src/service/plugin/DefaultPluginService.d.ts.map +1 -1
  26. package/dist/src/service/plugin/DefaultPluginService.js +21 -2
  27. package/dist/src/service/plugin/PluginServiceProvider.d.ts +17 -0
  28. package/dist/src/service/plugin/PluginServiceProvider.d.ts.map +1 -0
  29. package/dist/src/service/plugin/PluginServiceProvider.js +95 -0
  30. package/dist/src/service/upgrade/DefaultUpgradeService.d.ts +2 -2
  31. package/dist/src/service/upgrade/DefaultUpgradeService.d.ts.map +1 -1
  32. package/dist/src/service/upgrade/DefaultUpgradeService.js +79 -43
  33. package/dist/src/service/upgrade/UpgradeServiceProvider.d.ts.map +1 -1
  34. package/dist/src/service/upgrade/UpgradeServiceProvider.js +9 -5
  35. package/dist/src/service/upgrade/command/UpgradeSubCommand.d.ts.map +1 -1
  36. package/dist/src/service/upgrade/command/UpgradeSubCommand.js +10 -1
  37. package/index.ts +2 -7
  38. package/package.json +3 -3
  39. package/src/cli/BaseCLI.ts +17 -0
  40. package/src/cli/BaseCLIFeatureOptions.ts +7 -0
  41. package/src/command/VersionCommand.ts +2 -2
  42. package/src/launcher.ts +0 -35
  43. package/src/service/banner/BannerServiceProvider.ts +2 -2
  44. package/src/service/completion/CompletionServiceProvider.ts +4 -4
  45. package/src/service/configuration/ConfigurationServiceProvider.ts +36 -40
  46. package/src/service/configuration/DefaultKeyValueService.ts +76 -22
  47. package/src/service/configuration/resolveSecrets.ts +35 -0
  48. package/src/service/plugin/DefaultPluginService.ts +41 -3
  49. package/src/service/plugin/PluginServiceProvider.ts +142 -0
  50. package/src/service/upgrade/DefaultUpgradeService.ts +98 -52
  51. package/src/service/upgrade/UpgradeServiceProvider.ts +9 -5
  52. package/src/service/upgrade/command/UpgradeSubCommand.ts +15 -1
  53. package/dist/src/cli/DynamicPluginRuntimeCLI.d.ts +0 -20
  54. package/dist/src/cli/DynamicPluginRuntimeCLI.d.ts.map +0 -1
  55. package/dist/src/cli/DynamicPluginRuntimeCLI.js +0 -50
  56. package/dist/src/service/plugin/DefaultPluginServiceProvider.d.ts +0 -15
  57. package/dist/src/service/plugin/DefaultPluginServiceProvider.d.ts.map +0 -1
  58. package/dist/src/service/plugin/DefaultPluginServiceProvider.js +0 -56
  59. package/src/cli/DynamicPluginRuntimeCLI.ts +0 -77
  60. package/src/service/plugin/DefaultPluginServiceProvider.ts +0 -82
@@ -18,9 +18,6 @@ import {
18
18
  } from "@flowscripter/dynamic-cli-framework-api";
19
19
  import semver from "semver";
20
20
  import type { UpgradeLocationsConfig } from "./UpgradeLocationsConfig.ts";
21
- import getLogger from "../../util/logger.ts";
22
-
23
- const logger = getLogger("DefaultUpgradeService");
24
21
 
25
22
  // checkForUpgrade() runs opportunistically on every CLI invocation (via BannerServiceProvider),
26
23
  // so that opportunistic call is raced against this timeout so it never stalls CLI startup.
@@ -28,6 +25,10 @@ const logger = getLogger("DefaultUpgradeService");
28
25
  // directly with no timeout, so its underlying network/spawn calls are never artificially cut off.
29
26
  export const VERSION_CHECK_TIMEOUT_MS = 250;
30
27
 
28
+ type VersionLookupResult =
29
+ | { readonly ok: true; readonly version: string }
30
+ | { readonly ok: false; readonly error: Error };
31
+
31
32
  function describeSpawnFailure(result: Extract<SpawnResult, { ok: false }>): string {
32
33
  return "timedOut" in result
33
34
  ? "timed out"
@@ -43,7 +44,7 @@ const OS_LABELS: Record<SupportedOs, string> = {
43
44
  export default class DefaultUpgradeService implements UpgradeService {
44
45
  #spawnService: SpawnService | undefined;
45
46
  #fetchService: FetchService | undefined;
46
- #upgradeCheckPromise: Promise<UpgradeCheckResult | undefined> | undefined;
47
+ #upgradeCheckPromise: Promise<UpgradeCheckResult> | undefined;
47
48
  readonly #config: UpgradeLocationsConfig;
48
49
  readonly #cliConfig: CLIConfig;
49
50
 
@@ -60,16 +61,16 @@ export default class DefaultUpgradeService implements UpgradeService {
60
61
  this.#fetchService = fetchService;
61
62
  }
62
63
 
63
- public getUpgradeCheckResult(waitForResult = false): Promise<UpgradeCheckResult | undefined> {
64
+ public getUpgradeCheckResult(waitForResult = false): Promise<UpgradeCheckResult> {
64
65
  if (!this.#upgradeCheckPromise) {
65
- // Only cache a successful result. An `undefined` result can come from a transient
66
- // failure (e.g. the opportunistic startup check racing past VERSION_CHECK_TIMEOUT_MS
67
- // before checkForUpgrade() itself resolves) - caching that would permanently deny a
68
- // later, deliberate caller (e.g. the `upgrade` command explicitly waiting via
69
- // waitForResult=true) any chance of a fresh attempt for the rest of this process's
70
- // lifetime.
66
+ // Only cache a non-"failed" result. A "failed" result can come from a transient issue
67
+ // (e.g. a network blip, or the opportunistic startup check racing past
68
+ // VERSION_CHECK_TIMEOUT_MS before checkForUpgrade() itself resolves) - caching that would
69
+ // permanently deny a later, deliberate caller (e.g. the `upgrade` command explicitly
70
+ // waiting via waitForResult=true) any chance of a fresh attempt for the rest of this
71
+ // process's lifetime.
71
72
  this.#upgradeCheckPromise = this.checkForUpgrade().then((result) => {
72
- if (result === undefined) {
73
+ if (result.status === "failed") {
73
74
  this.#upgradeCheckPromise = undefined;
74
75
  }
75
76
  return result;
@@ -80,8 +81,8 @@ export default class DefaultUpgradeService implements UpgradeService {
80
81
  }
81
82
  return Promise.race([
82
83
  this.#upgradeCheckPromise,
83
- new Promise<undefined>((resolve) =>
84
- setTimeout(() => resolve(undefined), VERSION_CHECK_TIMEOUT_MS),
84
+ new Promise<UpgradeCheckResult>((resolve) =>
85
+ setTimeout(() => resolve({ status: "pending" }), VERSION_CHECK_TIMEOUT_MS),
85
86
  ),
86
87
  ]);
87
88
  }
@@ -130,34 +131,39 @@ export default class DefaultUpgradeService implements UpgradeService {
130
131
  osOverride?: SupportedOs,
131
132
  archOverride?: SupportedArch,
132
133
  installMethodOverride?: InstallMethod,
133
- ): Promise<UpgradeCheckResult | undefined> {
134
+ ): Promise<UpgradeCheckResult> {
134
135
  const os = osOverride ?? this.detectOs();
135
136
  const arch = archOverride ?? this.detectArch();
136
137
  if (!os || !arch || !this.#isPlatformSupported(os, arch)) {
137
- return undefined;
138
+ return { status: "unsupported" };
138
139
  }
139
140
 
140
141
  const installMethod = installMethodOverride ?? (await this.detectInstallMethod(os));
141
142
  if (!installMethod) {
142
- return undefined;
143
+ return { status: "unsupported" };
143
144
  }
144
145
 
145
- const latestVersion = await this.#getLatestVersion(installMethod);
146
- if (!latestVersion) {
147
- return undefined;
146
+ const versionLookup = await this.#getLatestVersion(installMethod);
147
+ if (!versionLookup.ok) {
148
+ return { status: "failed", error: versionLookup.error };
148
149
  }
149
150
 
150
151
  const currentVersion = this.#cliConfig.version;
151
152
  const coercedCurrent = semver.coerce(currentVersion);
152
- const coercedLatest = semver.coerce(latestVersion);
153
+ const coercedLatest = semver.coerce(versionLookup.version);
153
154
  if (!coercedCurrent || !coercedLatest) {
154
- logger.debug(() => `Unable to compare versions '${currentVersion}' and '${latestVersion}'`);
155
- return undefined;
155
+ return {
156
+ status: "failed",
157
+ error: new Error(
158
+ `Unable to compare versions '${currentVersion}' and '${versionLookup.version}'`,
159
+ ),
160
+ };
156
161
  }
157
162
 
158
163
  return {
164
+ status: "checked",
159
165
  currentVersion,
160
- latestVersion,
166
+ latestVersion: versionLookup.version,
161
167
  updateAvailable: semver.gt(coercedLatest, coercedCurrent),
162
168
  os,
163
169
  arch,
@@ -176,13 +182,20 @@ export default class DefaultUpgradeService implements UpgradeService {
176
182
  const checkResult = hasOverride
177
183
  ? await this.checkForUpgrade(osOverride, archOverride, installMethodOverride)
178
184
  : await this.getUpgradeCheckResult(true);
179
- if (!checkResult) {
185
+ if (checkResult.status === "unsupported") {
180
186
  return {
181
187
  ok: false,
182
188
  oldVersion,
183
189
  error: new Error("No upgrade location configured for the detected or requested platform"),
184
190
  };
185
191
  }
192
+ if (checkResult.status === "failed") {
193
+ return { ok: false, oldVersion, error: checkResult.error };
194
+ }
195
+ if (checkResult.status === "pending") {
196
+ // Unreachable: checkForUpgrade() and getUpgradeCheckResult(true) always run to completion.
197
+ return { ok: false, oldVersion, error: new Error("Upgrade check did not complete") };
198
+ }
186
199
  if (!this.#spawnService) {
187
200
  return { ok: false, oldVersion, error: new Error("SpawnService is not available") };
188
201
  }
@@ -243,7 +256,7 @@ export default class DefaultUpgradeService implements UpgradeService {
243
256
  return process.execPath.startsWith("/usr/local/bin/");
244
257
  }
245
258
 
246
- async #getLatestVersion(installMethod: InstallMethod): Promise<string | undefined> {
259
+ async #getLatestVersion(installMethod: InstallMethod): Promise<VersionLookupResult> {
247
260
  switch (installMethod) {
248
261
  case InstallMethod.GITHUB_RELEASE:
249
262
  case InstallMethod.LINUX_SCRIPT:
@@ -252,58 +265,91 @@ export default class DefaultUpgradeService implements UpgradeService {
252
265
  return this.#getLatestHomebrewVersion();
253
266
  case InstallMethod.WINGET:
254
267
  return this.#getLatestWingetVersion();
255
- default:
256
- return undefined;
257
268
  }
258
269
  }
259
270
 
260
- async #getLatestGithubReleaseVersion(): Promise<string | undefined> {
261
- if (!this.#config.githubRelease || !this.#fetchService) {
262
- return undefined;
271
+ async #getLatestGithubReleaseVersion(): Promise<VersionLookupResult> {
272
+ if (!this.#config.githubRelease) {
273
+ return { ok: false, error: new Error("No githubRelease location configured") };
274
+ }
275
+ if (!this.#fetchService) {
276
+ return { ok: false, error: new Error("FetchService is not available") };
263
277
  }
264
278
  const { owner, repo } = this.#config.githubRelease;
265
279
  try {
280
+ // Uses the plain web redirect rather than the api.github.com REST endpoint, since the
281
+ // latter's unauthenticated rate limit (60 requests/hour/IP) is easily exhausted, e.g. by
282
+ // CI runners sharing an IP pool.
266
283
  const response = await this.#fetchService.fetch(
267
- `https://api.github.com/repos/${owner}/${repo}/releases/latest`,
284
+ `https://github.com/${owner}/${repo}/releases/latest`,
285
+ { redirect: "manual" },
268
286
  );
269
- if (!response.ok) {
270
- return undefined;
287
+ const location = response.headers.get("location");
288
+ const version = location ? /\/releases\/tag\/v?([^/]+)$/.exec(location)?.[1] : undefined;
289
+ if (!version) {
290
+ return {
291
+ ok: false,
292
+ error: new Error(
293
+ `Unexpected response resolving latest release for ${owner}/${repo}: HTTP ${response.status}`,
294
+ ),
295
+ };
271
296
  }
272
- const data = (await response.json()) as { tag_name?: string };
273
- return data.tag_name?.replace(/^v/, "");
297
+ return { ok: true, version };
274
298
  } catch (error) {
275
- logger.debug(() => `Failed to fetch latest GitHub release for ${owner}/${repo}: ${error}`);
276
- return undefined;
299
+ return {
300
+ ok: false,
301
+ error: new Error(`Failed to fetch latest GitHub release for ${owner}/${repo}: ${error}`),
302
+ };
277
303
  }
278
304
  }
279
305
 
280
- async #getLatestHomebrewVersion(): Promise<string | undefined> {
281
- if (!this.#config.homebrew || !this.#fetchService) {
282
- return undefined;
306
+ async #getLatestHomebrewVersion(): Promise<VersionLookupResult> {
307
+ if (!this.#config.homebrew) {
308
+ return { ok: false, error: new Error("No homebrew location configured") };
309
+ }
310
+ if (!this.#fetchService) {
311
+ return { ok: false, error: new Error("FetchService is not available") };
283
312
  }
284
313
  const { tap, formula } = this.#config.homebrew;
285
314
  const [tapOwner, tapName] = tap.split("/");
286
315
  if (!tapOwner || !tapName) {
287
- return undefined;
316
+ return { ok: false, error: new Error(`Invalid homebrew tap '${tap}'`) };
288
317
  }
289
318
  try {
290
319
  const response = await this.#fetchService.fetch(
291
320
  `https://raw.githubusercontent.com/${tapOwner}/homebrew-${tapName}/main/${formula}.rb`,
292
321
  );
293
322
  if (!response.ok) {
294
- return undefined;
323
+ return {
324
+ ok: false,
325
+ error: new Error(
326
+ `Failed to fetch homebrew formula for ${tap}/${formula}: HTTP ${response.status}`,
327
+ ),
328
+ };
295
329
  }
296
330
  const text = await response.text();
297
- return /version\s+"v?([^"]+)"/.exec(text)?.[1];
331
+ const version = /version\s+"v?([^"]+)"/.exec(text)?.[1];
332
+ if (!version) {
333
+ return {
334
+ ok: false,
335
+ error: new Error(`Could not parse version from homebrew formula ${tap}/${formula}`),
336
+ };
337
+ }
338
+ return { ok: true, version };
298
339
  } catch (error) {
299
- logger.debug(() => `Failed to fetch homebrew formula for ${tap}/${formula}: ${error}`);
300
- return undefined;
340
+ return {
341
+ ok: false,
342
+ error: new Error(`Failed to fetch homebrew formula for ${tap}/${formula}: ${error}`),
343
+ };
301
344
  }
302
345
  }
303
346
 
304
- async #getLatestWingetVersion(): Promise<string | undefined> {
305
- if (!this.#spawnService || !this.#config.winget) {
306
- return undefined;
347
+ async #getLatestWingetVersion(): Promise<VersionLookupResult> {
348
+ if (!this.#config.winget) {
349
+ return { ok: false, error: new Error("No winget location configured") };
350
+ }
351
+ if (!this.#spawnService) {
352
+ return { ok: false, error: new Error("SpawnService is not available") };
307
353
  }
308
354
  const lines: string[] = [];
309
355
  const result = await this.#spawnService.spawn(
@@ -315,15 +361,15 @@ export default class DefaultUpgradeService implements UpgradeService {
315
361
  },
316
362
  );
317
363
  if (!result.ok) {
318
- return undefined;
364
+ return { ok: false, error: new Error(`winget show failed: ${describeSpawnFailure(result)}`) };
319
365
  }
320
366
  for (const line of lines) {
321
367
  const match = /Version:\s*(\S+)/.exec(line);
322
368
  if (match?.[1]) {
323
- return match[1];
369
+ return { ok: true, version: match[1] };
324
370
  }
325
371
  }
326
- return undefined;
372
+ return { ok: false, error: new Error("Could not parse version from winget output") };
327
373
  }
328
374
 
329
375
  async #upgradeViaLinuxScript(): Promise<void> {
@@ -71,8 +71,8 @@ export default class UpgradeServiceProvider implements ServiceProvider {
71
71
 
72
72
  const keyValueService = context.getServiceById(KEY_VALUE_SERVICE_ID) as KeyValueService;
73
73
 
74
- if (await keyValueService.hasKey("upgrade-status")) {
75
- const status = await keyValueService.getKey("upgrade-status");
74
+ if (await keyValueService.has("upgrade-status")) {
75
+ const status = await keyValueService.get("upgrade-status");
76
76
  if (status === "declined") {
77
77
  logger.debug(() => "Auto-upgrade previously declined, skipping");
78
78
  return;
@@ -120,11 +120,11 @@ export default class UpgradeServiceProvider implements ServiceProvider {
120
120
  }
121
121
 
122
122
  if (enableResult.value !== true) {
123
- await keyValueService.setKey("upgrade-status", "declined");
123
+ await keyValueService.set("upgrade-status", "declined");
124
124
  return;
125
125
  }
126
126
 
127
- await keyValueService.setKey("upgrade-status", "enabled");
127
+ await keyValueService.set("upgrade-status", "enabled");
128
128
  await this.#checkAndUpgrade(context, upgradeService, cliConfig);
129
129
  }
130
130
 
@@ -135,7 +135,11 @@ export default class UpgradeServiceProvider implements ServiceProvider {
135
135
  ): Promise<void> {
136
136
  try {
137
137
  const checkResult = await upgradeService.getUpgradeCheckResult();
138
- if (!checkResult?.updateAvailable) {
138
+ if (checkResult.status === "failed") {
139
+ logger.debug(() => `Auto-upgrade check failed: ${checkResult.error.message}`);
140
+ return;
141
+ }
142
+ if (checkResult.status !== "checked" || !checkResult.updateAvailable) {
139
143
  return;
140
144
  }
141
145
  const upgradeResult = await upgradeService.upgrade();
@@ -53,7 +53,7 @@ export class UpgradeSubCommand implements SubCommand {
53
53
  os === undefined && installMethod === undefined
54
54
  ? await this.#upgradeService.getUpgradeCheckResult(true)
55
55
  : await this.#upgradeService.checkForUpgrade(os, arch, installMethod);
56
- if (!checkResult) {
56
+ if (checkResult.status === "unsupported") {
57
57
  await printerService.error(
58
58
  `No upgrade location is configured for the detected or requested platform.\n`,
59
59
  Icon.FAILURE,
@@ -61,6 +61,20 @@ export class UpgradeSubCommand implements SubCommand {
61
61
  return;
62
62
  }
63
63
 
64
+ if (checkResult.status === "failed") {
65
+ await printerService.error(
66
+ `Failed to check for updates: ${checkResult.error.message}. Please try again later.\n`,
67
+ Icon.FAILURE,
68
+ );
69
+ return;
70
+ }
71
+
72
+ if (checkResult.status === "pending") {
73
+ // Unreachable: getUpgradeCheckResult(true) and checkForUpgrade() always run to completion.
74
+ await printerService.error(`Failed to check for updates.\n`, Icon.FAILURE);
75
+ return;
76
+ }
77
+
64
78
  if (!checkResult.updateAvailable) {
65
79
  await printerService.print(
66
80
  `${cliName} is already up to date (${checkResult.currentVersion}).\n`,
@@ -1,20 +0,0 @@
1
- import type { MarketplacePluginManager } from "@flowscripter/dynamic-plugin-framework";
2
- import type { CLIConfig } from "@flowscripter/dynamic-cli-framework-api";
3
- import type BaseCLIFeatureOptions from "./BaseCLIFeatureOptions.ts";
4
- import type { RunResult } from "@flowscripter/dynamic-cli-framework-api";
5
- import DefaultRuntimeCLI from "./DefaultRuntimeCLI.ts";
6
- /**
7
- * Extension of {@link DefaultRuntimeCLI} that discovers and loads installed plugins before running.
8
- *
9
- * On each invocation of {@link run}, all locally installed plugins are discovered via the
10
- * {@link MarketplacePluginManager}. Commands provided by {@link CommandFactory} extensions and
11
- * service providers provided by {@link ServiceProviderFactory} extensions are registered before
12
- * the runner starts, so they participate in the full initialization lifecycle.
13
- */
14
- export default class DynamicPluginRuntimeCLI extends DefaultRuntimeCLI {
15
- #private;
16
- constructor(cliConfig: CLIConfig, pluginManager: MarketplacePluginManager, options?: BaseCLIFeatureOptions);
17
- run(): Promise<RunResult>;
18
- loadPlugins(): Promise<void>;
19
- }
20
- //# sourceMappingURL=DynamicPluginRuntimeCLI.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DynamicPluginRuntimeCLI.d.ts","sourceRoot":"","sources":["../../../src/cli/DynamicPluginRuntimeCLI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,qBAAqB,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AAQvD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,iBAAiB;;gBAIlE,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,wBAAwB,EACvC,OAAO,CAAC,EAAE,qBAAqB;IAOlB,GAAG,IAAI,OAAO,CAAC,SAAS,CAAC;IAUlC,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAgCnC"}
@@ -1,50 +0,0 @@
1
- import { RunState } from "@flowscripter/dynamic-cli-framework-api";
2
- import DefaultRuntimeCLI from "./DefaultRuntimeCLI.js";
3
- import DefaultPluginServiceProvider from "../service/plugin/DefaultPluginServiceProvider.js";
4
- import { DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT } from "@flowscripter/dynamic-cli-framework-api";
5
- import { DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT } from "@flowscripter/dynamic-cli-framework-api";
6
- import process from "node:process";
7
- /**
8
- * Extension of {@link DefaultRuntimeCLI} that discovers and loads installed plugins before running.
9
- *
10
- * On each invocation of {@link run}, all locally installed plugins are discovered via the
11
- * {@link MarketplacePluginManager}. Commands provided by {@link CommandFactory} extensions and
12
- * service providers provided by {@link ServiceProviderFactory} extensions are registered before
13
- * the runner starts, so they participate in the full initialization lifecycle.
14
- */
15
- export default class DynamicPluginRuntimeCLI extends DefaultRuntimeCLI {
16
- #pluginManager;
17
- constructor(cliConfig, pluginManager, options) {
18
- super(cliConfig, options);
19
- this.#pluginManager = pluginManager;
20
- this.addServiceProvider(new DefaultPluginServiceProvider(pluginManager));
21
- }
22
- async run() {
23
- try {
24
- await this.loadPlugins();
25
- }
26
- catch (err) {
27
- console.error(err);
28
- process.exit(RunState.RUNTIME_ERROR);
29
- }
30
- return super.run();
31
- }
32
- async loadPlugins() {
33
- await this.#pluginManager.registerExtensions(DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT);
34
- await this.#pluginManager.registerExtensions(DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT);
35
- const commandFactoryExtensions = await this.#pluginManager.getRegisteredExtensions(DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT);
36
- for (const ext of commandFactoryExtensions) {
37
- const factory = (await this.#pluginManager.instantiate(ext.extensionHandle));
38
- for (const command of factory.getCommands()) {
39
- this.addCommand(command);
40
- }
41
- }
42
- const spFactoryExtensions = await this.#pluginManager.getRegisteredExtensions(DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT);
43
- for (const ext of spFactoryExtensions) {
44
- const factory = (await this.#pluginManager.instantiate(ext.extensionHandle));
45
- for (const sp of factory.getServiceProviders()) {
46
- this.addServiceProvider(sp);
47
- }
48
- }
49
- }
50
- }
@@ -1,15 +0,0 @@
1
- import type { ServiceInfo, ServiceProvider } from "@flowscripter/dynamic-cli-framework-api";
2
- import type { Context } from "@flowscripter/dynamic-cli-framework-api";
3
- import type { CLIConfig } from "@flowscripter/dynamic-cli-framework-api";
4
- import type { MarketplacePluginManager } from "@flowscripter/dynamic-plugin-framework";
5
- import { type SpawnInterfaceAdapterOptions } from "./SpawnInterfaceAdapter.ts";
6
- import { type FetchInterfaceAdapterOptions } from "./FetchInterfaceAdapter.ts";
7
- export default class DefaultPluginServiceProvider implements ServiceProvider {
8
- #private;
9
- readonly serviceId = "PLUGIN_SERVICE";
10
- readonly servicePriority: number;
11
- constructor(pluginManager: MarketplacePluginManager, servicePriority?: number, spawnInterfaceAdapterOptions?: SpawnInterfaceAdapterOptions, fetchInterfaceAdapterOptions?: FetchInterfaceAdapterOptions);
12
- getServiceInfo(_cliConfig: CLIConfig): Promise<ServiceInfo>;
13
- initService(context: Context): Promise<void>;
14
- }
15
- //# sourceMappingURL=DefaultPluginServiceProvider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DefaultPluginServiceProvider.d.ts","sourceRoot":"","sources":["../../../../src/service/plugin/DefaultPluginServiceProvider.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;AAKzE,OAAO,KAAK,EAEV,wBAAwB,EAEzB,MAAM,wCAAwC,CAAC;AAIhD,OAA8B,EAC5B,KAAK,4BAA4B,EAClC,MAAM,4BAA4B,CAAC;AACpC,OAA8B,EAC5B,KAAK,4BAA4B,EAClC,MAAM,4BAA4B,CAAC;AAKpC,MAAM,CAAC,OAAO,OAAO,4BAA6B,YAAW,eAAe;;IAC1E,QAAQ,CAAC,SAAS,oBAAqB;IACvC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;gBAO/B,aAAa,EAAE,wBAAwB,EACvC,eAAe,SAAK,EACpB,4BAA4B,GAAE,4BAAiC,EAC/D,4BAA4B,GAAE,4BAAiC;IAQ3D,cAAc,CAAC,UAAU,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC;IAQjE,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CA4B7C"}
@@ -1,56 +0,0 @@
1
- import { PRINTER_SERVICE_ID, SPAWN_SERVICE_ID } from "@flowscripter/dynamic-cli-framework-api";
2
- import { FETCH_SERVICE_ID } from "@flowscripter/dynamic-cli-framework-api";
3
- import { PLUGIN_SERVICE_ID } from "@flowscripter/dynamic-cli-framework-api";
4
- import DefaultPluginService from "./DefaultPluginService.js";
5
- import { PluginGroupCommand } from "./command/PluginGroupCommand.js";
6
- import SpawnInterfaceAdapter, {} from "./SpawnInterfaceAdapter.js";
7
- import FetchInterfaceAdapter, {} from "./FetchInterfaceAdapter.js";
8
- import getLogger from "../../util/logger.js";
9
- const logger = getLogger("DefaultPluginServiceProvider");
10
- export default class DefaultPluginServiceProvider {
11
- serviceId = PLUGIN_SERVICE_ID;
12
- servicePriority;
13
- #pluginManager;
14
- #spawnInterfaceAdapterOptions;
15
- #fetchInterfaceAdapterOptions;
16
- #pluginService;
17
- constructor(pluginManager, servicePriority = 50, spawnInterfaceAdapterOptions = {}, fetchInterfaceAdapterOptions = {}) {
18
- this.#pluginManager = pluginManager;
19
- this.servicePriority = servicePriority;
20
- this.#spawnInterfaceAdapterOptions = spawnInterfaceAdapterOptions;
21
- this.#fetchInterfaceAdapterOptions = fetchInterfaceAdapterOptions;
22
- }
23
- async getServiceInfo(_cliConfig) {
24
- this.#pluginService = new DefaultPluginService(this.#pluginManager);
25
- return {
26
- service: this.#pluginService,
27
- commands: [new PluginGroupCommand()],
28
- };
29
- }
30
- initService(context) {
31
- if (!context.doesServiceExist(SPAWN_SERVICE_ID)) {
32
- logger.debug("SpawnService not available, plugin manager will spawn processes directly");
33
- }
34
- else if (!("setSpawn" in this.#pluginManager)) {
35
- logger.debug("Plugin manager does not support SpawnCapable, skipping spawn injection");
36
- }
37
- else {
38
- const spawnService = context.getServiceById(SPAWN_SERVICE_ID);
39
- const printerService = context.getServiceById(PRINTER_SERVICE_ID);
40
- const adapter = new SpawnInterfaceAdapter(spawnService, printerService, this.#spawnInterfaceAdapterOptions);
41
- this.#pluginManager.setSpawn(adapter);
42
- }
43
- if (!context.doesServiceExist(FETCH_SERVICE_ID)) {
44
- logger.debug("FetchService not available, plugin manager will fetch directly");
45
- }
46
- else if (!("setFetch" in this.#pluginManager)) {
47
- logger.debug("Plugin manager does not support FetchCapable, skipping fetch injection");
48
- }
49
- else {
50
- const fetchService = context.getServiceById(FETCH_SERVICE_ID);
51
- const adapter = new FetchInterfaceAdapter(fetchService, this.#fetchInterfaceAdapterOptions);
52
- this.#pluginManager.setFetch(adapter);
53
- }
54
- return Promise.resolve();
55
- }
56
- }
@@ -1,77 +0,0 @@
1
- import type { MarketplacePluginManager } from "@flowscripter/dynamic-plugin-framework";
2
- import type { CLIConfig } from "@flowscripter/dynamic-cli-framework-api";
3
- import type BaseCLIFeatureOptions from "./BaseCLIFeatureOptions.ts";
4
- import type { RunResult } from "@flowscripter/dynamic-cli-framework-api";
5
- import { RunState } from "@flowscripter/dynamic-cli-framework-api";
6
- import DefaultRuntimeCLI from "./DefaultRuntimeCLI.ts";
7
- import DefaultPluginServiceProvider from "../service/plugin/DefaultPluginServiceProvider.ts";
8
- import { DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT } from "@flowscripter/dynamic-cli-framework-api";
9
- import { DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT } from "@flowscripter/dynamic-cli-framework-api";
10
- import type { CommandFactory } from "@flowscripter/dynamic-cli-framework-api";
11
- import type { ServiceProviderFactory } from "@flowscripter/dynamic-cli-framework-api";
12
- import process from "node:process";
13
-
14
- /**
15
- * Extension of {@link DefaultRuntimeCLI} that discovers and loads installed plugins before running.
16
- *
17
- * On each invocation of {@link run}, all locally installed plugins are discovered via the
18
- * {@link MarketplacePluginManager}. Commands provided by {@link CommandFactory} extensions and
19
- * service providers provided by {@link ServiceProviderFactory} extensions are registered before
20
- * the runner starts, so they participate in the full initialization lifecycle.
21
- */
22
- export default class DynamicPluginRuntimeCLI extends DefaultRuntimeCLI {
23
- readonly #pluginManager: MarketplacePluginManager;
24
-
25
- constructor(
26
- cliConfig: CLIConfig,
27
- pluginManager: MarketplacePluginManager,
28
- options?: BaseCLIFeatureOptions,
29
- ) {
30
- super(cliConfig, options);
31
- this.#pluginManager = pluginManager;
32
- this.addServiceProvider(new DefaultPluginServiceProvider(pluginManager));
33
- }
34
-
35
- override async run(): Promise<RunResult> {
36
- try {
37
- await this.loadPlugins();
38
- } catch (err) {
39
- console.error(err);
40
- process.exit(RunState.RUNTIME_ERROR);
41
- }
42
- return super.run();
43
- }
44
-
45
- async loadPlugins(): Promise<void> {
46
- await this.#pluginManager.registerExtensions(
47
- DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT,
48
- );
49
- await this.#pluginManager.registerExtensions(
50
- DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT,
51
- );
52
-
53
- const commandFactoryExtensions = await this.#pluginManager.getRegisteredExtensions(
54
- DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT,
55
- );
56
- for (const ext of commandFactoryExtensions) {
57
- const factory = (await this.#pluginManager.instantiate(
58
- ext.extensionHandle,
59
- )) as CommandFactory;
60
- for (const command of factory.getCommands()) {
61
- this.addCommand(command);
62
- }
63
- }
64
-
65
- const spFactoryExtensions = await this.#pluginManager.getRegisteredExtensions(
66
- DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT,
67
- );
68
- for (const ext of spFactoryExtensions) {
69
- const factory = (await this.#pluginManager.instantiate(
70
- ext.extensionHandle,
71
- )) as ServiceProviderFactory;
72
- for (const sp of factory.getServiceProviders()) {
73
- this.addServiceProvider(sp);
74
- }
75
- }
76
- }
77
- }
@@ -1,82 +0,0 @@
1
- import type { ServiceInfo, ServiceProvider } from "@flowscripter/dynamic-cli-framework-api";
2
- import type { Context } from "@flowscripter/dynamic-cli-framework-api";
3
- import type { CLIConfig } from "@flowscripter/dynamic-cli-framework-api";
4
- import type { PrinterService, SpawnService } from "@flowscripter/dynamic-cli-framework-api";
5
- import { PRINTER_SERVICE_ID, SPAWN_SERVICE_ID } from "@flowscripter/dynamic-cli-framework-api";
6
- import type { FetchService } from "@flowscripter/dynamic-cli-framework-api";
7
- import { FETCH_SERVICE_ID } from "@flowscripter/dynamic-cli-framework-api";
8
- import type {
9
- FetchCapable,
10
- MarketplacePluginManager,
11
- SpawnCapable,
12
- } from "@flowscripter/dynamic-plugin-framework";
13
- import { PLUGIN_SERVICE_ID } from "@flowscripter/dynamic-cli-framework-api";
14
- import DefaultPluginService from "./DefaultPluginService.ts";
15
- import { PluginGroupCommand } from "./command/PluginGroupCommand.ts";
16
- import SpawnInterfaceAdapter, {
17
- type SpawnInterfaceAdapterOptions,
18
- } from "./SpawnInterfaceAdapter.ts";
19
- import FetchInterfaceAdapter, {
20
- type FetchInterfaceAdapterOptions,
21
- } from "./FetchInterfaceAdapter.ts";
22
- import getLogger from "../../util/logger.ts";
23
-
24
- const logger = getLogger("DefaultPluginServiceProvider");
25
-
26
- export default class DefaultPluginServiceProvider implements ServiceProvider {
27
- readonly serviceId = PLUGIN_SERVICE_ID;
28
- readonly servicePriority: number;
29
- readonly #pluginManager: MarketplacePluginManager;
30
- readonly #spawnInterfaceAdapterOptions: SpawnInterfaceAdapterOptions;
31
- readonly #fetchInterfaceAdapterOptions: FetchInterfaceAdapterOptions;
32
- #pluginService: DefaultPluginService | undefined;
33
-
34
- constructor(
35
- pluginManager: MarketplacePluginManager,
36
- servicePriority = 50,
37
- spawnInterfaceAdapterOptions: SpawnInterfaceAdapterOptions = {},
38
- fetchInterfaceAdapterOptions: FetchInterfaceAdapterOptions = {},
39
- ) {
40
- this.#pluginManager = pluginManager;
41
- this.servicePriority = servicePriority;
42
- this.#spawnInterfaceAdapterOptions = spawnInterfaceAdapterOptions;
43
- this.#fetchInterfaceAdapterOptions = fetchInterfaceAdapterOptions;
44
- }
45
-
46
- async getServiceInfo(_cliConfig: CLIConfig): Promise<ServiceInfo> {
47
- this.#pluginService = new DefaultPluginService(this.#pluginManager);
48
- return {
49
- service: this.#pluginService,
50
- commands: [new PluginGroupCommand()],
51
- };
52
- }
53
-
54
- initService(context: Context): Promise<void> {
55
- if (!context.doesServiceExist(SPAWN_SERVICE_ID)) {
56
- logger.debug("SpawnService not available, plugin manager will spawn processes directly");
57
- } else if (!("setSpawn" in this.#pluginManager)) {
58
- logger.debug("Plugin manager does not support SpawnCapable, skipping spawn injection");
59
- } else {
60
- const spawnService = context.getServiceById(SPAWN_SERVICE_ID) as SpawnService;
61
- const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
62
- const adapter = new SpawnInterfaceAdapter(
63
- spawnService,
64
- printerService,
65
- this.#spawnInterfaceAdapterOptions,
66
- );
67
- (this.#pluginManager as unknown as SpawnCapable).setSpawn(adapter);
68
- }
69
-
70
- if (!context.doesServiceExist(FETCH_SERVICE_ID)) {
71
- logger.debug("FetchService not available, plugin manager will fetch directly");
72
- } else if (!("setFetch" in this.#pluginManager)) {
73
- logger.debug("Plugin manager does not support FetchCapable, skipping fetch injection");
74
- } else {
75
- const fetchService = context.getServiceById(FETCH_SERVICE_ID) as FetchService;
76
- const adapter = new FetchInterfaceAdapter(fetchService, this.#fetchInterfaceAdapterOptions);
77
- (this.#pluginManager as unknown as FetchCapable).setFetch(adapter);
78
- }
79
-
80
- return Promise.resolve();
81
- }
82
- }