@flowscripter/dynamic-cli-framework 3.0.2 → 4.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 (48) 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/launcher.d.ts +0 -2
  10. package/dist/src/launcher.d.ts.map +1 -1
  11. package/dist/src/launcher.js +0 -20
  12. package/dist/src/service/completion/CompletionServiceProvider.js +4 -4
  13. package/dist/src/service/configuration/ConfigurationServiceProvider.d.ts +19 -8
  14. package/dist/src/service/configuration/ConfigurationServiceProvider.d.ts.map +1 -1
  15. package/dist/src/service/configuration/ConfigurationServiceProvider.js +26 -33
  16. package/dist/src/service/configuration/DefaultKeyValueService.d.ts +6 -6
  17. package/dist/src/service/configuration/DefaultKeyValueService.d.ts.map +1 -1
  18. package/dist/src/service/configuration/DefaultKeyValueService.js +60 -19
  19. package/dist/src/service/configuration/resolveSecrets.d.ts +11 -0
  20. package/dist/src/service/configuration/resolveSecrets.d.ts.map +1 -0
  21. package/dist/src/service/configuration/resolveSecrets.js +31 -0
  22. package/dist/src/service/plugin/DefaultPluginService.d.ts +5 -2
  23. package/dist/src/service/plugin/DefaultPluginService.d.ts.map +1 -1
  24. package/dist/src/service/plugin/DefaultPluginService.js +21 -2
  25. package/dist/src/service/plugin/PluginServiceProvider.d.ts +17 -0
  26. package/dist/src/service/plugin/PluginServiceProvider.d.ts.map +1 -0
  27. package/dist/src/service/plugin/PluginServiceProvider.js +95 -0
  28. package/dist/src/service/upgrade/UpgradeServiceProvider.js +4 -4
  29. package/index.ts +2 -7
  30. package/package.json +3 -3
  31. package/src/cli/BaseCLI.ts +17 -0
  32. package/src/cli/BaseCLIFeatureOptions.ts +7 -0
  33. package/src/launcher.ts +0 -35
  34. package/src/service/completion/CompletionServiceProvider.ts +4 -4
  35. package/src/service/configuration/ConfigurationServiceProvider.ts +36 -40
  36. package/src/service/configuration/DefaultKeyValueService.ts +76 -22
  37. package/src/service/configuration/resolveSecrets.ts +35 -0
  38. package/src/service/plugin/DefaultPluginService.ts +41 -3
  39. package/src/service/plugin/PluginServiceProvider.ts +142 -0
  40. package/src/service/upgrade/UpgradeServiceProvider.ts +4 -4
  41. package/dist/src/cli/DynamicPluginRuntimeCLI.d.ts +0 -20
  42. package/dist/src/cli/DynamicPluginRuntimeCLI.d.ts.map +0 -1
  43. package/dist/src/cli/DynamicPluginRuntimeCLI.js +0 -50
  44. package/dist/src/service/plugin/DefaultPluginServiceProvider.d.ts +0 -15
  45. package/dist/src/service/plugin/DefaultPluginServiceProvider.d.ts.map +0 -1
  46. package/dist/src/service/plugin/DefaultPluginServiceProvider.js +0 -56
  47. package/src/cli/DynamicPluginRuntimeCLI.ts +0 -77
  48. package/src/service/plugin/DefaultPluginServiceProvider.ts +0 -82
