@flowscripter/dynamic-cli-framework 12.0.1 → 12.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/src/cli/BaseCLI.d.ts.map +1 -1
- package/dist/src/cli/BaseCLI.js +3 -1
- package/dist/src/cli/BaseCLIFeatureOptions.d.ts +6 -0
- package/dist/src/cli/BaseCLIFeatureOptions.d.ts.map +1 -1
- package/dist/src/runtime/runner.d.ts.map +1 -1
- package/dist/src/runtime/runner.js +4 -1
- package/dist/src/service/configuration/ConfigurationServiceProvider.d.ts +33 -15
- package/dist/src/service/configuration/ConfigurationServiceProvider.d.ts.map +1 -1
- package/dist/src/service/configuration/ConfigurationServiceProvider.js +80 -173
- package/dist/src/service/configuration/DefaultConfigurationService.d.ts +78 -0
- package/dist/src/service/configuration/DefaultConfigurationService.d.ts.map +1 -0
- package/dist/src/service/configuration/DefaultConfigurationService.js +296 -0
- package/dist/src/service/configuration/DefaultKeyValueService.d.ts.map +1 -1
- package/dist/src/service/configuration/DefaultKeyValueService.js +7 -3
- package/dist/src/service/configuration/DefaultSecretService.d.ts +17 -2
- package/dist/src/service/configuration/DefaultSecretService.d.ts.map +1 -1
- package/dist/src/service/configuration/DefaultSecretService.js +44 -5
- package/dist/src/service/configuration/KeyValueServiceProvider.d.ts +3 -1
- package/dist/src/service/configuration/KeyValueServiceProvider.d.ts.map +1 -1
- package/dist/src/service/configuration/KeyValueServiceProvider.js +6 -3
- package/dist/src/service/configuration/command/ConfigDumpSubCommand.d.ts +3 -7
- package/dist/src/service/configuration/command/ConfigDumpSubCommand.d.ts.map +1 -1
- package/dist/src/service/configuration/command/ConfigDumpSubCommand.js +5 -10
- package/dist/src/service/configuration/command/ConfigGetSubCommand.d.ts +16 -0
- package/dist/src/service/configuration/command/ConfigGetSubCommand.d.ts.map +1 -0
- package/dist/src/service/configuration/command/ConfigGetSubCommand.js +137 -0
- package/dist/src/service/configuration/command/ConfigSetSubCommand.d.ts +18 -0
- package/dist/src/service/configuration/command/ConfigSetSubCommand.d.ts.map +1 -0
- package/dist/src/service/configuration/command/ConfigSetSubCommand.js +289 -0
- package/dist/src/service/configuration/command/ConfigUnsetSubCommand.d.ts +15 -0
- package/dist/src/service/configuration/command/ConfigUnsetSubCommand.d.ts.map +1 -0
- package/dist/src/service/configuration/command/ConfigUnsetSubCommand.js +101 -0
- package/dist/src/service/configuration/configTargets.d.ts +91 -0
- package/dist/src/service/configuration/configTargets.d.ts.map +1 -0
- package/dist/src/service/configuration/configTargets.js +348 -0
- package/dist/src/service/configuration/format/ConfigFormat.d.ts +42 -0
- package/dist/src/service/configuration/format/ConfigFormat.d.ts.map +1 -0
- package/dist/src/service/configuration/format/ConfigFormat.js +0 -0
- package/dist/src/service/configuration/format/JsonConfigFormat.d.ts +7 -0
- package/dist/src/service/configuration/format/JsonConfigFormat.d.ts.map +1 -0
- package/dist/src/service/configuration/format/JsonConfigFormat.js +17 -0
- package/dist/src/service/configuration/format/TomlConfigFormat.d.ts +10 -0
- package/dist/src/service/configuration/format/TomlConfigFormat.d.ts.map +1 -0
- package/dist/src/service/configuration/format/TomlConfigFormat.js +78 -0
- package/dist/src/service/configuration/format/YamlConfigFormat.d.ts +9 -0
- package/dist/src/service/configuration/format/YamlConfigFormat.d.ts.map +1 -0
- package/dist/src/service/configuration/format/YamlConfigFormat.js +63 -0
- package/dist/src/service/configuration/resolveSecrets.d.ts.map +1 -1
- package/dist/src/service/configuration/resolveSecrets.js +7 -1
- package/dist/toml.d.ts +2 -0
- package/dist/toml.d.ts.map +1 -0
- package/dist/toml.js +1 -0
- package/dist/yaml.d.ts +2 -0
- package/dist/yaml.d.ts.map +1 -0
- package/dist/yaml.js +1 -0
- package/index.ts +3 -0
- package/package.json +27 -3
- package/src/cli/BaseCLI.ts +4 -0
- package/src/cli/BaseCLIFeatureOptions.ts +6 -0
- package/src/runtime/runner.ts +4 -1
- package/src/service/configuration/ConfigurationServiceProvider.ts +108 -214
- package/src/service/configuration/DefaultConfigurationService.ts +378 -0
- package/src/service/configuration/DefaultKeyValueService.ts +9 -3
- package/src/service/configuration/DefaultSecretService.ts +51 -8
- package/src/service/configuration/KeyValueServiceProvider.ts +7 -2
- package/src/service/configuration/command/ConfigDumpSubCommand.ts +6 -10
- package/src/service/configuration/command/ConfigGetSubCommand.ts +198 -0
- package/src/service/configuration/command/ConfigSetSubCommand.ts +401 -0
- package/src/service/configuration/command/ConfigUnsetSubCommand.ts +126 -0
- package/src/service/configuration/configTargets.ts +481 -0
- package/src/service/configuration/format/ConfigFormat.ts +42 -0
- package/src/service/configuration/format/JsonConfigFormat.ts +22 -0
- package/src/service/configuration/format/TomlConfigFormat.ts +92 -0
- package/src/service/configuration/format/YamlConfigFormat.ts +72 -0
- package/src/service/configuration/resolveSecrets.ts +7 -1
- package/toml.ts +1 -0
- package/yaml.ts +1 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Document, isMap, isSeq, parseDocument, stringify } from "yaml";
|
|
2
|
+
function isPlainObject(value) {
|
|
3
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function reconcile(doc, path, existing, updated) {
|
|
6
|
+
if (isPlainObject(existing) && isPlainObject(updated)) {
|
|
7
|
+
for (const key of Object.keys(existing)) {
|
|
8
|
+
if (!(key in updated)) {
|
|
9
|
+
doc.deleteIn([...path, key]);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
for (const key of Object.keys(updated)) {
|
|
13
|
+
if (key in existing) {
|
|
14
|
+
reconcile(doc, [...path, key], existing[key], updated[key]);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
doc.setIn([...path, key], updated[key]);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else if (Array.isArray(existing) &&
|
|
22
|
+
Array.isArray(updated) &&
|
|
23
|
+
existing.length === updated.length) {
|
|
24
|
+
updated.forEach((value, index) => reconcile(doc, [...path, index], existing[index], value));
|
|
25
|
+
}
|
|
26
|
+
else if (JSON.stringify(existing) !== JSON.stringify(updated)) {
|
|
27
|
+
doc.setIn(path, updated);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A YAML {@link ConfigFormat} which preserves comments, blank lines and key order when writing changes back.
|
|
32
|
+
*
|
|
33
|
+
* Requires the optional `yaml` peer dependency.
|
|
34
|
+
*/
|
|
35
|
+
const yamlFormat = {
|
|
36
|
+
fileExtension: "yaml",
|
|
37
|
+
parse(text) {
|
|
38
|
+
const doc = parseDocument(text);
|
|
39
|
+
if (doc.errors.length > 0) {
|
|
40
|
+
throw new Error(doc.errors.map((error) => error.message).join("; "));
|
|
41
|
+
}
|
|
42
|
+
const data = doc.toJS() ?? {};
|
|
43
|
+
if (!isPlainObject(data)) {
|
|
44
|
+
throw new Error("top level YAML value must be a mapping");
|
|
45
|
+
}
|
|
46
|
+
return { data, handle: doc };
|
|
47
|
+
},
|
|
48
|
+
apply(handle, changes) {
|
|
49
|
+
const doc = handle;
|
|
50
|
+
const existing = doc.toJS() ?? {};
|
|
51
|
+
if (!isMap(doc.contents) && !isSeq(doc.contents)) {
|
|
52
|
+
doc.contents = doc.createNode(changes);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
reconcile(doc, [], existing, changes);
|
|
56
|
+
}
|
|
57
|
+
return doc.toString();
|
|
58
|
+
},
|
|
59
|
+
serialize(data) {
|
|
60
|
+
return stringify(data);
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
export default yamlFormat;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveSecrets.d.ts","sourceRoot":"","sources":["../../../../src/service/configuration/resolveSecrets.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAA8B,cAAc,CAAC,CAAC,EAC5C,KAAK,EAAE,CAAC,EACR,aAAa,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GACzD,OAAO,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"resolveSecrets.d.ts","sourceRoot":"","sources":["../../../../src/service/configuration/resolveSecrets.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAA8B,cAAc,CAAC,CAAC,EAC5C,KAAK,EAAE,CAAC,EACR,aAAa,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GACzD,OAAO,CAAC,CAAC,CAAC,CA0BZ"}
|
|
@@ -23,7 +23,13 @@ export default async function resolveSecrets(value, resolveSecret) {
|
|
|
23
23
|
}
|
|
24
24
|
const resolved = {};
|
|
25
25
|
for (const [key, val] of Object.entries(value)) {
|
|
26
|
-
|
|
26
|
+
// defineProperty so a "__proto__" key is an own property rather than replacing the prototype
|
|
27
|
+
Object.defineProperty(resolved, key, {
|
|
28
|
+
value: await resolveSecrets(val, resolveSecret),
|
|
29
|
+
enumerable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
});
|
|
27
33
|
}
|
|
28
34
|
return resolved;
|
|
29
35
|
}
|
package/dist/toml.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toml.d.ts","sourceRoot":"","sources":["../toml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,wDAAwD,CAAC"}
|
package/dist/toml.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as tomlFormat } from "./src/service/configuration/format/TomlConfigFormat.js";
|
package/dist/yaml.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../yaml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,wDAAwD,CAAC"}
|
package/dist/yaml.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as yamlFormat } from "./src/service/configuration/format/YamlConfigFormat.js";
|
package/index.ts
CHANGED
|
@@ -68,6 +68,9 @@ export {
|
|
|
68
68
|
default as ConfigurationServiceProvider,
|
|
69
69
|
type KeyValueServiceScopeType,
|
|
70
70
|
} from "./src/service/configuration/ConfigurationServiceProvider.ts";
|
|
71
|
+
export type { default as ConfigFormat } from "./src/service/configuration/format/ConfigFormat.ts";
|
|
72
|
+
export type { ConfigData } from "./src/service/configuration/format/ConfigFormat.ts";
|
|
73
|
+
export { default as jsonFormat } from "./src/service/configuration/format/JsonConfigFormat.ts";
|
|
71
74
|
export { default as KeyValueServiceProvider } from "./src/service/configuration/KeyValueServiceProvider.ts";
|
|
72
75
|
|
|
73
76
|
export { PRINTER_SERVICE_ID } from "@flowscripter/dynamic-cli-framework-api";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowscripter/dynamic-cli-framework",
|
|
3
|
-
"version": "12.0
|
|
3
|
+
"version": "12.2.0",
|
|
4
4
|
"description": "A framework for developing CLI applications which supports dynamic discovery and installation of new commands",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
"src",
|
|
23
23
|
"index.ts",
|
|
24
24
|
"cli-plugin.ts",
|
|
25
|
+
"yaml.ts",
|
|
26
|
+
"toml.ts",
|
|
25
27
|
"README.md",
|
|
26
28
|
"LICENSE"
|
|
27
29
|
],
|
|
@@ -40,6 +42,16 @@
|
|
|
40
42
|
"bun": "./cli-plugin.ts",
|
|
41
43
|
"types": "./dist/cli-plugin.d.ts",
|
|
42
44
|
"default": "./dist/cli-plugin.js"
|
|
45
|
+
},
|
|
46
|
+
"./yaml": {
|
|
47
|
+
"bun": "./yaml.ts",
|
|
48
|
+
"types": "./dist/yaml.d.ts",
|
|
49
|
+
"default": "./dist/yaml.js"
|
|
50
|
+
},
|
|
51
|
+
"./toml": {
|
|
52
|
+
"bun": "./toml.ts",
|
|
53
|
+
"types": "./dist/toml.d.ts",
|
|
54
|
+
"default": "./dist/toml.js"
|
|
43
55
|
}
|
|
44
56
|
},
|
|
45
57
|
"publishConfig": {
|
|
@@ -61,14 +73,26 @@
|
|
|
61
73
|
"supports-terminal-graphics": "^0.1.0"
|
|
62
74
|
},
|
|
63
75
|
"devDependencies": {
|
|
76
|
+
"@decimalturn/toml-patch": "^3.3.1",
|
|
64
77
|
"@types/bun": "^1.4.3",
|
|
65
78
|
"@types/node": "^26.6.5",
|
|
66
79
|
"@types/semver": "^7.8.0",
|
|
67
80
|
"oxfmt": "0.74.0",
|
|
68
|
-
"oxlint": "1.89.0"
|
|
81
|
+
"oxlint": "1.89.0",
|
|
82
|
+
"yaml": "^2.9.1"
|
|
69
83
|
},
|
|
70
84
|
"peerDependencies": {
|
|
71
|
-
"
|
|
85
|
+
"@decimalturn/toml-patch": "^3.3.1",
|
|
86
|
+
"typescript": "^7.0.2",
|
|
87
|
+
"yaml": "^2.9.1"
|
|
88
|
+
},
|
|
89
|
+
"peerDependenciesMeta": {
|
|
90
|
+
"yaml": {
|
|
91
|
+
"optional": true
|
|
92
|
+
},
|
|
93
|
+
"@decimalturn/toml-patch": {
|
|
94
|
+
"optional": true
|
|
95
|
+
}
|
|
72
96
|
},
|
|
73
97
|
"typedocOptions": {
|
|
74
98
|
"readme": "none",
|
package/src/cli/BaseCLI.ts
CHANGED
|
@@ -31,6 +31,7 @@ import ShutdownServiceProvider from "../service/shutdown/ShutdownServiceProvider
|
|
|
31
31
|
import StartupServiceProvider from "../service/startup/StartupServiceProvider.ts";
|
|
32
32
|
import type { StartupTask } from "@flowscripter/dynamic-cli-framework-api";
|
|
33
33
|
import { shutdownState } from "../service/shutdown/ShutdownState.ts";
|
|
34
|
+
import jsonFormat from "../service/configuration/format/JsonConfigFormat.ts";
|
|
34
35
|
import ConfigurationServiceProvider from "../service/configuration/ConfigurationServiceProvider.ts";
|
|
35
36
|
import KeyValueServiceProvider from "../service/configuration/KeyValueServiceProvider.ts";
|
|
36
37
|
import PrinterServiceProvider from "../service/printer/PrinterServiceProvider.ts";
|
|
@@ -162,6 +163,7 @@ export default class BaseCLI implements CLI {
|
|
|
162
163
|
}
|
|
163
164
|
this.#cliConfig = cliConfig;
|
|
164
165
|
this.#options = {
|
|
166
|
+
configFormat: jsonFormat,
|
|
165
167
|
configFileSupportEnabled: false,
|
|
166
168
|
envVarsSupportEnabled: false,
|
|
167
169
|
keyValueServiceEnabled: false,
|
|
@@ -392,6 +394,8 @@ export default class BaseCLI implements CLI {
|
|
|
392
394
|
this.#options.envVarsSupportEnabled,
|
|
393
395
|
this.#options.configFileSupportEnabled,
|
|
394
396
|
this.#options.secretServiceEnabled,
|
|
397
|
+
this.#options.configFormat,
|
|
398
|
+
this.#commandRegistry,
|
|
395
399
|
);
|
|
396
400
|
this.addServiceProvider(configurationServiceProvider);
|
|
397
401
|
const keyValueServiceProvider = new KeyValueServiceProvider(
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type ConfigFormat from "../service/configuration/format/ConfigFormat.ts";
|
|
1
2
|
import type { UpgradeLocationsConfig } from "../service/upgrade/UpgradeLocationsConfig.ts";
|
|
2
3
|
import type {
|
|
3
4
|
NpmjsPluginRepositoryConfig,
|
|
@@ -6,6 +7,11 @@ import type {
|
|
|
6
7
|
|
|
7
8
|
export default interface BaseCLIFeatureOptions {
|
|
8
9
|
readonly configFileSupportEnabled?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* The syntax of the configuration file. Defaults to JSON. YAML and TOML are available from the
|
|
12
|
+
* `@flowscripter/dynamic-cli-framework/yaml` and `@flowscripter/dynamic-cli-framework/toml` entry points.
|
|
13
|
+
*/
|
|
14
|
+
readonly configFormat?: ConfigFormat;
|
|
9
15
|
readonly envVarsSupportEnabled?: boolean;
|
|
10
16
|
readonly keyValueServiceEnabled?: boolean;
|
|
11
17
|
readonly secretServiceEnabled?: boolean;
|
package/src/runtime/runner.ts
CHANGED
|
@@ -121,8 +121,11 @@ async function executeParsedCommand(
|
|
|
121
121
|
parseResult!.populatedArgumentValues,
|
|
122
122
|
);
|
|
123
123
|
|
|
124
|
+
const commandScopeKey = parseResult.groupCommand
|
|
125
|
+
? `${parseResult.groupCommand.name}:${parseResult.command.name}`
|
|
126
|
+
: parseResult.command.name;
|
|
124
127
|
const commandContext = keyValueServiceProvider
|
|
125
|
-
? keyValueServiceProvider.getContextForScope(context, "command",
|
|
128
|
+
? keyValueServiceProvider.getContextForScope(context, "command", commandScopeKey)
|
|
126
129
|
: context;
|
|
127
130
|
if (isSubCommand(parseResult.command)) {
|
|
128
131
|
await parseResult.command.execute(
|