@shell-shock/core 0.8.13 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.cjs +34 -0
- package/dist/api.cjs.map +1 -1
- package/dist/api.mjs +34 -0
- package/dist/api.mjs.map +1 -1
- package/dist/components/docs.d.cts +5 -5
- package/dist/components/docs.d.cts.map +1 -1
- package/dist/components/docs.d.mts +5 -5
- package/dist/components/helpers.d.cts +6 -6
- package/dist/components/helpers.d.mts +6 -6
- package/dist/components/index.cjs +1 -0
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.mts +2 -2
- package/dist/components/index.mjs +2 -2
- package/dist/components/options-parser-logic.d.cts +9 -9
- package/dist/components/options-parser-logic.d.mts +9 -9
- package/dist/components/usage.d.cts +2 -2
- package/dist/components/usage.d.cts.map +1 -1
- package/dist/components/usage.d.mts +2 -2
- package/dist/components/utils-builtin.cjs +341 -0
- package/dist/components/utils-builtin.cjs.map +1 -1
- package/dist/components/utils-builtin.d.cts +12 -8
- package/dist/components/utils-builtin.d.cts.map +1 -1
- package/dist/components/utils-builtin.d.mts +12 -8
- package/dist/components/utils-builtin.d.mts.map +1 -1
- package/dist/components/utils-builtin.mjs +342 -2
- package/dist/components/utils-builtin.mjs.map +1 -1
- package/dist/config.cjs +12 -0
- package/dist/config.cjs.map +1 -1
- package/dist/config.mjs +12 -0
- package/dist/config.mjs.map +1 -1
- package/dist/contexts/command.cjs +3 -2
- package/dist/contexts/command.cjs.map +1 -1
- package/dist/contexts/command.mjs +3 -2
- package/dist/contexts/command.mjs.map +1 -1
- package/dist/contexts/options.cjs +20 -4
- package/dist/contexts/options.cjs.map +1 -1
- package/dist/contexts/options.mjs +20 -4
- package/dist/contexts/options.mjs.map +1 -1
- package/dist/helpers/docs-helpers.cjs +6 -0
- package/dist/helpers/docs-helpers.cjs.map +1 -1
- package/dist/helpers/docs-helpers.mjs +6 -0
- package/dist/helpers/docs-helpers.mjs.map +1 -1
- package/dist/helpers/persistence.cjs +92 -11
- package/dist/helpers/persistence.cjs.map +1 -1
- package/dist/helpers/persistence.mjs +92 -11
- package/dist/helpers/persistence.mjs.map +1 -1
- package/dist/helpers/resolve-command.cjs +200 -18
- package/dist/helpers/resolve-command.cjs.map +1 -1
- package/dist/helpers/resolve-command.mjs +201 -19
- package/dist/helpers/resolve-command.mjs.map +1 -1
- package/dist/helpers/update-package-json.cjs +27 -3
- package/dist/helpers/update-package-json.cjs.map +1 -1
- package/dist/helpers/update-package-json.mjs +27 -3
- package/dist/helpers/update-package-json.mjs.map +1 -1
- package/dist/helpers/utilities.cjs +58 -4
- package/dist/helpers/utilities.cjs.map +1 -1
- package/dist/helpers/utilities.mjs +58 -4
- package/dist/helpers/utilities.mjs.map +1 -1
- package/dist/helpers/validations.cjs +28 -1
- package/dist/helpers/validations.cjs.map +1 -1
- package/dist/helpers/validations.mjs +28 -1
- package/dist/helpers/validations.mjs.map +1 -1
- package/dist/index.cjs +33 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +6 -1
- package/dist/index.mjs.map +1 -1
- package/dist/plugin-utils/context-helpers.cjs +78 -3
- package/dist/plugin-utils/context-helpers.cjs.map +1 -1
- package/dist/plugin-utils/context-helpers.mjs +78 -3
- package/dist/plugin-utils/context-helpers.mjs.map +1 -1
- package/dist/plugin-utils/get-command-tree.cjs +17 -1
- package/dist/plugin-utils/get-command-tree.cjs.map +1 -1
- package/dist/plugin-utils/get-command-tree.mjs +17 -1
- package/dist/plugin-utils/get-command-tree.mjs.map +1 -1
- package/dist/plugin-utils/reflect.cjs +31 -3
- package/dist/plugin-utils/reflect.cjs.map +1 -1
- package/dist/plugin-utils/reflect.mjs +31 -3
- package/dist/plugin-utils/reflect.mjs.map +1 -1
- package/dist/plugin-utils/traverse-command-tree.cjs +34 -4
- package/dist/plugin-utils/traverse-command-tree.cjs.map +1 -1
- package/dist/plugin-utils/traverse-command-tree.mjs +34 -4
- package/dist/plugin-utils/traverse-command-tree.mjs.map +1 -1
- package/dist/plugin.cjs +5 -1
- 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 +5 -1
- package/dist/plugin.mjs.map +1 -1
- package/dist/types/command.cjs +241 -0
- package/dist/types/command.cjs.map +1 -0
- package/dist/types/command.mjs +221 -1
- package/dist/types/command.mjs.map +1 -0
- package/dist/types/config.cjs +114 -0
- package/dist/types/config.cjs.map +1 -0
- package/dist/types/config.d.cts +11 -10
- package/dist/types/config.d.cts.map +1 -1
- package/dist/types/config.d.mts +11 -10
- package/dist/types/config.d.mts.map +1 -1
- package/dist/types/config.mjs +110 -1
- package/dist/types/config.mjs.map +1 -0
- package/dist/types/context.cjs +33 -0
- package/dist/types/context.cjs.map +1 -0
- package/dist/types/context.mjs +31 -1
- package/dist/types/context.mjs.map +1 -0
- package/dist/types/env.cjs +12 -0
- package/dist/types/env.cjs.map +1 -0
- package/dist/types/env.d.cts +17 -0
- package/dist/types/env.d.cts.map +1 -0
- package/dist/types/env.d.mts +17 -0
- package/dist/types/env.d.mts.map +1 -0
- package/dist/types/env.mjs +11 -0
- package/dist/types/env.mjs.map +1 -0
- package/dist/types/index.cjs +34 -0
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.mts +2 -2
- package/dist/types/index.mjs +7 -1
- package/dist/types/options.cjs +12 -0
- package/dist/types/options.cjs.map +1 -0
- package/dist/types/options.mjs +11 -1
- package/dist/types/options.mjs.map +1 -0
- package/dist/types/runtime.cjs +12 -0
- package/dist/types/runtime.cjs.map +1 -0
- package/dist/types/runtime.mjs +11 -1
- package/dist/types/runtime.mjs.map +1 -0
- package/package.json +25 -11
|
@@ -5,6 +5,10 @@ let __stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-str
|
|
|
5
5
|
let __stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
6
6
|
|
|
7
7
|
//#region src/plugin-utils/context-helpers.ts
|
|
8
|
+
function __assignType(fn, args) {
|
|
9
|
+
fn.__type = args;
|
|
10
|
+
return fn;
|
|
11
|
+
}
|
|
8
12
|
/**
|
|
9
13
|
* Sorts command argument aliases, placing single-character aliases first, followed by multi-character aliases, and then sorting them alphabetically.
|
|
10
14
|
*
|
|
@@ -13,10 +17,28 @@ let __stryke_string_format_title_case = require("@stryke/string-format/title-cas
|
|
|
13
17
|
*/
|
|
14
18
|
function sortArgAliases(aliases) {
|
|
15
19
|
if (aliases.length === 0) return [];
|
|
16
|
-
const result = aliases.filter((alias) => alias.length === 1
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
const result = aliases.filter(__assignType((alias) => alias.length === 1, [
|
|
21
|
+
"alias",
|
|
22
|
+
"",
|
|
23
|
+
"P\"2!\"/\""
|
|
24
|
+
]));
|
|
25
|
+
result.push(...aliases.filter(__assignType((alias) => alias.length > 1, [
|
|
26
|
+
"alias",
|
|
27
|
+
"",
|
|
28
|
+
"P\"2!\"/\""
|
|
29
|
+
])));
|
|
30
|
+
return result.sort(__assignType((a, b) => a.localeCompare(b), [
|
|
31
|
+
"a",
|
|
32
|
+
"b",
|
|
33
|
+
"",
|
|
34
|
+
"P\"2!\"2\"\"/#"
|
|
35
|
+
]));
|
|
19
36
|
}
|
|
37
|
+
sortArgAliases.__type = [
|
|
38
|
+
"aliases",
|
|
39
|
+
"sortArgAliases",
|
|
40
|
+
"P&F2!&F/\""
|
|
41
|
+
];
|
|
20
42
|
/**
|
|
21
43
|
* Retrieves the application name from the context and configuration.
|
|
22
44
|
*
|
|
@@ -29,6 +51,13 @@ function getAppName(context) {
|
|
|
29
51
|
if (!(0, __stryke_type_checks_is_set_string.isSetString)(result)) throw new Error("No application name found. Please provide a 'bin' option in the configuration or ensure the package.json has a valid 'name' field.");
|
|
30
52
|
return (0, __stryke_string_format_kebab_case.kebabCase)(result);
|
|
31
53
|
}
|
|
54
|
+
getAppName.__type = [
|
|
55
|
+
"UnresolvedContext",
|
|
56
|
+
"Context",
|
|
57
|
+
"context",
|
|
58
|
+
"getAppName",
|
|
59
|
+
"PP\"w!\"w\"J2#&/$"
|
|
60
|
+
];
|
|
32
61
|
/**
|
|
33
62
|
* Retrieves the application title from the context and configuration.
|
|
34
63
|
*
|
|
@@ -40,6 +69,14 @@ function getAppTitle(context, replaceCLI = false) {
|
|
|
40
69
|
const title = context.config.title || (0, __stryke_string_format_title_case.titleCase)(context.config.name || getAppName(context));
|
|
41
70
|
return (replaceCLI ? title.replace(/(?:cli|command-line|command line)\s*(?:interface\s*)?(?:application|app)?$/gi, "") : title).trim();
|
|
42
71
|
}
|
|
72
|
+
getAppTitle.__type = [
|
|
73
|
+
"UnresolvedContext",
|
|
74
|
+
"Context",
|
|
75
|
+
"context",
|
|
76
|
+
"replaceCLI",
|
|
77
|
+
"getAppTitle",
|
|
78
|
+
"PP\"w!\"w\"J2#\"2$&/%"
|
|
79
|
+
];
|
|
43
80
|
/**
|
|
44
81
|
* Retrieves the application description from the context and configuration.
|
|
45
82
|
*
|
|
@@ -49,6 +86,13 @@ function getAppTitle(context, replaceCLI = false) {
|
|
|
49
86
|
function getAppDescription(context) {
|
|
50
87
|
return context.config.description || context.packageJson?.description || `The ${getAppTitle(context, true)} command-line interface application.`;
|
|
51
88
|
}
|
|
89
|
+
getAppDescription.__type = [
|
|
90
|
+
"UnresolvedContext",
|
|
91
|
+
"Context",
|
|
92
|
+
"context",
|
|
93
|
+
"getAppDescription",
|
|
94
|
+
"PP\"w!\"w\"J2#&/$"
|
|
95
|
+
];
|
|
52
96
|
/**
|
|
53
97
|
* Retrieves the primary binary name for the application.
|
|
54
98
|
*
|
|
@@ -58,6 +102,12 @@ function getAppDescription(context) {
|
|
|
58
102
|
function getAppBin(context) {
|
|
59
103
|
return (0, __stryke_type_checks_is_set_object.isSetObject)(context.config.bin) ? Object.keys(context.config.bin)[0] : (0, __stryke_string_format_kebab_case.kebabCase)(getAppName(context));
|
|
60
104
|
}
|
|
105
|
+
getAppBin.__type = [
|
|
106
|
+
"Context",
|
|
107
|
+
"context",
|
|
108
|
+
"getAppBin",
|
|
109
|
+
"P\"w!2\"&/#"
|
|
110
|
+
];
|
|
61
111
|
/**
|
|
62
112
|
* Determines if a given command path segment is variable (enclosed in square brackets).
|
|
63
113
|
*
|
|
@@ -73,6 +123,11 @@ function getAppBin(context) {
|
|
|
73
123
|
function isDynamicPathSegment(path) {
|
|
74
124
|
return path.startsWith("[") && path.endsWith("]");
|
|
75
125
|
}
|
|
126
|
+
isDynamicPathSegment.__type = [
|
|
127
|
+
"path",
|
|
128
|
+
"isDynamicPathSegment",
|
|
129
|
+
"P&2!)/\""
|
|
130
|
+
];
|
|
76
131
|
/**
|
|
77
132
|
* Extracts the variable name from a command path segment by removing enclosing square brackets.
|
|
78
133
|
*
|
|
@@ -87,6 +142,11 @@ function isDynamicPathSegment(path) {
|
|
|
87
142
|
function getDynamicPathSegmentName(path) {
|
|
88
143
|
return path.replaceAll(/^\[+/g, "").replaceAll(/\]+$/g, "");
|
|
89
144
|
}
|
|
145
|
+
getDynamicPathSegmentName.__type = [
|
|
146
|
+
"path",
|
|
147
|
+
"getDynamicPathSegmentName",
|
|
148
|
+
"P&2!&/\""
|
|
149
|
+
];
|
|
90
150
|
/**
|
|
91
151
|
* Determines if a given command path segment is a path segment group (enclosed in parentheses).
|
|
92
152
|
*
|
|
@@ -103,6 +163,11 @@ function getDynamicPathSegmentName(path) {
|
|
|
103
163
|
function isPathSegmentGroup(path) {
|
|
104
164
|
return path.startsWith("(") && path.endsWith(")") || path.startsWith("_");
|
|
105
165
|
}
|
|
166
|
+
isPathSegmentGroup.__type = [
|
|
167
|
+
"path",
|
|
168
|
+
"isPathSegmentGroup",
|
|
169
|
+
"P&2!)/\""
|
|
170
|
+
];
|
|
106
171
|
/**
|
|
107
172
|
* Extracts the group name from a command path segment by removing enclosing parentheses.
|
|
108
173
|
*
|
|
@@ -118,6 +183,11 @@ function isPathSegmentGroup(path) {
|
|
|
118
183
|
function getPathSegmentGroupName(path) {
|
|
119
184
|
return path.replaceAll(/^\(+/g, "").replaceAll(/\)+$/g, "").replaceAll(/^_+/g, "");
|
|
120
185
|
}
|
|
186
|
+
getPathSegmentGroupName.__type = [
|
|
187
|
+
"path",
|
|
188
|
+
"getPathSegmentGroupName",
|
|
189
|
+
"P&2!&/\""
|
|
190
|
+
];
|
|
121
191
|
/**
|
|
122
192
|
* Extracts the variable name from a command path segment by removing enclosing square brackets.
|
|
123
193
|
*
|
|
@@ -132,6 +202,11 @@ function getPathSegmentGroupName(path) {
|
|
|
132
202
|
function getPathSegmentName(path) {
|
|
133
203
|
return getPathSegmentGroupName(getDynamicPathSegmentName(path));
|
|
134
204
|
}
|
|
205
|
+
getPathSegmentName.__type = [
|
|
206
|
+
"path",
|
|
207
|
+
"getPathSegmentName",
|
|
208
|
+
"P&2!&/\""
|
|
209
|
+
];
|
|
135
210
|
|
|
136
211
|
//#endregion
|
|
137
212
|
exports.getAppBin = getAppBin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-helpers.cjs","names":[
|
|
1
|
+
{"version":3,"file":"context-helpers.cjs","names":[],"sources":["../../src/plugin-utils/context-helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { kebabCase } from \"@stryke/string-format/kebab-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 type { Context, UnresolvedContext } from \"../types\";\n\n/**\n * Sorts command argument aliases, placing single-character aliases first, followed by multi-character aliases, and then sorting them alphabetically.\n *\n * @param aliases - An array of argument aliases to sort.\n * @returns A new array of sorted aliases.\n */\nexport function sortArgAliases(aliases: string[]): string[] {\n if (aliases.length === 0) {\n return [];\n }\n\n const result = aliases.filter(alias => alias.length === 1);\n result.push(...aliases.filter(alias => alias.length > 1));\n\n return result.sort((a, b) => a.localeCompare(b));\n}\n\n/**\n * Retrieves the application name from the context and configuration.\n *\n * @param context - The build context containing workspace and package information.\n * @returns The application name in kebab-case format.\n * @throws An error if no valid application name is found.\n */\nexport function getAppName(context: UnresolvedContext | Context): string {\n const result =\n context.config.name ||\n (isSetString(context.config.bin) ||\n (Array.isArray(context.config.bin) &&\n context.config.bin.length > 0 &&\n isSetString(context.config.bin[0]))\n ? isSetString(context.config.bin)\n ? context.config.bin\n : context.config.bin[0]\n : context.packageJson?.name);\n if (!isSetString(result)) {\n throw new Error(\n \"No application name found. Please provide a 'bin' option in the configuration or ensure the package.json has a valid 'name' field.\"\n );\n }\n\n return kebabCase(result);\n}\n\n/**\n * Retrieves the application title from the context and configuration.\n *\n * @param context - The build context containing workspace and package information.\n * @param replaceCLI - Whether to replace CLI-related terms in the title with the application name.\n * @returns The application title in title-case format.\n */\nexport function getAppTitle(\n context: UnresolvedContext | Context,\n replaceCLI = false\n): string {\n const title =\n context.config.title ||\n titleCase(context.config.name || getAppName(context));\n\n return (\n replaceCLI\n ? title.replace(\n /(?:cli|command-line|command line)\\s*(?:interface\\s*)?(?:application|app)?$/gi,\n \"\"\n )\n : title\n ).trim();\n}\n\n/**\n * Retrieves the application description from the context and configuration.\n *\n * @param context - The build context containing workspace and package information.\n * @returns The application description.\n */\nexport function getAppDescription(\n context: UnresolvedContext | Context\n): string {\n return (\n context.config.description ||\n context.packageJson?.description ||\n `The ${getAppTitle(context, true)} command-line interface application.`\n );\n}\n\n/**\n * Retrieves the primary binary name for the application.\n *\n * @param context - The build context containing workspace and package information.\n * @returns The primary binary name as a string.\n */\nexport function getAppBin(context: Context): string {\n return isSetObject(context.config.bin)\n ? Object.keys(context.config.bin)[0]!\n : kebabCase(getAppName(context));\n}\n\n/**\n * Determines if a given command path segment is variable (enclosed in square brackets).\n *\n * @example\n * ```typescript\n * isDynamicPathSegment(\"[user]\"); // true\n * isDynamicPathSegment(\"user\"); // false\n * ```\n *\n * @param path - The command path segment to check.\n * @returns True if the path is variable, false otherwise.\n */\nexport function isDynamicPathSegment(path: string): boolean {\n return path.startsWith(\"[\") && path.endsWith(\"]\");\n}\n\n/**\n * Extracts the variable name from a command path segment by removing enclosing square brackets.\n *\n * @example\n * ```typescript\n * getDynamicPathSegmentName(\"[user]\"); // \"user\"\n * ```\n *\n * @param path - The command path segment.\n * @returns The variable name without square brackets.\n */\nexport function getDynamicPathSegmentName(path: string): string {\n return path.replaceAll(/^\\[+/g, \"\").replaceAll(/\\]+$/g, \"\");\n}\n\n/**\n * Determines if a given command path segment is a path segment group (enclosed in parentheses).\n *\n * @example\n * ```typescript\n * isPathSegmentGroup(\"(user)\"); // true\n * isPathSegmentGroup(\"[user]\"); // false\n * isPathSegmentGroup(\"user\"); // false\n * ```\n *\n * @param path - The command path segment to check.\n * @returns True if the path is a path segment group, false otherwise.\n */\nexport function isPathSegmentGroup(path: string): boolean {\n return (path.startsWith(\"(\") && path.endsWith(\")\")) || path.startsWith(\"_\");\n}\n\n/**\n * Extracts the group name from a command path segment by removing enclosing parentheses.\n *\n * @example\n * ```typescript\n * getPathSegmentGroupName(\"(admin)\"); // \"admin\"\n * getPathSegmentGroupName(\"((group))\"); // \"group\"\n * ```\n *\n * @param path - The command path segment.\n * @returns The group name without parentheses.\n */\nexport function getPathSegmentGroupName(path: string): string {\n return path\n .replaceAll(/^\\(+/g, \"\")\n .replaceAll(/\\)+$/g, \"\")\n .replaceAll(/^_+/g, \"\");\n}\n\n/**\n * Extracts the variable name from a command path segment by removing enclosing square brackets.\n *\n * @example\n * ```typescript\n * getDynamicPathSegmentName(\"[user]\"); // \"user\"\n * ```\n *\n * @param path - The command path segment.\n * @returns The variable name without square brackets.\n */\nexport function getPathSegmentName(path: string): string {\n return getPathSegmentGroupName(getDynamicPathSegmentName(path));\n}\n"],"mappings":";;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;;;;;;;AA6BX,SAAgB,eAAY,SAAA;AACxB,KAAI,QAAK,WAAA,EACX,QAAA,EAAA;CAEE,MAAM,SAAS,QAAQ,OAAO,cAAa,UAAS,MAAI,WAAA,GAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA;AACxD,QAAO,KAAK,GAAG,QAAQ,OAAO,cAAa,UAAS,MAAG,SAAA,GAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA;;;;;;;;AAG3D,eAAA,SAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;AAQA,SAAE,WAAA,SAAA;CACE,MAAM,SAAS,QAAQ,OAAO,6DACnB,QAAA,OAAA,IAAA,IACF,MAAM,QAAM,QAAA,OAAA,IAAA,IACT,QAAQ,OAAO,IAAI,SAAG,yDACV,QAAQ,OAAI,IAAA,GAAA,uDACd,QAAQ,OAAG,IAAA,GACnB,QAAQ,OAAO,MACf,QAAQ,OAAO,IAAI,KACvB,QAAQ,aAAK;AACvB,KAAI,qDAAa,OAAO,CACpB,OAAM,IAAI,MAAM,qIAAU;AAE9B,yDAAe,OAAA;;AAEnB,WAAK,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;AAQL,SAAC,YAAA,SAAA,aAAA,OAAA;CACG,MAAM,QAAQ,QAAQ,OAAO,0DACf,QAAQ,OAAO,QAAQ,WAAW,QAAQ,CAAC;AACzD,SAAQ,aACV,MAAA,QAAA,gFAAA,GAAA,GACQ,OAAO,MAAM;;AAEvB,YAAY,SAAO;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;AAOnB,SAAa,kBAAA,SAAA;AACT,QAAQ,QAAQ,OAAC,eACb,QAAQ,aAAa,eACrB,OAAG,YAAA,SAAA,KAAA,CAAA;;AAEX,kBAAY,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;AAOZ,SAAgB,UAAU,SAAS;AAC/B,4DAAmB,QAAQ,OAAO,IAAC,GACrC,OAAA,KAAA,QAAA,OAAA,IAAA,CAAA,sDACkB,WAAW,QAAE,CAAA;;AAEjC,UAAU,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;;;;;;AAaV,SAAE,qBAAA,MAAA;AACE,QAAO,KAAK,WAAW,IAAI,IAAI,KAAK,SAAS,IAAG;;AAEpD,qBAAqB,SAAS;CAAC;CAAQ;CAAC;CAAA;;;;;;;;;;;;AAYxC,SAAC,0BAAA,MAAA;AACG,QAAO,KAAK,WAAW,SAAS,GAAG,CAAC,WAAU,SAAA,GAAA;;AAElD,0BAAE,SAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;;;;;;;AAcF,SAAgB,mBAAmB,MAAM;AACvC,QAAA,KAAA,WAAA,IAAA,IAAA,KAAA,SAAA,IAAA,IAAA,KAAA,WAAA,IAAA;;AAEF,mBAAmB,SAAS;CAAC;CAAQ;CAAsB;CAAE;;;;;;;;;;;;;AAa7D,SAAgB,wBAAwB,MAAM;AAC1C,QAAO,KACT,WAAA,SAAA,GAAA,CACO,WAAW,SAAS,GAAG,CACvB,WAAW,QAAQ,GAAG;;;;;;;;;;;;;;;;;;AAc/B,SAAE,mBAAA,MAAA;AACE,QAAO,wBAAwB,0BAA0B,KAAC,CAAA;;AAE9D,mBAAmB,SAAQ;CAAA;CAAA;CAAA;CAAA"}
|
|
@@ -4,6 +4,10 @@ import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
|
4
4
|
import { titleCase } from "@stryke/string-format/title-case";
|
|
5
5
|
|
|
6
6
|
//#region src/plugin-utils/context-helpers.ts
|
|
7
|
+
function __assignType(fn, args) {
|
|
8
|
+
fn.__type = args;
|
|
9
|
+
return fn;
|
|
10
|
+
}
|
|
7
11
|
/**
|
|
8
12
|
* Sorts command argument aliases, placing single-character aliases first, followed by multi-character aliases, and then sorting them alphabetically.
|
|
9
13
|
*
|
|
@@ -12,10 +16,28 @@ import { titleCase } from "@stryke/string-format/title-case";
|
|
|
12
16
|
*/
|
|
13
17
|
function sortArgAliases(aliases) {
|
|
14
18
|
if (aliases.length === 0) return [];
|
|
15
|
-
const result = aliases.filter((alias) => alias.length === 1
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
const result = aliases.filter(__assignType((alias) => alias.length === 1, [
|
|
20
|
+
"alias",
|
|
21
|
+
"",
|
|
22
|
+
"P\"2!\"/\""
|
|
23
|
+
]));
|
|
24
|
+
result.push(...aliases.filter(__assignType((alias) => alias.length > 1, [
|
|
25
|
+
"alias",
|
|
26
|
+
"",
|
|
27
|
+
"P\"2!\"/\""
|
|
28
|
+
])));
|
|
29
|
+
return result.sort(__assignType((a, b) => a.localeCompare(b), [
|
|
30
|
+
"a",
|
|
31
|
+
"b",
|
|
32
|
+
"",
|
|
33
|
+
"P\"2!\"2\"\"/#"
|
|
34
|
+
]));
|
|
18
35
|
}
|
|
36
|
+
sortArgAliases.__type = [
|
|
37
|
+
"aliases",
|
|
38
|
+
"sortArgAliases",
|
|
39
|
+
"P&F2!&F/\""
|
|
40
|
+
];
|
|
19
41
|
/**
|
|
20
42
|
* Retrieves the application name from the context and configuration.
|
|
21
43
|
*
|
|
@@ -28,6 +50,13 @@ function getAppName(context) {
|
|
|
28
50
|
if (!isSetString(result)) throw new Error("No application name found. Please provide a 'bin' option in the configuration or ensure the package.json has a valid 'name' field.");
|
|
29
51
|
return kebabCase(result);
|
|
30
52
|
}
|
|
53
|
+
getAppName.__type = [
|
|
54
|
+
"UnresolvedContext",
|
|
55
|
+
"Context",
|
|
56
|
+
"context",
|
|
57
|
+
"getAppName",
|
|
58
|
+
"PP\"w!\"w\"J2#&/$"
|
|
59
|
+
];
|
|
31
60
|
/**
|
|
32
61
|
* Retrieves the application title from the context and configuration.
|
|
33
62
|
*
|
|
@@ -39,6 +68,14 @@ function getAppTitle(context, replaceCLI = false) {
|
|
|
39
68
|
const title = context.config.title || titleCase(context.config.name || getAppName(context));
|
|
40
69
|
return (replaceCLI ? title.replace(/(?:cli|command-line|command line)\s*(?:interface\s*)?(?:application|app)?$/gi, "") : title).trim();
|
|
41
70
|
}
|
|
71
|
+
getAppTitle.__type = [
|
|
72
|
+
"UnresolvedContext",
|
|
73
|
+
"Context",
|
|
74
|
+
"context",
|
|
75
|
+
"replaceCLI",
|
|
76
|
+
"getAppTitle",
|
|
77
|
+
"PP\"w!\"w\"J2#\"2$&/%"
|
|
78
|
+
];
|
|
42
79
|
/**
|
|
43
80
|
* Retrieves the application description from the context and configuration.
|
|
44
81
|
*
|
|
@@ -48,6 +85,13 @@ function getAppTitle(context, replaceCLI = false) {
|
|
|
48
85
|
function getAppDescription(context) {
|
|
49
86
|
return context.config.description || context.packageJson?.description || `The ${getAppTitle(context, true)} command-line interface application.`;
|
|
50
87
|
}
|
|
88
|
+
getAppDescription.__type = [
|
|
89
|
+
"UnresolvedContext",
|
|
90
|
+
"Context",
|
|
91
|
+
"context",
|
|
92
|
+
"getAppDescription",
|
|
93
|
+
"PP\"w!\"w\"J2#&/$"
|
|
94
|
+
];
|
|
51
95
|
/**
|
|
52
96
|
* Retrieves the primary binary name for the application.
|
|
53
97
|
*
|
|
@@ -57,6 +101,12 @@ function getAppDescription(context) {
|
|
|
57
101
|
function getAppBin(context) {
|
|
58
102
|
return isSetObject(context.config.bin) ? Object.keys(context.config.bin)[0] : kebabCase(getAppName(context));
|
|
59
103
|
}
|
|
104
|
+
getAppBin.__type = [
|
|
105
|
+
"Context",
|
|
106
|
+
"context",
|
|
107
|
+
"getAppBin",
|
|
108
|
+
"P\"w!2\"&/#"
|
|
109
|
+
];
|
|
60
110
|
/**
|
|
61
111
|
* Determines if a given command path segment is variable (enclosed in square brackets).
|
|
62
112
|
*
|
|
@@ -72,6 +122,11 @@ function getAppBin(context) {
|
|
|
72
122
|
function isDynamicPathSegment(path) {
|
|
73
123
|
return path.startsWith("[") && path.endsWith("]");
|
|
74
124
|
}
|
|
125
|
+
isDynamicPathSegment.__type = [
|
|
126
|
+
"path",
|
|
127
|
+
"isDynamicPathSegment",
|
|
128
|
+
"P&2!)/\""
|
|
129
|
+
];
|
|
75
130
|
/**
|
|
76
131
|
* Extracts the variable name from a command path segment by removing enclosing square brackets.
|
|
77
132
|
*
|
|
@@ -86,6 +141,11 @@ function isDynamicPathSegment(path) {
|
|
|
86
141
|
function getDynamicPathSegmentName(path) {
|
|
87
142
|
return path.replaceAll(/^\[+/g, "").replaceAll(/\]+$/g, "");
|
|
88
143
|
}
|
|
144
|
+
getDynamicPathSegmentName.__type = [
|
|
145
|
+
"path",
|
|
146
|
+
"getDynamicPathSegmentName",
|
|
147
|
+
"P&2!&/\""
|
|
148
|
+
];
|
|
89
149
|
/**
|
|
90
150
|
* Determines if a given command path segment is a path segment group (enclosed in parentheses).
|
|
91
151
|
*
|
|
@@ -102,6 +162,11 @@ function getDynamicPathSegmentName(path) {
|
|
|
102
162
|
function isPathSegmentGroup(path) {
|
|
103
163
|
return path.startsWith("(") && path.endsWith(")") || path.startsWith("_");
|
|
104
164
|
}
|
|
165
|
+
isPathSegmentGroup.__type = [
|
|
166
|
+
"path",
|
|
167
|
+
"isPathSegmentGroup",
|
|
168
|
+
"P&2!)/\""
|
|
169
|
+
];
|
|
105
170
|
/**
|
|
106
171
|
* Extracts the group name from a command path segment by removing enclosing parentheses.
|
|
107
172
|
*
|
|
@@ -117,6 +182,11 @@ function isPathSegmentGroup(path) {
|
|
|
117
182
|
function getPathSegmentGroupName(path) {
|
|
118
183
|
return path.replaceAll(/^\(+/g, "").replaceAll(/\)+$/g, "").replaceAll(/^_+/g, "");
|
|
119
184
|
}
|
|
185
|
+
getPathSegmentGroupName.__type = [
|
|
186
|
+
"path",
|
|
187
|
+
"getPathSegmentGroupName",
|
|
188
|
+
"P&2!&/\""
|
|
189
|
+
];
|
|
120
190
|
/**
|
|
121
191
|
* Extracts the variable name from a command path segment by removing enclosing square brackets.
|
|
122
192
|
*
|
|
@@ -131,6 +201,11 @@ function getPathSegmentGroupName(path) {
|
|
|
131
201
|
function getPathSegmentName(path) {
|
|
132
202
|
return getPathSegmentGroupName(getDynamicPathSegmentName(path));
|
|
133
203
|
}
|
|
204
|
+
getPathSegmentName.__type = [
|
|
205
|
+
"path",
|
|
206
|
+
"getPathSegmentName",
|
|
207
|
+
"P&2!&/\""
|
|
208
|
+
];
|
|
134
209
|
|
|
135
210
|
//#endregion
|
|
136
211
|
export { getAppBin, getAppDescription, getAppName, getAppTitle, getDynamicPathSegmentName, getPathSegmentGroupName, getPathSegmentName, isDynamicPathSegment, isPathSegmentGroup, sortArgAliases };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-helpers.mjs","names":[
|
|
1
|
+
{"version":3,"file":"context-helpers.mjs","names":[],"sources":["../../src/plugin-utils/context-helpers.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { kebabCase } from \"@stryke/string-format/kebab-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 type { Context, UnresolvedContext } from \"../types\";\n\n/**\n * Sorts command argument aliases, placing single-character aliases first, followed by multi-character aliases, and then sorting them alphabetically.\n *\n * @param aliases - An array of argument aliases to sort.\n * @returns A new array of sorted aliases.\n */\nexport function sortArgAliases(aliases: string[]): string[] {\n if (aliases.length === 0) {\n return [];\n }\n\n const result = aliases.filter(alias => alias.length === 1);\n result.push(...aliases.filter(alias => alias.length > 1));\n\n return result.sort((a, b) => a.localeCompare(b));\n}\n\n/**\n * Retrieves the application name from the context and configuration.\n *\n * @param context - The build context containing workspace and package information.\n * @returns The application name in kebab-case format.\n * @throws An error if no valid application name is found.\n */\nexport function getAppName(context: UnresolvedContext | Context): string {\n const result =\n context.config.name ||\n (isSetString(context.config.bin) ||\n (Array.isArray(context.config.bin) &&\n context.config.bin.length > 0 &&\n isSetString(context.config.bin[0]))\n ? isSetString(context.config.bin)\n ? context.config.bin\n : context.config.bin[0]\n : context.packageJson?.name);\n if (!isSetString(result)) {\n throw new Error(\n \"No application name found. Please provide a 'bin' option in the configuration or ensure the package.json has a valid 'name' field.\"\n );\n }\n\n return kebabCase(result);\n}\n\n/**\n * Retrieves the application title from the context and configuration.\n *\n * @param context - The build context containing workspace and package information.\n * @param replaceCLI - Whether to replace CLI-related terms in the title with the application name.\n * @returns The application title in title-case format.\n */\nexport function getAppTitle(\n context: UnresolvedContext | Context,\n replaceCLI = false\n): string {\n const title =\n context.config.title ||\n titleCase(context.config.name || getAppName(context));\n\n return (\n replaceCLI\n ? title.replace(\n /(?:cli|command-line|command line)\\s*(?:interface\\s*)?(?:application|app)?$/gi,\n \"\"\n )\n : title\n ).trim();\n}\n\n/**\n * Retrieves the application description from the context and configuration.\n *\n * @param context - The build context containing workspace and package information.\n * @returns The application description.\n */\nexport function getAppDescription(\n context: UnresolvedContext | Context\n): string {\n return (\n context.config.description ||\n context.packageJson?.description ||\n `The ${getAppTitle(context, true)} command-line interface application.`\n );\n}\n\n/**\n * Retrieves the primary binary name for the application.\n *\n * @param context - The build context containing workspace and package information.\n * @returns The primary binary name as a string.\n */\nexport function getAppBin(context: Context): string {\n return isSetObject(context.config.bin)\n ? Object.keys(context.config.bin)[0]!\n : kebabCase(getAppName(context));\n}\n\n/**\n * Determines if a given command path segment is variable (enclosed in square brackets).\n *\n * @example\n * ```typescript\n * isDynamicPathSegment(\"[user]\"); // true\n * isDynamicPathSegment(\"user\"); // false\n * ```\n *\n * @param path - The command path segment to check.\n * @returns True if the path is variable, false otherwise.\n */\nexport function isDynamicPathSegment(path: string): boolean {\n return path.startsWith(\"[\") && path.endsWith(\"]\");\n}\n\n/**\n * Extracts the variable name from a command path segment by removing enclosing square brackets.\n *\n * @example\n * ```typescript\n * getDynamicPathSegmentName(\"[user]\"); // \"user\"\n * ```\n *\n * @param path - The command path segment.\n * @returns The variable name without square brackets.\n */\nexport function getDynamicPathSegmentName(path: string): string {\n return path.replaceAll(/^\\[+/g, \"\").replaceAll(/\\]+$/g, \"\");\n}\n\n/**\n * Determines if a given command path segment is a path segment group (enclosed in parentheses).\n *\n * @example\n * ```typescript\n * isPathSegmentGroup(\"(user)\"); // true\n * isPathSegmentGroup(\"[user]\"); // false\n * isPathSegmentGroup(\"user\"); // false\n * ```\n *\n * @param path - The command path segment to check.\n * @returns True if the path is a path segment group, false otherwise.\n */\nexport function isPathSegmentGroup(path: string): boolean {\n return (path.startsWith(\"(\") && path.endsWith(\")\")) || path.startsWith(\"_\");\n}\n\n/**\n * Extracts the group name from a command path segment by removing enclosing parentheses.\n *\n * @example\n * ```typescript\n * getPathSegmentGroupName(\"(admin)\"); // \"admin\"\n * getPathSegmentGroupName(\"((group))\"); // \"group\"\n * ```\n *\n * @param path - The command path segment.\n * @returns The group name without parentheses.\n */\nexport function getPathSegmentGroupName(path: string): string {\n return path\n .replaceAll(/^\\(+/g, \"\")\n .replaceAll(/\\)+$/g, \"\")\n .replaceAll(/^_+/g, \"\");\n}\n\n/**\n * Extracts the variable name from a command path segment by removing enclosing square brackets.\n *\n * @example\n * ```typescript\n * getDynamicPathSegmentName(\"[user]\"); // \"user\"\n * ```\n *\n * @param path - The command path segment.\n * @returns The variable name without square brackets.\n */\nexport function getPathSegmentName(path: string): string {\n return getPathSegmentGroupName(getDynamicPathSegmentName(path));\n}\n"],"mappings":";;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;;;;;;;AA6BX,SAAgB,eAAY,SAAA;AACxB,KAAI,QAAK,WAAA,EACX,QAAA,EAAA;CAEE,MAAM,SAAS,QAAQ,OAAO,cAAa,UAAS,MAAI,WAAA,GAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA;AACxD,QAAO,KAAK,GAAG,QAAQ,OAAO,cAAa,UAAS,MAAG,SAAA,GAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA;;;;;;;;AAG3D,eAAA,SAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;AAQA,SAAE,WAAA,SAAA;CACE,MAAM,SAAS,QAAQ,OAAO,SACzB,YAAM,QAAA,OAAA,IAAA,IACF,MAAM,QAAM,QAAA,OAAA,IAAA,IACT,QAAQ,OAAO,IAAI,SAAG,KACtB,YAAY,QAAQ,OAAI,IAAA,GAAA,GAC1B,YAAY,QAAQ,OAAG,IAAA,GACnB,QAAQ,OAAO,MACf,QAAQ,OAAO,IAAI,KACvB,QAAQ,aAAK;AACvB,KAAI,CAAC,YAAY,OAAO,CACpB,OAAM,IAAI,MAAM,qIAAU;AAE9B,QAAO,UAAQ,OAAA;;AAEnB,WAAK,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;AAQL,SAAC,YAAA,SAAA,aAAA,OAAA;CACG,MAAM,QAAQ,QAAQ,OAAO,SACzB,UAAU,QAAQ,OAAO,QAAQ,WAAW,QAAQ,CAAC;AACzD,SAAQ,aACV,MAAA,QAAA,gFAAA,GAAA,GACQ,OAAO,MAAM;;AAEvB,YAAY,SAAO;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;AAOnB,SAAa,kBAAA,SAAA;AACT,QAAQ,QAAQ,OAAC,eACb,QAAQ,aAAa,eACrB,OAAG,YAAA,SAAA,KAAA,CAAA;;AAEX,kBAAY,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;AAOZ,SAAgB,UAAU,SAAS;AAC/B,QAAO,YAAY,QAAQ,OAAO,IAAC,GACrC,OAAA,KAAA,QAAA,OAAA,IAAA,CAAA,KACQ,UAAU,WAAW,QAAE,CAAA;;AAEjC,UAAU,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;;;;;;AAaV,SAAE,qBAAA,MAAA;AACE,QAAO,KAAK,WAAW,IAAI,IAAI,KAAK,SAAS,IAAG;;AAEpD,qBAAqB,SAAS;CAAC;CAAQ;CAAC;CAAA;;;;;;;;;;;;AAYxC,SAAC,0BAAA,MAAA;AACG,QAAO,KAAK,WAAW,SAAS,GAAG,CAAC,WAAU,SAAA,GAAA;;AAElD,0BAAE,SAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;;;;;;;AAcF,SAAgB,mBAAmB,MAAM;AACvC,QAAA,KAAA,WAAA,IAAA,IAAA,KAAA,SAAA,IAAA,IAAA,KAAA,WAAA,IAAA;;AAEF,mBAAmB,SAAS;CAAC;CAAQ;CAAsB;CAAE;;;;;;;;;;;;;AAa7D,SAAgB,wBAAwB,MAAM;AAC1C,QAAO,KACT,WAAA,SAAA,GAAA,CACO,WAAW,SAAS,GAAG,CACvB,WAAW,QAAQ,GAAG;;;;;;;;;;;;;;;;;;AAc/B,SAAE,mBAAA,MAAA;AACE,QAAO,wBAAwB,0BAA0B,KAAC,CAAA;;AAE9D,mBAAmB,SAAQ;CAAA;CAAA;CAAA;CAAA"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const require_plugin_utils_context_helpers = require('./context-helpers.cjs');
|
|
2
2
|
|
|
3
3
|
//#region src/plugin-utils/get-command-tree.ts
|
|
4
|
+
function __assignType(fn, args) {
|
|
5
|
+
fn.__type = args;
|
|
6
|
+
return fn;
|
|
7
|
+
}
|
|
4
8
|
/**
|
|
5
9
|
* Retrieves a specific command tree based on the provided path.
|
|
6
10
|
*
|
|
@@ -12,12 +16,24 @@ function getCommandTree(context, path = []) {
|
|
|
12
16
|
if (path.length === 0) return null;
|
|
13
17
|
let currentTree = context.commands[path[0]] ?? null;
|
|
14
18
|
if (path.length > 1) {
|
|
15
|
-
const segments = path.slice(1).filter((segment) => !require_plugin_utils_context_helpers.isDynamicPathSegment(segment)
|
|
19
|
+
const segments = path.slice(1).filter(__assignType((segment) => !require_plugin_utils_context_helpers.isDynamicPathSegment(segment), [
|
|
20
|
+
"segment",
|
|
21
|
+
"",
|
|
22
|
+
"P\"2!\"/\""
|
|
23
|
+
]));
|
|
16
24
|
for (const segment of segments) if (currentTree?.children && Object.prototype.hasOwnProperty.call(currentTree.children, segment)) currentTree = currentTree.children[segment] ?? null;
|
|
17
25
|
else return null;
|
|
18
26
|
}
|
|
19
27
|
return currentTree;
|
|
20
28
|
}
|
|
29
|
+
getCommandTree.__type = [
|
|
30
|
+
"Context",
|
|
31
|
+
"context",
|
|
32
|
+
"path",
|
|
33
|
+
"CommandTree",
|
|
34
|
+
"getCommandTree",
|
|
35
|
+
"P\"w!2\"\"2#P\"w$,J/%"
|
|
36
|
+
];
|
|
21
37
|
|
|
22
38
|
//#endregion
|
|
23
39
|
exports.getCommandTree = getCommandTree;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-command-tree.cjs","names":[
|
|
1
|
+
{"version":3,"file":"get-command-tree.cjs","names":[],"sources":["../../src/plugin-utils/get-command-tree.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 type { CommandTree } from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport { isDynamicPathSegment } from \"./context-helpers\";\n\n/**\n * Retrieves a specific command tree based on the provided path.\n *\n * @param context - The build context containing the command definitions.\n * @param path - An array of strings representing the command path.\n * @returns The command tree at the specified path, or null if not found.\n */\nexport function getCommandTree(\n context: Context,\n path = [] as string[]\n): CommandTree | null {\n if (path.length === 0) {\n return null;\n }\n\n let currentTree: CommandTree | null = context.commands[path[0]!] ?? null;\n if (path.length > 1) {\n const segments = path\n .slice(1)\n .filter(segment => !isDynamicPathSegment(segment));\n for (const segment of segments) {\n if (\n currentTree?.children &&\n Object.prototype.hasOwnProperty.call(currentTree.children, segment)\n ) {\n currentTree = currentTree.children[segment] ?? null;\n } else {\n return null;\n }\n }\n }\n\n return currentTree;\n}\n"],"mappings":";;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;;;;;;;;AAUX,SAAgB,eAAe,SAAS,OAAO,EAAE,EAAE;uBAE3C,QAAO;CAEX,IAAI,cAAc,QAAQ,SAAS,KAAK,OAAO;;EAE3C,MAAM,WAAW,KACZ,MAAM,EAAE,CACR,OAAO,cAAa,YAAW,CAAC,0DAAW,QAAA,EAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;iCAEtD,KAAA,aAAA,YACc,OAAO,UAAU,eAAe,KAAK,YAAU,UAAA,QAAA,CAC9D,eAAA,YAAA,SAAA,YAAA;MAGe,QAAO;;AAInB,QAAO;;AAEX,eAAe,SAAS;CAAC;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { isDynamicPathSegment } from "./context-helpers.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugin-utils/get-command-tree.ts
|
|
4
|
+
function __assignType(fn, args) {
|
|
5
|
+
fn.__type = args;
|
|
6
|
+
return fn;
|
|
7
|
+
}
|
|
4
8
|
/**
|
|
5
9
|
* Retrieves a specific command tree based on the provided path.
|
|
6
10
|
*
|
|
@@ -12,12 +16,24 @@ function getCommandTree(context, path = []) {
|
|
|
12
16
|
if (path.length === 0) return null;
|
|
13
17
|
let currentTree = context.commands[path[0]] ?? null;
|
|
14
18
|
if (path.length > 1) {
|
|
15
|
-
const segments = path.slice(1).filter((segment) => !isDynamicPathSegment(segment)
|
|
19
|
+
const segments = path.slice(1).filter(__assignType((segment) => !isDynamicPathSegment(segment), [
|
|
20
|
+
"segment",
|
|
21
|
+
"",
|
|
22
|
+
"P\"2!\"/\""
|
|
23
|
+
]));
|
|
16
24
|
for (const segment of segments) if (currentTree?.children && Object.prototype.hasOwnProperty.call(currentTree.children, segment)) currentTree = currentTree.children[segment] ?? null;
|
|
17
25
|
else return null;
|
|
18
26
|
}
|
|
19
27
|
return currentTree;
|
|
20
28
|
}
|
|
29
|
+
getCommandTree.__type = [
|
|
30
|
+
"Context",
|
|
31
|
+
"context",
|
|
32
|
+
"path",
|
|
33
|
+
"CommandTree",
|
|
34
|
+
"getCommandTree",
|
|
35
|
+
"P\"w!2\"\"2#P\"w$,J/%"
|
|
36
|
+
];
|
|
21
37
|
|
|
22
38
|
//#endregion
|
|
23
39
|
export { getCommandTree };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-command-tree.mjs","names":[
|
|
1
|
+
{"version":3,"file":"get-command-tree.mjs","names":[],"sources":["../../src/plugin-utils/get-command-tree.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 type { CommandTree } from \"../types/command\";\nimport type { Context } from \"../types/context\";\nimport { isDynamicPathSegment } from \"./context-helpers\";\n\n/**\n * Retrieves a specific command tree based on the provided path.\n *\n * @param context - The build context containing the command definitions.\n * @param path - An array of strings representing the command path.\n * @returns The command tree at the specified path, or null if not found.\n */\nexport function getCommandTree(\n context: Context,\n path = [] as string[]\n): CommandTree | null {\n if (path.length === 0) {\n return null;\n }\n\n let currentTree: CommandTree | null = context.commands[path[0]!] ?? null;\n if (path.length > 1) {\n const segments = path\n .slice(1)\n .filter(segment => !isDynamicPathSegment(segment));\n for (const segment of segments) {\n if (\n currentTree?.children &&\n Object.prototype.hasOwnProperty.call(currentTree.children, segment)\n ) {\n currentTree = currentTree.children[segment] ?? null;\n } else {\n return null;\n }\n }\n }\n\n return currentTree;\n}\n"],"mappings":";;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;;;;;;;;AAUX,SAAgB,eAAe,SAAS,OAAO,EAAE,EAAE;uBAE3C,QAAO;CAEX,IAAI,cAAc,QAAQ,SAAS,KAAK,OAAO;;EAE3C,MAAM,WAAW,KACZ,MAAM,EAAE,CACR,OAAO,cAAa,YAAW,CAAC,qBAAW,QAAA,EAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;iCAEtD,KAAA,aAAA,YACc,OAAO,UAAU,eAAe,KAAK,YAAU,UAAA,QAAA,CAC9D,eAAA,YAAA,SAAA,YAAA;MAGe,QAAO;;AAInB,QAAO;;AAEX,eAAe,SAAS;CAAC;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
|
|
@@ -2,6 +2,10 @@ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
|
2
2
|
let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
3
3
|
|
|
4
4
|
//#region src/plugin-utils/reflect.ts
|
|
5
|
+
function __assignType(fn, args) {
|
|
6
|
+
fn.__type = args;
|
|
7
|
+
return fn;
|
|
8
|
+
}
|
|
5
9
|
/**
|
|
6
10
|
* Sort command options alphabetically by name, placing boolean options with negatives appropriately.
|
|
7
11
|
*
|
|
@@ -10,15 +14,39 @@ let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type"
|
|
|
10
14
|
*/
|
|
11
15
|
function sortOptions(options) {
|
|
12
16
|
if (!options || options.length === 0) return [];
|
|
13
|
-
return options.filter((arg) => arg.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.boolean || !arg.isNegativeOf
|
|
17
|
+
return options.filter(__assignType((arg) => arg.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.boolean || !arg.isNegativeOf, [
|
|
18
|
+
"arg",
|
|
19
|
+
"",
|
|
20
|
+
"P\"2!\"/\""
|
|
21
|
+
])).sort(__assignType((a, b) => a.name.localeCompare(b.name), [
|
|
22
|
+
"a",
|
|
23
|
+
"b",
|
|
24
|
+
"",
|
|
25
|
+
"P\"2!\"2\"\"/#"
|
|
26
|
+
])).reduce(__assignType((ret, arg) => {
|
|
14
27
|
ret.push(arg);
|
|
15
28
|
if (arg.kind === __powerlines_deepkit_vendor_type.ReflectionKind.boolean) {
|
|
16
|
-
const negativeArg = options.find((a) => a.kind === __powerlines_deepkit_vendor_type.ReflectionKind.boolean && a.isNegativeOf === arg.name
|
|
29
|
+
const negativeArg = options.find(__assignType((a) => a.kind === __powerlines_deepkit_vendor_type.ReflectionKind.boolean && a.isNegativeOf === arg.name, [
|
|
30
|
+
"a",
|
|
31
|
+
"",
|
|
32
|
+
"P\"2!\"/\""
|
|
33
|
+
]));
|
|
17
34
|
if (negativeArg) ret.push(negativeArg);
|
|
18
35
|
}
|
|
19
36
|
return ret;
|
|
20
|
-
}, [
|
|
37
|
+
}, [
|
|
38
|
+
"ret",
|
|
39
|
+
"arg",
|
|
40
|
+
"",
|
|
41
|
+
"P\"2!\"2\"\"/#"
|
|
42
|
+
]), []);
|
|
21
43
|
}
|
|
44
|
+
sortOptions.__type = [
|
|
45
|
+
"CommandOption",
|
|
46
|
+
"options",
|
|
47
|
+
"sortOptions",
|
|
48
|
+
"P\"w!F2\"\"w!F/#"
|
|
49
|
+
];
|
|
22
50
|
|
|
23
51
|
//#endregion
|
|
24
52
|
exports.sortOptions = sortOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reflect.cjs","names":[
|
|
1
|
+
{"version":3,"file":"reflect.cjs","names":[],"sources":["../../src/plugin-utils/reflect.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 { ReflectionKind } from \"@powerlines/deepkit/vendor/type\";\nimport type { CommandOption } from \"../types/command\";\n\n/**\n * Sort command options alphabetically by name, placing boolean options with negatives appropriately.\n *\n * @param options - The array of command options to sort.\n * @returns A new array of sorted command options.\n */\nexport function sortOptions(options: CommandOption[]): CommandOption[] {\n if (!options || options.length === 0) {\n return [];\n }\n\n return options\n .filter(arg => arg.kind !== ReflectionKind.boolean || !arg.isNegativeOf)\n .sort((a, b) => a.name.localeCompare(b.name))\n .reduce((ret, arg) => {\n ret.push(arg);\n\n if (arg.kind === ReflectionKind.boolean) {\n // Add the negative argument if it exists\n const negativeArg = options.find(\n a => a.kind === ReflectionKind.boolean && a.isNegativeOf === arg.name\n );\n if (negativeArg) {\n ret.push(negativeArg);\n }\n }\n\n return ret;\n }, [] as CommandOption[]);\n}\n"],"mappings":";;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;;;;;;;AA0BX,SAAgB,YAAY,SAAS;AACjC,KAAI,CAAC,WAAI,QAAA,WAAA,EACX,QAAA,EAAA;AAEE,QAAO,QACF,OAAO,cAAa,QAAO,IAAI,SAAS,gDAAe,WAAW,CAAA,IAAA,cAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAClE,KAAK,cAAc,GAAG,MAAM,EAAE,KAAK,cAAI,EAAA,KAAA,EAAA;EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CACvC,OAAO,cAAU,KAAA,QAAA;AAClB,MAAI,KAAK,IAAE;;GAGP,MAAM,cAAc,QAAQ,KAAK,cAAG,MAAA,EAAA,SAAA,gDAAA,WAAA,EAAA,iBAAA,IAAA,MAAA;IAAA;IAAA;IAAA;IAAA,CAAA,CAAA;AACpC,OAAI,YACA,KAAI,KAAK,YAAY;;AAG7B,SAAO;IACR;EAAC;EAAA;EAAA;EAAA;EAAA,CAAA,EAAA,EAAA,CAAA"}
|