@@ -0,0 +1,35 @@
1
+ import { SECRET_SENTINEL_PREFIX } from "@flowscripter/dynamic-cli-framework-api";
2
+
3
+ /**
4
+ * Recursively walk the provided value and resolve any string leaf - at any depth - which starts
5
+ * with {@link SECRET_SENTINEL_PREFIX}, via the provided resolver callback.
6
+ *
7
+ * @param value the value to walk (a JSON-serializable value or a `PopulatedValues` /
8
+ * `PopulatedValueType` tree).
9
+ * @param resolveSecret callback used to resolve a sentinel-prefixed string (with the prefix
10
+ * stripped) to its actual value. Should throw if the secret cannot be found.
11
+ */
12
+ export default async function resolveSecrets<T>(
13
+ value: T,
14
+ resolveSecret: (sentinelValue: string) => Promise<unknown>,
15
+ ): Promise<T> {
16
+ if (typeof value === "string" && value.startsWith(SECRET_SENTINEL_PREFIX)) {
17
+ const bunSecretName = value.slice(SECRET_SENTINEL_PREFIX.length);
18
+ return (await resolveSecret(bunSecretName)) as unknown as T;
19
+ }
20
+ if (typeof value === "object" && value !== null) {
21
+ if (Array.isArray(value)) {
22
+ const resolved = [];
23
+ for (const item of value) {
24
+ resolved.push(await resolveSecrets(item, resolveSecret));
25
+ }
26
+ return resolved as unknown as T;
27
+ }
28
+ const resolved: Record<string, unknown> = {};
29
+ for (const [key, val] of Object.entries(value)) {
30
+ resolved[key] = await resolveSecrets(val, resolveSecret);
31
+ }
32
+ return resolved as unknown as T;
33
+ }
34
+ return value;
35
+ }
@@ -1,15 +1,53 @@
1
1
  import type { PluginService } from "@flowscripter/dynamic-cli-framework-api";
2
+ import type { KeyValueService } from "@flowscripter/dynamic-cli-framework-api";
2
3
  import type {
3
4
  MarketplacePluginManager,
4
5
  SearchQuery,
5
6
  VersionedPluginDescriptor,
7
+ NpmjsPluginRepositoryConfig,
8
+ NpmPluginRepositoryConfig,
9
+ } from "@flowscripter/dynamic-plugin-framework";
10
+ import {
11
+ NpmPluginManager,
12
+ NpmjsPluginRepository,
13
+ NpmPluginRepository,
6
14
  } from "@flowscripter/dynamic-plugin-framework";
7
15
 
8
16
  export default class DefaultPluginService implements PluginService {
9
- readonly #pluginManager: MarketplacePluginManager;
17
+ readonly #defaultRemoteConfig: NpmjsPluginRepositoryConfig;
18
+ readonly #defaultLocalConfig: NpmPluginRepositoryConfig;
19
+ #pluginManager: MarketplacePluginManager;
20
+
21
+ constructor(remoteConfig: NpmjsPluginRepositoryConfig, localConfig: NpmPluginRepositoryConfig) {
22
+ this.#defaultRemoteConfig = remoteConfig;
23
+ this.#defaultLocalConfig = localConfig;
24
+ this.#pluginManager = new NpmPluginManager(
25
+ [new NpmjsPluginRepository(remoteConfig)],
26
+ new NpmPluginRepository(localConfig),
27
+ );
28
+ }
29
+
30
+ get pluginManager(): MarketplacePluginManager {
31
+ return this.#pluginManager;
32
+ }
10
33
 
