@shell-shock/core 0.17.10 → 0.17.11
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/api.cjs +31 -143
- package/dist/api.cjs.map +1 -0
- package/dist/api.d.cts +2 -77
- package/dist/api.d.cts.map +1 -1
- package/dist/api.d.mts +2 -76
- package/dist/api.d.mts.map +1 -1
- package/dist/api.mjs +30 -140
- package/dist/api.mjs.map +1 -1
- package/dist/components/command-validation-logic.cjs +14 -15
- package/dist/components/command-validation-logic.cjs.map +1 -0
- package/dist/components/command-validation-logic.d.cts +1 -3
- package/dist/components/command-validation-logic.d.cts.map +1 -1
- package/dist/components/command-validation-logic.d.mts +1 -3
- package/dist/components/command-validation-logic.d.mts.map +1 -1
- package/dist/components/command-validation-logic.mjs +12 -13
- package/dist/components/command-validation-logic.mjs.map +1 -1
- package/dist/components/docs.cjs +6 -6
- package/dist/components/docs.cjs.map +1 -0
- package/dist/components/docs.d.cts +4 -5
- package/dist/components/docs.d.cts.map +1 -1
- package/dist/components/docs.d.mts +4 -5
- package/dist/components/docs.d.mts.map +1 -1
- package/dist/components/docs.mjs +4 -4
- package/dist/components/docs.mjs.map +1 -1
- package/dist/components/exec-builtin.cjs +9 -11
- package/dist/components/exec-builtin.cjs.map +1 -0
- package/dist/components/exec-builtin.d.cts +1 -2
- package/dist/components/exec-builtin.d.cts.map +1 -1
- package/dist/components/exec-builtin.d.mts +1 -2
- package/dist/components/exec-builtin.d.mts.map +1 -1
- package/dist/components/exec-builtin.mjs +7 -10
- package/dist/components/exec-builtin.mjs.map +1 -1
- package/dist/components/helpers.cjs +4 -5
- package/dist/components/helpers.cjs.map +1 -0
- package/dist/components/helpers.d.cts +6 -8
- package/dist/components/helpers.d.cts.map +1 -1
- package/dist/components/helpers.d.mts +6 -8
- package/dist/components/helpers.d.mts.map +1 -1
- package/dist/components/helpers.mjs +2 -3
- package/dist/components/helpers.mjs.map +1 -1
- package/dist/components/options-parser-logic.cjs +29 -30
- package/dist/components/options-parser-logic.cjs.map +1 -0
- package/dist/components/options-parser-logic.d.cts +8 -9
- package/dist/components/options-parser-logic.d.cts.map +1 -1
- package/dist/components/options-parser-logic.d.mts +8 -9
- package/dist/components/options-parser-logic.d.mts.map +1 -1
- package/dist/components/options-parser-logic.mjs +27 -28
- package/dist/components/options-parser-logic.mjs.map +1 -1
- package/dist/components/state-builtin.cjs +3 -2
- package/dist/components/state-builtin.cjs.map +1 -0
- package/dist/components/state-builtin.d.cts +4 -5
- package/dist/components/state-builtin.d.cts.map +1 -1
- package/dist/components/state-builtin.d.mts +4 -5
- package/dist/components/state-builtin.d.mts.map +1 -1
- package/dist/components/state-builtin.mjs +1 -1
- package/dist/components/state-builtin.mjs.map +1 -1
- package/dist/components/usage.cjs +4 -5
- package/dist/components/usage.cjs.map +1 -0
- package/dist/components/usage.d.cts +1 -2
- package/dist/components/usage.d.cts.map +1 -1
- package/dist/components/usage.d.mts +1 -2
- package/dist/components/usage.d.mts.map +1 -1
- package/dist/components/usage.mjs +2 -3
- package/dist/components/usage.mjs.map +1 -1
- package/dist/components/utils-builtin.cjs +5 -4
- package/dist/components/utils-builtin.cjs.map +1 -0
- package/dist/components/utils-builtin.d.cts +7 -8
- package/dist/components/utils-builtin.d.cts.map +1 -1
- package/dist/components/utils-builtin.d.mts +7 -8
- package/dist/components/utils-builtin.d.mts.map +1 -1
- package/dist/components/utils-builtin.mjs +3 -3
- package/dist/components/utils-builtin.mjs.map +1 -1
- package/dist/config.cjs +53 -19
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +29 -8
- package/dist/config.d.cts.map +1 -1
- package/dist/config.d.mts +29 -8
- package/dist/config.d.mts.map +1 -1
- package/dist/config.mjs +51 -18
- package/dist/config.mjs.map +1 -1
- package/dist/contexts/command.cjs +2 -2
- package/dist/contexts/command.cjs.map +1 -0
- package/dist/contexts/command.d.cts.map +1 -1
- package/dist/contexts/command.d.mts.map +1 -1
- package/dist/contexts/command.mjs.map +1 -1
- package/dist/contexts/options.cjs +4 -4
- package/dist/contexts/options.cjs.map +1 -0
- package/dist/contexts/options.d.cts.map +1 -1
- package/dist/contexts/options.d.mts.map +1 -1
- package/dist/contexts/options.mjs +2 -3
- package/dist/contexts/options.mjs.map +1 -1
- package/dist/engine.cjs +138 -0
- package/dist/engine.cjs.map +1 -0
- package/dist/engine.d.cts +79 -0
- package/dist/engine.d.cts.map +1 -0
- package/dist/engine.d.mts +79 -0
- package/dist/engine.d.mts.map +1 -0
- package/dist/engine.mjs +136 -0
- package/dist/engine.mjs.map +1 -0
- package/dist/helpers/automd.cjs +6 -7
- package/dist/helpers/automd.cjs.map +1 -0
- package/dist/helpers/automd.mjs +2 -3
- package/dist/helpers/automd.mjs.map +1 -1
- package/dist/helpers/docs-helpers.cjs +2 -2
- package/dist/helpers/docs-helpers.cjs.map +1 -0
- package/dist/helpers/docs-helpers.mjs.map +1 -1
- package/dist/helpers/get-framework.cjs +24 -0
- package/dist/helpers/get-framework.cjs.map +1 -0
- package/dist/helpers/get-framework.mjs +24 -0
- package/dist/helpers/get-framework.mjs.map +1 -0
- package/dist/helpers/paths.cjs +5 -5
- package/dist/helpers/paths.cjs.map +1 -0
- package/dist/helpers/paths.mjs +4 -4
- package/dist/helpers/paths.mjs.map +1 -1
- package/dist/helpers/persistence.cjs +4 -6
- package/dist/helpers/persistence.cjs.map +1 -0
- package/dist/helpers/persistence.mjs +3 -3
- package/dist/helpers/persistence.mjs.map +1 -1
- package/dist/helpers/update-package-json.cjs +2 -2
- package/dist/helpers/update-package-json.cjs.map +1 -0
- package/dist/helpers/update-package-json.mjs.map +1 -1
- package/dist/helpers/utilities.cjs +3 -3
- package/dist/helpers/utilities.cjs.map +1 -0
- package/dist/helpers/utilities.mjs +1 -1
- package/dist/helpers/utilities.mjs.map +1 -1
- package/dist/helpers/validations.cjs +3 -3
- package/dist/helpers/validations.cjs.map +1 -0
- package/dist/helpers/validations.mjs +1 -3
- package/dist/helpers/validations.mjs.map +1 -1
- package/dist/index.cjs +121 -51
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +80 -5
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +80 -5
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +118 -6
- package/dist/index.mjs.map +1 -0
- package/dist/package.cjs +12 -0
- package/dist/package.cjs.map +1 -0
- package/dist/package.mjs +6 -0
- package/dist/package.mjs.map +1 -0
- package/dist/plugin-utils/compute-bin.cjs +8 -10
- package/dist/plugin-utils/compute-bin.cjs.map +1 -0
- package/dist/plugin-utils/compute-bin.d.cts +2 -2
- package/dist/plugin-utils/compute-bin.d.cts.map +1 -1
- package/dist/plugin-utils/compute-bin.d.mts +2 -2
- package/dist/plugin-utils/compute-bin.d.mts.map +1 -1
- package/dist/plugin-utils/compute-bin.mjs +6 -8
- package/dist/plugin-utils/compute-bin.mjs.map +1 -1
- package/dist/plugin-utils/context-helpers.cjs +7 -14
- package/dist/plugin-utils/context-helpers.cjs.map +1 -0
- package/dist/plugin-utils/context-helpers.d.cts +4 -4
- package/dist/plugin-utils/context-helpers.d.cts.map +1 -1
- package/dist/plugin-utils/context-helpers.d.mts +4 -4
- package/dist/plugin-utils/context-helpers.d.mts.map +1 -1
- package/dist/plugin-utils/context-helpers.mjs +5 -12
- package/dist/plugin-utils/context-helpers.mjs.map +1 -1
- package/dist/plugin-utils/deepkit.cjs +15 -16
- package/dist/plugin-utils/deepkit.cjs.map +1 -0
- package/dist/plugin-utils/deepkit.d.cts +5 -5
- package/dist/plugin-utils/deepkit.d.cts.map +1 -1
- package/dist/plugin-utils/deepkit.d.mts +5 -5
- package/dist/plugin-utils/deepkit.d.mts.map +1 -1
- package/dist/plugin-utils/deepkit.mjs +14 -15
- package/dist/plugin-utils/deepkit.mjs.map +1 -1
- package/dist/plugin-utils/description-helpers.cjs +2 -1
- package/dist/plugin-utils/description-helpers.cjs.map +1 -0
- package/dist/plugin-utils/description-helpers.d.cts.map +1 -1
- package/dist/plugin-utils/description-helpers.d.mts.map +1 -1
- package/dist/plugin-utils/description-helpers.mjs.map +1 -1
- package/dist/plugin-utils/get-command-tree.cjs +2 -1
- package/dist/plugin-utils/get-command-tree.cjs.map +1 -0
- package/dist/plugin-utils/get-command-tree.d.cts.map +1 -1
- package/dist/plugin-utils/get-command-tree.d.mts.map +1 -1
- package/dist/plugin-utils/get-command-tree.mjs.map +1 -1
- package/dist/plugin-utils/index.cjs +1 -1
- package/dist/plugin-utils/index.d.cts +2 -2
- package/dist/plugin-utils/index.d.mts +2 -2
- package/dist/plugin-utils/index.mjs +2 -2
- package/dist/plugin-utils/reflect.cjs +5 -5
- package/dist/plugin-utils/reflect.cjs.map +1 -0
- package/dist/plugin-utils/reflect.d.cts.map +1 -1
- package/dist/plugin-utils/reflect.d.mts.map +1 -1
- package/dist/plugin-utils/reflect.mjs +3 -5
- package/dist/plugin-utils/reflect.mjs.map +1 -1
- package/dist/plugin-utils/traverse-command-tree.cjs +2 -1
- package/dist/plugin-utils/traverse-command-tree.cjs.map +1 -0
- package/dist/plugin-utils/traverse-command-tree.d.cts.map +1 -1
- package/dist/plugin-utils/traverse-command-tree.d.mts.map +1 -1
- package/dist/plugin-utils/traverse-command-tree.mjs.map +1 -1
- package/dist/plugin-utils/type-checks.cjs +146 -17
- package/dist/plugin-utils/type-checks.cjs.map +1 -0
- package/dist/plugin-utils/type-checks.d.cts +5 -5
- package/dist/plugin-utils/type-checks.d.cts.map +1 -1
- package/dist/plugin-utils/type-checks.d.mts +5 -5
- package/dist/plugin-utils/type-checks.d.mts.map +1 -1
- package/dist/plugin-utils/type-checks.mjs +145 -16
- package/dist/plugin-utils/type-checks.mjs.map +1 -1
- package/dist/plugin.cjs +80 -56
- package/dist/plugin.cjs.map +1 -0
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +75 -52
- package/dist/plugin.mjs.map +1 -1
- package/dist/resolver/helpers.cjs +33 -24
- package/dist/resolver/helpers.cjs.map +1 -0
- package/dist/resolver/helpers.mjs +32 -22
- package/dist/resolver/helpers.mjs.map +1 -1
- package/dist/resolver/resolve.cjs +316 -59
- package/dist/resolver/resolve.cjs.map +1 -0
- package/dist/resolver/resolve.mjs +313 -56
- package/dist/resolver/resolve.mjs.map +1 -1
- package/dist/types/command.cjs +43 -82
- package/dist/types/command.cjs.map +1 -0
- package/dist/types/command.d.cts +61 -119
- package/dist/types/command.d.cts.map +1 -1
- package/dist/types/command.d.mts +61 -119
- package/dist/types/command.d.mts.map +1 -1
- package/dist/types/command.mjs +42 -80
- package/dist/types/command.mjs.map +1 -1
- package/dist/types/config.cjs +45 -4
- package/dist/types/config.cjs.map +1 -0
- package/dist/types/config.d.cts +15 -10
- package/dist/types/config.d.cts.map +1 -1
- package/dist/types/config.d.mts +15 -10
- package/dist/types/config.d.mts.map +1 -1
- package/dist/types/config.mjs +40 -4
- package/dist/types/config.mjs.map +1 -1
- package/dist/types/context.cjs +9 -1
- package/dist/types/context.cjs.map +1 -0
- package/dist/types/context.d.cts +3 -2
- package/dist/types/context.d.cts.map +1 -1
- package/dist/types/context.d.mts +3 -2
- package/dist/types/context.d.mts.map +1 -1
- package/dist/types/context.mjs +7 -1
- package/dist/types/context.mjs.map +1 -1
- package/dist/types/env.cjs +2 -1
- package/dist/types/env.cjs.map +1 -0
- package/dist/types/env.d.cts.map +1 -1
- package/dist/types/env.d.mts.map +1 -1
- package/dist/types/env.mjs.map +1 -1
- package/dist/types/index.cjs +6 -3
- package/dist/types/index.d.cts +4 -4
- package/dist/types/index.d.mts +4 -4
- package/dist/types/index.mjs +4 -4
- package/dist/types/options.cjs +2 -1
- package/dist/types/options.cjs.map +1 -0
- package/dist/types/options.d.cts.map +1 -1
- package/dist/types/options.d.mts.map +1 -1
- package/dist/types/options.mjs.map +1 -1
- package/package.json +43 -35
- package/dist/resolver/deepkit.cjs +0 -135
- package/dist/resolver/deepkit.mjs +0 -135
- package/dist/resolver/deepkit.mjs.map +0 -1
- package/dist/resolver/module.cjs +0 -145
- package/dist/resolver/module.mjs +0 -145
- package/dist/resolver/module.mjs.map +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { getAppTitle, isDynamicPathSegment } from "../plugin-utils/context-helpers.mjs";
|
|
2
|
-
import { CommandParameterKinds } from "../types/command.mjs";
|
|
3
2
|
import { constantCase } from "@stryke/string-format/constant-case";
|
|
4
3
|
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
5
4
|
import { createDefu } from "defu";
|
|
@@ -16,53 +15,57 @@ function __assignType(fn, args) {
|
|
|
16
15
|
* Resolves the description for a command option based on its reflection.
|
|
17
16
|
*
|
|
18
17
|
* @param name - The name of the command option.
|
|
19
|
-
* @param
|
|
20
|
-
* @param
|
|
18
|
+
* @param type - The reflection kind of the command option.
|
|
19
|
+
* @param required - Whether the command option is required.
|
|
21
20
|
* @param variadic - Whether the command option is variadic (i.e., an array).
|
|
22
21
|
* @param title - The title of the command option, if any.
|
|
23
22
|
* @param defaultValue - The default value of the command option, if any.
|
|
24
23
|
* @returns The resolved description for the command option.
|
|
25
24
|
*/
|
|
26
|
-
function resolveCommandOptionDescription(name,
|
|
27
|
-
return `A${
|
|
25
|
+
function resolveCommandOptionDescription(name, type, required = true, variadic = false, title, defaultValue) {
|
|
26
|
+
return `A${!required && !defaultValue ? "n optional" : ""} command-line ${type === "boolean" ? "flag" : "option"} that allows the user to ${type === "boolean" ? "set the" : variadic ? "specify custom" : "specify a custom"} ${title?.trim() || titleCase(name)} ${type === "boolean" ? "indicator" : `${type === "number" ? "numeric" : "string"} value${variadic ? "s" : ""}`}.`;
|
|
28
27
|
}
|
|
29
28
|
resolveCommandOptionDescription.__type = [
|
|
30
29
|
"name",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
30
|
+
"string",
|
|
31
|
+
"number",
|
|
32
|
+
"boolean",
|
|
33
|
+
"type",
|
|
34
|
+
"required",
|
|
34
35
|
"variadic",
|
|
35
36
|
"title",
|
|
36
37
|
"defaultValue",
|
|
37
38
|
"resolveCommandOptionDescription",
|
|
38
39
|
"Resolves the description for a command option based on its reflection.",
|
|
39
|
-
"P&2
|
|
40
|
+
"P&2!P.\".#.$J2%\"2&\"2'&2(8\"2)8&/*?+"
|
|
40
41
|
];
|
|
41
42
|
/**
|
|
42
43
|
* Resolves the description for a command argument based on its reflection.
|
|
43
44
|
*
|
|
44
45
|
* @param name - The name of the command argument.
|
|
45
|
-
* @param
|
|
46
|
-
* @param
|
|
46
|
+
* @param type - The reflection kind of the command argument.
|
|
47
|
+
* @param required - Whether the command argument is required.
|
|
47
48
|
* @param variadic - Whether the command argument is variadic (i.e., an array).
|
|
48
49
|
* @param title - The title of the command argument, if any.
|
|
49
50
|
* @param defaultValue - The default value of the command argument, if any.
|
|
50
51
|
* @returns The resolved description for the command argument.
|
|
51
52
|
*/
|
|
52
|
-
function resolveCommandArgumentDescription(name,
|
|
53
|
-
return `An${
|
|
53
|
+
function resolveCommandArgumentDescription(name, type, required = true, variadic = false, title, defaultValue) {
|
|
54
|
+
return `An${!required && !defaultValue ? " optional" : ""} argument that allows the user to ${type === "boolean" ? "set the" : variadic ? "specify custom" : "specify a custom"} ${title?.trim() || titleCase(name)} ${type === "boolean" ? "indicator" : `${type === "number" ? "numeric" : "string"} value${variadic ? "s" : ""}`}.`;
|
|
54
55
|
}
|
|
55
56
|
resolveCommandArgumentDescription.__type = [
|
|
56
57
|
"name",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
58
|
+
"string",
|
|
59
|
+
"number",
|
|
60
|
+
"boolean",
|
|
61
|
+
"type",
|
|
62
|
+
"required",
|
|
60
63
|
"variadic",
|
|
61
64
|
"title",
|
|
62
65
|
"defaultValue",
|
|
63
66
|
"resolveCommandArgumentDescription",
|
|
64
67
|
"Resolves the description for a command argument based on its reflection.",
|
|
65
|
-
"P&2
|
|
68
|
+
"P&2!P.\".#.$J2%\"2&\"2'&2(8\"2)8&/*?+"
|
|
66
69
|
];
|
|
67
70
|
function applyOptionsDefaults(ctx) {
|
|
68
71
|
return Object.fromEntries(Object.entries(ctx.output.options).map(__assignType(([key, option]) => {
|
|
@@ -72,7 +75,7 @@ function applyOptionsDefaults(ctx) {
|
|
|
72
75
|
...option,
|
|
73
76
|
name,
|
|
74
77
|
title,
|
|
75
|
-
description: option.description || resolveCommandOptionDescription(name, option.
|
|
78
|
+
description: option.description || resolveCommandOptionDescription(name, option.type, option.required, option.type !== "boolean" && option.variadic, title, option.default),
|
|
76
79
|
env: option.env || option.env === false ? option.env : ctx.input.context.config.autoAssignEnv ? constantCase(name) : false
|
|
77
80
|
}];
|
|
78
81
|
}, [
|
|
@@ -95,7 +98,7 @@ function applyArgsDefaults(ctx) {
|
|
|
95
98
|
...arg,
|
|
96
99
|
name,
|
|
97
100
|
title,
|
|
98
|
-
description: arg.description || resolveCommandArgumentDescription(name, arg.
|
|
101
|
+
description: arg.description || resolveCommandArgumentDescription(name, arg.type, arg.required, arg.type !== "boolean" && arg.variadic, title, arg.default),
|
|
99
102
|
env: arg.name ? arg.env || arg.env === false ? arg.env : ctx.input.context.config.autoAssignEnv ? constantCase(name) : false : false
|
|
100
103
|
};
|
|
101
104
|
}, [
|
|
@@ -114,7 +117,7 @@ applyArgsDefaults.__type = [
|
|
|
114
117
|
];
|
|
115
118
|
function applyDefaults(ctx) {
|
|
116
119
|
ctx.output.description ??= `The ${ctx.output.title.replace(/(?:c|C)ommands?$/, "").trim()} executable command-line interface.`;
|
|
117
|
-
if (isSetString(ctx.input.context.config.reference?.commands) && ctx.input.context.config.reference.commands.includes("{command}")) ctx.output.
|
|
120
|
+
if (isSetString(ctx.input.context.config.reference?.commands) && ctx.input.context.config.reference.commands.includes("{command}")) ctx.output.docs ??= ctx.input.context.config.reference.commands ? ctx.input.context.config.reference.commands.replace("{command}", ctx.input.command.segments.filter(__assignType((segment) => !isDynamicPathSegment(segment), [
|
|
118
121
|
"segment",
|
|
119
122
|
"",
|
|
120
123
|
"P\"2!\"/\""
|
|
@@ -126,6 +129,12 @@ applyDefaults.__type = [
|
|
|
126
129
|
"applyDefaults",
|
|
127
130
|
"P\"w!2\"\"/#"
|
|
128
131
|
];
|
|
132
|
+
/**
|
|
133
|
+
* Resolves a virtual command by applying default values to its title and description based on the command name and application title.
|
|
134
|
+
*
|
|
135
|
+
* @template TContext - The type of the context object.
|
|
136
|
+
* @param ctx - The resolver context containing the input and output for the command resolution process.
|
|
137
|
+
*/
|
|
129
138
|
function resolveVirtualCommand(ctx) {
|
|
130
139
|
ctx.output.title ??= titleCase(ctx.input.command.name);
|
|
131
140
|
ctx.output.description ??= `A collection of available ${ctx.output.title.replace(/(?:c|C)ommands?$/, "").trim() || titleCase(ctx.input.command.name)} commands that are included in the ${getAppTitle(ctx.input.context, true)} command-line application.`;
|
|
@@ -134,7 +143,8 @@ resolveVirtualCommand.__type = [
|
|
|
134
143
|
"ResolverContext",
|
|
135
144
|
"ctx",
|
|
136
145
|
"resolveVirtualCommand",
|
|
137
|
-
"
|
|
146
|
+
"Resolves a virtual command by applying default values to its title and description based on the command name and application title.",
|
|
147
|
+
"P\"w!2\"\"/#?$"
|
|
138
148
|
];
|
|
139
149
|
/**
|
|
140
150
|
* Merges two command parameters, giving precedence to string values in the second configuration.
|
|
@@ -165,5 +175,5 @@ const mergeCommandParameter = createDefu(__assignType((obj, key, value) => {
|
|
|
165
175
|
]));
|
|
166
176
|
|
|
167
177
|
//#endregion
|
|
168
|
-
export { applyArgsDefaults, applyDefaults, applyOptionsDefaults,
|
|
178
|
+
export { applyArgsDefaults, applyDefaults, applyOptionsDefaults, resolveVirtualCommand };
|
|
169
179
|
//# sourceMappingURL=helpers.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../src/resolver/helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { getUniqueBy } from \"@stryke/helpers/get-unique\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { createDefu } from \"defu\";\nimport {\n getAppTitle,\n isDynamicPathSegment\n} from \"../plugin-utils/context-helpers\";\nimport type { CommandArgument, CommandParameterKind } from \"../types/command\";\nimport { CommandParameterKinds } from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport type { ResolverContext } from \"./types\";\n\n/**\n * Resolves the description for a command option based on its reflection.\n *\n * @param name - The name of the command option.\n * @param kind - The reflection kind of the command option.\n * @param optional - Whether the command option is optional.\n * @param variadic - Whether the command option is variadic (i.e., an array).\n * @param title - The title of the command option, if any.\n * @param defaultValue - The default value of the command option, if any.\n * @returns The resolved description for the command option.\n */\nexport function resolveCommandOptionDescription(\n name: string,\n kind: CommandParameterKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `A${optional && !defaultValue ? \"n optional\" : \"\"} command-line ${\n kind === CommandParameterKinds.boolean ? \"flag\" : \"option\"\n } that allows the user to ${\n kind === CommandParameterKinds.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === CommandParameterKinds.boolean\n ? \"indicator\"\n : `${kind === CommandParameterKinds.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\n/**\n * Resolves the description for a command argument based on its reflection.\n *\n * @param name - The name of the command argument.\n * @param kind - The reflection kind of the command argument.\n * @param optional - Whether the command argument is optional.\n * @param variadic - Whether the command argument is variadic (i.e., an array).\n * @param title - The title of the command argument, if any.\n * @param defaultValue - The default value of the command argument, if any.\n * @returns The resolved description for the command argument.\n */\nexport function resolveCommandArgumentDescription(\n name: string,\n kind: CommandParameterKind,\n optional = false,\n variadic = false,\n title?: string,\n defaultValue?: any\n): string {\n return `An${\n optional && !defaultValue ? \" optional\" : \"\"\n } argument that allows the user to ${\n kind === CommandParameterKinds.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === CommandParameterKinds.boolean\n ? \"indicator\"\n : `${kind === CommandParameterKinds.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\nexport function applyOptionsDefaults(ctx: ResolverContext) {\n return Object.fromEntries(\n Object.entries(ctx.output.options).map(([key, option]) => {\n const name = option.name || key;\n const title = option.title || titleCase(name);\n\n return [\n key,\n {\n ...option,\n name,\n title,\n description:\n option.description ||\n resolveCommandOptionDescription(\n name,\n option.kind,\n option.optional,\n option.kind !== CommandParameterKinds.boolean && option.variadic,\n title,\n option.default\n ),\n env:\n option.env || option.env === false\n ? option.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(name)\n : false\n }\n ];\n })\n );\n}\n\nexport function applyArgsDefaults(ctx: ResolverContext): CommandArgument[] {\n return ctx.output.args.map((arg, i) => {\n const name = arg.name || `arg${i + 1}`;\n const title = arg.title || titleCase(name);\n\n return {\n ...arg,\n name,\n title,\n description:\n arg.description ||\n resolveCommandArgumentDescription(\n name,\n arg.kind,\n arg.optional,\n arg.kind !== CommandParameterKinds.boolean && arg.variadic,\n title,\n arg.default\n ),\n env: arg.name\n ? arg.env || arg.env === false\n ? arg.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(name)\n : false\n : false\n };\n });\n}\n\nexport function applyDefaults(ctx: ResolverContext) {\n ctx.output.description ??= `The ${ctx.output.title.replace(/(?:c|C)ommands?$/, \"\").trim()} executable command-line interface.`;\n if (\n isSetString(ctx.input.context.config.reference?.commands) &&\n ctx.input.context.config.reference.commands.includes(\"{command}\")\n ) {\n ctx.output.reference ??= ctx.input.context.config.reference.commands\n ? ctx.input.context.config.reference.commands.replace(\n \"{command}\",\n ctx.input.command.segments\n .filter(segment => !isDynamicPathSegment(segment))\n .join(\"/\")\n )\n : undefined;\n }\n}\n\nexport function resolveVirtualCommand<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n ctx.output.title ??= titleCase(ctx.input.command.name);\n ctx.output.description ??= `A collection of available ${\n ctx.output.title.replace(/(?:c|C)ommands?$/, \"\").trim() ||\n titleCase(ctx.input.command.name)\n } commands that are included in the ${getAppTitle(\n ctx.input.context,\n true\n )} command-line application.`;\n}\n\n/**\n * Merges two command parameters, giving precedence to string values in the second configuration.\n *\n * @param objA - The first command parameter object.\n * @param objB - The second command parameter object.\n * @returns The merged command parameter object.\n */\nexport const mergeCommandParameter = createDefu((obj, key, value) => {\n if (isString(obj[key]) && isString(value)) {\n if (isSetString(value)) {\n obj[key] = value;\n }\n\n return true;\n } else if (Array.isArray(obj[key]) && Array.isArray(value)) {\n if (value.length > 0) {\n obj[key] = getUniqueBy((obj[key] as unknown[]).concat(value), item =>\n isString(item) ? item : JSON.stringify(item)\n ) as (typeof obj)[typeof key];\n }\n\n return true;\n }\n\n return false;\n});\n"],"mappings":";;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE9B,QAAO;;;;;;;;;;;;;AAsCT,SAAgB,gCAA2B,MAAW,MAAG,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACvD,QAAO,IAAC,YAAe,CAAA,eAAY,eAAa,GAAQ,gBAAc,SAAA,sBAAA,UAAA,SAAA,SAAA,2BAAA,SAAA,sBAAA,UAAA,YAAA,WAAA,mBAAA,mBAAA,GAAA,OAAA,MAAA,IAAA,UAAA,KAAA,CAAA,GAAA,SAAA,sBAAA,UAAA,cAAA,GAAA,SAAA,sBAAA,SAAA,YAAA,SAAA,QAAA,WAAA,MAAA,KAAA;;AAExE,gCAAE,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;;;;;AAYF,SAAa,kCAAsB,MAAA,MAAA,WAAA,OAAA,WAAA,OAAA,OAAA,cAAA;AACjC,QAAO,KAAI,YAAG,CAAA,eAAA,cAAA,GAAA,oCAAA,SAAA,sBAAA,UAAA,YAAA,WAAA,mBAAA,mBAAA,GAAA,OAAA,MAAA,IAAA,UAAA,KAAA,CAAA,GAAA,SAAA,sBAAA,UAAA,cAAA,GAAA,SAAA,sBAAA,SAAA,YAAA,SAAA,QAAA,WAAA,MAAA,KAAA;;AAEhB,kCAAyB,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AACzB,SAAW,qBAAgB,KAAA;AACzB,QAAI,OAAO,YAAU,OAAU,QAAQ,IAAA,OAAA,QAAA,CAAA,IAAA,cAAA,CAAA,KAAA,YAAA;EACrC,MAAM,OAAG,OAAA,QAAA;EACT,MAAK,QAAS,OAAA,SAAA,UAAA,KAAA;AACd,SAAO,CAAA,KAAM;GACX,GAAG;GACH;GACD;GACL,aAAA,OAAA,eAAA,gCAAA,MAAA,OAAA,MAAA,OAAA,UAAA,OAAA,SAAA,sBAAA,WAAA,OAAA,UAAA,OAAA,OAAA,QAAA;;GAEE,CAAA;IACC;EAAA;EAAa;EAAA;EAAY,CAAG,CAAC,CAAC;;AAEjC,qBAAqB,SAAQ;CAAA;CAAoB;CAAA;CAAA;CAAA;AACjD,SAAgB,kBAAgB,KAAO;AACrC,QAAO,IAAC,OAAU,KAAC,IAAQ,cAAY,KAAA,MAAY;EACjD,MAAM,OAAA,IAAW,QAAQ,MAAI,IAAA;EAC7B,MAAM,QAAQ,IAAI,SAAS,UAAI,KAAQ;AACvC,SAAM;GACN,GAAA;GACF;GACI;GACA,aAAQ,IAAA,eAAA,kCAAA,MAAA,IAAA,MAAA,IAAA,UAAA,IAAA,SAAA,sBAAA,WAAA,IAAA,UAAA,OAAA,IAAA,QAAA;GACR,KAAE,IAAA,OAAA,IAAA,OAAoB,IAAA,QAAA,QAAA,IAAA,MAAA,IAAA,MAAA,QAAA,OAAA,gBAAA,aAAA,KAAA,GAAA,QAAA;GAC1B;IACA;EAAA;EAAW;EAAK;EAAA;EAAA,CAAA,CAAA;;AAElB,kBAAiB,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AACjB,SAAU,cAAA,KAAA;AACR,KAAA,OAAW,gBAAA,OAAA,IAAA,OAAA,MAAA,QAAA,oBAAA,GAAA,CAAA,MAAA,CAAA;AACX,KAAE,YAAa,IAAA,MAAA,QAAiB,OAAS,WAAI,SAAA,IAAA,IAAA,MAAA,QAAA,OAAA,UAAA,SAAA,SAAA,YAAA,CAC3C,KAAA,OAAS,cAAgB,IAAI,MAAK,QAAA,OAAA,UAAA,WAAA,IAAA,MAAA,QAAA,OAAA,UAAA,SAAA,QAAA,aAAA,IAAA,MAAA,QAAA,SAAA,OAAA,cAAA,YAAA,CAAA,qBAAA,QAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA,KAAA,IAAA,CAAA,GAAA;;AAGtC,cAAQ,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AACR,SAAW,sBAAc,KAAA;AACvB,KAAI,OAAK,UAAU,UAAM,IAAA,MAAA,QAAA,KAAA;AACzB,KAAI,OAAO,gBAAU,6BAAkB,IAAA,OAAA,MAAA,QAAA,oBAAA,GAAA,CAAA,MAAA,IAAA,UAAA,IAAA,MAAA,QAAA,KAAA,CAAA,qCAAA,YAAA,IAAA,MAAA,SAAA,KAAA,CAAA;;AAEzC,sBAAkB,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;AAQlB,MAAS,wBAAkB,WAAA,cAAA,KAAA,KAAA,UAAA;AACzB,KAAE,SAAO,IAAQ,KAAI,IAAA,SAAc,MAAM,EAAE;AACzC,MAAE,YAAa,MAAO,CACpB,KAAA,OAAW;AAEb,SAAE;YACK,MAAA,QAAA,IAAA,KAAA,IAAA,MAAA,QAAA,MAAA,EAAA;AACP,MAAI,MAAA,SAAA,EACF,KAAI,OAAG,YAAM,IAAA,KAAA,OAAA,MAAA,EAAA,cAAA,SAAA,SAAA,KAAA,GAAA,OAAA,KAAA,UAAA,KAAA,EAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;AAEf,SAAM;;AAER,QAAO;GACN;CAAC;CAAO;CAAC;CAAA;CAAA;CAA+B,CAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1,25 +1,268 @@
|
|
|
1
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
1
|
const require_context_helpers = require('../plugin-utils/context-helpers.cjs');
|
|
3
|
-
const require_deepkit = require('../plugin-utils/deepkit.cjs');
|
|
4
2
|
const require_utilities = require('../helpers/utilities.cjs');
|
|
5
3
|
const require_helpers = require('./helpers.cjs');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
4
|
+
let _powerlines_schema = require("@powerlines/schema");
|
|
5
|
+
let _stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
9
6
|
let _stryke_string_format_constant_case = require("@stryke/string-format/constant-case");
|
|
10
|
-
let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
11
7
|
let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
8
|
+
let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
9
|
+
let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
10
|
+
let _stryke_type_checks_is_boolean = require("@stryke/type-checks/is-boolean");
|
|
11
|
+
let _stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
|
|
12
12
|
let _powerlines_deepkit_esbuild_plugin = require("@powerlines/deepkit/esbuild-plugin");
|
|
13
|
-
let
|
|
13
|
+
let _stryke_json = require("@stryke/json");
|
|
14
14
|
|
|
15
15
|
//#region src/resolver/resolve.ts
|
|
16
|
+
const __ΩRecord = [
|
|
17
|
+
"K",
|
|
18
|
+
"T",
|
|
19
|
+
"Record",
|
|
20
|
+
"l'e#\"Rb!b\"Pde\"!N#!w#y"
|
|
21
|
+
];
|
|
16
22
|
function __assignType(fn, args) {
|
|
17
23
|
fn.__type = args;
|
|
18
24
|
return fn;
|
|
19
25
|
}
|
|
20
|
-
|
|
26
|
+
function isFiniteNumber(value) {
|
|
27
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
28
|
+
}
|
|
29
|
+
isFiniteNumber.__type = [
|
|
30
|
+
"value",
|
|
31
|
+
"isFiniteNumber",
|
|
32
|
+
"P#2!!/\""
|
|
33
|
+
];
|
|
34
|
+
function asRecord(value) {
|
|
35
|
+
return (0, _stryke_type_checks_is_set_object.isSetObject)(value) ? value : {};
|
|
36
|
+
}
|
|
37
|
+
asRecord.__type = [
|
|
38
|
+
"value",
|
|
39
|
+
() => __ΩRecord,
|
|
40
|
+
"asRecord",
|
|
41
|
+
"P#2!&#o\"#/#"
|
|
42
|
+
];
|
|
43
|
+
function toAliasList(value) {
|
|
44
|
+
if (Array.isArray(value)) return (0, _stryke_helpers_get_unique.getUnique)(value.filter(_stryke_type_checks_is_set_string.isSetString));
|
|
45
|
+
return (0, _stryke_type_checks_is_set_string.isSetString)(value) ? [value] : [];
|
|
46
|
+
}
|
|
47
|
+
toAliasList.__type = [
|
|
48
|
+
"value",
|
|
49
|
+
"toAliasList",
|
|
50
|
+
"P#2!&F/\""
|
|
51
|
+
];
|
|
52
|
+
function inferParameterType(input) {
|
|
53
|
+
const schemaType = input.type;
|
|
54
|
+
if (Array.isArray(schemaType)) {
|
|
55
|
+
const first = schemaType.find(__assignType((type) => type !== "null", [
|
|
56
|
+
"type",
|
|
57
|
+
"",
|
|
58
|
+
"P\"2!\"/\""
|
|
59
|
+
]));
|
|
60
|
+
if (first === "integer" || first === "number") return "number";
|
|
61
|
+
if (first === "boolean") return "boolean";
|
|
62
|
+
if (first === "array") {
|
|
63
|
+
const nestedType = asRecord(input.items).type;
|
|
64
|
+
if (nestedType === "integer" || nestedType === "number") return "number";
|
|
65
|
+
if (nestedType === "boolean") return "boolean";
|
|
66
|
+
return "string";
|
|
67
|
+
}
|
|
68
|
+
return "string";
|
|
69
|
+
}
|
|
70
|
+
if (schemaType === "integer" || schemaType === "number") return "number";
|
|
71
|
+
if (schemaType === "boolean") return "boolean";
|
|
72
|
+
if (schemaType === "array") {
|
|
73
|
+
const nestedType = asRecord(input.items).type;
|
|
74
|
+
if (nestedType === "integer" || nestedType === "number") return "number";
|
|
75
|
+
if (nestedType === "boolean") return "boolean";
|
|
76
|
+
return "string";
|
|
77
|
+
}
|
|
78
|
+
if (Array.isArray(input.enum) && input.enum.length > 0) {
|
|
79
|
+
const first = input.enum.find(__assignType((value) => value !== null, [
|
|
80
|
+
"value",
|
|
81
|
+
"",
|
|
82
|
+
"P\"2!\"/\""
|
|
83
|
+
]));
|
|
84
|
+
if (isFiniteNumber(first)) return "number";
|
|
85
|
+
if ((0, _stryke_type_checks_is_boolean.isBoolean)(first)) return "boolean";
|
|
86
|
+
}
|
|
87
|
+
if (isFiniteNumber(input.default)) return "number";
|
|
88
|
+
if ((0, _stryke_type_checks_is_boolean.isBoolean)(input.default)) return "boolean";
|
|
89
|
+
return "string";
|
|
90
|
+
}
|
|
91
|
+
inferParameterType.__type = [
|
|
92
|
+
() => __ΩRecord,
|
|
93
|
+
"input",
|
|
94
|
+
"CommandOption",
|
|
95
|
+
"type",
|
|
96
|
+
"inferParameterType",
|
|
97
|
+
"P&#o!#2\"\"w#.$f/%"
|
|
98
|
+
];
|
|
99
|
+
function inferVariadic(input) {
|
|
100
|
+
if ((0, _stryke_type_checks_is_boolean.isBoolean)(input.variadic)) return input.variadic;
|
|
101
|
+
return input.type === "array";
|
|
102
|
+
}
|
|
103
|
+
inferVariadic.__type = [
|
|
104
|
+
() => __ΩRecord,
|
|
105
|
+
"input",
|
|
106
|
+
"inferVariadic",
|
|
107
|
+
"P&#o!#2\")/#"
|
|
108
|
+
];
|
|
109
|
+
function normalizeDefault(input, type, variadic) {
|
|
110
|
+
const defaultValue = input.default;
|
|
111
|
+
if (defaultValue === void 0) return;
|
|
112
|
+
if (type === "boolean") {
|
|
113
|
+
if (variadic) {
|
|
114
|
+
if (Array.isArray(defaultValue)) return defaultValue.filter(_stryke_type_checks_is_boolean.isBoolean);
|
|
115
|
+
return (0, _stryke_type_checks_is_boolean.isBoolean)(defaultValue) ? [defaultValue] : void 0;
|
|
116
|
+
}
|
|
117
|
+
if (Array.isArray(defaultValue)) return defaultValue.find(_stryke_type_checks_is_boolean.isBoolean);
|
|
118
|
+
return (0, _stryke_type_checks_is_boolean.isBoolean)(defaultValue) ? defaultValue : void 0;
|
|
119
|
+
}
|
|
120
|
+
if (type === "number") {
|
|
121
|
+
if (variadic) {
|
|
122
|
+
if (Array.isArray(defaultValue)) return defaultValue.map(__assignType((item) => typeof item === "bigint" ? Number(item) : item, [
|
|
123
|
+
"item",
|
|
124
|
+
"",
|
|
125
|
+
"P\"2!\"/\""
|
|
126
|
+
])).filter(isFiniteNumber);
|
|
127
|
+
const normalized = typeof defaultValue === "bigint" ? Number(defaultValue) : defaultValue;
|
|
128
|
+
return isFiniteNumber(normalized) ? [normalized] : void 0;
|
|
129
|
+
}
|
|
130
|
+
if (Array.isArray(defaultValue)) return defaultValue.map(__assignType((item) => typeof item === "bigint" ? Number(item) : item, [
|
|
131
|
+
"item",
|
|
132
|
+
"",
|
|
133
|
+
"P\"2!\"/\""
|
|
134
|
+
])).find(isFiniteNumber);
|
|
135
|
+
const normalized = typeof defaultValue === "bigint" ? Number(defaultValue) : defaultValue;
|
|
136
|
+
return isFiniteNumber(normalized) ? normalized : void 0;
|
|
137
|
+
}
|
|
138
|
+
if (variadic) {
|
|
139
|
+
if (Array.isArray(defaultValue)) return defaultValue.filter(_stryke_type_checks_is_set_string.isSetString);
|
|
140
|
+
return (0, _stryke_type_checks_is_set_string.isSetString)(defaultValue) ? [defaultValue] : void 0;
|
|
141
|
+
}
|
|
142
|
+
if (Array.isArray(defaultValue)) return defaultValue.find(_stryke_type_checks_is_set_string.isSetString);
|
|
143
|
+
return (0, _stryke_type_checks_is_set_string.isSetString)(defaultValue) ? defaultValue : void 0;
|
|
144
|
+
}
|
|
145
|
+
normalizeDefault.__type = [
|
|
146
|
+
() => __ΩRecord,
|
|
147
|
+
"input",
|
|
148
|
+
"CommandOption",
|
|
149
|
+
"type",
|
|
150
|
+
"type",
|
|
151
|
+
"variadic",
|
|
152
|
+
"normalizeDefault",
|
|
153
|
+
"P&#o!#2\"\"w#.$f2%)2&\"/'"
|
|
154
|
+
];
|
|
155
|
+
function normalizeStringChoices(input) {
|
|
156
|
+
const source = Array.isArray(input.choices) ? input.choices : input.enum;
|
|
157
|
+
if (!Array.isArray(source)) return;
|
|
158
|
+
return source.filter(_stryke_type_checks_is_set_string.isSetString);
|
|
159
|
+
}
|
|
160
|
+
normalizeStringChoices.__type = [
|
|
161
|
+
() => __ΩRecord,
|
|
162
|
+
"input",
|
|
163
|
+
"normalizeStringChoices",
|
|
164
|
+
"P&#o!#2\"\"/#"
|
|
165
|
+
];
|
|
166
|
+
function normalizeNumberChoices(input) {
|
|
167
|
+
const source = Array.isArray(input.choices) ? input.choices : input.enum;
|
|
168
|
+
if (!Array.isArray(source)) return;
|
|
169
|
+
return source.map(__assignType((item) => typeof item === "bigint" ? Number(item) : item, [
|
|
170
|
+
"item",
|
|
171
|
+
"",
|
|
172
|
+
"P\"2!\"/\""
|
|
173
|
+
])).filter(isFiniteNumber);
|
|
174
|
+
}
|
|
175
|
+
normalizeNumberChoices.__type = [
|
|
176
|
+
() => __ΩRecord,
|
|
177
|
+
"input",
|
|
178
|
+
"normalizeNumberChoices",
|
|
179
|
+
"P&#o!#2\"\"/#"
|
|
180
|
+
];
|
|
181
|
+
function resolveCommandParameter(schema, defaults) {
|
|
182
|
+
const input = asRecord(schema);
|
|
183
|
+
const type = inferParameterType(input);
|
|
184
|
+
const variadic = inferVariadic(input);
|
|
185
|
+
const defaultValue = normalizeDefault(input, type, variadic);
|
|
186
|
+
const required = (0, _stryke_type_checks_is_boolean.isBoolean)(input.required) ? input.required : defaultValue === void 0 ? defaults.fallbackRequired : false;
|
|
187
|
+
const env = (0, _stryke_type_checks_is_set_string.isSetString)(input.env) ? input.env : false;
|
|
188
|
+
const result = {
|
|
189
|
+
name: (0, _stryke_type_checks_is_set_string.isSetString)(input.name) ? input.name : "",
|
|
190
|
+
type,
|
|
191
|
+
title: (0, _stryke_type_checks_is_set_string.isSetString)(input.title) ? input.title : "",
|
|
192
|
+
description: (0, _stryke_type_checks_is_set_string.isSetString)(input.description) ? input.description : "",
|
|
193
|
+
alias: toAliasList(input.alias),
|
|
194
|
+
default: defaultValue,
|
|
195
|
+
env,
|
|
196
|
+
required,
|
|
197
|
+
variadic
|
|
198
|
+
};
|
|
199
|
+
if (type === "string") {
|
|
200
|
+
const stringChoices = normalizeStringChoices(input);
|
|
201
|
+
if (Array.isArray(stringChoices)) result.choices = stringChoices;
|
|
202
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(input.format)) result.format = input.format;
|
|
203
|
+
}
|
|
204
|
+
if (type === "number") {
|
|
205
|
+
const numberChoices = normalizeNumberChoices(input);
|
|
206
|
+
if (Array.isArray(numberChoices)) result.choices = numberChoices;
|
|
207
|
+
}
|
|
208
|
+
if (defaults.includeBooleanOptionFields && type === "boolean" && !variadic) {
|
|
209
|
+
const optionResult = result;
|
|
210
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(input.isNegativeOf)) optionResult.isNegativeOf = input.isNegativeOf;
|
|
211
|
+
if ((0, _stryke_type_checks_is_boolean.isBoolean)(input.skipAddingNegative)) optionResult.skipAddingNegative = input.skipAddingNegative;
|
|
212
|
+
}
|
|
213
|
+
return result;
|
|
214
|
+
}
|
|
215
|
+
resolveCommandParameter.__type = [
|
|
216
|
+
"schema",
|
|
217
|
+
"fallbackRequired",
|
|
218
|
+
"includeBooleanOptionFields",
|
|
219
|
+
"defaults",
|
|
220
|
+
"CommandOption",
|
|
221
|
+
"CommandArgument",
|
|
222
|
+
"resolveCommandParameter",
|
|
223
|
+
"P#2!P)4\")4#M2$P\"w%\"w&J/'"
|
|
224
|
+
];
|
|
225
|
+
/**
|
|
226
|
+
* Resolves a command option from the given schema.
|
|
227
|
+
*
|
|
228
|
+
* @param schema - The command option schema, which can be a command option configuration or a JSON schema input.
|
|
229
|
+
* @returns The resolved command option definition.
|
|
230
|
+
*/
|
|
231
|
+
function resolveCommandOption(schema) {
|
|
232
|
+
return resolveCommandParameter(schema, {
|
|
233
|
+
fallbackRequired: false,
|
|
234
|
+
includeBooleanOptionFields: true
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
resolveCommandOption.__type = [
|
|
238
|
+
"schema",
|
|
239
|
+
"CommandOption",
|
|
240
|
+
"resolveCommandOption",
|
|
241
|
+
"Resolves a command option from the given schema.",
|
|
242
|
+
"P#2!\"w\"/#?$"
|
|
243
|
+
];
|
|
244
|
+
/**
|
|
245
|
+
* Resolves a command argument from the given schema.
|
|
246
|
+
*
|
|
247
|
+
* @param schema - The command argument schema, which can be a command argument configuration or a JSON schema input.
|
|
248
|
+
* @returns The resolved command argument definition.
|
|
249
|
+
*/
|
|
250
|
+
function resolveCommandArgument(schema) {
|
|
251
|
+
return resolveCommandParameter(schema, {
|
|
252
|
+
fallbackRequired: true,
|
|
253
|
+
includeBooleanOptionFields: false
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
resolveCommandArgument.__type = [
|
|
257
|
+
"schema",
|
|
258
|
+
"CommandArgument",
|
|
259
|
+
"resolveCommandArgument",
|
|
260
|
+
"Resolves a command argument from the given schema.",
|
|
261
|
+
"P#2!\"w\"/#?$"
|
|
262
|
+
];
|
|
263
|
+
async function preprocess(input) {
|
|
21
264
|
const { context, command, parent } = input;
|
|
22
|
-
const title = command.title || `${parent?.title ? `${parent.
|
|
265
|
+
const title = command.title || `${parent?.title ? `${parent.virtual ? parent.title.replace(/(?:c|C)ommands?$/, "").trim() : parent.title} - ` : ""}${(0, _stryke_string_format_title_case.titleCase)(command.name)}${command.virtual ? " Commands" : ""}`;
|
|
23
266
|
const result = {
|
|
24
267
|
input,
|
|
25
268
|
output: {
|
|
@@ -35,26 +278,25 @@ async function initialize(input) {
|
|
|
35
278
|
children: {}
|
|
36
279
|
}
|
|
37
280
|
};
|
|
38
|
-
if (!command.
|
|
281
|
+
if (!command.virtual) {
|
|
39
282
|
if (!command.entry.input?.file || !context.fs.existsSync(command.entry.input.file)) throw new Error(`${!command.entry.input?.file ? "Missing" : "Non-existent"} command entry file for "${command.name}"`);
|
|
40
283
|
context.debug(`Adding reflection for CLI command: ${command.id} (file: ${command.entry.input.file})`);
|
|
41
|
-
result.module = await (
|
|
284
|
+
result.module = await (_powerlines_schema.resolveModule.Ω = [["CommandModule", "\"w!"]], (0, _powerlines_schema.resolveModule)(context, command.entry.input, {
|
|
42
285
|
name: command.title || (0, _stryke_string_format_title_case.titleCase)(command.name),
|
|
43
|
-
treeShaking: true,
|
|
44
|
-
resolve: { skipNodeModulesBundle: true },
|
|
45
286
|
plugins: [(0, _powerlines_deepkit_esbuild_plugin.esbuildPlugin)(context, {
|
|
46
287
|
reflection: "default",
|
|
47
288
|
level: "all"
|
|
48
|
-
})]
|
|
289
|
+
})],
|
|
290
|
+
resolve: { skipNodeModulesBundle: true }
|
|
49
291
|
}));
|
|
50
292
|
}
|
|
51
293
|
return result;
|
|
52
294
|
}
|
|
53
|
-
|
|
295
|
+
preprocess.__type = [
|
|
54
296
|
"ResolverInput",
|
|
55
297
|
"input",
|
|
56
298
|
"ResolverContext",
|
|
57
|
-
"
|
|
299
|
+
"preprocess",
|
|
58
300
|
"P\"w!2\"\"w#`/$"
|
|
59
301
|
];
|
|
60
302
|
async function postprocess(ctx) {
|
|
@@ -95,26 +337,18 @@ async function postprocess(ctx) {
|
|
|
95
337
|
"",
|
|
96
338
|
"P\"2!\"/\""
|
|
97
339
|
])).forEach(__assignType((option) => {
|
|
98
|
-
ctx.input.context.env.
|
|
340
|
+
(0, _powerlines_schema.addProperty)(ctx.input.context.env.config.schema, option.env, {
|
|
341
|
+
...option,
|
|
99
342
|
name: option.env,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
"",
|
|
110
|
-
"P\"2!\"/\""
|
|
111
|
-
])).map(__assignType((alias) => (0, _stryke_string_format_constant_case.constantCase)(alias), [
|
|
112
|
-
"alias",
|
|
113
|
-
"",
|
|
114
|
-
"P\"2!\"/\""
|
|
115
|
-
])),
|
|
116
|
-
domain: "cli"
|
|
117
|
-
}
|
|
343
|
+
alias: option.alias.filter(__assignType((alias) => alias.length > 1, [
|
|
344
|
+
"alias",
|
|
345
|
+
"",
|
|
346
|
+
"P\"2!\"/\""
|
|
347
|
+
])).map(__assignType((alias) => (0, _stryke_string_format_constant_case.constantCase)(alias), [
|
|
348
|
+
"alias",
|
|
349
|
+
"",
|
|
350
|
+
"P\"2!\"/\""
|
|
351
|
+
]))
|
|
118
352
|
});
|
|
119
353
|
}, [
|
|
120
354
|
"option",
|
|
@@ -125,25 +359,18 @@ async function postprocess(ctx) {
|
|
|
125
359
|
"arg",
|
|
126
360
|
"",
|
|
127
361
|
"P\"2!\"/\""
|
|
128
|
-
])).forEach(__assignType((arg) => ctx.input.context.env.
|
|
362
|
+
])).forEach(__assignType((arg) => (0, _powerlines_schema.addProperty)(ctx.input.context.env.config.schema, arg.env, {
|
|
363
|
+
...arg,
|
|
129
364
|
name: arg.env,
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
"P\"2!\"/\""
|
|
140
|
-
])).map(__assignType((alias) => (0, _stryke_string_format_constant_case.constantCase)(alias), [
|
|
141
|
-
"alias",
|
|
142
|
-
"",
|
|
143
|
-
"P\"2!\"/\""
|
|
144
|
-
])),
|
|
145
|
-
domain: "cli"
|
|
146
|
-
}
|
|
365
|
+
alias: arg.alias.filter(__assignType((alias) => alias.length > 1, [
|
|
366
|
+
"alias",
|
|
367
|
+
"",
|
|
368
|
+
"P\"2!\"/\""
|
|
369
|
+
])).map(__assignType((alias) => (0, _stryke_string_format_constant_case.constantCase)(alias), [
|
|
370
|
+
"alias",
|
|
371
|
+
"",
|
|
372
|
+
"P\"2!\"/\""
|
|
373
|
+
]))
|
|
147
374
|
}), [
|
|
148
375
|
"arg",
|
|
149
376
|
"",
|
|
@@ -198,14 +425,43 @@ postprocess.__type = [
|
|
|
198
425
|
* @returns A promise that resolves to the resolved command tree.
|
|
199
426
|
*/
|
|
200
427
|
async function resolve(input) {
|
|
201
|
-
const ctx = await (
|
|
428
|
+
const ctx = await (preprocess.Ω = [[
|
|
202
429
|
() => input,
|
|
203
430
|
"ResolverInput",
|
|
204
431
|
"Pi!\"w\"q\"!j"
|
|
205
|
-
]],
|
|
206
|
-
if (!ctx.output.
|
|
207
|
-
|
|
208
|
-
|
|
432
|
+
]], preprocess(input));
|
|
433
|
+
if (!ctx.output.virtual) {
|
|
434
|
+
if (!ctx.module) throw new Error(`Command module at path "${ctx.input.command.path}" is undefined or null. Please ensure the module exports a valid command.`);
|
|
435
|
+
else if (!(0, _stryke_type_checks_is_set_object.isSetObject)(ctx.module)) throw new TypeError(`Command module at path "${ctx.input.command.path}" is not an object. Please ensure the module exports a valid command.`);
|
|
436
|
+
else if (!("default" in ctx.module)) throw new Error(`Command module at path "${ctx.input.command.path}" does not appear to be valid. Please ensure the module's default export is a valid command handler function.`);
|
|
437
|
+
const metadata = ctx.module.metadata ?? {};
|
|
438
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(metadata.title)) ctx.output.title = metadata.title;
|
|
439
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(metadata.description)) ctx.output.description = metadata.description;
|
|
440
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(metadata.alias) || Array.isArray(metadata.alias) && metadata.alias.length > 0) ctx.output.alias = (0, _stryke_convert_to_array.toArray)(metadata.alias);
|
|
441
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(metadata.icon)) ctx.output.icon = metadata.icon;
|
|
442
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(metadata.tags)) ctx.output.tags = (0, _stryke_helpers_get_unique.getUnique)(ctx.output.tags.concat((0, _stryke_convert_to_array.toArray)(metadata.tags)));
|
|
443
|
+
if ((0, _stryke_type_checks_is_set_object.isSetObject)(ctx.module.options)) {
|
|
444
|
+
const options = await (0, _powerlines_schema.extract)(ctx.input.context, ctx.module.options);
|
|
445
|
+
if (!(0, _stryke_type_checks_is_set_object.isSetObject)(options) || !(0, _stryke_json.isJsonSchemaObjectType)(options.schema)) throw new TypeError(`Command options for command at path "${ctx.input.command.path}" must resolve to an object.`);
|
|
446
|
+
ctx.output.options = (0, _powerlines_schema.getPropertiesList)(options).reduce(__assignType((ret, property) => {
|
|
447
|
+
ret[property.name] = resolveCommandOption(property);
|
|
448
|
+
return ret;
|
|
449
|
+
}, [
|
|
450
|
+
"ret",
|
|
451
|
+
"property",
|
|
452
|
+
"",
|
|
453
|
+
"P\"2!\"2\"\"/#"
|
|
454
|
+
]), {});
|
|
455
|
+
}
|
|
456
|
+
if (ctx.module.args && Array.isArray(ctx.module.args)) {
|
|
457
|
+
const args = await (0, _powerlines_schema.extract)(ctx.input.context, ctx.module.args);
|
|
458
|
+
if (!(0, _stryke_type_checks_is_set_object.isSetObject)(args) || !(0, _stryke_json.isJsonSchemaTupleType)(args.schema)) throw new TypeError(`Command arguments for command at path "${ctx.input.command.path}" must resolve to a tuple.`);
|
|
459
|
+
ctx.output.args = args.schema.items.map(__assignType((item) => resolveCommandArgument(item), [
|
|
460
|
+
"item",
|
|
461
|
+
"",
|
|
462
|
+
"P\"2!\"/\""
|
|
463
|
+
]));
|
|
464
|
+
}
|
|
209
465
|
} else require_helpers.resolveVirtualCommand(ctx);
|
|
210
466
|
return postprocess(ctx);
|
|
211
467
|
}
|
|
@@ -219,4 +475,5 @@ resolve.__type = [
|
|
|
219
475
|
];
|
|
220
476
|
|
|
221
477
|
//#endregion
|
|
222
|
-
exports.resolve = resolve;
|
|
478
|
+
exports.resolve = resolve;
|
|
479
|
+
//# sourceMappingURL=resolve.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.cjs","names":[],"sources":[],"mappings":""}
|