@shell-shock/core 0.4.3 → 0.5.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/README.md +1 -1
- package/dist/components/docs.cjs +6 -28
- package/dist/components/docs.cjs.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/docs.d.mts.map +1 -1
- package/dist/components/docs.mjs +8 -30
- package/dist/components/docs.mjs.map +1 -1
- package/dist/components/index.cjs +10 -1
- package/dist/components/index.d.cts +3 -1
- package/dist/components/index.d.mts +3 -1
- package/dist/components/index.mjs +3 -1
- package/dist/components/options-parser-logic.cjs +504 -0
- package/dist/components/options-parser-logic.cjs.map +1 -0
- package/dist/components/options-parser-logic.d.cts +86 -0
- package/dist/components/options-parser-logic.d.cts.map +1 -0
- package/dist/components/options-parser-logic.d.mts +86 -0
- package/dist/components/options-parser-logic.d.mts.map +1 -0
- package/dist/components/options-parser-logic.mjs +498 -0
- package/dist/components/options-parser-logic.mjs.map +1 -0
- package/dist/components/usage.cjs +41 -0
- package/dist/components/usage.cjs.map +1 -0
- package/dist/components/usage.d.cts +30 -0
- package/dist/components/usage.d.cts.map +1 -0
- package/dist/components/usage.d.mts +30 -0
- package/dist/components/usage.d.mts.map +1 -0
- package/dist/components/usage.mjs +40 -0
- package/dist/components/usage.mjs.map +1 -0
- package/dist/contexts/index.cjs +5 -1
- package/dist/contexts/index.d.cts +2 -1
- package/dist/contexts/index.d.mts +2 -1
- package/dist/contexts/index.mjs +2 -1
- package/dist/contexts/options.cjs +43 -0
- package/dist/contexts/options.cjs.map +1 -0
- package/dist/contexts/options.d.cts +22 -0
- package/dist/contexts/options.d.cts.map +1 -0
- package/dist/contexts/options.d.mts +22 -0
- package/dist/contexts/options.d.mts.map +1 -0
- package/dist/contexts/options.mjs +39 -0
- package/dist/contexts/options.mjs.map +1 -0
- package/dist/helpers/resolve-command.cjs +91 -61
- package/dist/helpers/resolve-command.cjs.map +1 -1
- package/dist/helpers/resolve-command.mjs +93 -63
- package/dist/helpers/resolve-command.mjs.map +1 -1
- package/dist/helpers/validations.cjs +20 -48
- package/dist/helpers/validations.cjs.map +1 -1
- package/dist/helpers/validations.mjs +21 -49
- package/dist/helpers/validations.mjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/plugin-utils/context-helpers.cjs +5 -5
- package/dist/plugin-utils/context-helpers.cjs.map +1 -1
- package/dist/plugin-utils/context-helpers.d.cts +3 -3
- package/dist/plugin-utils/context-helpers.d.cts.map +1 -1
- package/dist/plugin-utils/context-helpers.d.mts +3 -3
- package/dist/plugin-utils/context-helpers.d.mts.map +1 -1
- package/dist/plugin-utils/context-helpers.mjs +4 -4
- package/dist/plugin-utils/context-helpers.mjs.map +1 -1
- package/dist/plugin-utils/get-command-tree.cjs +1 -1
- package/dist/plugin-utils/get-command-tree.cjs.map +1 -1
- package/dist/plugin-utils/get-command-tree.mjs +2 -2
- package/dist/plugin-utils/get-command-tree.mjs.map +1 -1
- package/dist/plugin-utils/index.cjs +2 -2
- package/dist/plugin-utils/index.d.cts +2 -2
- package/dist/plugin-utils/index.d.mts +2 -2
- package/dist/plugin-utils/index.mjs +2 -2
- package/dist/plugin.cjs +1 -1
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.mjs +2 -2
- package/dist/plugin.mjs.map +1 -1
- package/dist/types/command.d.cts +14 -10
- package/dist/types/command.d.cts.map +1 -1
- package/dist/types/command.d.mts +14 -10
- package/dist/types/command.d.mts.map +1 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.mts +2 -2
- package/package.json +57 -28
- package/dist/types/internal.cjs +0 -0
- package/dist/types/internal.d.cts +0 -24
- package/dist/types/internal.d.cts.map +0 -1
- package/dist/types/internal.d.mts +0 -24
- package/dist/types/internal.d.mts.map +0 -1
- package/dist/types/internal.mjs +0 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_plugin_utils_context_helpers = require('../plugin-utils/context-helpers.cjs');
|
|
3
|
+
let __alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
4
|
+
let __alloy_js_core = require("@alloy-js/core");
|
|
5
|
+
let __stryke_string_format_snake_case = require("@stryke/string-format/snake-case");
|
|
6
|
+
|
|
7
|
+
//#region src/components/usage.tsx
|
|
8
|
+
/**
|
|
9
|
+
* A component that generates the usage display for a command.
|
|
10
|
+
*/
|
|
11
|
+
function Usage(props) {
|
|
12
|
+
const { command, bin, packageManager } = props;
|
|
13
|
+
return [
|
|
14
|
+
__alloy_js_core.code`$ `,
|
|
15
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Switch, { get children() {
|
|
16
|
+
return [
|
|
17
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Match, {
|
|
18
|
+
when: packageManager === "yarn",
|
|
19
|
+
children: `yarn exec `
|
|
20
|
+
}),
|
|
21
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Match, {
|
|
22
|
+
when: packageManager === "pnpm",
|
|
23
|
+
children: `pnpm exec `
|
|
24
|
+
}),
|
|
25
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Match, {
|
|
26
|
+
when: packageManager === "bun",
|
|
27
|
+
children: `bun x `
|
|
28
|
+
}),
|
|
29
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Match, {
|
|
30
|
+
"else": true,
|
|
31
|
+
children: `npx `
|
|
32
|
+
})
|
|
33
|
+
];
|
|
34
|
+
} }),
|
|
35
|
+
(0, __alloy_js_core_jsx_runtime.memo)(() => __alloy_js_core.code`${bin} ${command.path.segments.map((segment) => require_plugin_utils_context_helpers.isPositionalCommandOption(segment) ? `<${(0, __stryke_string_format_snake_case.snakeCase)(command.path.positional[segment]?.name || require_plugin_utils_context_helpers.getPositionalCommandOptionName(segment))}${command.path.positional[segment]?.variadic ? "..." : ""}>` : segment).join(" ")}${Object.values(command.children).length > 0 ? " [commands]" : ""} [options]`)
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
exports.Usage = Usage;
|
|
41
|
+
//# sourceMappingURL=usage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.cjs","names":["code","Match","Switch","snakeCase","getPositionalCommandOptionName","isPositionalCommandOption","Usage","props","command","bin","packageManager","_$createComponent","children","when","_$memo","path","segments","map","segment","positional","name","variadic","join","Object","values","length"],"sources":["../../src/components/usage.tsx"],"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 { code, Match, Switch } from \"@alloy-js/core\";\nimport { snakeCase } from \"@stryke/string-format/snake-case\";\nimport {\n getPositionalCommandOptionName,\n isPositionalCommandOption\n} from \"../plugin-utils/context-helpers\";\nimport type { CommandTree } from \"../types/command\";\n\nexport interface UsageProps {\n /**\n * The command to generate help for.\n */\n command: CommandTree;\n\n /**\n * The package manager to generate the usage example for.\n *\n * @remarks\n * If not specified, examples for all supported package managers will be generated.\n *\n * @defaultValue \"npm\"\n */\n packageManager?: \"npm\" | \"yarn\" | \"pnpm\" | \"bun\";\n\n /**\n * The bin name to use in the usage display.\n */\n bin: string;\n}\n\n/**\n * A component that generates the usage display for a command.\n */\nexport function Usage(props: UsageProps) {\n const { command, bin, packageManager } = props;\n\n return (\n <>\n {code`$ `}\n <Switch>\n <Match when={packageManager === \"yarn\"}>{`yarn exec `}</Match>\n <Match when={packageManager === \"pnpm\"}>{`pnpm exec `}</Match>\n <Match when={packageManager === \"bun\"}>{`bun x `}</Match>\n <Match else>{`npx `}</Match>\n </Switch>\n {code`${bin} ${command.path.segments\n .map(segment =>\n isPositionalCommandOption(segment)\n ? `<${snakeCase(\n command.path.positional[segment]?.name ||\n getPositionalCommandOptionName(segment)\n )}${command.path.positional[segment]?.variadic ? \"...\" : \"\"}>`\n : segment\n )\n .join(\" \")}${\n Object.values(command.children).length > 0 ? \" [commands]\" : \"\"\n } [options]`}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;AAmDA,SAAgBM,MAAMC,OAAmB;CACvC,MAAM,EAAEC,SAASC,KAAKC,mBAAmBH;AAEzC,QAAA;EAEKP,oBAAI;mDACJE,wBAAM,EAAA,IAAAU,WAAA;AAAA,UAAA;qDACJX,uBAAK;KAACY,MAAMH,mBAAmB;KAAME,UAAG;KAAY,CAAA;qDACpDX,uBAAK;KAACY,MAAMH,mBAAmB;KAAME,UAAG;KAAY,CAAA;qDACpDX,uBAAK;KAACY,MAAMH,mBAAmB;KAAKE,UAAG;KAAQ,CAAA;qDAC/CX,uBAAK;KAAA,QAAA;KAAAW,UAAO;KAAM,CAAA;IAAA;KAAA,CAAA;8CAEpBZ,oBAAI,GAAGS,IAAG,GAAID,QAAQO,KAAKC,SACzBC,KAAIC,YACHb,+DAA0Ba,QAAQ,GAC9B,qDACEV,QAAQO,KAAKI,WAAWD,UAAUE,QAChChB,oEAA+Bc,QACnC,CAAC,GAAGV,QAAQO,KAAKI,WAAWD,UAAUG,WAAW,QAAQ,GAAE,KAC3DH,QACL,CACAI,KAAK,IAAI,GACVC,OAAOC,OAAOhB,QAAQI,SAAS,CAACa,SAAS,IAAI,gBAAgB,GAAE,YACrD;EAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CommandTree } from "../types/command.cjs";
|
|
2
|
+
import * as _alloy_js_core5 from "@alloy-js/core";
|
|
3
|
+
|
|
4
|
+
//#region src/components/usage.d.ts
|
|
5
|
+
interface UsageProps {
|
|
6
|
+
/**
|
|
7
|
+
* The command to generate help for.
|
|
8
|
+
*/
|
|
9
|
+
command: CommandTree;
|
|
10
|
+
/**
|
|
11
|
+
* The package manager to generate the usage example for.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* If not specified, examples for all supported package managers will be generated.
|
|
15
|
+
*
|
|
16
|
+
* @defaultValue "npm"
|
|
17
|
+
*/
|
|
18
|
+
packageManager?: "npm" | "yarn" | "pnpm" | "bun";
|
|
19
|
+
/**
|
|
20
|
+
* The bin name to use in the usage display.
|
|
21
|
+
*/
|
|
22
|
+
bin: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A component that generates the usage display for a command.
|
|
26
|
+
*/
|
|
27
|
+
declare function Usage(props: UsageProps): _alloy_js_core5.Children;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { Usage, UsageProps };
|
|
30
|
+
//# sourceMappingURL=usage.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.d.cts","names":[],"sources":["../../src/components/usage.tsx"],"sourcesContent":[],"mappings":";;;;UA0BiB,UAAA;;;AAAjB;EAyBgB,OAAA,EArBL,WAqBkB;;;;;;;;;;;;;;;;;;iBAAb,KAAA,QAAa,aAAU,eAAA,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CommandTree } from "../types/command.mjs";
|
|
2
|
+
import * as _alloy_js_core5 from "@alloy-js/core";
|
|
3
|
+
|
|
4
|
+
//#region src/components/usage.d.ts
|
|
5
|
+
interface UsageProps {
|
|
6
|
+
/**
|
|
7
|
+
* The command to generate help for.
|
|
8
|
+
*/
|
|
9
|
+
command: CommandTree;
|
|
10
|
+
/**
|
|
11
|
+
* The package manager to generate the usage example for.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* If not specified, examples for all supported package managers will be generated.
|
|
15
|
+
*
|
|
16
|
+
* @defaultValue "npm"
|
|
17
|
+
*/
|
|
18
|
+
packageManager?: "npm" | "yarn" | "pnpm" | "bun";
|
|
19
|
+
/**
|
|
20
|
+
* The bin name to use in the usage display.
|
|
21
|
+
*/
|
|
22
|
+
bin: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A component that generates the usage display for a command.
|
|
26
|
+
*/
|
|
27
|
+
declare function Usage(props: UsageProps): _alloy_js_core5.Children;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { Usage, UsageProps };
|
|
30
|
+
//# sourceMappingURL=usage.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.d.mts","names":[],"sources":["../../src/components/usage.tsx"],"sourcesContent":[],"mappings":";;;;UA0BiB,UAAA;;;AAAjB;EAyBgB,OAAA,EArBL,WAqBkB;;;;;;;;;;;;;;;;;;iBAAb,KAAA,QAAa,aAAU,eAAA,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getPositionalCommandOptionName, isPositionalCommandOption } from "../plugin-utils/context-helpers.mjs";
|
|
2
|
+
import { createComponent, memo } from "@alloy-js/core/jsx-runtime";
|
|
3
|
+
import { Match, Switch, code } from "@alloy-js/core";
|
|
4
|
+
import { snakeCase } from "@stryke/string-format/snake-case";
|
|
5
|
+
|
|
6
|
+
//#region src/components/usage.tsx
|
|
7
|
+
/**
|
|
8
|
+
* A component that generates the usage display for a command.
|
|
9
|
+
*/
|
|
10
|
+
function Usage(props) {
|
|
11
|
+
const { command, bin, packageManager } = props;
|
|
12
|
+
return [
|
|
13
|
+
code`$ `,
|
|
14
|
+
createComponent(Switch, { get children() {
|
|
15
|
+
return [
|
|
16
|
+
createComponent(Match, {
|
|
17
|
+
when: packageManager === "yarn",
|
|
18
|
+
children: `yarn exec `
|
|
19
|
+
}),
|
|
20
|
+
createComponent(Match, {
|
|
21
|
+
when: packageManager === "pnpm",
|
|
22
|
+
children: `pnpm exec `
|
|
23
|
+
}),
|
|
24
|
+
createComponent(Match, {
|
|
25
|
+
when: packageManager === "bun",
|
|
26
|
+
children: `bun x `
|
|
27
|
+
}),
|
|
28
|
+
createComponent(Match, {
|
|
29
|
+
"else": true,
|
|
30
|
+
children: `npx `
|
|
31
|
+
})
|
|
32
|
+
];
|
|
33
|
+
} }),
|
|
34
|
+
memo(() => code`${bin} ${command.path.segments.map((segment) => isPositionalCommandOption(segment) ? `<${snakeCase(command.path.positional[segment]?.name || getPositionalCommandOptionName(segment))}${command.path.positional[segment]?.variadic ? "..." : ""}>` : segment).join(" ")}${Object.values(command.children).length > 0 ? " [commands]" : ""} [options]`)
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { Usage };
|
|
40
|
+
//# sourceMappingURL=usage.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.mjs","names":["code","Match","Switch","snakeCase","getPositionalCommandOptionName","isPositionalCommandOption","Usage","props","command","bin","packageManager","_$createComponent","children","when","_$memo","path","segments","map","segment","positional","name","variadic","join","Object","values","length"],"sources":["../../src/components/usage.tsx"],"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 { code, Match, Switch } from \"@alloy-js/core\";\nimport { snakeCase } from \"@stryke/string-format/snake-case\";\nimport {\n getPositionalCommandOptionName,\n isPositionalCommandOption\n} from \"../plugin-utils/context-helpers\";\nimport type { CommandTree } from \"../types/command\";\n\nexport interface UsageProps {\n /**\n * The command to generate help for.\n */\n command: CommandTree;\n\n /**\n * The package manager to generate the usage example for.\n *\n * @remarks\n * If not specified, examples for all supported package managers will be generated.\n *\n * @defaultValue \"npm\"\n */\n packageManager?: \"npm\" | \"yarn\" | \"pnpm\" | \"bun\";\n\n /**\n * The bin name to use in the usage display.\n */\n bin: string;\n}\n\n/**\n * A component that generates the usage display for a command.\n */\nexport function Usage(props: UsageProps) {\n const { command, bin, packageManager } = props;\n\n return (\n <>\n {code`$ `}\n <Switch>\n <Match when={packageManager === \"yarn\"}>{`yarn exec `}</Match>\n <Match when={packageManager === \"pnpm\"}>{`pnpm exec `}</Match>\n <Match when={packageManager === \"bun\"}>{`bun x `}</Match>\n <Match else>{`npx `}</Match>\n </Switch>\n {code`${bin} ${command.path.segments\n .map(segment =>\n isPositionalCommandOption(segment)\n ? `<${snakeCase(\n command.path.positional[segment]?.name ||\n getPositionalCommandOptionName(segment)\n )}${command.path.positional[segment]?.variadic ? \"...\" : \"\"}>`\n : segment\n )\n .join(\" \")}${\n Object.values(command.children).length > 0 ? \" [commands]\" : \"\"\n } [options]`}\n </>\n );\n}\n"],"mappings":";;;;;;;;;AAmDA,SAAgBM,MAAMC,OAAmB;CACvC,MAAM,EAAEC,SAASC,KAAKC,mBAAmBH;AAEzC,QAAA;EAEKP,IAAI;EAAIW,gBACRT,QAAM,EAAA,IAAAU,WAAA;AAAA,UAAA;IAAAD,gBACJV,OAAK;KAACY,MAAMH,mBAAmB;KAAME,UAAG;KAAY,CAAA;IAAAD,gBACpDV,OAAK;KAACY,MAAMH,mBAAmB;KAAME,UAAG;KAAY,CAAA;IAAAD,gBACpDV,OAAK;KAACY,MAAMH,mBAAmB;KAAKE,UAAG;KAAQ,CAAA;IAAAD,gBAC/CV,OAAK;KAAA,QAAA;KAAAW,UAAO;KAAM,CAAA;IAAA;KAAA,CAAA;EAAAE,WAEpBd,IAAI,GAAGS,IAAG,GAAID,QAAQO,KAAKC,SACzBC,KAAIC,YACHb,0BAA0Ba,QAAQ,GAC9B,IAAIf,UACFK,QAAQO,KAAKI,WAAWD,UAAUE,QAChChB,+BAA+Bc,QACnC,CAAC,GAAGV,QAAQO,KAAKI,WAAWD,UAAUG,WAAW,QAAQ,GAAE,KAC3DH,QACL,CACAI,KAAK,IAAI,GACVC,OAAOC,OAAOhB,QAAQI,SAAS,CAACa,SAAS,IAAI,gBAAgB,GAAE,YACrD;EAAA"}
|
package/dist/contexts/index.cjs
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
const require_contexts_command = require('./command.cjs');
|
|
2
|
+
const require_contexts_options = require('./options.cjs');
|
|
2
3
|
|
|
3
4
|
exports.CommandContext = require_contexts_command.CommandContext;
|
|
4
|
-
exports.
|
|
5
|
+
exports.ExistingOptionsContext = require_contexts_options.ExistingOptionsContext;
|
|
6
|
+
exports.computedOptions = require_contexts_options.computedOptions;
|
|
7
|
+
exports.useCommand = require_contexts_command.useCommand;
|
|
8
|
+
exports.useExistingOptions = require_contexts_options.useExistingOptions;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { CommandContext, useCommand } from "./command.cjs";
|
|
2
|
-
|
|
2
|
+
import { ExistingOptionsContext, computedOptions, useExistingOptions } from "./options.cjs";
|
|
3
|
+
export { CommandContext, ExistingOptionsContext, computedOptions, useCommand, useExistingOptions };
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { CommandContext, useCommand } from "./command.mjs";
|
|
2
|
-
|
|
2
|
+
import { ExistingOptionsContext, computedOptions, useExistingOptions } from "./options.mjs";
|
|
3
|
+
export { CommandContext, ExistingOptionsContext, computedOptions, useCommand, useExistingOptions };
|
package/dist/contexts/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { CommandContext, useCommand } from "./command.mjs";
|
|
2
|
+
import { ExistingOptionsContext, computedOptions, useExistingOptions } from "./options.mjs";
|
|
2
3
|
|
|
3
|
-
export { CommandContext, useCommand };
|
|
4
|
+
export { CommandContext, ExistingOptionsContext, computedOptions, useCommand, useExistingOptions };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let __stryke_string_format_camel_case = require("@stryke/string-format/camel-case");
|
|
3
|
+
let __stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
4
|
+
let defu = require("defu");
|
|
5
|
+
defu = require_rolldown_runtime.__toESM(defu);
|
|
6
|
+
let __alloy_js_core = require("@alloy-js/core");
|
|
7
|
+
let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
8
|
+
|
|
9
|
+
//#region src/contexts/options.ts
|
|
10
|
+
/**
|
|
11
|
+
* The reflection parameter context used in template rendering.
|
|
12
|
+
*/
|
|
13
|
+
const ExistingOptionsContext = (0, __alloy_js_core.createNamedContext)("ExistingOptions", []);
|
|
14
|
+
/**
|
|
15
|
+
* Hook to access the ExistingOptions context.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* This context provides a list of option names that already exist on the interface definition.
|
|
19
|
+
*
|
|
20
|
+
* @returns A reactive version of the current reflection.
|
|
21
|
+
*/
|
|
22
|
+
function useExistingOptions() {
|
|
23
|
+
return (0, __alloy_js_core.useContext)(ExistingOptionsContext);
|
|
24
|
+
}
|
|
25
|
+
function computedOptions(command) {
|
|
26
|
+
return Object.entries(command.options).reduce((ret, [name, option]) => {
|
|
27
|
+
ret[(0, __stryke_string_format_camel_case.camelCase)(name)] ??= (0, defu.default)({ name: (0, __stryke_string_format_camel_case.camelCase)(name) }, ret[name] ?? {}, option);
|
|
28
|
+
if (option.kind === __powerlines_deepkit_vendor_type.ReflectionKind.boolean && option.isNegativeOf) ret[(0, __stryke_string_format_camel_case.camelCase)(option.isNegativeOf)] = (0, defu.default)({ name: (0, __stryke_string_format_camel_case.camelCase)(option.isNegativeOf) }, ret[option.isNegativeOf] ?? {}, {
|
|
29
|
+
...option,
|
|
30
|
+
env: (0, __stryke_type_checks_is_set_string.isSetString)(option.env) ? `NO_${option.env}` : false,
|
|
31
|
+
description: `${option.description.replace(/\.+$/, "")}. This property is the negative form of ${name}.`,
|
|
32
|
+
isNegativeOf: (0, __stryke_string_format_camel_case.camelCase)(name),
|
|
33
|
+
default: !option.default
|
|
34
|
+
});
|
|
35
|
+
return ret;
|
|
36
|
+
}, {});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
exports.ExistingOptionsContext = ExistingOptionsContext;
|
|
41
|
+
exports.computedOptions = computedOptions;
|
|
42
|
+
exports.useExistingOptions = useExistingOptions;
|
|
43
|
+
//# sourceMappingURL=options.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.cjs","names":["createNamedContext","useContext","ReflectionKind","camelCase","isSetString","defu","ExistingOptionsContext","useExistingOptions","computedOptions","command","Object","entries","options","reduce","ret","name","option","kind","boolean","isNegativeOf","env","description","replace","default"],"sources":["../../src/contexts/options.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 { ComponentContext } from \"@alloy-js/core\";\nimport { createNamedContext, useContext } from \"@alloy-js/core\";\nimport { ReflectionKind } from \"@powerlines/deepkit/vendor/type\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport defu from \"defu\";\nimport type {\n BooleanCommandOption,\n CommandOption,\n CommandTree\n} from \"../types\";\n\n/**\n * The reflection parameter context used in template rendering.\n */\nexport const ExistingOptionsContext: ComponentContext<string[]> =\n createNamedContext<string[]>(\"ExistingOptions\", []);\n\n/**\n * Hook to access the ExistingOptions context.\n *\n * @remarks\n * This context provides a list of option names that already exist on the interface definition.\n *\n * @returns A reactive version of the current reflection.\n */\nexport function useExistingOptions() {\n return useContext<string[]>(ExistingOptionsContext)!;\n}\n\nexport function computedOptions(command: CommandTree) {\n return Object.entries(command.options).reduce(\n (ret, [name, option]) => {\n ret[camelCase(name)] ??= defu(\n {\n name: camelCase(name)\n },\n ret[name] ?? {},\n option\n ) as CommandOption;\n\n if (option.kind === ReflectionKind.boolean && option.isNegativeOf) {\n ret[camelCase(option.isNegativeOf)] = defu(\n {\n name: camelCase(option.isNegativeOf)\n },\n ret[option.isNegativeOf] ?? {},\n {\n ...option,\n env: isSetString(option.env) ? `NO_${option.env}` : false,\n description: `${option.description.replace(\n /\\.+$/,\n \"\"\n )}. This property is the negative form of ${name}.`,\n isNegativeOf: camelCase(name),\n default: !option.default\n }\n ) as BooleanCommandOption;\n }\n\n return ret;\n },\n {} as Record<string, CommandOption>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAiCA,MAAaM,iEACkB,mBAAmB,EAAE,CAAC;;;;;;;;;AAUrD,SAAgBC,qBAAqB;AACnC,wCAA4BD,uBAAuB;;AAGrD,SAAgBE,gBAAgBC,SAAsB;AACpD,QAAOC,OAAOC,QAAQF,QAAQG,QAAQ,CAACC,QACpCC,KAAK,CAACC,MAAMC,YAAY;AACvBF,uDAAcC,KAAK,wBACjB,EACEA,uDAAgBA,KAAI,EACrB,EACDD,IAAIC,SAAS,EAAE,EACfC,OACgB;AAElB,MAAIA,OAAOC,SAASf,gDAAegB,WAAWF,OAAOG,aACnDL,sDAAcE,OAAOG,aAAa,sBAChC,EACEJ,uDAAgBC,OAAOG,aAAY,EACpC,EACDL,IAAIE,OAAOG,iBAAiB,EAAE,EAC9B;GACE,GAAGH;GACHI,yDAAiBJ,OAAOI,IAAI,GAAG,MAAMJ,OAAOI,QAAQ;GACpDC,aAAa,GAAGL,OAAOK,YAAYC,QACjC,QACA,GACD,CAAA,0CAA2CP,KAAI;GAChDI,+DAAwBJ,KAAK;GAC7BQ,SAAS,CAACP,OAAOO;GAErB,CAAyB;AAG3B,SAAOT;IAET,EACF,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CommandOption, CommandTree } from "../types/command.cjs";
|
|
2
|
+
import "../types/index.cjs";
|
|
3
|
+
import { ComponentContext } from "@alloy-js/core";
|
|
4
|
+
|
|
5
|
+
//#region src/contexts/options.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* The reflection parameter context used in template rendering.
|
|
8
|
+
*/
|
|
9
|
+
declare const ExistingOptionsContext: ComponentContext<string[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Hook to access the ExistingOptions context.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* This context provides a list of option names that already exist on the interface definition.
|
|
15
|
+
*
|
|
16
|
+
* @returns A reactive version of the current reflection.
|
|
17
|
+
*/
|
|
18
|
+
declare function useExistingOptions(): string[];
|
|
19
|
+
declare function computedOptions(command: CommandTree): Record<string, CommandOption>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { ExistingOptionsContext, computedOptions, useExistingOptions };
|
|
22
|
+
//# sourceMappingURL=options.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.cts","names":[],"sources":["../../src/contexts/options.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAiCa,cAAA,sBAAwB,EAAA,gBAAgB,CAAA,MAAA,EAAA,CAAA;AAWrD;AAIA;;;;;;;iBAJgB,kBAAA,CAAA;iBAIA,eAAA,UAAyB,cAAW,eAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CommandOption, CommandTree } from "../types/command.mjs";
|
|
2
|
+
import "../types/index.mjs";
|
|
3
|
+
import { ComponentContext } from "@alloy-js/core";
|
|
4
|
+
|
|
5
|
+
//#region src/contexts/options.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* The reflection parameter context used in template rendering.
|
|
8
|
+
*/
|
|
9
|
+
declare const ExistingOptionsContext: ComponentContext<string[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Hook to access the ExistingOptions context.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* This context provides a list of option names that already exist on the interface definition.
|
|
15
|
+
*
|
|
16
|
+
* @returns A reactive version of the current reflection.
|
|
17
|
+
*/
|
|
18
|
+
declare function useExistingOptions(): string[];
|
|
19
|
+
declare function computedOptions(command: CommandTree): Record<string, CommandOption>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { ExistingOptionsContext, computedOptions, useExistingOptions };
|
|
22
|
+
//# sourceMappingURL=options.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.mts","names":[],"sources":["../../src/contexts/options.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAiCa,cAAA,sBAAwB,EAAA,gBAAgB,CAAA,MAAA,EAAA,CAAA;AAWrD;AAIA;;;;;;;iBAJgB,kBAAA,CAAA;iBAIA,eAAA,UAAyB,cAAW,eAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { camelCase } from "@stryke/string-format/camel-case";
|
|
2
|
+
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
3
|
+
import defu$1 from "defu";
|
|
4
|
+
import { createNamedContext, useContext } from "@alloy-js/core";
|
|
5
|
+
import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
|
|
6
|
+
|
|
7
|
+
//#region src/contexts/options.ts
|
|
8
|
+
/**
|
|
9
|
+
* The reflection parameter context used in template rendering.
|
|
10
|
+
*/
|
|
11
|
+
const ExistingOptionsContext = createNamedContext("ExistingOptions", []);
|
|
12
|
+
/**
|
|
13
|
+
* Hook to access the ExistingOptions context.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* This context provides a list of option names that already exist on the interface definition.
|
|
17
|
+
*
|
|
18
|
+
* @returns A reactive version of the current reflection.
|
|
19
|
+
*/
|
|
20
|
+
function useExistingOptions() {
|
|
21
|
+
return useContext(ExistingOptionsContext);
|
|
22
|
+
}
|
|
23
|
+
function computedOptions(command) {
|
|
24
|
+
return Object.entries(command.options).reduce((ret, [name, option]) => {
|
|
25
|
+
ret[camelCase(name)] ??= defu$1({ name: camelCase(name) }, ret[name] ?? {}, option);
|
|
26
|
+
if (option.kind === ReflectionKind.boolean && option.isNegativeOf) ret[camelCase(option.isNegativeOf)] = defu$1({ name: camelCase(option.isNegativeOf) }, ret[option.isNegativeOf] ?? {}, {
|
|
27
|
+
...option,
|
|
28
|
+
env: isSetString(option.env) ? `NO_${option.env}` : false,
|
|
29
|
+
description: `${option.description.replace(/\.+$/, "")}. This property is the negative form of ${name}.`,
|
|
30
|
+
isNegativeOf: camelCase(name),
|
|
31
|
+
default: !option.default
|
|
32
|
+
});
|
|
33
|
+
return ret;
|
|
34
|
+
}, {});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { ExistingOptionsContext, computedOptions, useExistingOptions };
|
|
39
|
+
//# sourceMappingURL=options.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.mjs","names":["createNamedContext","useContext","ReflectionKind","camelCase","isSetString","defu","ExistingOptionsContext","useExistingOptions","computedOptions","command","Object","entries","options","reduce","ret","name","option","kind","boolean","isNegativeOf","env","description","replace","default"],"sources":["../../src/contexts/options.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 { ComponentContext } from \"@alloy-js/core\";\nimport { createNamedContext, useContext } from \"@alloy-js/core\";\nimport { ReflectionKind } from \"@powerlines/deepkit/vendor/type\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport defu from \"defu\";\nimport type {\n BooleanCommandOption,\n CommandOption,\n CommandTree\n} from \"../types\";\n\n/**\n * The reflection parameter context used in template rendering.\n */\nexport const ExistingOptionsContext: ComponentContext<string[]> =\n createNamedContext<string[]>(\"ExistingOptions\", []);\n\n/**\n * Hook to access the ExistingOptions context.\n *\n * @remarks\n * This context provides a list of option names that already exist on the interface definition.\n *\n * @returns A reactive version of the current reflection.\n */\nexport function useExistingOptions() {\n return useContext<string[]>(ExistingOptionsContext)!;\n}\n\nexport function computedOptions(command: CommandTree) {\n return Object.entries(command.options).reduce(\n (ret, [name, option]) => {\n ret[camelCase(name)] ??= defu(\n {\n name: camelCase(name)\n },\n ret[name] ?? {},\n option\n ) as CommandOption;\n\n if (option.kind === ReflectionKind.boolean && option.isNegativeOf) {\n ret[camelCase(option.isNegativeOf)] = defu(\n {\n name: camelCase(option.isNegativeOf)\n },\n ret[option.isNegativeOf] ?? {},\n {\n ...option,\n env: isSetString(option.env) ? `NO_${option.env}` : false,\n description: `${option.description.replace(\n /\\.+$/,\n \"\"\n )}. This property is the negative form of ${name}.`,\n isNegativeOf: camelCase(name),\n default: !option.default\n }\n ) as BooleanCommandOption;\n }\n\n return ret;\n },\n {} as Record<string, CommandOption>\n );\n}\n"],"mappings":";;;;;;;;;;AAiCA,MAAaM,yBACXN,mBAA6B,mBAAmB,EAAE,CAAC;;;;;;;;;AAUrD,SAAgBO,qBAAqB;AACnC,QAAON,WAAqBK,uBAAuB;;AAGrD,SAAgBE,gBAAgBC,SAAsB;AACpD,QAAOC,OAAOC,QAAQF,QAAQG,QAAQ,CAACC,QACpCC,KAAK,CAACC,MAAMC,YAAY;AACvBF,MAAIX,UAAUY,KAAK,MAAMV,OACvB,EACEU,MAAMZ,UAAUY,KAAI,EACrB,EACDD,IAAIC,SAAS,EAAE,EACfC,OACgB;AAElB,MAAIA,OAAOC,SAASf,eAAegB,WAAWF,OAAOG,aACnDL,KAAIX,UAAUa,OAAOG,aAAa,IAAId,OACpC,EACEU,MAAMZ,UAAUa,OAAOG,aAAY,EACpC,EACDL,IAAIE,OAAOG,iBAAiB,EAAE,EAC9B;GACE,GAAGH;GACHI,KAAKhB,YAAYY,OAAOI,IAAI,GAAG,MAAMJ,OAAOI,QAAQ;GACpDC,aAAa,GAAGL,OAAOK,YAAYC,QACjC,QACA,GACD,CAAA,0CAA2CP,KAAI;GAChDI,cAAchB,UAAUY,KAAK;GAC7BQ,SAAS,CAACP,OAAOO;GAErB,CAAyB;AAG3B,SAAOT;IAET,EACF,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_plugin_utils_context_helpers = require('../plugin-utils/context-helpers.cjs');
|
|
3
3
|
const require_utilities = require('./utilities.cjs');
|
|
4
|
+
let __stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
4
5
|
let __stryke_path_append = require("@stryke/path/append");
|
|
5
6
|
let __stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
|
|
6
7
|
let __stryke_path_replace = require("@stryke/path/replace");
|
|
@@ -10,22 +11,27 @@ let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-obj
|
|
|
10
11
|
let __stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
11
12
|
let __stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
12
13
|
let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
13
|
-
let
|
|
14
|
+
let __powerlines_deepkit_esbuild_plugin = require("@powerlines/deepkit/esbuild-plugin");
|
|
14
15
|
let __stryke_path_common = require("@stryke/path/common");
|
|
15
16
|
let __stryke_path_normalize = require("@stryke/path/normalize");
|
|
17
|
+
let powerlines_lib_utilities_resolve = require("powerlines/lib/utilities/resolve");
|
|
16
18
|
|
|
17
19
|
//#region src/helpers/resolve-command.ts
|
|
18
20
|
/**
|
|
19
21
|
* Resolves the description for a command option based on its reflection.
|
|
20
22
|
*
|
|
21
|
-
* @param
|
|
23
|
+
* @param kind - The reflection kind of the command option.
|
|
24
|
+
* @param optional - Whether the command option is optional.
|
|
25
|
+
* @param name - The name of the command option.
|
|
26
|
+
* @param title - The title of the command option, if any.
|
|
27
|
+
* @param defaultValue - The default value of the command option, if any.
|
|
22
28
|
* @returns The resolved description for the command option.
|
|
23
29
|
*/
|
|
24
|
-
function
|
|
25
|
-
return
|
|
30
|
+
function resolveCommandOptionDescription(kind, optional, name, title, defaultValue) {
|
|
31
|
+
return `A${optional && !defaultValue ? "n optional" : ""} ${kind === __powerlines_deepkit_vendor_type.ReflectionKind.boolean ? "flag provided via the command-line" : "command-line option"} that allows the user to ${kind === __powerlines_deepkit_vendor_type.ReflectionKind.boolean ? "set the" : kind === __powerlines_deepkit_vendor_type.ReflectionKind.array ? "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${kind === __powerlines_deepkit_vendor_type.ReflectionKind.array ? "s" : ""}`} that will be used in the application.`;
|
|
26
32
|
}
|
|
27
33
|
function resolveCommandId(context, file) {
|
|
28
|
-
return (0, __stryke_path_replace.replacePath)((0, __stryke_path_file_path_fns.findFilePath)(file), context.commandsPath).split("/").filter((p) => Boolean(p) && !require_plugin_utils_context_helpers.
|
|
34
|
+
return (0, __stryke_path_replace.replacePath)((0, __stryke_path_file_path_fns.findFilePath)(file), context.commandsPath).split("/").filter((p) => Boolean(p) && !require_plugin_utils_context_helpers.isPositionalCommandOption(p)).join("/").replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "").replaceAll("/", "-");
|
|
29
35
|
}
|
|
30
36
|
/**
|
|
31
37
|
* Finds the command name from the given file path.
|
|
@@ -36,7 +42,7 @@ function resolveCommandId(context, file) {
|
|
|
36
42
|
function resolveCommandName(file) {
|
|
37
43
|
let path = (0, __stryke_path_file_path_fns.findFilePath)(file);
|
|
38
44
|
let name = (0, __stryke_path_file_path_fns.findFolderName)(file, { requireExtension: true });
|
|
39
|
-
while (require_plugin_utils_context_helpers.
|
|
45
|
+
while (require_plugin_utils_context_helpers.isPositionalCommandOption(name)) {
|
|
40
46
|
path = (0, __stryke_path_resolve_parent_path.resolveParentPath)(path);
|
|
41
47
|
name = (0, __stryke_path_file_path_fns.findFolderName)(path, { requireExtension: true });
|
|
42
48
|
}
|
|
@@ -54,17 +60,56 @@ function findCommandsRoot(context) {
|
|
|
54
60
|
/**
|
|
55
61
|
* Extracts command parameter information from a type parameter reflection.
|
|
56
62
|
*
|
|
57
|
-
* @param
|
|
58
|
-
* @
|
|
63
|
+
* @param command - The command tree to which the parameter belongs.
|
|
64
|
+
* @param reflection - The type parameter reflection to extract information from.
|
|
65
|
+
* @returns The extracted command option information.
|
|
59
66
|
*/
|
|
60
|
-
function
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
function extractCommandOption(command, reflection) {
|
|
68
|
+
const propertyType = reflection.getType();
|
|
69
|
+
const option = {
|
|
70
|
+
name: reflection.getNameAsString(),
|
|
71
|
+
alias: reflection.getTags().alias ?? [],
|
|
72
|
+
title: reflection.getTags().title?.trim() || (0, __stryke_string_format_title_case.titleCase)(reflection.getNameAsString()),
|
|
73
|
+
description: reflection.getDescription() || resolveCommandOptionDescription(reflection.getKind(), reflection.isOptional(), reflection.getNameAsString(), reflection.getTags().title, reflection.getDefaultValue()),
|
|
74
|
+
env: (0, __stryke_string_format_constant_case.constantCase)(reflection.getNameAsString()),
|
|
75
|
+
kind: propertyType.kind,
|
|
76
|
+
optional: reflection.isOptional(),
|
|
77
|
+
default: reflection.getDefaultValue(),
|
|
78
|
+
variadic: false
|
|
67
79
|
};
|
|
80
|
+
if (propertyType.kind === __powerlines_deepkit_vendor_type.ReflectionKind.array) if (propertyType.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string || propertyType.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.number) {
|
|
81
|
+
option.variadic = true;
|
|
82
|
+
option.kind = propertyType.type.kind;
|
|
83
|
+
} else throw new Error(`Unsupported array type for option "${reflection.getNameAsString()}" in command "${command.name}". Only string[] and number[] are supported.`);
|
|
84
|
+
else if (propertyType.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.boolean && propertyType.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.string && propertyType.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.number) throw new Error(`Unsupported type for option "${reflection.getNameAsString()}" in command "${command.name}". Only string, number, boolean, string[] and number[] are supported, received ${(0, __powerlines_deepkit_vendor_type.stringifyType)(propertyType).trim().replaceAll(" | ", ", or ")}.`);
|
|
85
|
+
return option;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Extracts command parameter information from a type parameter reflection.
|
|
89
|
+
*
|
|
90
|
+
* @param command - The command tree to which the parameter belongs.
|
|
91
|
+
* @param segment - The command path segment corresponding to the parameter.
|
|
92
|
+
* @param reflection - The type parameter reflection to extract information from.
|
|
93
|
+
* @returns The extracted command option information.
|
|
94
|
+
*/
|
|
95
|
+
function extractCommandPositionalOption(command, segment, reflection) {
|
|
96
|
+
if (reflection.type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.string && reflection.type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.number && !(reflection.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.array && (reflection.type.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string || reflection.type.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.number))) throw new Error(`Unsupported type for positional option "${segment}" in command "${command.name}". Only string and number types (or string[] and number[]) are supported, received ${(0, __powerlines_deepkit_vendor_type.stringifyType)(reflection.type).trim().replaceAll(" | ", ", or ")}.`);
|
|
97
|
+
const option = {
|
|
98
|
+
name: segment,
|
|
99
|
+
alias: [],
|
|
100
|
+
title: (0, __stryke_string_format_title_case.titleCase)(segment),
|
|
101
|
+
description: reflection.description || resolveCommandOptionDescription(reflection.type.kind, !!reflection.optional, segment, (0, __stryke_string_format_title_case.titleCase)(segment), reflection.default),
|
|
102
|
+
env: (0, __stryke_string_format_constant_case.constantCase)(segment),
|
|
103
|
+
kind: reflection.type.kind,
|
|
104
|
+
optional: reflection.optional,
|
|
105
|
+
default: reflection.default,
|
|
106
|
+
variadic: false
|
|
107
|
+
};
|
|
108
|
+
if (reflection.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.array) if (reflection.type.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string || reflection.type.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.number) {
|
|
109
|
+
option.variadic = true;
|
|
110
|
+
option.kind = reflection.type.type.kind;
|
|
111
|
+
} else throw new Error(`Unsupported array type for option "${segment}" in command "${command.name}". Only string[] and number[] are supported.`);
|
|
112
|
+
return option;
|
|
68
113
|
}
|
|
69
114
|
/**
|
|
70
115
|
* Reflects the command tree for a given command input.
|
|
@@ -77,59 +122,46 @@ function extractCommandParameters(param) {
|
|
|
77
122
|
async function reflectCommandTree(context, command, parent) {
|
|
78
123
|
const title = command.title || `${parent?.title ? `${parent.isVirtual ? parent.title.replace(/ Commands$/, "") : parent.title} - ` : ""}${(0, __stryke_string_format_title_case.titleCase)(command.name)}${command.isVirtual ? " Commands" : ""}`;
|
|
79
124
|
const tree = {
|
|
125
|
+
alias: [],
|
|
80
126
|
...command,
|
|
81
127
|
title,
|
|
82
|
-
description: command.description || (command.isVirtual ? `A collection of available ${command.title || (0, __stryke_string_format_title_case.titleCase)(command.name)} commands that are included in the ${require_plugin_utils_context_helpers.getAppTitle(context)} command-line application.` : `The ${title} executable command-line interface.`),
|
|
83
128
|
path: {
|
|
84
129
|
...command.path,
|
|
85
|
-
|
|
130
|
+
positional: {}
|
|
86
131
|
},
|
|
87
132
|
options: require_utilities.getDefaultOptions(context, command),
|
|
88
|
-
params: [],
|
|
89
133
|
parent: parent ?? null,
|
|
90
134
|
children: {}
|
|
91
135
|
};
|
|
92
136
|
if (!command.isVirtual) {
|
|
93
137
|
if (!command.entry.input?.file || !context.fs.existsSync(command.entry.input.file)) throw new Error(`${!command.entry.input?.file ? "Missing" : "Non-existent"} command entry file for "${command.name}"`);
|
|
94
138
|
context.debug(`Adding reflection for user-defined command: ${command.id} (file: ${command.entry.input.file})`);
|
|
95
|
-
const
|
|
139
|
+
const resolved = await (0, powerlines_lib_utilities_resolve.resolveModule)(context, command.entry.input, { plugins: [(0, __powerlines_deepkit_esbuild_plugin.esbuildPlugin)(context, {
|
|
140
|
+
reflection: "default",
|
|
141
|
+
reflectionLevel: "verbose"
|
|
142
|
+
})] });
|
|
143
|
+
const metadata = resolved.metadata ?? {};
|
|
144
|
+
if ((0, __stryke_type_checks_is_set_string.isSetString)(metadata.title)) tree.title = metadata.title;
|
|
145
|
+
if ((0, __stryke_type_checks_is_set_string.isSetString)(metadata.description)) tree.description = metadata.description;
|
|
146
|
+
if ((0, __stryke_type_checks_is_set_string.isSetString)(metadata.alias) || Array.isArray(metadata.alias) && metadata.alias.length > 0) tree.alias = (0, __stryke_convert_to_array.toArray)(metadata.alias);
|
|
147
|
+
const type = (0, __powerlines_deepkit_vendor_type.reflect)(resolved);
|
|
96
148
|
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.`);
|
|
149
|
+
tree.description ??= command.description || type.description || `The ${tree.title} executable command-line interface.`;
|
|
97
150
|
if (type.parameters.length > 0 && type.parameters[0]) {
|
|
98
151
|
const firstParam = type.parameters[0];
|
|
99
152
|
if (firstParam.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral || firstParam.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.class) {
|
|
100
153
|
const optionsReflection = __powerlines_deepkit_vendor_type.ReflectionClass.from(firstParam.type);
|
|
101
|
-
for (const propertyReflection of optionsReflection.getProperties())
|
|
102
|
-
const propertyType = propertyReflection.getType();
|
|
103
|
-
tree.options[propertyReflection.getNameAsString()] = {
|
|
104
|
-
name: propertyReflection.getNameAsString(),
|
|
105
|
-
alias: propertyReflection.getTags().alias ?? [],
|
|
106
|
-
title: propertyReflection.getTags().title?.trim() || (0, __stryke_string_format_title_case.titleCase)(propertyReflection.getNameAsString()),
|
|
107
|
-
description: resolveCommandDescription(propertyReflection),
|
|
108
|
-
env: (0, __stryke_string_format_constant_case.constantCase)(propertyReflection.getNameAsString()),
|
|
109
|
-
kind: propertyType.kind,
|
|
110
|
-
optional: propertyReflection.isOptional(),
|
|
111
|
-
default: propertyReflection.getDefaultValue(),
|
|
112
|
-
variadic: false
|
|
113
|
-
};
|
|
114
|
-
if (propertyType.kind === __powerlines_deepkit_vendor_type.ReflectionKind.array) if (propertyType.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string || propertyType.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.number) {
|
|
115
|
-
tree.options[propertyReflection.getNameAsString()].variadic = true;
|
|
116
|
-
tree.options[propertyReflection.getNameAsString()].kind = propertyType.type.kind;
|
|
117
|
-
} else throw new Error(`Unsupported array type for option "${propertyReflection.getNameAsString()}" in command "${command.name}". Only string[] and number[] are supported.`);
|
|
118
|
-
else if (propertyType.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.boolean && propertyType.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.string && propertyType.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.number) throw new Error(`Unsupported type for option "${propertyReflection.getNameAsString()}" in command "${command.name}". Only string, number, boolean, string[] and number[] are supported, received ${(0, __powerlines_deepkit_vendor_type.stringifyType)(propertyType).trim().replaceAll(" | ", ", or ")}.`);
|
|
119
|
-
}
|
|
154
|
+
for (const propertyReflection of optionsReflection.getProperties()) tree.options[propertyReflection.getNameAsString()] = extractCommandOption(command, propertyReflection);
|
|
120
155
|
}
|
|
121
|
-
tree.path.
|
|
156
|
+
tree.path.positional = tree.path.segments.filter((segment) => require_plugin_utils_context_helpers.isPositionalCommandOption(segment)).reduce((obj, segment, index) => {
|
|
122
157
|
if (type.parameters.length < index + 2 || !type.parameters[index + 1]) return obj;
|
|
123
|
-
const paramName = require_plugin_utils_context_helpers.
|
|
124
|
-
obj[paramName] =
|
|
125
|
-
obj[paramName].description = obj[paramName].description || `The ${paramName}
|
|
158
|
+
const paramName = require_plugin_utils_context_helpers.getPositionalCommandOptionName(segment);
|
|
159
|
+
obj[paramName] = extractCommandPositionalOption(command, paramName, type.parameters[index + 1]);
|
|
160
|
+
obj[paramName].description = obj[paramName].description || `The ${paramName} positional option for the ${command.name} command.`;
|
|
126
161
|
return obj;
|
|
127
162
|
}, {});
|
|
128
|
-
if (type.parameters.length > 1) type.parameters.slice(tree.path.segments.filter((segment) => require_plugin_utils_context_helpers.isVariableCommandPath(segment)).length + 1).forEach((param) => {
|
|
129
|
-
tree.params.push(extractCommandParameters(param));
|
|
130
|
-
});
|
|
131
163
|
}
|
|
132
|
-
}
|
|
164
|
+
} else tree.description ??= `A collection of available ${tree.title || (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.`;
|
|
133
165
|
if (context.env) {
|
|
134
166
|
if ((0, __stryke_type_checks_is_set_object.isSetObject)(tree.options)) Object.values(tree.options).filter((option) => option.env !== false).forEach((option) => {
|
|
135
167
|
context.env.types.env.addProperty({
|
|
@@ -149,22 +181,20 @@ async function reflectCommandTree(context, command, parent) {
|
|
|
149
181
|
}
|
|
150
182
|
});
|
|
151
183
|
});
|
|
152
|
-
if (tree.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
});
|
|
165
|
-
});
|
|
184
|
+
if (Object.values(tree.path.positional).filter((option) => option.env !== false).length > 0) Object.values(tree.path.positional).filter((option) => option.env !== false).forEach((option) => context.env.types.env.addProperty({
|
|
185
|
+
name: (0, __stryke_string_format_constant_case.constantCase)(option.name),
|
|
186
|
+
optional: option.optional ? true : void 0,
|
|
187
|
+
description: option.description,
|
|
188
|
+
visibility: __powerlines_deepkit_vendor_type.ReflectionVisibility.public,
|
|
189
|
+
type: option.variadic ? {
|
|
190
|
+
kind: __powerlines_deepkit_vendor_type.ReflectionKind.array,
|
|
191
|
+
type: { kind: __powerlines_deepkit_vendor_type.ReflectionKind.string }
|
|
192
|
+
} : { kind: __powerlines_deepkit_vendor_type.ReflectionKind.string },
|
|
193
|
+
default: option.default,
|
|
194
|
+
tags: { domain: "cli" }
|
|
195
|
+
}));
|
|
166
196
|
}
|
|
167
|
-
for (const input of context.inputs.filter((input$1) => input$1.path.segments.filter((segment) => !require_plugin_utils_context_helpers.
|
|
197
|
+
for (const input of context.inputs.filter((input$1) => input$1.path.segments.filter((segment) => !require_plugin_utils_context_helpers.isPositionalCommandOption(segment)).length === command.path.segments.filter((segment) => !require_plugin_utils_context_helpers.isPositionalCommandOption(segment)).length + 1 && input$1.path.segments.slice(0, command.path.segments.length).every((value, index) => value === command.path.segments[index]))) tree.children[input.name] = await reflectCommandTree(context, input, tree);
|
|
168
198
|
return tree;
|
|
169
199
|
}
|
|
170
200
|
|