@shell-shock/core 0.8.9 → 0.8.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/components/docs.d.cts +5 -5
- package/dist/components/docs.d.mts +5 -5
- package/dist/components/helpers.d.cts +2 -2
- package/dist/components/helpers.d.cts.map +1 -1
- package/dist/components/options-parser-logic.d.mts +9 -9
- package/dist/components/usage.d.mts +2 -2
- package/dist/components/usage.d.mts.map +1 -1
- package/dist/helpers/resolve-command.cjs +3 -3
- package/dist/helpers/resolve-command.cjs.map +1 -1
- package/dist/helpers/resolve-command.mjs +3 -3
- package/dist/helpers/resolve-command.mjs.map +1 -1
- package/dist/plugin-utils/context-helpers.cjs +5 -3
- package/dist/plugin-utils/context-helpers.cjs.map +1 -1
- package/dist/plugin-utils/context-helpers.d.cts +2 -1
- package/dist/plugin-utils/context-helpers.d.cts.map +1 -1
- package/dist/plugin-utils/context-helpers.d.mts +2 -1
- package/dist/plugin-utils/context-helpers.d.mts.map +1 -1
- package/dist/plugin-utils/context-helpers.mjs +5 -3
- package/dist/plugin-utils/context-helpers.mjs.map +1 -1
- package/dist/plugin.cjs +3 -3
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +4 -4
- package/dist/plugin.mjs.map +1 -1
- package/dist/types/command.d.cts +3 -0
- package/dist/types/command.d.cts.map +1 -1
- package/dist/types/command.d.mts +3 -0
- package/dist/types/command.d.mts.map +1 -1
- package/package.json +11 -11
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommandTree } from "../types/command.cjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _alloy_js_core9 from "@alloy-js/core";
|
|
3
3
|
import { MarkdownFileProps } from "@powerlines/plugin-alloy/markdown/components/markdown-file";
|
|
4
4
|
|
|
5
5
|
//#region src/components/docs.d.ts
|
|
@@ -12,7 +12,7 @@ interface CommandOptionsDocsProps {
|
|
|
12
12
|
/**
|
|
13
13
|
* Generates the options markdown documentation for a command.
|
|
14
14
|
*/
|
|
15
|
-
declare function CommandOptionsDocs(props: CommandOptionsDocsProps):
|
|
15
|
+
declare function CommandOptionsDocs(props: CommandOptionsDocsProps): _alloy_js_core9.Children;
|
|
16
16
|
interface CommandDocsUsageExampleProps {
|
|
17
17
|
/**
|
|
18
18
|
* The package manager to generate the usage example for.
|
|
@@ -31,7 +31,7 @@ interface CommandDocsUsageExampleProps {
|
|
|
31
31
|
/**
|
|
32
32
|
* Generates the markdown documentation for a command.
|
|
33
33
|
*/
|
|
34
|
-
declare function CommandDocsUsageExample(props: CommandDocsUsageExampleProps):
|
|
34
|
+
declare function CommandDocsUsageExample(props: CommandDocsUsageExampleProps): _alloy_js_core9.Children;
|
|
35
35
|
interface CommandDocsProps {
|
|
36
36
|
/**
|
|
37
37
|
* The heading level offset to apply to the generated documentation.
|
|
@@ -56,7 +56,7 @@ interface CommandDocsProps {
|
|
|
56
56
|
/**
|
|
57
57
|
* Generates the markdown documentation for a command.
|
|
58
58
|
*/
|
|
59
|
-
declare function CommandDocs(props: CommandDocsProps):
|
|
59
|
+
declare function CommandDocs(props: CommandDocsProps): _alloy_js_core9.Children;
|
|
60
60
|
interface CommandDocsFileProps extends Partial<MarkdownFileProps> {
|
|
61
61
|
/**
|
|
62
62
|
* The heading level offset to apply to the generated documentation.
|
|
@@ -75,7 +75,7 @@ interface CommandDocsFileProps extends Partial<MarkdownFileProps> {
|
|
|
75
75
|
/**
|
|
76
76
|
* Generates the markdown documentation file for a command.
|
|
77
77
|
*/
|
|
78
|
-
declare function CommandDocsFile(props: CommandDocsFileProps):
|
|
78
|
+
declare function CommandDocsFile(props: CommandDocsFileProps): _alloy_js_core9.Children;
|
|
79
79
|
//#endregion
|
|
80
80
|
export { CommandDocs, CommandDocsFile, CommandDocsFileProps, CommandDocsProps, CommandDocsUsageExample, CommandDocsUsageExampleProps, CommandOptionsDocs, CommandOptionsDocsProps };
|
|
81
81
|
//# sourceMappingURL=docs.d.cts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommandTree } from "../types/command.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _alloy_js_core1 from "@alloy-js/core";
|
|
3
3
|
import { MarkdownFileProps } from "@powerlines/plugin-alloy/markdown/components/markdown-file";
|
|
4
4
|
|
|
5
5
|
//#region src/components/docs.d.ts
|
|
@@ -12,7 +12,7 @@ interface CommandOptionsDocsProps {
|
|
|
12
12
|
/**
|
|
13
13
|
* Generates the options markdown documentation for a command.
|
|
14
14
|
*/
|
|
15
|
-
declare function CommandOptionsDocs(props: CommandOptionsDocsProps):
|
|
15
|
+
declare function CommandOptionsDocs(props: CommandOptionsDocsProps): _alloy_js_core1.Children;
|
|
16
16
|
interface CommandDocsUsageExampleProps {
|
|
17
17
|
/**
|
|
18
18
|
* The package manager to generate the usage example for.
|
|
@@ -31,7 +31,7 @@ interface CommandDocsUsageExampleProps {
|
|
|
31
31
|
/**
|
|
32
32
|
* Generates the markdown documentation for a command.
|
|
33
33
|
*/
|
|
34
|
-
declare function CommandDocsUsageExample(props: CommandDocsUsageExampleProps):
|
|
34
|
+
declare function CommandDocsUsageExample(props: CommandDocsUsageExampleProps): _alloy_js_core1.Children;
|
|
35
35
|
interface CommandDocsProps {
|
|
36
36
|
/**
|
|
37
37
|
* The heading level offset to apply to the generated documentation.
|
|
@@ -56,7 +56,7 @@ interface CommandDocsProps {
|
|
|
56
56
|
/**
|
|
57
57
|
* Generates the markdown documentation for a command.
|
|
58
58
|
*/
|
|
59
|
-
declare function CommandDocs(props: CommandDocsProps):
|
|
59
|
+
declare function CommandDocs(props: CommandDocsProps): _alloy_js_core1.Children;
|
|
60
60
|
interface CommandDocsFileProps extends Partial<MarkdownFileProps> {
|
|
61
61
|
/**
|
|
62
62
|
* The heading level offset to apply to the generated documentation.
|
|
@@ -75,7 +75,7 @@ interface CommandDocsFileProps extends Partial<MarkdownFileProps> {
|
|
|
75
75
|
/**
|
|
76
76
|
* Generates the markdown documentation file for a command.
|
|
77
77
|
*/
|
|
78
|
-
declare function CommandDocsFile(props: CommandDocsFileProps):
|
|
78
|
+
declare function CommandDocsFile(props: CommandDocsFileProps): _alloy_js_core1.Children;
|
|
79
79
|
//#endregion
|
|
80
80
|
export { CommandDocs, CommandDocsFile, CommandDocsFileProps, CommandDocsProps, CommandDocsUsageExample, CommandDocsUsageExampleProps, CommandOptionsDocs, CommandOptionsDocsProps };
|
|
81
81
|
//# sourceMappingURL=docs.d.mts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _alloy_js_core8 from "@alloy-js/core";
|
|
2
2
|
|
|
3
3
|
//#region src/components/helpers.d.ts
|
|
4
4
|
interface BooleanInputParserLogicProps {
|
|
@@ -7,7 +7,7 @@ interface BooleanInputParserLogicProps {
|
|
|
7
7
|
/**
|
|
8
8
|
* Parses a string input into a boolean value, interpreting common truthy and falsy string representations.
|
|
9
9
|
*/
|
|
10
|
-
declare function BooleanInputParserLogic(props: BooleanInputParserLogicProps):
|
|
10
|
+
declare function BooleanInputParserLogic(props: BooleanInputParserLogicProps): _alloy_js_core8.Children;
|
|
11
11
|
//#endregion
|
|
12
12
|
export { BooleanInputParserLogic, BooleanInputParserLogicProps };
|
|
13
13
|
//# sourceMappingURL=helpers.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.cts","names":[],"sources":["../../src/components/helpers.tsx"],"sourcesContent":[],"mappings":";;;UAoBiB,4BAAA;;;AAAjB;AAOA;;iBAAgB,uBAAA,QAA+B,+BAA4B,
|
|
1
|
+
{"version":3,"file":"helpers.d.cts","names":[],"sources":["../../src/components/helpers.tsx"],"sourcesContent":[],"mappings":";;;UAoBiB,4BAAA;;;AAAjB;AAOA;;iBAAgB,uBAAA,QAA+B,+BAA4B,eAAA,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommandOption, CommandTree } from "../types/command.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _alloy_js_core5 from "@alloy-js/core";
|
|
3
3
|
|
|
4
4
|
//#region src/components/options-parser-logic.d.ts
|
|
5
5
|
interface DynamicSegmentsParserLogicProps {
|
|
@@ -12,7 +12,7 @@ interface DynamicSegmentsParserLogicProps {
|
|
|
12
12
|
*/
|
|
13
13
|
isCaseSensitive: boolean;
|
|
14
14
|
}
|
|
15
|
-
declare function DynamicSegmentsParserLogic(props: DynamicSegmentsParserLogicProps):
|
|
15
|
+
declare function DynamicSegmentsParserLogic(props: DynamicSegmentsParserLogicProps): _alloy_js_core5.Children;
|
|
16
16
|
interface ArgumentsParserLogicProps {
|
|
17
17
|
/**
|
|
18
18
|
* The command to generate the positional parameters parser logic for.
|
|
@@ -27,7 +27,7 @@ interface ArgumentsParserLogicProps {
|
|
|
27
27
|
*/
|
|
28
28
|
isCaseSensitive: boolean;
|
|
29
29
|
}
|
|
30
|
-
declare function ArgumentsParserLogic(props: ArgumentsParserLogicProps):
|
|
30
|
+
declare function ArgumentsParserLogic(props: ArgumentsParserLogicProps): _alloy_js_core5.Children;
|
|
31
31
|
/**
|
|
32
32
|
* The command option interface property.
|
|
33
33
|
*/
|
|
@@ -35,7 +35,7 @@ declare function OptionsMember({
|
|
|
35
35
|
option
|
|
36
36
|
}: {
|
|
37
37
|
option: CommandOption;
|
|
38
|
-
}):
|
|
38
|
+
}): _alloy_js_core5.Children;
|
|
39
39
|
interface OptionsMemberParserLogicProps {
|
|
40
40
|
/**
|
|
41
41
|
* The option name to generate the parser logic for.
|
|
@@ -55,7 +55,7 @@ interface OptionsMemberParserLogicProps {
|
|
|
55
55
|
/**
|
|
56
56
|
* The command option property parser logic.
|
|
57
57
|
*/
|
|
58
|
-
declare function OptionsMemberParserLogic(props: OptionsMemberParserLogicProps):
|
|
58
|
+
declare function OptionsMemberParserLogic(props: OptionsMemberParserLogicProps): _alloy_js_core5.Children;
|
|
59
59
|
interface OptionsMemberParserConditionProps {
|
|
60
60
|
/**
|
|
61
61
|
* The option name to generate the parser logic for.
|
|
@@ -72,10 +72,10 @@ interface OptionsMemberParserConditionProps {
|
|
|
72
72
|
*/
|
|
73
73
|
isCaseSensitive: boolean;
|
|
74
74
|
}
|
|
75
|
-
declare function OptionsMemberParserCondition(props: OptionsMemberParserConditionProps):
|
|
75
|
+
declare function OptionsMemberParserCondition(props: OptionsMemberParserConditionProps): _alloy_js_core5.Children;
|
|
76
76
|
declare function OptionsInterfaceDeclaration(props: {
|
|
77
77
|
command: CommandTree;
|
|
78
|
-
}):
|
|
78
|
+
}): _alloy_js_core5.Children;
|
|
79
79
|
interface OptionsParserLogicProps {
|
|
80
80
|
/**
|
|
81
81
|
* The command to generate the options parser logic for.
|
|
@@ -95,7 +95,7 @@ interface OptionsParserLogicProps {
|
|
|
95
95
|
/**
|
|
96
96
|
* The command options parser logic.
|
|
97
97
|
*/
|
|
98
|
-
declare function OptionsParserLogic(props: OptionsParserLogicProps):
|
|
98
|
+
declare function OptionsParserLogic(props: OptionsParserLogicProps): _alloy_js_core5.Children;
|
|
99
99
|
interface CommandParserLogicProps {
|
|
100
100
|
/**
|
|
101
101
|
* The command to generate the parser logic for.
|
|
@@ -115,7 +115,7 @@ interface CommandParserLogicProps {
|
|
|
115
115
|
/**
|
|
116
116
|
* The command parser logic, which includes parsing dynamic path segments, positional parameters, and options.
|
|
117
117
|
*/
|
|
118
|
-
declare function CommandParserLogic(props: CommandParserLogicProps):
|
|
118
|
+
declare function CommandParserLogic(props: CommandParserLogicProps): _alloy_js_core5.Children;
|
|
119
119
|
//#endregion
|
|
120
120
|
export { ArgumentsParserLogic, ArgumentsParserLogicProps, CommandParserLogic, CommandParserLogicProps, DynamicSegmentsParserLogic, DynamicSegmentsParserLogicProps, OptionsInterfaceDeclaration, OptionsMember, OptionsMemberParserCondition, OptionsMemberParserConditionProps, OptionsMemberParserLogic, OptionsMemberParserLogicProps, OptionsParserLogic, OptionsParserLogicProps };
|
|
121
121
|
//# sourceMappingURL=options-parser-logic.d.mts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommandTree } from "../types/command.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _alloy_js_core0 from "@alloy-js/core";
|
|
3
3
|
|
|
4
4
|
//#region src/components/usage.d.ts
|
|
5
5
|
interface UsageProps {
|
|
@@ -22,7 +22,7 @@ interface UsageProps {
|
|
|
22
22
|
/**
|
|
23
23
|
* A component that generates the usage display for a command.
|
|
24
24
|
*/
|
|
25
|
-
declare function Usage(props: UsageProps):
|
|
25
|
+
declare function Usage(props: UsageProps): _alloy_js_core0.Children;
|
|
26
26
|
//#endregion
|
|
27
27
|
export { Usage, UsageProps };
|
|
28
28
|
//# sourceMappingURL=usage.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.d.mts","names":[],"sources":["../../src/components/usage.tsx"],"sourcesContent":[],"mappings":";;;;UA2BiB,UAAA;;;AAAjB;EAuBgB,OAAA,EAnBL,WAmBkB;;;;;;;;;;;;;;;;iBAAb,KAAA,QAAa,aAAU,
|
|
1
|
+
{"version":3,"file":"usage.d.mts","names":[],"sources":["../../src/components/usage.tsx"],"sourcesContent":[],"mappings":";;;;UA2BiB,UAAA;;;AAAjB;EAuBgB,OAAA,EAnBL,WAmBkB;;;;;;;;;;;;;;;;iBAAb,KAAA,QAAa,aAAU,eAAA,CAAA"}
|
|
@@ -29,7 +29,7 @@ let powerlines_lib_utilities_resolve = require("powerlines/lib/utilities/resolve
|
|
|
29
29
|
* @returns The resolved description for the command option.
|
|
30
30
|
*/
|
|
31
31
|
function resolveCommandOptionDescription(name, kind, optional = false, variadic = false, title, defaultValue) {
|
|
32
|
-
return `A${optional && !defaultValue ? "n optional" : ""} command
|
|
32
|
+
return `A${optional && !defaultValue ? "n optional" : ""} command-line ${kind === __powerlines_deepkit_vendor_type.ReflectionKind.boolean ? "flag" : "option"} that allows the user to ${kind === __powerlines_deepkit_vendor_type.ReflectionKind.boolean ? "set the" : variadic ? "specify custom" : "specify a custom"} ${title?.trim() || (0, __stryke_string_format_title_case.titleCase)(name)} ${kind === __powerlines_deepkit_vendor_type.ReflectionKind.boolean ? "indicator" : `${kind === __powerlines_deepkit_vendor_type.ReflectionKind.number ? "numeric" : "string"} value${variadic ? "s" : ""}`}.`;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* Resolves the description for a command argument based on its reflection.
|
|
@@ -164,7 +164,7 @@ async function reflectCommandTree(context, command, parent) {
|
|
|
164
164
|
const type = (0, __powerlines_deepkit_vendor_type.reflect)(resolved);
|
|
165
165
|
if (type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.function) throw new Error(`The command entry file "${command.entry.input.file}" does not export a valid function.`);
|
|
166
166
|
tree.reflection = new __powerlines_deepkit_vendor_type.ReflectionFunction(type);
|
|
167
|
-
tree.description ??= command.description || type.description || `The ${tree.title.replace(/(?:c|C)ommands?$/, "").trim()} executable command
|
|
167
|
+
tree.description ??= command.description || type.description || `The ${tree.title.replace(/(?:c|C)ommands?$/, "").trim()} executable command-line interface.`;
|
|
168
168
|
const parameters = tree.reflection.getParameters();
|
|
169
169
|
if (parameters.length > 0 && parameters[0]) {
|
|
170
170
|
if (parameters[0].type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral || parameters[0].type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.class) {
|
|
@@ -180,7 +180,7 @@ async function reflectCommandTree(context, command, parent) {
|
|
|
180
180
|
}
|
|
181
181
|
});
|
|
182
182
|
}
|
|
183
|
-
} else tree.description ??= `A collection of available ${tree.title.replace(/(?:c|C)ommands?$/, "").trim() || (0, __stryke_string_format_title_case.titleCase)(tree.name)} commands that are included in the ${require_plugin_utils_context_helpers.getAppTitle(context)} command
|
|
183
|
+
} else tree.description ??= `A collection of available ${tree.title.replace(/(?:c|C)ommands?$/, "").trim() || (0, __stryke_string_format_title_case.titleCase)(tree.name)} commands that are included in the ${require_plugin_utils_context_helpers.getAppTitle(context)} command-line application.`;
|
|
184
184
|
if (context.env) {
|
|
185
185
|
if ((0, __stryke_type_checks_is_set_object.isSetObject)(tree.options)) Object.values(tree.options).filter((option) => option.env !== false).forEach((option) => {
|
|
186
186
|
context.env.types.env.addProperty({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-command.cjs","names":["esbuildPlugin","reflect","ReflectionClass","ReflectionFunction","ReflectionKind","ReflectionVisibility","stringifyType","toArray","appendPath","commonPath","findFilePath","findFolderName","stripStars","replacePath","resolveParentPath","constantCase","titleCase","isSetObject","isSetString","resolveModule","getAppTitle","getDynamicPathSegmentName","isDynamicPathSegment","isPathSegmentGroup","getDefaultOptions","resolveCommandOptionDescription","name","kind","optional","variadic","title","defaultValue","boolean","trim","number","resolveCommandArgumentDescription","resolveCommandId","context","file","commandsPath","split","filter","p","Boolean","join","replaceAll","resolveCommandName","path","requireExtension","resolveCommandPath","resolveCommandDynamicPathSegments","map","findCommandsRoot","config","entry","projectRoot","workspaceConfig","workspaceRoot","Array","isArray","length","sourceRoot","extractCommandOption","command","reflection","type","getType","option","getNameAsString","alias","getTags","description","getDescription","getKind","isOptional","getDefaultValue","env","default","string","Error","extractCommandArgument","array","getName","argument","getAlias","parameter","reflectCommandTree","parent","isVirtual","replace","tree","icon","options","arguments","children","input","fs","existsSync","debug","id","resolved","plugins","reflectionLevel","metadata","function","parameters","getParameters","objectLiteral","class","optionsReflection","from","propertyReflection","getProperties","slice","arg","forEach","index","found","findIndex","segments","some","segment","Object","values","types","addProperty","undefined","visibility","public","tags","domain","inputs","every","value"],"sources":["../../src/helpers/resolve-command.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 { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport type {\n ReflectionParameter,\n ReflectionProperty,\n TypeArray\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n reflect,\n ReflectionClass,\n ReflectionFunction,\n ReflectionKind,\n ReflectionVisibility,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { commonPath } from \"@stryke/path/common\";\nimport { findFilePath, findFolderName } from \"@stryke/path/file-path-fns\";\nimport { stripStars } from \"@stryke/path/normalize\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { resolveModule } from \"powerlines/lib/utilities/resolve\";\nimport {\n getAppTitle,\n getDynamicPathSegmentName,\n isDynamicPathSegment,\n isPathSegmentGroup\n} from \"../plugin-utils/context-helpers\";\nimport type {\n CommandArgument,\n CommandInput,\n CommandModule,\n CommandOption,\n CommandTree,\n NumberCommandArgument,\n NumberCommandOption,\n StringCommandArgument,\n StringCommandOption\n} from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport { getDefaultOptions } from \"./utilities\";\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: ReflectionKind,\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 === ReflectionKind.boolean ? \"flag\" : \"option\"\n } that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.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: ReflectionKind,\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 === ReflectionKind.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\nexport function resolveCommandId(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(p => Boolean(p) && !isDynamicPathSegment(p))\n .join(\"/\")\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .replaceAll(\"/\", \"-\");\n}\n\n/**\n * Finds the command name from the given file path.\n *\n * @param file - The file path to extract the command name from.\n * @returns The command name.\n */\nexport function resolveCommandName(file: string) {\n let path = findFilePath(file);\n let name = findFolderName(file, {\n requireExtension: true\n });\n\n while (isDynamicPathSegment(name)) {\n path = resolveParentPath(path);\n name = findFolderName(path, {\n requireExtension: true\n });\n }\n\n return name;\n}\n\nexport function resolveCommandPath(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .split(\"/\")\n .filter(path => path && !isPathSegmentGroup(path))\n .join(\"/\");\n}\n\nexport function resolveCommandDynamicPathSegments(\n context: Context,\n file: string\n): string[] {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(path => Boolean(path) && isDynamicPathSegment(path))\n .map(path => getDynamicPathSegmentName(path));\n}\n\nexport function findCommandsRoot(context: Context): string {\n if (isSetString(context.config.entry)) {\n return appendPath(\n appendPath(stripStars(context.config.entry), context.config.projectRoot),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n isSetObject(context.config.entry) &&\n \"file\" in context.config.entry\n ) {\n return appendPath(\n appendPath(\n stripStars(context.config.entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n Array.isArray(context.config.entry) &&\n context.config.entry.length > 0\n ) {\n return commonPath(\n context.config.entry.map(entry =>\n appendPath(\n appendPath(\n stripStars(isSetString(entry) ? entry : entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\n }\n\n return appendPath(\n context.config.sourceRoot || context.config.projectRoot,\n context.workspaceConfig.workspaceRoot\n );\n}\n\n/**\n * Extracts command parameter information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command option information.\n */\nexport function extractCommandOption(\n command: CommandInput,\n reflection: ReflectionProperty\n): CommandOption {\n const type = reflection.getType();\n\n const option = {\n name: reflection.getNameAsString(),\n alias: reflection.getTags().alias ?? [],\n title:\n reflection.getTags().title?.trim() ||\n titleCase(reflection.getNameAsString()),\n description:\n reflection.getDescription() ||\n resolveCommandOptionDescription(\n reflection.getNameAsString(),\n reflection.getKind(),\n reflection.isOptional(),\n reflection.isArray(),\n reflection.getTags().title,\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getNameAsString()),\n kind: type.kind as\n | ReflectionKind.string\n | ReflectionKind.number\n | ReflectionKind.boolean,\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n variadic: reflection.isArray(),\n reflection\n } as CommandOption;\n\n if (reflection.isArray()) {\n if (\n (type as TypeArray).type.kind === ReflectionKind.string ||\n (type as TypeArray).type.kind === ReflectionKind.number\n ) {\n (option as StringCommandOption | NumberCommandOption).variadic = true;\n (option as StringCommandOption | NumberCommandOption).kind = (\n type as TypeArray\n ).type.kind as ReflectionKind.string | ReflectionKind.number;\n } else {\n throw new Error(\n `Unsupported array type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return option;\n}\n\n/**\n * Extracts command positional argument information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command positional argument information.\n */\nexport function extractCommandArgument(\n command: CommandInput,\n reflection: ReflectionParameter\n): CommandArgument {\n const type = reflection.getType();\n\n if (\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number &&\n type.kind !== ReflectionKind.boolean &&\n !(\n type.kind === ReflectionKind.array &&\n (type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number)\n )\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string types (or an array of strings) are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const argument = {\n name: reflection.getName(),\n alias: reflection.getAlias(),\n kind: type.kind,\n title: titleCase(reflection.getName()),\n description:\n reflection.parameter.description ||\n resolveCommandArgumentDescription(\n reflection.getName(),\n type.kind === ReflectionKind.array ? type.type.kind : type.kind,\n reflection.isOptional(),\n type.kind === ReflectionKind.array,\n titleCase(reflection.getName()),\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getName()),\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n reflection\n } as CommandArgument;\n\n if (type.kind === ReflectionKind.array) {\n if (\n type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number\n ) {\n (argument as StringCommandArgument | NumberCommandArgument).variadic =\n true;\n (argument as StringCommandArgument | NumberCommandArgument).kind =\n type.type.kind;\n } else {\n throw new Error(\n `Unsupported array type for argument \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return argument;\n}\n\n/**\n * Reflects the command tree for a given command input.\n *\n * @param context - The context in which the command is being reflected.\n * @param command - The command input to reflect.\n * @param parent - The parent command tree, if any.\n * @returns The reflected command tree.\n */\nexport async function reflectCommandTree<TContext extends Context = Context>(\n context: TContext,\n command: CommandInput,\n parent?: CommandTree\n): Promise<CommandTree> {\n const title =\n command.title ||\n `${\n parent?.title\n ? `${\n parent.isVirtual\n ? parent.title.replace(/(?:c|C)ommands?$/, \"\").trim()\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const tree = {\n alias: [],\n icon: parent?.icon,\n ...command,\n title,\n options: getDefaultOptions(context, command),\n arguments: [],\n parent: parent ?? null,\n children: {},\n reflection: null\n } as CommandTree;\n\n if (!command.isVirtual) {\n if (\n !command.entry.input?.file ||\n !context.fs.existsSync(command.entry.input.file)\n ) {\n throw new Error(\n `${\n !command.entry.input?.file ? \"Missing\" : \"Non-existent\"\n } command entry file for \"${command.name}\"`\n );\n }\n\n context.debug(\n `Adding reflection for user-defined command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n const resolved = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n reflectionLevel: \"verbose\"\n })\n ]\n }\n );\n\n const metadata = resolved.metadata ?? {};\n if (isSetString(metadata.title)) {\n tree.title = metadata.title;\n }\n if (isSetString(metadata.description)) {\n tree.description = metadata.description;\n }\n if (\n isSetString(metadata.alias) ||\n (Array.isArray(metadata.alias) && metadata.alias.length > 0)\n ) {\n tree.alias = toArray(metadata.alias);\n }\n if (isSetString(metadata.icon)) {\n tree.icon = metadata.icon;\n }\n\n const type = reflect(resolved);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `The command entry file \"${command.entry.input.file}\" does not export a valid function.`\n );\n }\n\n tree.reflection = new ReflectionFunction(type);\n tree.description ??=\n command.description ||\n type.description ||\n `The ${tree.title.replace(/(?:c|C)ommands?$/, \"\").trim()} executable command line interface.`;\n\n const parameters = tree.reflection.getParameters();\n if (parameters.length > 0 && parameters[0]) {\n if (\n parameters[0].type.kind === ReflectionKind.objectLiteral ||\n parameters[0].type.kind === ReflectionKind.class\n ) {\n const optionsReflection = ReflectionClass.from(parameters[0].type);\n for (const propertyReflection of optionsReflection.getProperties()) {\n tree.options[propertyReflection.getNameAsString()] =\n extractCommandOption(command, propertyReflection);\n }\n } else {\n throw new Error(\n `The first parameter of the command handler function in \"${\n command.entry.input.file\n }\" must be an object literal or class type representing the command options.`\n );\n }\n\n tree.arguments = parameters\n .slice(1)\n .map(arg => extractCommandArgument(command, arg));\n\n // Ensure unique argument names by appending an index suffix to duplicates\n tree.arguments.forEach((argument, index) => {\n const found = tree.arguments.findIndex(\n arg => arg.name === argument.name\n );\n if (\n (found !== -1 && found !== index) ||\n tree.segments.some(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment) === argument.name\n )\n ) {\n argument.name += `_${\n tree.segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(/_\\d+$/, \"\") ===\n argument.name\n ).length +\n tree.arguments.filter(\n arg => arg.name.replace(/_\\d+$/, \"\") === argument.name\n ).length\n }`;\n argument.env = constantCase(argument.name);\n }\n });\n }\n } else {\n tree.description ??= `A collection of available ${\n tree.title.replace(/(?:c|C)ommands?$/, \"\").trim() || titleCase(tree.name)\n } commands that are included in the ${getAppTitle(\n context\n )} command line application.`;\n }\n\n if (context.env) {\n if (isSetObject(tree.options)) {\n Object.values(tree.options)\n .filter(option => option.env !== false)\n .forEach(option => {\n context.env.types.env.addProperty({\n name: option.env as string,\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type:\n option.reflection?.getType() ??\n ((option as StringCommandOption | NumberCommandOption).variadic\n ? { kind: ReflectionKind.array, type: { kind: option.kind } }\n : { kind: option.kind }),\n default: option.default,\n tags: {\n ...option.reflection?.getTags(),\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n tree.arguments\n .filter(arg => arg.env !== false)\n .forEach(arg =>\n context.env.types.env.addProperty({\n name: arg.env as string,\n optional: arg.optional ? true : undefined,\n description: arg.description,\n visibility: ReflectionVisibility.public,\n type: arg.reflection.getType(),\n default: arg.default,\n tags: {\n ...arg.reflection.getTags(),\n alias: arg.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n })\n );\n }\n\n for (const input of context.inputs.filter(\n input =>\n input.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n command.segments.filter(segment => !isDynamicPathSegment(segment))\n .length +\n 1 &&\n input.segments\n .slice(0, command.segments.length)\n .every((value, index) => value === command.segments[index])\n )) {\n tree.children[input.name] = await reflectCommandTree(context, input, tree);\n }\n\n return tree;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,SAAgByB,gCACdC,MACAC,MACAC,WAAW,OACXC,WAAW,OACXC,OACAC,cACQ;AACR,QAAO,IAAIH,YAAY,CAACG,eAAe,eAAe,GAAE,gBACtDJ,SAASvB,gDAAe4B,UAAU,SAAS,SAAQ,2BAEnDL,SAASvB,gDAAe4B,UACpB,YACAH,WACE,mBACA,mBAAkB,GACtBC,OAAOG,MAAM,qDAAcP,KAAK,CAAA,GAClCC,SAASvB,gDAAe4B,UACpB,cACA,GAAGL,SAASvB,gDAAe8B,SAAS,YAAY,SAAQ,QACtDL,WAAW,MAAM,KACjB;;;;;;;;;;;;;AAeV,SAAgBM,kCACdT,MACAC,MACAC,WAAW,OACXC,WAAW,OACXC,OACAC,cACQ;AACR,QAAO,KACLH,YAAY,CAACG,eAAe,cAAc,GAAE,oCAE5CJ,SAASvB,gDAAe4B,UACpB,YACAH,WACE,mBACA,mBAAkB,GACtBC,OAAOG,MAAM,qDAAcP,KAAK,CAAA,GAClCC,SAASvB,gDAAe4B,UACpB,cACA,GAAGL,SAASvB,gDAAe8B,SAAS,YAAY,SAAQ,QACtDL,WAAW,MAAM,KACjB;;AAIV,SAAgBO,iBAAiBC,SAAkBC,MAAsB;AACvE,6FAAgCA,KAAK,EAAED,QAAQE,aAAa,CACzDC,MAAM,IAAI,CACVC,QAAOC,MAAKC,QAAQD,EAAE,IAAI,CAAC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{"version":3,"file":"resolve-command.cjs","names":["esbuildPlugin","reflect","ReflectionClass","ReflectionFunction","ReflectionKind","ReflectionVisibility","stringifyType","toArray","appendPath","commonPath","findFilePath","findFolderName","stripStars","replacePath","resolveParentPath","constantCase","titleCase","isSetObject","isSetString","resolveModule","getAppTitle","getDynamicPathSegmentName","isDynamicPathSegment","isPathSegmentGroup","getDefaultOptions","resolveCommandOptionDescription","name","kind","optional","variadic","title","defaultValue","boolean","trim","number","resolveCommandArgumentDescription","resolveCommandId","context","file","commandsPath","split","filter","p","Boolean","join","replaceAll","resolveCommandName","path","requireExtension","resolveCommandPath","resolveCommandDynamicPathSegments","map","findCommandsRoot","config","entry","projectRoot","workspaceConfig","workspaceRoot","Array","isArray","length","sourceRoot","extractCommandOption","command","reflection","type","getType","option","getNameAsString","alias","getTags","description","getDescription","getKind","isOptional","getDefaultValue","env","default","string","Error","extractCommandArgument","array","getName","argument","getAlias","parameter","reflectCommandTree","parent","isVirtual","replace","tree","icon","options","arguments","children","input","fs","existsSync","debug","id","resolved","plugins","reflectionLevel","metadata","function","parameters","getParameters","objectLiteral","class","optionsReflection","from","propertyReflection","getProperties","slice","arg","forEach","index","found","findIndex","segments","some","segment","Object","values","types","addProperty","undefined","visibility","public","tags","domain","inputs","every","value"],"sources":["../../src/helpers/resolve-command.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 { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport type {\n ReflectionParameter,\n ReflectionProperty,\n TypeArray\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n reflect,\n ReflectionClass,\n ReflectionFunction,\n ReflectionKind,\n ReflectionVisibility,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { commonPath } from \"@stryke/path/common\";\nimport { findFilePath, findFolderName } from \"@stryke/path/file-path-fns\";\nimport { stripStars } from \"@stryke/path/normalize\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { resolveModule } from \"powerlines/lib/utilities/resolve\";\nimport {\n getAppTitle,\n getDynamicPathSegmentName,\n isDynamicPathSegment,\n isPathSegmentGroup\n} from \"../plugin-utils/context-helpers\";\nimport type {\n CommandArgument,\n CommandInput,\n CommandModule,\n CommandOption,\n CommandTree,\n NumberCommandArgument,\n NumberCommandOption,\n StringCommandArgument,\n StringCommandOption\n} from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport { getDefaultOptions } from \"./utilities\";\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: ReflectionKind,\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 === ReflectionKind.boolean ? \"flag\" : \"option\"\n } that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.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: ReflectionKind,\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 === ReflectionKind.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\nexport function resolveCommandId(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(p => Boolean(p) && !isDynamicPathSegment(p))\n .join(\"/\")\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .replaceAll(\"/\", \"-\");\n}\n\n/**\n * Finds the command name from the given file path.\n *\n * @param file - The file path to extract the command name from.\n * @returns The command name.\n */\nexport function resolveCommandName(file: string) {\n let path = findFilePath(file);\n let name = findFolderName(file, {\n requireExtension: true\n });\n\n while (isDynamicPathSegment(name)) {\n path = resolveParentPath(path);\n name = findFolderName(path, {\n requireExtension: true\n });\n }\n\n return name;\n}\n\nexport function resolveCommandPath(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .split(\"/\")\n .filter(path => path && !isPathSegmentGroup(path))\n .join(\"/\");\n}\n\nexport function resolveCommandDynamicPathSegments(\n context: Context,\n file: string\n): string[] {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(path => Boolean(path) && isDynamicPathSegment(path))\n .map(path => getDynamicPathSegmentName(path));\n}\n\nexport function findCommandsRoot(context: Context): string {\n if (isSetString(context.config.entry)) {\n return appendPath(\n appendPath(stripStars(context.config.entry), context.config.projectRoot),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n isSetObject(context.config.entry) &&\n \"file\" in context.config.entry\n ) {\n return appendPath(\n appendPath(\n stripStars(context.config.entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n Array.isArray(context.config.entry) &&\n context.config.entry.length > 0\n ) {\n return commonPath(\n context.config.entry.map(entry =>\n appendPath(\n appendPath(\n stripStars(isSetString(entry) ? entry : entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\n }\n\n return appendPath(\n context.config.sourceRoot || context.config.projectRoot,\n context.workspaceConfig.workspaceRoot\n );\n}\n\n/**\n * Extracts command parameter information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command option information.\n */\nexport function extractCommandOption(\n command: CommandInput,\n reflection: ReflectionProperty\n): CommandOption {\n const type = reflection.getType();\n\n const option = {\n name: reflection.getNameAsString(),\n alias: reflection.getTags().alias ?? [],\n title:\n reflection.getTags().title?.trim() ||\n titleCase(reflection.getNameAsString()),\n description:\n reflection.getDescription() ||\n resolveCommandOptionDescription(\n reflection.getNameAsString(),\n reflection.getKind(),\n reflection.isOptional(),\n reflection.isArray(),\n reflection.getTags().title,\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getNameAsString()),\n kind: type.kind as\n | ReflectionKind.string\n | ReflectionKind.number\n | ReflectionKind.boolean,\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n variadic: reflection.isArray(),\n reflection\n } as CommandOption;\n\n if (reflection.isArray()) {\n if (\n (type as TypeArray).type.kind === ReflectionKind.string ||\n (type as TypeArray).type.kind === ReflectionKind.number\n ) {\n (option as StringCommandOption | NumberCommandOption).variadic = true;\n (option as StringCommandOption | NumberCommandOption).kind = (\n type as TypeArray\n ).type.kind as ReflectionKind.string | ReflectionKind.number;\n } else {\n throw new Error(\n `Unsupported array type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return option;\n}\n\n/**\n * Extracts command positional argument information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command positional argument information.\n */\nexport function extractCommandArgument(\n command: CommandInput,\n reflection: ReflectionParameter\n): CommandArgument {\n const type = reflection.getType();\n\n if (\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number &&\n type.kind !== ReflectionKind.boolean &&\n !(\n type.kind === ReflectionKind.array &&\n (type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number)\n )\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string types (or an array of strings) are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const argument = {\n name: reflection.getName(),\n alias: reflection.getAlias(),\n kind: type.kind,\n title: titleCase(reflection.getName()),\n description:\n reflection.parameter.description ||\n resolveCommandArgumentDescription(\n reflection.getName(),\n type.kind === ReflectionKind.array ? type.type.kind : type.kind,\n reflection.isOptional(),\n type.kind === ReflectionKind.array,\n titleCase(reflection.getName()),\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getName()),\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n reflection\n } as CommandArgument;\n\n if (type.kind === ReflectionKind.array) {\n if (\n type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number\n ) {\n (argument as StringCommandArgument | NumberCommandArgument).variadic =\n true;\n (argument as StringCommandArgument | NumberCommandArgument).kind =\n type.type.kind;\n } else {\n throw new Error(\n `Unsupported array type for argument \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return argument;\n}\n\n/**\n * Reflects the command tree for a given command input.\n *\n * @param context - The context in which the command is being reflected.\n * @param command - The command input to reflect.\n * @param parent - The parent command tree, if any.\n * @returns The reflected command tree.\n */\nexport async function reflectCommandTree<TContext extends Context = Context>(\n context: TContext,\n command: CommandInput,\n parent?: CommandTree\n): Promise<CommandTree> {\n const title =\n command.title ||\n `${\n parent?.title\n ? `${\n parent.isVirtual\n ? parent.title.replace(/(?:c|C)ommands?$/, \"\").trim()\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const tree = {\n alias: [],\n icon: parent?.icon,\n ...command,\n title,\n options: getDefaultOptions(context, command),\n arguments: [],\n parent: parent ?? null,\n children: {},\n reflection: null\n } as CommandTree;\n\n if (!command.isVirtual) {\n if (\n !command.entry.input?.file ||\n !context.fs.existsSync(command.entry.input.file)\n ) {\n throw new Error(\n `${\n !command.entry.input?.file ? \"Missing\" : \"Non-existent\"\n } command entry file for \"${command.name}\"`\n );\n }\n\n context.debug(\n `Adding reflection for user-defined command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n const resolved = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n reflectionLevel: \"verbose\"\n })\n ]\n }\n );\n\n const metadata = resolved.metadata ?? {};\n if (isSetString(metadata.title)) {\n tree.title = metadata.title;\n }\n if (isSetString(metadata.description)) {\n tree.description = metadata.description;\n }\n if (\n isSetString(metadata.alias) ||\n (Array.isArray(metadata.alias) && metadata.alias.length > 0)\n ) {\n tree.alias = toArray(metadata.alias);\n }\n if (isSetString(metadata.icon)) {\n tree.icon = metadata.icon;\n }\n\n const type = reflect(resolved);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `The command entry file \"${command.entry.input.file}\" does not export a valid function.`\n );\n }\n\n tree.reflection = new ReflectionFunction(type);\n tree.description ??=\n command.description ||\n type.description ||\n `The ${tree.title.replace(/(?:c|C)ommands?$/, \"\").trim()} executable command-line interface.`;\n\n const parameters = tree.reflection.getParameters();\n if (parameters.length > 0 && parameters[0]) {\n if (\n parameters[0].type.kind === ReflectionKind.objectLiteral ||\n parameters[0].type.kind === ReflectionKind.class\n ) {\n const optionsReflection = ReflectionClass.from(parameters[0].type);\n for (const propertyReflection of optionsReflection.getProperties()) {\n tree.options[propertyReflection.getNameAsString()] =\n extractCommandOption(command, propertyReflection);\n }\n } else {\n throw new Error(\n `The first parameter of the command handler function in \"${\n command.entry.input.file\n }\" must be an object literal or class type representing the command options.`\n );\n }\n\n tree.arguments = parameters\n .slice(1)\n .map(arg => extractCommandArgument(command, arg));\n\n // Ensure unique argument names by appending an index suffix to duplicates\n tree.arguments.forEach((argument, index) => {\n const found = tree.arguments.findIndex(\n arg => arg.name === argument.name\n );\n if (\n (found !== -1 && found !== index) ||\n tree.segments.some(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment) === argument.name\n )\n ) {\n argument.name += `_${\n tree.segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(/_\\d+$/, \"\") ===\n argument.name\n ).length +\n tree.arguments.filter(\n arg => arg.name.replace(/_\\d+$/, \"\") === argument.name\n ).length\n }`;\n argument.env = constantCase(argument.name);\n }\n });\n }\n } else {\n tree.description ??= `A collection of available ${\n tree.title.replace(/(?:c|C)ommands?$/, \"\").trim() || titleCase(tree.name)\n } commands that are included in the ${getAppTitle(\n context\n )} command-line application.`;\n }\n\n if (context.env) {\n if (isSetObject(tree.options)) {\n Object.values(tree.options)\n .filter(option => option.env !== false)\n .forEach(option => {\n context.env.types.env.addProperty({\n name: option.env as string,\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type:\n option.reflection?.getType() ??\n ((option as StringCommandOption | NumberCommandOption).variadic\n ? { kind: ReflectionKind.array, type: { kind: option.kind } }\n : { kind: option.kind }),\n default: option.default,\n tags: {\n ...option.reflection?.getTags(),\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n tree.arguments\n .filter(arg => arg.env !== false)\n .forEach(arg =>\n context.env.types.env.addProperty({\n name: arg.env as string,\n optional: arg.optional ? true : undefined,\n description: arg.description,\n visibility: ReflectionVisibility.public,\n type: arg.reflection.getType(),\n default: arg.default,\n tags: {\n ...arg.reflection.getTags(),\n alias: arg.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n })\n );\n }\n\n for (const input of context.inputs.filter(\n input =>\n input.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n command.segments.filter(segment => !isDynamicPathSegment(segment))\n .length +\n 1 &&\n input.segments\n .slice(0, command.segments.length)\n .every((value, index) => value === command.segments[index])\n )) {\n tree.children[input.name] = await reflectCommandTree(context, input, tree);\n }\n\n return tree;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,SAAgByB,gCACdC,MACAC,MACAC,WAAW,OACXC,WAAW,OACXC,OACAC,cACQ;AACR,QAAO,IAAIH,YAAY,CAACG,eAAe,eAAe,GAAE,gBACtDJ,SAASvB,gDAAe4B,UAAU,SAAS,SAAQ,2BAEnDL,SAASvB,gDAAe4B,UACpB,YACAH,WACE,mBACA,mBAAkB,GACtBC,OAAOG,MAAM,qDAAcP,KAAK,CAAA,GAClCC,SAASvB,gDAAe4B,UACpB,cACA,GAAGL,SAASvB,gDAAe8B,SAAS,YAAY,SAAQ,QACtDL,WAAW,MAAM,KACjB;;;;;;;;;;;;;AAeV,SAAgBM,kCACdT,MACAC,MACAC,WAAW,OACXC,WAAW,OACXC,OACAC,cACQ;AACR,QAAO,KACLH,YAAY,CAACG,eAAe,cAAc,GAAE,oCAE5CJ,SAASvB,gDAAe4B,UACpB,YACAH,WACE,mBACA,mBAAkB,GACtBC,OAAOG,MAAM,qDAAcP,KAAK,CAAA,GAClCC,SAASvB,gDAAe4B,UACpB,cACA,GAAGL,SAASvB,gDAAe8B,SAAS,YAAY,SAAQ,QACtDL,WAAW,MAAM,KACjB;;AAIV,SAAgBO,iBAAiBC,SAAkBC,MAAsB;AACvE,6FAAgCA,KAAK,EAAED,QAAQE,aAAa,CACzDC,MAAM,IAAI,CACVC,QAAOC,MAAKC,QAAQD,EAAE,IAAI,CAACpB,0DAAqBoB,EAAE,CAAC,CACnDE,KAAK,IAAI,CACTC,WAAW,SAAS,GAAG,CACvBA,WAAW,SAAS,GAAG,CACvBA,WAAW,KAAK,IAAI;;;;;;;;AASzB,SAAgBC,mBAAmBR,MAAc;CAC/C,IAAIS,qDAAoBT,KAAK;CAC7B,IAAIZ,uDAAsBY,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S,EAAE,CACjCT,KAAIkB,iEAAsBA,MAAM,CAAC;KACpC6D,QAAQ;KACV;IACD,CAAC;IACF;AAGNxC,OAAKG,UACFpD,QAAOyE,QAAOA,IAAItC,QAAQ,MAAM,CAChCuC,SAAQD,QACP7E,QAAQuC,IAAIgD,MAAMhD,IAAIiD,YAAY;GAChCnG,MAAMwF,IAAItC;GACVhD,UAAUsF,IAAItF,WAAW,OAAOkG;GAChCvD,aAAa2C,IAAI3C;GACjBwD,YAAY1H,sDAAqB2H;GACjC/D,MAAMiD,IAAIlD,WAAWE,SAAS;GAC9BW,SAASqC,IAAIrC;GACboD,MAAM;IACJ,GAAGf,IAAIlD,WAAWM,SAAS;IAC3BD,OAAO6C,IAAI7C,MACR5B,QAAO4B,UAASA,MAAMT,SAAS,EAAE,CACjCT,KAAIkB,iEAAsBA,MAAM,CAAC;IACpC6D,QAAQ;IACV;GACD,CACH,CAAC;;AAGL,MAAK,MAAMnC,SAAS1D,QAAQ8F,OAAO1F,QACjCsD,YACEA,QAAMwB,SAAS9E,QAAOgF,YAAW,CAACnG,0DAAqBmG,QAAQ,CAAC,CAC7D7D,WACDG,QAAQwD,SAAS9E,QAAOgF,YAAW,CAACnG,0DAAqBmG,QAAQ,CAAC,CAC/D7D,SACD,KACJmC,QAAMwB,SACHN,MAAM,GAAGlD,QAAQwD,SAAS3D,OAAO,CACjCwE,OAAOC,OAAOjB,UAAUiB,UAAUtE,QAAQwD,SAASH,OAC1D,CAAC,CACC1B,MAAKI,SAASC,MAAMrE,QAAQ,MAAM4D,mBAAmBjD,SAAS0D,OAAOL,KAAK;AAG5E,QAAOA"}
|
|
@@ -28,7 +28,7 @@ import { resolveModule } from "powerlines/lib/utilities/resolve";
|
|
|
28
28
|
* @returns The resolved description for the command option.
|
|
29
29
|
*/
|
|
30
30
|
function resolveCommandOptionDescription(name, kind, optional = false, variadic = false, title, defaultValue) {
|
|
31
|
-
return `A${optional && !defaultValue ? "n optional" : ""} command
|
|
31
|
+
return `A${optional && !defaultValue ? "n optional" : ""} command-line ${kind === ReflectionKind.boolean ? "flag" : "option"} that allows the user to ${kind === ReflectionKind.boolean ? "set the" : variadic ? "specify custom" : "specify a custom"} ${title?.trim() || titleCase(name)} ${kind === ReflectionKind.boolean ? "indicator" : `${kind === ReflectionKind.number ? "numeric" : "string"} value${variadic ? "s" : ""}`}.`;
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Resolves the description for a command argument based on its reflection.
|
|
@@ -163,7 +163,7 @@ async function reflectCommandTree(context, command, parent) {
|
|
|
163
163
|
const type = reflect(resolved);
|
|
164
164
|
if (type.kind !== ReflectionKind.function) throw new Error(`The command entry file "${command.entry.input.file}" does not export a valid function.`);
|
|
165
165
|
tree.reflection = new ReflectionFunction(type);
|
|
166
|
-
tree.description ??= command.description || type.description || `The ${tree.title.replace(/(?:c|C)ommands?$/, "").trim()} executable command
|
|
166
|
+
tree.description ??= command.description || type.description || `The ${tree.title.replace(/(?:c|C)ommands?$/, "").trim()} executable command-line interface.`;
|
|
167
167
|
const parameters = tree.reflection.getParameters();
|
|
168
168
|
if (parameters.length > 0 && parameters[0]) {
|
|
169
169
|
if (parameters[0].type.kind === ReflectionKind.objectLiteral || parameters[0].type.kind === ReflectionKind.class) {
|
|
@@ -179,7 +179,7 @@ async function reflectCommandTree(context, command, parent) {
|
|
|
179
179
|
}
|
|
180
180
|
});
|
|
181
181
|
}
|
|
182
|
-
} else tree.description ??= `A collection of available ${tree.title.replace(/(?:c|C)ommands?$/, "").trim() || titleCase(tree.name)} commands that are included in the ${getAppTitle(context)} command
|
|
182
|
+
} else tree.description ??= `A collection of available ${tree.title.replace(/(?:c|C)ommands?$/, "").trim() || titleCase(tree.name)} commands that are included in the ${getAppTitle(context)} command-line application.`;
|
|
183
183
|
if (context.env) {
|
|
184
184
|
if (isSetObject(tree.options)) Object.values(tree.options).filter((option) => option.env !== false).forEach((option) => {
|
|
185
185
|
context.env.types.env.addProperty({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-command.mjs","names":["esbuildPlugin","reflect","ReflectionClass","ReflectionFunction","ReflectionKind","ReflectionVisibility","stringifyType","toArray","appendPath","commonPath","findFilePath","findFolderName","stripStars","replacePath","resolveParentPath","constantCase","titleCase","isSetObject","isSetString","resolveModule","getAppTitle","getDynamicPathSegmentName","isDynamicPathSegment","isPathSegmentGroup","getDefaultOptions","resolveCommandOptionDescription","name","kind","optional","variadic","title","defaultValue","boolean","trim","number","resolveCommandArgumentDescription","resolveCommandId","context","file","commandsPath","split","filter","p","Boolean","join","replaceAll","resolveCommandName","path","requireExtension","resolveCommandPath","resolveCommandDynamicPathSegments","map","findCommandsRoot","config","entry","projectRoot","workspaceConfig","workspaceRoot","Array","isArray","length","sourceRoot","extractCommandOption","command","reflection","type","getType","option","getNameAsString","alias","getTags","description","getDescription","getKind","isOptional","getDefaultValue","env","default","string","Error","extractCommandArgument","array","getName","argument","getAlias","parameter","reflectCommandTree","parent","isVirtual","replace","tree","icon","options","arguments","children","input","fs","existsSync","debug","id","resolved","plugins","reflectionLevel","metadata","function","parameters","getParameters","objectLiteral","class","optionsReflection","from","propertyReflection","getProperties","slice","arg","forEach","index","found","findIndex","segments","some","segment","Object","values","types","addProperty","undefined","visibility","public","tags","domain","inputs","every","value"],"sources":["../../src/helpers/resolve-command.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 { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport type {\n ReflectionParameter,\n ReflectionProperty,\n TypeArray\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n reflect,\n ReflectionClass,\n ReflectionFunction,\n ReflectionKind,\n ReflectionVisibility,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { commonPath } from \"@stryke/path/common\";\nimport { findFilePath, findFolderName } from \"@stryke/path/file-path-fns\";\nimport { stripStars } from \"@stryke/path/normalize\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { resolveModule } from \"powerlines/lib/utilities/resolve\";\nimport {\n getAppTitle,\n getDynamicPathSegmentName,\n isDynamicPathSegment,\n isPathSegmentGroup\n} from \"../plugin-utils/context-helpers\";\nimport type {\n CommandArgument,\n CommandInput,\n CommandModule,\n CommandOption,\n CommandTree,\n NumberCommandArgument,\n NumberCommandOption,\n StringCommandArgument,\n StringCommandOption\n} from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport { getDefaultOptions } from \"./utilities\";\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: ReflectionKind,\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 === ReflectionKind.boolean ? \"flag\" : \"option\"\n } that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.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: ReflectionKind,\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 === ReflectionKind.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\nexport function resolveCommandId(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(p => Boolean(p) && !isDynamicPathSegment(p))\n .join(\"/\")\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .replaceAll(\"/\", \"-\");\n}\n\n/**\n * Finds the command name from the given file path.\n *\n * @param file - The file path to extract the command name from.\n * @returns The command name.\n */\nexport function resolveCommandName(file: string) {\n let path = findFilePath(file);\n let name = findFolderName(file, {\n requireExtension: true\n });\n\n while (isDynamicPathSegment(name)) {\n path = resolveParentPath(path);\n name = findFolderName(path, {\n requireExtension: true\n });\n }\n\n return name;\n}\n\nexport function resolveCommandPath(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .split(\"/\")\n .filter(path => path && !isPathSegmentGroup(path))\n .join(\"/\");\n}\n\nexport function resolveCommandDynamicPathSegments(\n context: Context,\n file: string\n): string[] {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(path => Boolean(path) && isDynamicPathSegment(path))\n .map(path => getDynamicPathSegmentName(path));\n}\n\nexport function findCommandsRoot(context: Context): string {\n if (isSetString(context.config.entry)) {\n return appendPath(\n appendPath(stripStars(context.config.entry), context.config.projectRoot),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n isSetObject(context.config.entry) &&\n \"file\" in context.config.entry\n ) {\n return appendPath(\n appendPath(\n stripStars(context.config.entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n Array.isArray(context.config.entry) &&\n context.config.entry.length > 0\n ) {\n return commonPath(\n context.config.entry.map(entry =>\n appendPath(\n appendPath(\n stripStars(isSetString(entry) ? entry : entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\n }\n\n return appendPath(\n context.config.sourceRoot || context.config.projectRoot,\n context.workspaceConfig.workspaceRoot\n );\n}\n\n/**\n * Extracts command parameter information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command option information.\n */\nexport function extractCommandOption(\n command: CommandInput,\n reflection: ReflectionProperty\n): CommandOption {\n const type = reflection.getType();\n\n const option = {\n name: reflection.getNameAsString(),\n alias: reflection.getTags().alias ?? [],\n title:\n reflection.getTags().title?.trim() ||\n titleCase(reflection.getNameAsString()),\n description:\n reflection.getDescription() ||\n resolveCommandOptionDescription(\n reflection.getNameAsString(),\n reflection.getKind(),\n reflection.isOptional(),\n reflection.isArray(),\n reflection.getTags().title,\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getNameAsString()),\n kind: type.kind as\n | ReflectionKind.string\n | ReflectionKind.number\n | ReflectionKind.boolean,\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n variadic: reflection.isArray(),\n reflection\n } as CommandOption;\n\n if (reflection.isArray()) {\n if (\n (type as TypeArray).type.kind === ReflectionKind.string ||\n (type as TypeArray).type.kind === ReflectionKind.number\n ) {\n (option as StringCommandOption | NumberCommandOption).variadic = true;\n (option as StringCommandOption | NumberCommandOption).kind = (\n type as TypeArray\n ).type.kind as ReflectionKind.string | ReflectionKind.number;\n } else {\n throw new Error(\n `Unsupported array type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return option;\n}\n\n/**\n * Extracts command positional argument information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command positional argument information.\n */\nexport function extractCommandArgument(\n command: CommandInput,\n reflection: ReflectionParameter\n): CommandArgument {\n const type = reflection.getType();\n\n if (\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number &&\n type.kind !== ReflectionKind.boolean &&\n !(\n type.kind === ReflectionKind.array &&\n (type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number)\n )\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string types (or an array of strings) are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const argument = {\n name: reflection.getName(),\n alias: reflection.getAlias(),\n kind: type.kind,\n title: titleCase(reflection.getName()),\n description:\n reflection.parameter.description ||\n resolveCommandArgumentDescription(\n reflection.getName(),\n type.kind === ReflectionKind.array ? type.type.kind : type.kind,\n reflection.isOptional(),\n type.kind === ReflectionKind.array,\n titleCase(reflection.getName()),\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getName()),\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n reflection\n } as CommandArgument;\n\n if (type.kind === ReflectionKind.array) {\n if (\n type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number\n ) {\n (argument as StringCommandArgument | NumberCommandArgument).variadic =\n true;\n (argument as StringCommandArgument | NumberCommandArgument).kind =\n type.type.kind;\n } else {\n throw new Error(\n `Unsupported array type for argument \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return argument;\n}\n\n/**\n * Reflects the command tree for a given command input.\n *\n * @param context - The context in which the command is being reflected.\n * @param command - The command input to reflect.\n * @param parent - The parent command tree, if any.\n * @returns The reflected command tree.\n */\nexport async function reflectCommandTree<TContext extends Context = Context>(\n context: TContext,\n command: CommandInput,\n parent?: CommandTree\n): Promise<CommandTree> {\n const title =\n command.title ||\n `${\n parent?.title\n ? `${\n parent.isVirtual\n ? parent.title.replace(/(?:c|C)ommands?$/, \"\").trim()\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const tree = {\n alias: [],\n icon: parent?.icon,\n ...command,\n title,\n options: getDefaultOptions(context, command),\n arguments: [],\n parent: parent ?? null,\n children: {},\n reflection: null\n } as CommandTree;\n\n if (!command.isVirtual) {\n if (\n !command.entry.input?.file ||\n !context.fs.existsSync(command.entry.input.file)\n ) {\n throw new Error(\n `${\n !command.entry.input?.file ? \"Missing\" : \"Non-existent\"\n } command entry file for \"${command.name}\"`\n );\n }\n\n context.debug(\n `Adding reflection for user-defined command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n const resolved = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n reflectionLevel: \"verbose\"\n })\n ]\n }\n );\n\n const metadata = resolved.metadata ?? {};\n if (isSetString(metadata.title)) {\n tree.title = metadata.title;\n }\n if (isSetString(metadata.description)) {\n tree.description = metadata.description;\n }\n if (\n isSetString(metadata.alias) ||\n (Array.isArray(metadata.alias) && metadata.alias.length > 0)\n ) {\n tree.alias = toArray(metadata.alias);\n }\n if (isSetString(metadata.icon)) {\n tree.icon = metadata.icon;\n }\n\n const type = reflect(resolved);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `The command entry file \"${command.entry.input.file}\" does not export a valid function.`\n );\n }\n\n tree.reflection = new ReflectionFunction(type);\n tree.description ??=\n command.description ||\n type.description ||\n `The ${tree.title.replace(/(?:c|C)ommands?$/, \"\").trim()} executable command line interface.`;\n\n const parameters = tree.reflection.getParameters();\n if (parameters.length > 0 && parameters[0]) {\n if (\n parameters[0].type.kind === ReflectionKind.objectLiteral ||\n parameters[0].type.kind === ReflectionKind.class\n ) {\n const optionsReflection = ReflectionClass.from(parameters[0].type);\n for (const propertyReflection of optionsReflection.getProperties()) {\n tree.options[propertyReflection.getNameAsString()] =\n extractCommandOption(command, propertyReflection);\n }\n } else {\n throw new Error(\n `The first parameter of the command handler function in \"${\n command.entry.input.file\n }\" must be an object literal or class type representing the command options.`\n );\n }\n\n tree.arguments = parameters\n .slice(1)\n .map(arg => extractCommandArgument(command, arg));\n\n // Ensure unique argument names by appending an index suffix to duplicates\n tree.arguments.forEach((argument, index) => {\n const found = tree.arguments.findIndex(\n arg => arg.name === argument.name\n );\n if (\n (found !== -1 && found !== index) ||\n tree.segments.some(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment) === argument.name\n )\n ) {\n argument.name += `_${\n tree.segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(/_\\d+$/, \"\") ===\n argument.name\n ).length +\n tree.arguments.filter(\n arg => arg.name.replace(/_\\d+$/, \"\") === argument.name\n ).length\n }`;\n argument.env = constantCase(argument.name);\n }\n });\n }\n } else {\n tree.description ??= `A collection of available ${\n tree.title.replace(/(?:c|C)ommands?$/, \"\").trim() || titleCase(tree.name)\n } commands that are included in the ${getAppTitle(\n context\n )} command line application.`;\n }\n\n if (context.env) {\n if (isSetObject(tree.options)) {\n Object.values(tree.options)\n .filter(option => option.env !== false)\n .forEach(option => {\n context.env.types.env.addProperty({\n name: option.env as string,\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type:\n option.reflection?.getType() ??\n ((option as StringCommandOption | NumberCommandOption).variadic\n ? { kind: ReflectionKind.array, type: { kind: option.kind } }\n : { kind: option.kind }),\n default: option.default,\n tags: {\n ...option.reflection?.getTags(),\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n tree.arguments\n .filter(arg => arg.env !== false)\n .forEach(arg =>\n context.env.types.env.addProperty({\n name: arg.env as string,\n optional: arg.optional ? true : undefined,\n description: arg.description,\n visibility: ReflectionVisibility.public,\n type: arg.reflection.getType(),\n default: arg.default,\n tags: {\n ...arg.reflection.getTags(),\n alias: arg.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n })\n );\n }\n\n for (const input of context.inputs.filter(\n input =>\n input.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n command.segments.filter(segment => !isDynamicPathSegment(segment))\n .length +\n 1 &&\n input.segments\n .slice(0, command.segments.length)\n .every((value, index) => value === command.segments[index])\n )) {\n tree.children[input.name] = await reflectCommandTree(context, input, tree);\n }\n\n return tree;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,SAAgByB,gCACdC,MACAC,MACAC,WAAW,OACXC,WAAW,OACXC,OACAC,cACQ;AACR,QAAO,IAAIH,YAAY,CAACG,eAAe,eAAe,GAAE,gBACtDJ,SAASvB,eAAe4B,UAAU,SAAS,SAAQ,2BAEnDL,SAASvB,eAAe4B,UACpB,YACAH,WACE,mBACA,mBAAkB,GACtBC,OAAOG,MAAM,IAAIjB,UAAUU,KAAK,CAAA,GAClCC,SAASvB,eAAe4B,UACpB,cACA,GAAGL,SAASvB,eAAe8B,SAAS,YAAY,SAAQ,QACtDL,WAAW,MAAM,KACjB;;;;;;;;;;;;;AAeV,SAAgBM,kCACdT,MACAC,MACAC,WAAW,OACXC,WAAW,OACXC,OACAC,cACQ;AACR,QAAO,KACLH,YAAY,CAACG,eAAe,cAAc,GAAE,oCAE5CJ,SAASvB,eAAe4B,UACpB,YACAH,WACE,mBACA,mBAAkB,GACtBC,OAAOG,MAAM,IAAIjB,UAAUU,KAAK,CAAA,GAClCC,SAASvB,eAAe4B,UACpB,cACA,GAAGL,SAASvB,eAAe8B,SAAS,YAAY,SAAQ,QACtDL,WAAW,MAAM,KACjB;;AAIV,SAAgBO,iBAAiBC,SAAkBC,MAAsB;AACvE,QAAOzB,YAAYH,aAAa4B,KAAK,EAAED,QAAQE,aAAa,CACzDC,MAAM,IAAI,CACVC,QAAOC,MAAKC,QAAQD,EAAE,IAAI,CAACpB,qBAAqBoB,EAAE,CAAC,CACnDE,KAAK,IAAI,CACTC,WAAW,SAAS,GAAG,CACvBA,WAAW,SAAS,GAAG,CACvBA,WAAW,KAAK,IAAI;;;;;;;;AASzB,SAAgBC,mBAAmBR,MAAc;CAC/C,IAAIS,OAAOrC,aAAa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KI,SAASC,MAAMrE,QAAQ,MAAM4D,mBAAmBjD,SAAS0D,OAAOL,KAAK;AAG5E,QAAOA"}
|
|
1
|
+
{"version":3,"file":"resolve-command.mjs","names":["esbuildPlugin","reflect","ReflectionClass","ReflectionFunction","ReflectionKind","ReflectionVisibility","stringifyType","toArray","appendPath","commonPath","findFilePath","findFolderName","stripStars","replacePath","resolveParentPath","constantCase","titleCase","isSetObject","isSetString","resolveModule","getAppTitle","getDynamicPathSegmentName","isDynamicPathSegment","isPathSegmentGroup","getDefaultOptions","resolveCommandOptionDescription","name","kind","optional","variadic","title","defaultValue","boolean","trim","number","resolveCommandArgumentDescription","resolveCommandId","context","file","commandsPath","split","filter","p","Boolean","join","replaceAll","resolveCommandName","path","requireExtension","resolveCommandPath","resolveCommandDynamicPathSegments","map","findCommandsRoot","config","entry","projectRoot","workspaceConfig","workspaceRoot","Array","isArray","length","sourceRoot","extractCommandOption","command","reflection","type","getType","option","getNameAsString","alias","getTags","description","getDescription","getKind","isOptional","getDefaultValue","env","default","string","Error","extractCommandArgument","array","getName","argument","getAlias","parameter","reflectCommandTree","parent","isVirtual","replace","tree","icon","options","arguments","children","input","fs","existsSync","debug","id","resolved","plugins","reflectionLevel","metadata","function","parameters","getParameters","objectLiteral","class","optionsReflection","from","propertyReflection","getProperties","slice","arg","forEach","index","found","findIndex","segments","some","segment","Object","values","types","addProperty","undefined","visibility","public","tags","domain","inputs","every","value"],"sources":["../../src/helpers/resolve-command.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 { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport type {\n ReflectionParameter,\n ReflectionProperty,\n TypeArray\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n reflect,\n ReflectionClass,\n ReflectionFunction,\n ReflectionKind,\n ReflectionVisibility,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { commonPath } from \"@stryke/path/common\";\nimport { findFilePath, findFolderName } from \"@stryke/path/file-path-fns\";\nimport { stripStars } from \"@stryke/path/normalize\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { resolveModule } from \"powerlines/lib/utilities/resolve\";\nimport {\n getAppTitle,\n getDynamicPathSegmentName,\n isDynamicPathSegment,\n isPathSegmentGroup\n} from \"../plugin-utils/context-helpers\";\nimport type {\n CommandArgument,\n CommandInput,\n CommandModule,\n CommandOption,\n CommandTree,\n NumberCommandArgument,\n NumberCommandOption,\n StringCommandArgument,\n StringCommandOption\n} from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport { getDefaultOptions } from \"./utilities\";\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: ReflectionKind,\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 === ReflectionKind.boolean ? \"flag\" : \"option\"\n } that allows the user to ${\n kind === ReflectionKind.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.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: ReflectionKind,\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 === ReflectionKind.boolean\n ? \"set the\"\n : variadic\n ? \"specify custom\"\n : \"specify a custom\"\n } ${title?.trim() || titleCase(name)} ${\n kind === ReflectionKind.boolean\n ? \"indicator\"\n : `${kind === ReflectionKind.number ? \"numeric\" : \"string\"} value${\n variadic ? \"s\" : \"\"\n }`\n }.`;\n}\n\nexport function resolveCommandId(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(p => Boolean(p) && !isDynamicPathSegment(p))\n .join(\"/\")\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .replaceAll(\"/\", \"-\");\n}\n\n/**\n * Finds the command name from the given file path.\n *\n * @param file - The file path to extract the command name from.\n * @returns The command name.\n */\nexport function resolveCommandName(file: string) {\n let path = findFilePath(file);\n let name = findFolderName(file, {\n requireExtension: true\n });\n\n while (isDynamicPathSegment(name)) {\n path = resolveParentPath(path);\n name = findFolderName(path, {\n requireExtension: true\n });\n }\n\n return name;\n}\n\nexport function resolveCommandPath(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .split(\"/\")\n .filter(path => path && !isPathSegmentGroup(path))\n .join(\"/\");\n}\n\nexport function resolveCommandDynamicPathSegments(\n context: Context,\n file: string\n): string[] {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(path => Boolean(path) && isDynamicPathSegment(path))\n .map(path => getDynamicPathSegmentName(path));\n}\n\nexport function findCommandsRoot(context: Context): string {\n if (isSetString(context.config.entry)) {\n return appendPath(\n appendPath(stripStars(context.config.entry), context.config.projectRoot),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n isSetObject(context.config.entry) &&\n \"file\" in context.config.entry\n ) {\n return appendPath(\n appendPath(\n stripStars(context.config.entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n Array.isArray(context.config.entry) &&\n context.config.entry.length > 0\n ) {\n return commonPath(\n context.config.entry.map(entry =>\n appendPath(\n appendPath(\n stripStars(isSetString(entry) ? entry : entry.file),\n context.config.projectRoot\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\n }\n\n return appendPath(\n context.config.sourceRoot || context.config.projectRoot,\n context.workspaceConfig.workspaceRoot\n );\n}\n\n/**\n * Extracts command parameter information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command option information.\n */\nexport function extractCommandOption(\n command: CommandInput,\n reflection: ReflectionProperty\n): CommandOption {\n const type = reflection.getType();\n\n const option = {\n name: reflection.getNameAsString(),\n alias: reflection.getTags().alias ?? [],\n title:\n reflection.getTags().title?.trim() ||\n titleCase(reflection.getNameAsString()),\n description:\n reflection.getDescription() ||\n resolveCommandOptionDescription(\n reflection.getNameAsString(),\n reflection.getKind(),\n reflection.isOptional(),\n reflection.isArray(),\n reflection.getTags().title,\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getNameAsString()),\n kind: type.kind as\n | ReflectionKind.string\n | ReflectionKind.number\n | ReflectionKind.boolean,\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n variadic: reflection.isArray(),\n reflection\n } as CommandOption;\n\n if (reflection.isArray()) {\n if (\n (type as TypeArray).type.kind === ReflectionKind.string ||\n (type as TypeArray).type.kind === ReflectionKind.number\n ) {\n (option as StringCommandOption | NumberCommandOption).variadic = true;\n (option as StringCommandOption | NumberCommandOption).kind = (\n type as TypeArray\n ).type.kind as ReflectionKind.string | ReflectionKind.number;\n } else {\n throw new Error(\n `Unsupported array type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for option \"${reflection.getNameAsString()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return option;\n}\n\n/**\n * Extracts command positional argument information from a type parameter reflection.\n *\n * @param command - The command tree to which the parameter belongs.\n * @param reflection - The type parameter reflection to extract information from.\n * @returns The extracted command positional argument information.\n */\nexport function extractCommandArgument(\n command: CommandInput,\n reflection: ReflectionParameter\n): CommandArgument {\n const type = reflection.getType();\n\n if (\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number &&\n type.kind !== ReflectionKind.boolean &&\n !(\n type.kind === ReflectionKind.array &&\n (type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number)\n )\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string types (or an array of strings) are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n const argument = {\n name: reflection.getName(),\n alias: reflection.getAlias(),\n kind: type.kind,\n title: titleCase(reflection.getName()),\n description:\n reflection.parameter.description ||\n resolveCommandArgumentDescription(\n reflection.getName(),\n type.kind === ReflectionKind.array ? type.type.kind : type.kind,\n reflection.isOptional(),\n type.kind === ReflectionKind.array,\n titleCase(reflection.getName()),\n reflection.getDefaultValue()\n ),\n env: constantCase(reflection.getName()),\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n reflection\n } as CommandArgument;\n\n if (type.kind === ReflectionKind.array) {\n if (\n type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number\n ) {\n (argument as StringCommandArgument | NumberCommandArgument).variadic =\n true;\n (argument as StringCommandArgument | NumberCommandArgument).kind =\n type.type.kind;\n } else {\n throw new Error(\n `Unsupported array type for argument \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for argument \"${reflection.getName()}\" in command \"${\n command.name\n }\". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return argument;\n}\n\n/**\n * Reflects the command tree for a given command input.\n *\n * @param context - The context in which the command is being reflected.\n * @param command - The command input to reflect.\n * @param parent - The parent command tree, if any.\n * @returns The reflected command tree.\n */\nexport async function reflectCommandTree<TContext extends Context = Context>(\n context: TContext,\n command: CommandInput,\n parent?: CommandTree\n): Promise<CommandTree> {\n const title =\n command.title ||\n `${\n parent?.title\n ? `${\n parent.isVirtual\n ? parent.title.replace(/(?:c|C)ommands?$/, \"\").trim()\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const tree = {\n alias: [],\n icon: parent?.icon,\n ...command,\n title,\n options: getDefaultOptions(context, command),\n arguments: [],\n parent: parent ?? null,\n children: {},\n reflection: null\n } as CommandTree;\n\n if (!command.isVirtual) {\n if (\n !command.entry.input?.file ||\n !context.fs.existsSync(command.entry.input.file)\n ) {\n throw new Error(\n `${\n !command.entry.input?.file ? \"Missing\" : \"Non-existent\"\n } command entry file for \"${command.name}\"`\n );\n }\n\n context.debug(\n `Adding reflection for user-defined command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n const resolved = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n reflectionLevel: \"verbose\"\n })\n ]\n }\n );\n\n const metadata = resolved.metadata ?? {};\n if (isSetString(metadata.title)) {\n tree.title = metadata.title;\n }\n if (isSetString(metadata.description)) {\n tree.description = metadata.description;\n }\n if (\n isSetString(metadata.alias) ||\n (Array.isArray(metadata.alias) && metadata.alias.length > 0)\n ) {\n tree.alias = toArray(metadata.alias);\n }\n if (isSetString(metadata.icon)) {\n tree.icon = metadata.icon;\n }\n\n const type = reflect(resolved);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `The command entry file \"${command.entry.input.file}\" does not export a valid function.`\n );\n }\n\n tree.reflection = new ReflectionFunction(type);\n tree.description ??=\n command.description ||\n type.description ||\n `The ${tree.title.replace(/(?:c|C)ommands?$/, \"\").trim()} executable command-line interface.`;\n\n const parameters = tree.reflection.getParameters();\n if (parameters.length > 0 && parameters[0]) {\n if (\n parameters[0].type.kind === ReflectionKind.objectLiteral ||\n parameters[0].type.kind === ReflectionKind.class\n ) {\n const optionsReflection = ReflectionClass.from(parameters[0].type);\n for (const propertyReflection of optionsReflection.getProperties()) {\n tree.options[propertyReflection.getNameAsString()] =\n extractCommandOption(command, propertyReflection);\n }\n } else {\n throw new Error(\n `The first parameter of the command handler function in \"${\n command.entry.input.file\n }\" must be an object literal or class type representing the command options.`\n );\n }\n\n tree.arguments = parameters\n .slice(1)\n .map(arg => extractCommandArgument(command, arg));\n\n // Ensure unique argument names by appending an index suffix to duplicates\n tree.arguments.forEach((argument, index) => {\n const found = tree.arguments.findIndex(\n arg => arg.name === argument.name\n );\n if (\n (found !== -1 && found !== index) ||\n tree.segments.some(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment) === argument.name\n )\n ) {\n argument.name += `_${\n tree.segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(/_\\d+$/, \"\") ===\n argument.name\n ).length +\n tree.arguments.filter(\n arg => arg.name.replace(/_\\d+$/, \"\") === argument.name\n ).length\n }`;\n argument.env = constantCase(argument.name);\n }\n });\n }\n } else {\n tree.description ??= `A collection of available ${\n tree.title.replace(/(?:c|C)ommands?$/, \"\").trim() || titleCase(tree.name)\n } commands that are included in the ${getAppTitle(\n context\n )} command-line application.`;\n }\n\n if (context.env) {\n if (isSetObject(tree.options)) {\n Object.values(tree.options)\n .filter(option => option.env !== false)\n .forEach(option => {\n context.env.types.env.addProperty({\n name: option.env as string,\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type:\n option.reflection?.getType() ??\n ((option as StringCommandOption | NumberCommandOption).variadic\n ? { kind: ReflectionKind.array, type: { kind: option.kind } }\n : { kind: option.kind }),\n default: option.default,\n tags: {\n ...option.reflection?.getTags(),\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n tree.arguments\n .filter(arg => arg.env !== false)\n .forEach(arg =>\n context.env.types.env.addProperty({\n name: arg.env as string,\n optional: arg.optional ? true : undefined,\n description: arg.description,\n visibility: ReflectionVisibility.public,\n type: arg.reflection.getType(),\n default: arg.default,\n tags: {\n ...arg.reflection.getTags(),\n alias: arg.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n })\n );\n }\n\n for (const input of context.inputs.filter(\n input =>\n input.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n command.segments.filter(segment => !isDynamicPathSegment(segment))\n .length +\n 1 &&\n input.segments\n .slice(0, command.segments.length)\n .every((value, index) => value === command.segments[index])\n )) {\n tree.children[input.name] = await reflectCommandTree(context, input, tree);\n }\n\n return tree;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,SAAgByB,gCACdC,MACAC,MACAC,WAAW,OACXC,WAAW,OACXC,OACAC,cACQ;AACR,QAAO,IAAIH,YAAY,CAACG,eAAe,eAAe,GAAE,gBACtDJ,SAASvB,eAAe4B,UAAU,SAAS,SAAQ,2BAEnDL,SAASvB,eAAe4B,UACpB,YACAH,WACE,mBACA,mBAAkB,GACtBC,OAAOG,MAAM,IAAIjB,UAAUU,KAAK,CAAA,GAClCC,SAASvB,eAAe4B,UACpB,cACA,GAAGL,SAASvB,eAAe8B,SAAS,YAAY,SAAQ,QACtDL,WAAW,MAAM,KACjB;;;;;;;;;;;;;AAeV,SAAgBM,kCACdT,MACAC,MACAC,WAAW,OACXC,WAAW,OACXC,OACAC,cACQ;AACR,QAAO,KACLH,YAAY,CAACG,eAAe,cAAc,GAAE,oCAE5CJ,SAASvB,eAAe4B,UACpB,YACAH,WACE,mBACA,mBAAkB,GACtBC,OAAOG,MAAM,IAAIjB,UAAUU,KAAK,CAAA,GAClCC,SAASvB,eAAe4B,UACpB,cACA,GAAGL,SAASvB,eAAe8B,SAAS,YAAY,SAAQ,QACtDL,WAAW,MAAM,KACjB;;AAIV,SAAgBO,iBAAiBC,SAAkBC,MAAsB;AACvE,QAAOzB,YAAYH,aAAa4B,KAAK,EAAED,QAAQE,aAAa,CACzDC,MAAM,IAAI,CACVC,QAAOC,MAAKC,QAAQD,EAAE,IAAI,CAACpB,qBAAqBoB,EAAE,CAAC,CACnDE,KAAK,IAAI,CACTC,WAAW,SAAS,GAAG,CACvBA,WAAW,SAAS,GAAG,CACvB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,OAAO,CACjCwE,OAAOC,OAAOjB,UAAUiB,UAAUtE,QAAQwD,SAASH,OAC1D,CAAC,CACC1B,MAAKI,SAASC,MAAMrE,QAAQ,MAAM4D,mBAAmBjD,SAAS0D,OAAOL,KAAK;AAG5E,QAAOA"}
|
|
@@ -33,10 +33,12 @@ function getAppName(context) {
|
|
|
33
33
|
* Retrieves the application title from the context and configuration.
|
|
34
34
|
*
|
|
35
35
|
* @param context - The build context containing workspace and package information.
|
|
36
|
+
* @param replaceCLI - Whether to replace CLI-related terms in the title with the application name.
|
|
36
37
|
* @returns The application title in title-case format.
|
|
37
38
|
*/
|
|
38
|
-
function getAppTitle(context) {
|
|
39
|
-
|
|
39
|
+
function getAppTitle(context, replaceCLI = false) {
|
|
40
|
+
const title = context.config.title || (0, __stryke_string_format_title_case.titleCase)(context.config.name || getAppName(context));
|
|
41
|
+
return (replaceCLI ? title.replace(/(?:cli|command-line|command line)\s*(?:interface\s*)?(?:application|app)?$/gi, "") : title).trim();
|
|
40
42
|
}
|
|
41
43
|
/**
|
|
42
44
|
* Retrieves the application description from the context and configuration.
|
|
@@ -45,7 +47,7 @@ function getAppTitle(context) {
|
|
|
45
47
|
* @returns The application description.
|
|
46
48
|
*/
|
|
47
49
|
function getAppDescription(context) {
|
|
48
|
-
return context.config.description || context.packageJson?.description || `The ${getAppTitle(context)} command-line interface application.`;
|
|
50
|
+
return context.config.description || context.packageJson?.description || `The ${getAppTitle(context, true)} command-line interface application.`;
|
|
49
51
|
}
|
|
50
52
|
/**
|
|
51
53
|
* Retrieves the primary binary name for the application.
|