11
- constructor(pluginManager: MarketplacePluginManager) {
12
- this.#pluginManager = pluginManager;
34
+ async applyKeyValueOverrides(keyValueService: KeyValueService): Promise<void> {
35
+ let remotesConfig: NpmjsPluginRepositoryConfig[] = [this.#defaultRemoteConfig];
36
+ if (await keyValueService.has("remotes-config")) {
37
+ remotesConfig = (await keyValueService.get(
38
+ "remotes-config",
39
+ )) as unknown as NpmjsPluginRepositoryConfig[];
40
+ }
41
+ let localConfig: NpmPluginRepositoryConfig = this.#defaultLocalConfig;
42
+ if (await keyValueService.has("local-config")) {
43
+ localConfig = (await keyValueService.get(
44
+ "local-config",
45
+ )) as unknown as NpmPluginRepositoryConfig;
46
+ }
47
+ this.#pluginManager = new NpmPluginManager(
48
+ remotesConfig.map((config) => new NpmjsPluginRepository(config)),
49
+ new NpmPluginRepository(localConfig),
50
+ );
13
51
  }
14
52
 
15
53
  search(query: Readonly<SearchQuery>): AsyncIterable<Readonly<VersionedPluginDescriptor>> {
@@ -0,0 +1,142 @@
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 { KEY_VALUE_SERVICE_ID } from "@flowscripter/dynamic-cli-framework-api";
9
+ import type { KeyValueService } from "@flowscripter/dynamic-cli-framework-api";
10
+ import { DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT } from "@flowscripter/dynamic-cli-framework-api";
11
+ import { DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT } from "@flowscripter/dynamic-cli-framework-api";
12
+ import type { CommandFactory } from "@flowscripter/dynamic-cli-framework-api";
13
+ import type { ServiceProviderFactory } from "@flowscripter/dynamic-cli-framework-api";
14
+ import type {
15
+ FetchCapable,
16
+ NpmjsPluginRepositoryConfig,
17
+ NpmPluginRepositoryConfig,
18
+ SpawnCapable,
19
+ } from "@flowscripter/dynamic-plugin-framework";
20
+ import { PLUGIN_SERVICE_ID } from "@flowscripter/dynamic-cli-framework-api";
21
+ import DefaultPluginService from "./DefaultPluginService.ts";
22
+ import { PluginGroupCommand } from "./command/PluginGroupCommand.ts";
23
+ import SpawnInterfaceAdapter, {
24
+ type SpawnInterfaceAdapterOptions,
25
+ } from "./SpawnInterfaceAdapter.ts";
26
+ import FetchInterfaceAdapter, {
27
+ type FetchInterfaceAdapterOptions,
28
+ } from "./FetchInterfaceAdapter.ts";
29
+ import DefaultCommandRegistry from "../../runtime/registry/DefaultCommandRegistry.ts";
30
+ import DefaultServiceProviderRegistry from "../../runtime/registry/DefaultServiceProviderRegistry.ts";
31
+ import type DefaultContext from "../../runtime/DefaultContext.ts";
32
+ import getLogger from "../../util/logger.ts";
33
+
34
+ const logger = getLogger("PluginServiceProvider");
35
+
36
+ export default class PluginServiceProvider implements ServiceProvider {
37
+ readonly serviceId = PLUGIN_SERVICE_ID;
38
+ readonly servicePriority: number;
39
+ readonly #remoteConfig: NpmjsPluginRepositoryConfig;
40
+ readonly #localConfig: NpmPluginRepositoryConfig;
41
+ readonly #commandRegistry: DefaultCommandRegistry;
42
+ readonly #serviceProviderRegistry: DefaultServiceProviderRegistry;
43
+ readonly #spawnInterfaceAdapterOptions: SpawnInterfaceAdapterOptions;
44
+ readonly #fetchInterfaceAdapterOptions: FetchInterfaceAdapterOptions;
45
+ #pluginService: DefaultPluginService | undefined;
46
+ #cliConfig: CLIConfig | undefined;
47
+
48
+ constructor(
49
+ servicePriority: number,
50
+ remoteConfig: NpmjsPluginRepositoryConfig,
51
+ localConfig: NpmPluginRepositoryConfig,
52
+ commandRegistry: DefaultCommandRegistry,
53
+ serviceProviderRegistry: DefaultServiceProviderRegistry,
54
+ spawnInterfaceAdapterOptions: SpawnInterfaceAdapterOptions = {},
55
+ fetchInterfaceAdapterOptions: FetchInterfaceAdapterOptions = {},
56
+ ) {
57
+ this.servicePriority = servicePriority;
58
+ this.#remoteConfig = remoteConfig;
59
+ this.#localConfig = localConfig;
60
+ this.#commandRegistry = commandRegistry;
61
+ this.#serviceProviderRegistry = serviceProviderRegistry;
62
+ this.#spawnInterfaceAdapterOptions = spawnInterfaceAdapterOptions;
63
+ this.#fetchInterfaceAdapterOptions = fetchInterfaceAdapterOptions;
64
+ }
65
+
66
+ async getServiceInfo(cliConfig: CLIConfig): Promise<ServiceInfo> {
67
+ this.#cliConfig = cliConfig;
68
+ this.#pluginService = new DefaultPluginService(this.#remoteConfig, this.#localConfig);
69
+ return {
70
+ service: this.#pluginService,
71
+ commands: [new PluginGroupCommand()],
72
+ };
73
+ }
74
+
75
+ async initService(context: Context): Promise<void> {
76
+ const pluginService = this.#pluginService!;
77
+
78
+ if (context.doesServiceExist(KEY_VALUE_SERVICE_ID)) {
79
+ const keyValueService = context.getServiceById(KEY_VALUE_SERVICE_ID) as KeyValueService;
80
+ await pluginService.applyKeyValueOverrides(keyValueService);
81
+ }
82
+
83
+ const pluginManager = pluginService.pluginManager;
84
+
85
+ if (!context.doesServiceExist(SPAWN_SERVICE_ID)) {
86
+ logger.debug("SpawnService not available, plugin manager will spawn processes directly");
87
+ } else if (!("setSpawn" in pluginManager)) {
88
+ logger.debug("Plugin manager does not support SpawnCapable, skipping spawn injection");
89
+ } else {
90
+ const spawnService = context.getServiceById(SPAWN_SERVICE_ID) as SpawnService;
91
+ const printerService = context.getServiceById(PRINTER_SERVICE_ID) as PrinterService;
92
+ const adapter = new SpawnInterfaceAdapter(
93
+ spawnService,
94
+ printerService,
95
+ this.#spawnInterfaceAdapterOptions,
96
+ );
97
+ (pluginManager as unknown as SpawnCapable).setSpawn(adapter);
98
+ }
99
+
100
+ if (!context.doesServiceExist(FETCH_SERVICE_ID)) {
101
+ logger.debug("FetchService not available, plugin manager will fetch directly");
102
+ } else if (!("setFetch" in pluginManager)) {
103
+ logger.debug("Plugin manager does not support FetchCapable, skipping fetch injection");
104
+ } else {
105
+ const fetchService = context.getServiceById(FETCH_SERVICE_ID) as FetchService;
106
+ const adapter = new FetchInterfaceAdapter(fetchService, this.#fetchInterfaceAdapterOptions);
107
+ (pluginManager as unknown as FetchCapable).setFetch(adapter);
108
+ }
109
+
110
+ await pluginManager.registerExtensions(DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT);
111
+ await pluginManager.registerExtensions(
112
+ DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT,
113
+ );
114
+
115
+ const commandFactoryExtensions = await pluginManager.getRegisteredExtensions(
116
+ DYNAMIC_CLI_FRAMEWORK_COMMAND_FACTORY_EXTENSION_POINT,
117
+ );
118
+ for (const ext of commandFactoryExtensions) {
119
+ const factory = (await pluginManager.instantiate(ext.extensionHandle)) as CommandFactory;
120
+ for (const command of factory.getCommands()) {
121
+ this.#commandRegistry.addCommand(command);
122
+ }
123
+ }
124
+
125
+ const spFactoryExtensions = await pluginManager.getRegisteredExtensions(
126
+ DYNAMIC_CLI_FRAMEWORK_SERVICE_PROVIDER_FACTORY_EXTENSION_POINT,
127
+ );
128
+ for (const ext of spFactoryExtensions) {
129
+ const factory = (await pluginManager.instantiate(
130
+ ext.extensionHandle,
131
+ )) as ServiceProviderFactory;
132
+ for (const sp of factory.getServiceProviders()) {
133
+ const info = await sp.getServiceInfo(this.#cliConfig!);
134
+ if (info.service) {
135
+ (context as DefaultContext).addServiceInstance(sp.serviceId, info.service);
136
+ }
137
+ info.commands.forEach((cmd) => this.#commandRegistry.addCommand(cmd, sp.serviceId));
138
+ this.#serviceProviderRegistry.addServiceProvider(sp);
139
+ }
140
+ }
141
+ }
142
+ }
@@ -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
 
@@ -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
- }