@shell-shock/preset-script 0.6.63 → 0.6.65

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.
@@ -1,5 +1,202 @@
1
- import{VirtualCommandEntry as e}from"./virtual-command-entry.mjs";import{createComponent as t,createIntrinsic as n,memo as r,mergeProps as i}from"@alloy-js/core/jsx-runtime";import{For as a,Show as o,code as s,computed as c}from"@alloy-js/core";import{ElseClause as l,FunctionDeclaration as u,IfStatement as d}from"@alloy-js/typescript";import{Spacing as f}from"@powerlines/plugin-alloy/core/components/spacing";import{usePowerlines as p}from"@powerlines/plugin-alloy/core/contexts/context";import{EntryFile as m}from"@powerlines/plugin-alloy/typescript/components/entry-file";import{TSDoc as h,TSDocParam as g,TSDocRemarks as _,TSDocTitle as v}from"@powerlines/plugin-alloy/typescript/components/tsdoc";import{getAppBin as y,getDynamicPathSegmentName as b,isDynamicPathSegment as x}from"@shell-shock/core/plugin-utils";import{replaceExtension as S}from"@stryke/path/replace";import{pascalCase as C}from"@stryke/string-format/pascal-case";import w from"defu";import{IsDebug as T}from"@shell-shock/core/components/helpers";import{CommandValidationLogic as E}from"@shell-shock/core/components/command-validation-logic";import{CommandParserLogic as D,OptionsInterfaceDeclaration as O}from"@shell-shock/core/components/options-parser-logic";import{findFilePath as k,relativePath as A}from"@stryke/path/find";import{joinPaths as j}from"@stryke/path/join";import{camelCase as M}from"@stryke/string-format/camel-case";import{constantCase as N}from"@stryke/string-format/constant-case";import{kebabCase as P}from"@stryke/string-format/kebab-case";function F(e){let{command:t}=e;return[r(()=>s` return withCommand("${t.path}", [${t.segments.map(e=>x(e)?M(b(e)):`"${e}"`).join(`, `)}], [${Object.keys(t.options).length>0?`options`:``}${t.args.length>0?`${Object.keys(t.options).length>0?`, `:``}${t.args.map(e=>M(e.name)).join(`, `)}`:``}], handle${C(t.name)}); `),n(`hbr`,{})]}function I(e){let{command:r,banner:i,children:a}=e,c=p();return[t(O,{command:r}),t(f,{}),t(h,{get heading(){return`The ${r.title} (${y(c)} ${r.segments.map(e=>x(e)?`[${N(b(e))}]`:e).join(` `)}) command.`},get children(){return[t(_,{get children(){return`${r.description.replace(/\.+$/,``)}.`}}),n(`hbr`,{}),t(v,{get children(){return r.title}}),t(g,{name:`args`,children:`The command-line arguments passed to the command.`})]}}),t(u,{export:!0,async:!0,name:`handler`,parameters:[{name:`args`,type:`string[]`,default:`useArgs()`}],get children(){return[t(D,{command:r,get appSpecificEnvPrefix(){return c.config.appSpecificEnvPrefix},get isCaseSensitive(){return c.config.isCaseSensitive}}),t(f,{}),t(o,{get when(){return!!i},children:i}),t(f,{}),s`writeLine("");`,t(d,{get condition(){return t(T,{})},get children(){return s`writeLine(textColors.body.tertiary("Debug mode is enabled. Additional debug information may be logged to the console."));
1
+ import { VirtualCommandEntry } from "./virtual-command-entry.mjs";
2
+ import { createComponent, createIntrinsic, memo, mergeProps } from "@alloy-js/core/jsx-runtime";
3
+ import { For, Show, code, computed } from "@alloy-js/core";
4
+ import { ElseClause, FunctionDeclaration, IfStatement } from "@alloy-js/typescript";
5
+ import { Spacing } from "@powerlines/plugin-alloy/core/components/spacing";
6
+ import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
7
+ import { EntryFile } from "@powerlines/plugin-alloy/typescript/components/entry-file";
8
+ import { TSDoc, TSDocParam, TSDocRemarks, TSDocTitle } from "@powerlines/plugin-alloy/typescript/components/tsdoc";
9
+ import { getAppBin, getDynamicPathSegmentName, isDynamicPathSegment } from "@shell-shock/core/plugin-utils";
10
+ import { replaceExtension } from "@stryke/path/replace";
11
+ import { pascalCase } from "@stryke/string-format/pascal-case";
12
+ import defu from "defu";
13
+ import { IsDebug } from "@shell-shock/core/components/helpers";
14
+ import { CommandValidationLogic } from "@shell-shock/core/components/command-validation-logic";
15
+ import { CommandParserLogic, OptionsInterfaceDeclaration } from "@shell-shock/core/components/options-parser-logic";
16
+ import { findFilePath, relativePath } from "@stryke/path/find";
17
+ import { joinPaths } from "@stryke/path/join";
18
+ import { camelCase } from "@stryke/string-format/camel-case";
19
+ import { constantCase } from "@stryke/string-format/constant-case";
20
+ import { kebabCase } from "@stryke/string-format/kebab-case";
21
+
22
+ //#region src/components/command-entry.tsx
23
+ function CommandInvocation(props) {
24
+ const { command } = props;
25
+ return [memo(() => code` return withCommand("${command.path}", [${command.segments.map((segment) => isDynamicPathSegment(segment) ? camelCase(getDynamicPathSegmentName(segment)) : `"${segment}"`).join(", ")}], [${Object.keys(command.options).length > 0 ? `options` : ""}${command.args.length > 0 ? `${Object.keys(command.options).length > 0 ? ", " : ""}${command.args.map((arg) => camelCase(arg.name)).join(", ")}` : ""}], handle${pascalCase(command.name)}); `), createIntrinsic("hbr", {})];
26
+ }
27
+ /**
28
+ * A component that generates the `handler` function declaration for a command.
29
+ */
30
+ function CommandHandlerDeclaration(props) {
31
+ const { command, banner, children } = props;
32
+ const context = usePowerlines();
33
+ return [
34
+ createComponent(OptionsInterfaceDeclaration, { command }),
35
+ createComponent(Spacing, {}),
36
+ createComponent(TSDoc, {
37
+ get heading() {
38
+ return `The ${command.title} (${getAppBin(context)} ${command.segments.map((segment) => isDynamicPathSegment(segment) ? `[${constantCase(getDynamicPathSegmentName(segment))}]` : segment).join(" ")}) command.`;
39
+ },
40
+ get children() {
41
+ return [
42
+ createComponent(TSDocRemarks, { get children() {
43
+ return `${command.description.replace(/\.+$/, "")}.`;
44
+ } }),
45
+ createIntrinsic("hbr", {}),
46
+ createComponent(TSDocTitle, { get children() {
47
+ return command.title;
48
+ } }),
49
+ createComponent(TSDocParam, {
50
+ name: "args",
51
+ children: `The command-line arguments passed to the command.`
52
+ })
53
+ ];
54
+ }
55
+ }),
56
+ createComponent(FunctionDeclaration, {
57
+ "export": true,
58
+ async: true,
59
+ name: "handler",
60
+ parameters: [{
61
+ name: "args",
62
+ type: "string[]",
63
+ default: "useArgs()"
64
+ }],
65
+ get children() {
66
+ return [
67
+ createComponent(CommandParserLogic, {
68
+ command,
69
+ get appSpecificEnvPrefix() {
70
+ return context.config.appSpecificEnvPrefix;
71
+ },
72
+ get isCaseSensitive() {
73
+ return context.config.isCaseSensitive;
74
+ }
75
+ }),
76
+ createComponent(Spacing, {}),
77
+ createComponent(Show, {
78
+ get when() {
79
+ return Boolean(banner);
80
+ },
81
+ children: banner
82
+ }),
83
+ createComponent(Spacing, {}),
84
+ code`writeLine("");`,
85
+ createComponent(IfStatement, {
86
+ get condition() {
87
+ return createComponent(IsDebug, {});
88
+ },
89
+ get children() {
90
+ return code`writeLine(textColors.body.tertiary("Debug mode is enabled. Additional debug information may be logged to the console."));
2
91
  writeLine("");
3
- debug(\`Command path: ${r.segments.map(e=>x(e)?`\${${M(b(e))}}`:e).join(` / `)} \\n\\nOptions: \\n${Object.values(r.options).map(e=>` - ${P(e.name)}: \${options.${M(e.name)} === undefined ? "" : JSON.stringify(options.${M(e.name)})}`).join(`\\n`)}${r.args.length>0?` \\n\\nArguments: \\n${r.args.map(e=>` - ${P(e.name)}: \${${M(e.name)} === undefined ? "" : JSON.stringify(${M(e.name)})}`).join(`\\n`)}`:``}\`); `}}),t(f,{}),a,t(f,{}),t(d,{condition:s`options.help`,children:s`return showHelp(); `}),t(l,{get children(){return[n(`hbr`,{}),t(F,{command:r})]}})]}})]}function L(n){let{command:r,imports:l,builtinImports:u,...h}=n,g=p(),_=c(()=>j(r.segments.filter(e=>!x(e)).join(`/`),`index.ts`)),v=c(()=>S(A(j(g.entryPath,k(_.value)),r.entry.input?.file||r.entry.file))),y=c(()=>({...r.entry,output:r.id}));return[t(m,i(h,{get path(){return _.value},get typeDefinition(){return y.value},get imports(){return w(l??{},{[v.value.startsWith(`.`)?v.value:`./${v.value}`]:`handle${C(r.name)}`})},get builtinImports(){return w(u??{},{env:[`env`,`isDevelopment`,`isDebug`],console:[`debug`,`warn`,`error`,`writeLine`,`textColors`],utils:[`isMinimal`,`isUnicodeSupported`],state:[{name:`GlobalOptions`,type:!0},`useGlobal`,`useGlobalOptions`,`useArgs`,`hasFlag`,`withCommand`],[j(`help`,...r.segments.filter(e=>!x(e)))]:[`showHelp`],[j(`banner`,...r.segments.filter(e=>!x(e)))]:[`showBanner`]})},get children(){return[t(f,{}),t(O,{command:r}),t(f,{}),t(I,{command:r,banner:s`await showBanner(); `,get children(){return[t(E,{command:r}),t(d,{condition:s`failures.length > 0`,get children(){return s`error(\`The following validation failures were found while processing the user provided input, and must be corrected before the \${italic("${r.title}")} command can be executed: \\n\\n\${failures.map(failure => " - " + failure).join("\\n")}\`);
4
- options.help = true; `}})]}})]}})),t(a,{get each(){return Object.values(r.children)},children:n=>t(o,{get when(){return n.isVirtual},get fallback(){return t(L,{command:n})},get children(){return t(e,{command:n})}})})]}export{L as CommandEntry,I as CommandHandlerDeclaration,F as CommandInvocation};
92
+ debug(\`Command path: ${command.segments.map((segment) => isDynamicPathSegment(segment) ? `\${${camelCase(getDynamicPathSegmentName(segment))}}` : segment).join(" / ")} \\n\\nOptions: \\n${Object.values(command.options).map((option) => ` - ${kebabCase(option.name)}: \${options.${camelCase(option.name)} === undefined ? "" : JSON.stringify(options.${camelCase(option.name)})}`).join("\\n")}${command.args.length > 0 ? ` \\n\\nArguments: \\n${command.args.map((arg) => ` - ${kebabCase(arg.name)}: \${${camelCase(arg.name)} === undefined ? "" : JSON.stringify(${camelCase(arg.name)})}`).join("\\n")}` : ""}\`); `;
93
+ }
94
+ }),
95
+ createComponent(Spacing, {}),
96
+ children,
97
+ createComponent(Spacing, {}),
98
+ createComponent(IfStatement, {
99
+ condition: code`options.help`,
100
+ children: code`return showHelp(); `
101
+ }),
102
+ createComponent(ElseClause, { get children() {
103
+ return [createIntrinsic("hbr", {}), createComponent(CommandInvocation, { command })];
104
+ } })
105
+ ];
106
+ }
107
+ })
108
+ ];
109
+ }
110
+ /**
111
+ * The command entry point for the Shell Shock project.
112
+ */
113
+ function CommandEntry(props) {
114
+ const { command, imports, builtinImports, ...rest } = props;
115
+ const context = usePowerlines();
116
+ const filePath = computed(() => joinPaths(command.segments.filter((segment) => !isDynamicPathSegment(segment)).join("/"), "index.ts"));
117
+ const commandSourcePath = computed(() => replaceExtension(relativePath(joinPaths(context.entryPath, findFilePath(filePath.value)), command.entry.input?.file || command.entry.file)));
118
+ const typeDefinition = computed(() => ({
119
+ ...command.entry,
120
+ output: command.id
121
+ }));
122
+ return [createComponent(EntryFile, mergeProps(rest, {
123
+ get path() {
124
+ return filePath.value;
125
+ },
126
+ get typeDefinition() {
127
+ return typeDefinition.value;
128
+ },
129
+ get imports() {
130
+ return defu(imports ?? {}, { [commandSourcePath.value.startsWith(".") ? commandSourcePath.value : `./${commandSourcePath.value}`]: `handle${pascalCase(command.name)}` });
131
+ },
132
+ get builtinImports() {
133
+ return defu(builtinImports ?? {}, {
134
+ env: [
135
+ "env",
136
+ "isDevelopment",
137
+ "isDebug"
138
+ ],
139
+ console: [
140
+ "debug",
141
+ "warn",
142
+ "error",
143
+ "writeLine",
144
+ "textColors"
145
+ ],
146
+ utils: ["isMinimal", "isUnicodeSupported"],
147
+ state: [
148
+ {
149
+ name: "GlobalOptions",
150
+ type: true
151
+ },
152
+ "useGlobal",
153
+ "useGlobalOptions",
154
+ "useArgs",
155
+ "hasFlag",
156
+ "withCommand"
157
+ ],
158
+ [joinPaths("help", ...command.segments.filter((segment) => !isDynamicPathSegment(segment)))]: ["showHelp"],
159
+ [joinPaths("banner", ...command.segments.filter((segment) => !isDynamicPathSegment(segment)))]: ["showBanner"]
160
+ });
161
+ },
162
+ get children() {
163
+ return [
164
+ createComponent(Spacing, {}),
165
+ createComponent(OptionsInterfaceDeclaration, { command }),
166
+ createComponent(Spacing, {}),
167
+ createComponent(CommandHandlerDeclaration, {
168
+ command,
169
+ banner: code`await showBanner(); `,
170
+ get children() {
171
+ return [createComponent(CommandValidationLogic, { command }), createComponent(IfStatement, {
172
+ condition: code`failures.length > 0`,
173
+ get children() {
174
+ return code`error(\`The following validation failures were found while processing the user provided input, and must be corrected before the \${italic("${command.title}")} command can be executed: \\n\\n\${failures.map(failure => " - " + failure).join("\\n")}\`);
175
+ options.help = true; `;
176
+ }
177
+ })];
178
+ }
179
+ })
180
+ ];
181
+ }
182
+ })), createComponent(For, {
183
+ get each() {
184
+ return Object.values(command.children);
185
+ },
186
+ children: (child) => createComponent(Show, {
187
+ get when() {
188
+ return child.isVirtual;
189
+ },
190
+ get fallback() {
191
+ return createComponent(CommandEntry, { command: child });
192
+ },
193
+ get children() {
194
+ return createComponent(VirtualCommandEntry, { command: child });
195
+ }
196
+ })
197
+ })];
198
+ }
199
+
200
+ //#endregion
201
+ export { CommandEntry, CommandHandlerDeclaration, CommandInvocation };
5
202
  //# sourceMappingURL=command-entry.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"command-entry.mjs","names":[],"sources":["../../src/components/command-entry.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 type { Children } from \"@alloy-js/core\";\nimport { code, computed, For, Show } from \"@alloy-js/core\";\nimport {\n ElseClause,\n FunctionDeclaration,\n IfStatement\n} from \"@alloy-js/typescript\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core/components/spacing\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport type { EntryFileProps } from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport { EntryFile } from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport {\n TSDoc,\n TSDocParam,\n TSDocRemarks,\n TSDocTitle\n} from \"@powerlines/plugin-alloy/typescript/components/tsdoc\";\nimport type { CommandTree } from \"@shell-shock/core\";\nimport { CommandValidationLogic } from \"@shell-shock/core/components/command-validation-logic\";\nimport { IsDebug } from \"@shell-shock/core/components/helpers\";\nimport {\n CommandParserLogic,\n OptionsInterfaceDeclaration\n} from \"@shell-shock/core/components/options-parser-logic\";\nimport {\n getAppBin,\n getDynamicPathSegmentName,\n isDynamicPathSegment\n} from \"@shell-shock/core/plugin-utils\";\nimport { findFilePath, relativePath } from \"@stryke/path/find\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { replaceExtension } from \"@stryke/path/replace\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport defu from \"defu\";\nimport type { ScriptPresetContext } from \"../types/plugin\";\nimport { VirtualCommandEntry } from \"./virtual-command-entry\";\n\nexport function CommandInvocation(props: { command: CommandTree }) {\n const { command } = props;\n\n return (\n <>\n {code` return withCommand(\"${command.path}\", [${command.segments\n .map(segment =>\n isDynamicPathSegment(segment)\n ? camelCase(getDynamicPathSegmentName(segment))\n : `\"${segment}\"`\n )\n .join(\", \")}], [${\n Object.keys(command.options).length > 0 ? `options` : \"\"\n }${\n command.args.length > 0\n ? `${\n Object.keys(command.options).length > 0 ? \", \" : \"\"\n }${command.args.map(arg => camelCase(arg.name)).join(\", \")}`\n : \"\"\n }], handle${pascalCase(command.name)}); `}\n <hbr />\n </>\n );\n}\n\nexport interface CommandHandlerDeclarationProps {\n command: CommandTree;\n banner?: Children;\n children?: Children;\n}\n\n/**\n * A component that generates the `handler` function declaration for a command.\n */\nexport function CommandHandlerDeclaration(\n props: CommandHandlerDeclarationProps\n) {\n const { command, banner, children } = props;\n\n const context = usePowerlines<ScriptPresetContext>();\n\n return (\n <>\n <OptionsInterfaceDeclaration command={command} />\n <Spacing />\n <TSDoc\n heading={`The ${command.title} (${getAppBin(context)} ${command.segments\n .map(segment =>\n isDynamicPathSegment(segment)\n ? `[${constantCase(getDynamicPathSegmentName(segment))}]`\n : segment\n )\n .join(\" \")}) command.`}>\n <TSDocRemarks>{`${command.description.replace(/\\.+$/, \"\")}.`}</TSDocRemarks>\n <hbr />\n <TSDocTitle>{command.title}</TSDocTitle>\n <TSDocParam name=\"args\">{`The command-line arguments passed to the command.`}</TSDocParam>\n </TSDoc>\n <FunctionDeclaration\n export\n async\n name=\"handler\"\n parameters={[{ name: \"args\", type: \"string[]\", default: \"useArgs()\" }]}>\n <CommandParserLogic\n command={command}\n appSpecificEnvPrefix={context.config.appSpecificEnvPrefix}\n isCaseSensitive={context.config.isCaseSensitive}\n />\n <Spacing />\n <Show when={Boolean(banner)}>{banner}</Show>\n <Spacing />\n {code`writeLine(\"\");`}\n <IfStatement condition={<IsDebug />}>\n {code`writeLine(textColors.body.tertiary(\"Debug mode is enabled. Additional debug information may be logged to the console.\"));\n writeLine(\"\");\n debug(\\`Command path: ${command.segments\n .map(segment =>\n isDynamicPathSegment(segment)\n ? `\\${${camelCase(getDynamicPathSegmentName(segment))}}`\n : segment\n )\n .join(\" / \")} \\\\n\\\\nOptions: \\\\n${Object.values(command.options)\n .map(\n option =>\n ` - ${kebabCase(option.name)}: \\${options.${camelCase(\n option.name\n )} === undefined ? \"\" : JSON.stringify(options.${camelCase(\n option.name\n )})}`\n )\n .join(\"\\\\n\")}${\n command.args.length > 0\n ? ` \\\\n\\\\nArguments: \\\\n${command.args\n .map(\n arg =>\n ` - ${kebabCase(arg.name)}: \\${${camelCase(\n arg.name\n )} === undefined ? \"\" : JSON.stringify(${camelCase(\n arg.name\n )})}`\n )\n .join(\"\\\\n\")}`\n : \"\"\n }\\`); `}\n </IfStatement>\n <Spacing />\n {children}\n <Spacing />\n <IfStatement condition={code`options.help`}>\n {code`return showHelp(); `}\n </IfStatement>\n <ElseClause>\n <hbr />\n <CommandInvocation command={command} />\n </ElseClause>\n </FunctionDeclaration>\n </>\n );\n}\n\nexport interface CommandEntryProps extends Omit<\n EntryFileProps,\n \"path\" | \"typeDefinition\"\n> {\n command: CommandTree;\n}\n\n/**\n * The command entry point for the Shell Shock project.\n */\nexport function CommandEntry(props: CommandEntryProps) {\n const { command, imports, builtinImports, ...rest } = props;\n\n const context = usePowerlines<ScriptPresetContext>();\n const filePath = computed(() =>\n joinPaths(\n command.segments\n .filter(segment => !isDynamicPathSegment(segment))\n .join(\"/\"),\n \"index.ts\"\n )\n );\n const commandSourcePath = computed(() =>\n replaceExtension(\n relativePath(\n joinPaths(context.entryPath, findFilePath(filePath.value)),\n command.entry.input?.file || command.entry.file\n )\n )\n );\n const typeDefinition = computed(() => ({\n ...command.entry,\n output: command.id\n }));\n\n return (\n <>\n <EntryFile\n {...rest}\n path={filePath.value}\n typeDefinition={typeDefinition.value}\n imports={defu(imports ?? {}, {\n [commandSourcePath.value.startsWith(\".\")\n ? commandSourcePath.value\n : `./${commandSourcePath.value}`]:\n `handle${pascalCase(command.name)}`\n })}\n builtinImports={defu(builtinImports ?? {}, {\n env: [\"env\", \"isDevelopment\", \"isDebug\"],\n console: [\"debug\", \"warn\", \"error\", \"writeLine\", \"textColors\"],\n utils: [\"isMinimal\", \"isUnicodeSupported\"],\n state: [\n { name: \"GlobalOptions\", type: true },\n \"useGlobal\",\n \"useGlobalOptions\",\n \"useArgs\",\n \"hasFlag\",\n \"withCommand\"\n ],\n [joinPaths(\n \"help\",\n ...command.segments.filter(\n segment => !isDynamicPathSegment(segment)\n )\n )]: [\"showHelp\"],\n [joinPaths(\n \"banner\",\n ...command.segments.filter(\n segment => !isDynamicPathSegment(segment)\n )\n )]: [\"showBanner\"]\n })}>\n <Spacing />\n <OptionsInterfaceDeclaration command={command} />\n <Spacing />\n <CommandHandlerDeclaration\n command={command}\n banner={code`await showBanner(); `}>\n <CommandValidationLogic command={command} />\n <IfStatement condition={code`failures.length > 0`}>\n {code`error(\\`The following validation failures were found while processing the user provided input, and must be corrected before the \\${italic(\"${\n command.title\n }\")} command can be executed: \\\\n\\\\n\\${failures.map(failure => \" - \" + failure).join(\"\\\\n\")}\\`);\n options.help = true; `}\n </IfStatement>\n </CommandHandlerDeclaration>\n </EntryFile>\n <For each={Object.values(command.children)}>\n {child => (\n <Show\n when={child.isVirtual}\n fallback={<CommandEntry command={child} />}>\n <VirtualCommandEntry command={child} />\n </Show>\n )}\n </For>\n </>\n );\n}\n"],"mappings":"mgDAsCA,SAAO,EAAA,EAAA,CACL,GAAA,CACA,WACI,EACN,MAAO,CAAA,MAAA,CAAA,wBAAA,EAAA,KAAA,MAAA,EAAA,SAAA,IAAA,GAAA,EAAA,EAAA,CAAA,EAAA,EAAA,EAAA,CAAA,CAAA,IAAA,EAAA,GAAA,CAAA,KAAA,KAAA,CAAA,MAAA,OAAA,KAAA,EAAA,QAAA,CAAA,OAAA,EAAA,UAAA,KAAA,EAAA,KAAA,OAAA,EAAA,GAAA,OAAA,KAAA,EAAA,QAAA,CAAA,OAAA,EAAA,KAAA,KAAA,EAAA,KAAA,IAAA,GAAA,EAAA,EAAA,KAAA,CAAA,CAAA,KAAA,KAAA,GAAA,GAAA,WAAA,EAAA,EAAA,KAAA,CAAA,KAAA,CAAA,EAAA,MAAA,EAAA,CAAA,CAAA,CAKP,SAAS,EAAiC,EAAG,CAC7C,GAAQ,CACR,UACA,SACA,YACM,EACE,EAAC,GAAoB,CAC7B,MAAO,CAAA,EAAgB,EAAA,CACV,UACb,CAAA,CAAM,EAAG,EAAsB,EAAI,CAAC,CAAE,EAAiB,EAAM,eAEvD,MAAC,OAAS,EAAA,MAAkB,IAAA,EAAS,EAAS,CAAA,GAAA,EAAe,SAAA,IAAA,GAAA,EAAA,EAAA,CAAA,IAAA,EAAA,EAAA,EAAA,CAAA,CAAA,GAAA,EAAA,CAAA,KAAA,IAAA,CAAA,4BAGjE,MAAO,CAAA,EAAA,EAAA,CACJ,IAAA,UAAA,CACE,MAAM,GAAO,EAAA,YAAe,QAAa,OAAM,GAAA,CAAA,IAE/C,CAAC,CAAE,EAAA,MAAqB,EA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A,GAAA,EAAA,SAAA,OAAA,GAAA,CAAA,EAAA,EAAA,CAAA,CAAA,EAAA,CAAA,aAAA,CACX,CAAC,EAEJ,IAAI,UAAS,CACX,MAAI,CAAA,EAAW,EAAA,EAAA,CAAA,CAAA,EAAA,EAAA,CACJ,UACV,CAAC,CAAC,EAAQ,EAAA,EAAA,CAAA,CAAA,EAAA,EAAA,CACA,UACT,OAAC,CAAW,uBACZ,IAAG,UAAY,CACb,MAAA,CAAA,EAAW,EAAA,CACF,UACR,CAAA,CAAG,EAAE,EAAA,CACL,UAAA,CAAA,sBACD,IAAA,UAAU,CACZ,MAAA,EAAA,8IAAmB,EAAA,MAAA;wCAG3B,CAAA,CAAA,EAEO,CAAA,CAAA,EAEJ,CAAA,CAAA,CAAI,EAAK,EAAc,CACxB,IAAA,MAAA,CACA,OAAS,OAAA,OAAW,EAAA,SAAA,mBAGpB,IAAA,MAAA,CACK,OAAQ,EAAM,WAEf,IAAC,UAAS,CACR,OAAE,EAAkB,EAAmB,CAAA,QAAA,EAEvC,CAAA,EAEJ,IAAA,UAAS,CACP,OAAQ,EAAA,EAAA,CACL,QAAO,EACP,CAAA,EAEL,CAAA,CACD,CAAA,CAAA"}
1
+ {"version":3,"file":"command-entry.mjs","names":[],"sources":["../../src/components/command-entry.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 type { Children } from \"@alloy-js/core\";\nimport { code, computed, For, Show } from \"@alloy-js/core\";\nimport {\n ElseClause,\n FunctionDeclaration,\n IfStatement\n} from \"@alloy-js/typescript\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core/components/spacing\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport type { EntryFileProps } from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport { EntryFile } from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport {\n TSDoc,\n TSDocParam,\n TSDocRemarks,\n TSDocTitle\n} from \"@powerlines/plugin-alloy/typescript/components/tsdoc\";\nimport type { CommandTree } from \"@shell-shock/core\";\nimport { CommandValidationLogic } from \"@shell-shock/core/components/command-validation-logic\";\nimport { IsDebug } from \"@shell-shock/core/components/helpers\";\nimport {\n CommandParserLogic,\n OptionsInterfaceDeclaration\n} from \"@shell-shock/core/components/options-parser-logic\";\nimport {\n getAppBin,\n getDynamicPathSegmentName,\n isDynamicPathSegment\n} from \"@shell-shock/core/plugin-utils\";\nimport { findFilePath, relativePath } from \"@stryke/path/find\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { replaceExtension } from \"@stryke/path/replace\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport defu from \"defu\";\nimport type { ScriptPresetContext } from \"../types/plugin\";\nimport { VirtualCommandEntry } from \"./virtual-command-entry\";\n\nexport function CommandInvocation(props: { command: CommandTree }) {\n const { command } = props;\n\n return (\n <>\n {code` return withCommand(\"${command.path}\", [${command.segments\n .map(segment =>\n isDynamicPathSegment(segment)\n ? camelCase(getDynamicPathSegmentName(segment))\n : `\"${segment}\"`\n )\n .join(\", \")}], [${\n Object.keys(command.options).length > 0 ? `options` : \"\"\n }${\n command.args.length > 0\n ? `${\n Object.keys(command.options).length > 0 ? \", \" : \"\"\n }${command.args.map(arg => camelCase(arg.name)).join(\", \")}`\n : \"\"\n }], handle${pascalCase(command.name)}); `}\n <hbr />\n </>\n );\n}\n\nexport interface CommandHandlerDeclarationProps {\n command: CommandTree;\n banner?: Children;\n children?: Children;\n}\n\n/**\n * A component that generates the `handler` function declaration for a command.\n */\nexport function CommandHandlerDeclaration(\n props: CommandHandlerDeclarationProps\n) {\n const { command, banner, children } = props;\n\n const context = usePowerlines<ScriptPresetContext>();\n\n return (\n <>\n <OptionsInterfaceDeclaration command={command} />\n <Spacing />\n <TSDoc\n heading={`The ${command.title} (${getAppBin(context)} ${command.segments\n .map(segment =>\n isDynamicPathSegment(segment)\n ? `[${constantCase(getDynamicPathSegmentName(segment))}]`\n : segment\n )\n .join(\" \")}) command.`}>\n <TSDocRemarks>{`${command.description.replace(/\\.+$/, \"\")}.`}</TSDocRemarks>\n <hbr />\n <TSDocTitle>{command.title}</TSDocTitle>\n <TSDocParam name=\"args\">{`The command-line arguments passed to the command.`}</TSDocParam>\n </TSDoc>\n <FunctionDeclaration\n export\n async\n name=\"handler\"\n parameters={[{ name: \"args\", type: \"string[]\", default: \"useArgs()\" }]}>\n <CommandParserLogic\n command={command}\n appSpecificEnvPrefix={context.config.appSpecificEnvPrefix}\n isCaseSensitive={context.config.isCaseSensitive}\n />\n <Spacing />\n <Show when={Boolean(banner)}>{banner}</Show>\n <Spacing />\n {code`writeLine(\"\");`}\n <IfStatement condition={<IsDebug />}>\n {code`writeLine(textColors.body.tertiary(\"Debug mode is enabled. Additional debug information may be logged to the console.\"));\n writeLine(\"\");\n debug(\\`Command path: ${command.segments\n .map(segment =>\n isDynamicPathSegment(segment)\n ? `\\${${camelCase(getDynamicPathSegmentName(segment))}}`\n : segment\n )\n .join(\" / \")} \\\\n\\\\nOptions: \\\\n${Object.values(command.options)\n .map(\n option =>\n ` - ${kebabCase(option.name)}: \\${options.${camelCase(\n option.name\n )} === undefined ? \"\" : JSON.stringify(options.${camelCase(\n option.name\n )})}`\n )\n .join(\"\\\\n\")}${\n command.args.length > 0\n ? ` \\\\n\\\\nArguments: \\\\n${command.args\n .map(\n arg =>\n ` - ${kebabCase(arg.name)}: \\${${camelCase(\n arg.name\n )} === undefined ? \"\" : JSON.stringify(${camelCase(\n arg.name\n )})}`\n )\n .join(\"\\\\n\")}`\n : \"\"\n }\\`); `}\n </IfStatement>\n <Spacing />\n {children}\n <Spacing />\n <IfStatement condition={code`options.help`}>\n {code`return showHelp(); `}\n </IfStatement>\n <ElseClause>\n <hbr />\n <CommandInvocation command={command} />\n </ElseClause>\n </FunctionDeclaration>\n </>\n );\n}\n\nexport interface CommandEntryProps extends Omit<\n EntryFileProps,\n \"path\" | \"typeDefinition\"\n> {\n command: CommandTree;\n}\n\n/**\n * The command entry point for the Shell Shock project.\n */\nexport function CommandEntry(props: CommandEntryProps) {\n const { command, imports, builtinImports, ...rest } = props;\n\n const context = usePowerlines<ScriptPresetContext>();\n const filePath = computed(() =>\n joinPaths(\n command.segments\n .filter(segment => !isDynamicPathSegment(segment))\n .join(\"/\"),\n \"index.ts\"\n )\n );\n const commandSourcePath = computed(() =>\n replaceExtension(\n relativePath(\n joinPaths(context.entryPath, findFilePath(filePath.value)),\n command.entry.input?.file || command.entry.file\n )\n )\n );\n const typeDefinition = computed(() => ({\n ...command.entry,\n output: command.id\n }));\n\n return (\n <>\n <EntryFile\n {...rest}\n path={filePath.value}\n typeDefinition={typeDefinition.value}\n imports={defu(imports ?? {}, {\n [commandSourcePath.value.startsWith(\".\")\n ? commandSourcePath.value\n : `./${commandSourcePath.value}`]:\n `handle${pascalCase(command.name)}`\n })}\n builtinImports={defu(builtinImports ?? {}, {\n env: [\"env\", \"isDevelopment\", \"isDebug\"],\n console: [\"debug\", \"warn\", \"error\", \"writeLine\", \"textColors\"],\n utils: [\"isMinimal\", \"isUnicodeSupported\"],\n state: [\n { name: \"GlobalOptions\", type: true },\n \"useGlobal\",\n \"useGlobalOptions\",\n \"useArgs\",\n \"hasFlag\",\n \"withCommand\"\n ],\n [joinPaths(\n \"help\",\n ...command.segments.filter(\n segment => !isDynamicPathSegment(segment)\n )\n )]: [\"showHelp\"],\n [joinPaths(\n \"banner\",\n ...command.segments.filter(\n segment => !isDynamicPathSegment(segment)\n )\n )]: [\"showBanner\"]\n })}>\n <Spacing />\n <OptionsInterfaceDeclaration command={command} />\n <Spacing />\n <CommandHandlerDeclaration\n command={command}\n banner={code`await showBanner(); `}>\n <CommandValidationLogic command={command} />\n <IfStatement condition={code`failures.length > 0`}>\n {code`error(\\`The following validation failures were found while processing the user provided input, and must be corrected before the \\${italic(\"${\n command.title\n }\")} command can be executed: \\\\n\\\\n\\${failures.map(failure => \" - \" + failure).join(\"\\\\n\")}\\`);\n options.help = true; `}\n </IfStatement>\n </CommandHandlerDeclaration>\n </EntryFile>\n <For each={Object.values(command.children)}>\n {child => (\n <Show\n when={child.isVirtual}\n fallback={<CommandEntry command={child} />}>\n <VirtualCommandEntry command={child} />\n </Show>\n )}\n </For>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAO,kBAAA,OAAA;CACL,MAAA,EACA,YACI;AACN,QAAO,CAAA,WAAA,IAAA,wBAAA,QAAA,KAAA,MAAA,QAAA,SAAA,KAAA,YAAA,qBAAA,QAAA,GAAA,UAAA,0BAAA,QAAA,CAAA,GAAA,IAAA,QAAA,GAAA,CAAA,KAAA,KAAA,CAAA,MAAA,OAAA,KAAA,QAAA,QAAA,CAAA,SAAA,IAAA,YAAA,KAAA,QAAA,KAAA,SAAA,IAAA,GAAA,OAAA,KAAA,QAAA,QAAA,CAAA,SAAA,IAAA,OAAA,KAAA,QAAA,KAAA,KAAA,QAAA,UAAA,IAAA,KAAA,CAAA,CAAA,KAAA,KAAA,KAAA,GAAA,WAAA,WAAA,QAAA,KAAA,CAAA,KAAA,EAAA,gBAAA,OAAA,EAAA,CAAA,CAAA;;;;;AAKP,SAAS,0BAAiC,OAAG;CAC7C,MAAQ,EACR,SACA,QACA,aACM;CACN,MAAQ,UAAC,eAAoB;AAC7B,QAAO;EAAA,gBAAgB,6BAAA,EACV,SACb,CAAA;EA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
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`@alloy-js/core/jsx-runtime`),t=require(`@alloy-js/core`),n=require(`@alloy-js/typescript`),r=require(`@powerlines/plugin-alloy/core/components/spacing`),i=require(`@powerlines/plugin-alloy/core/contexts/context`),a=require(`@shell-shock/core/plugin-utils`),o=require(`@stryke/string-format/pascal-case`),s=require(`@powerlines/plugin-alloy/typescript/components/dynamic-import-statement`),c=require(`@shell-shock/core/contexts/command`);function l(){let n=(0,c.useCommand)();return[(0,e.createComponent)(t.Show,{get when(){return!n.isVirtual},get children(){return(0,e.createComponent)(s.DynamicImportStatement,{get name(){return`handle${(0,o.pascalCase)(n.name)}`},get importPath(){return`./${n.segments.filter(e=>!(0,a.isDynamicPathSegment)(e))[n.segments.filter(e=>!(0,a.isDynamicPathSegment)(e)).length-1]}`},exportName:`handler`})}}),(0,e.createIntrinsic)(`hbr`,{}),(0,e.memo)(()=>t.code`return handle${(0,o.pascalCase)(n.name)}(args);`)]}function u(i){let{segments:a,commands:o,route:s}=i,c=(0,t.computed)(()=>2+(a.length??0));return(0,e.createComponent)(t.Show,{get when(){return o&&Object.keys(o).length>0},get children(){return[(0,e.createComponent)(n.VarDeclaration,{let:!0,name:`command`,type:`string`,initializer:t.code`"";`}),(0,e.createComponent)(r.Spacing,{}),(0,e.createComponent)(t.Show,{get when(){return o&&Object.keys(o).length>0},get children(){return[(0,e.createComponent)(n.IfStatement,{get condition(){return t.code`args.length > ${c.value} && args[${c.value}]`},get children(){return t.code`command = args[${c.value}];`}}),(0,e.createComponent)(r.Spacing,{})]}}),(0,e.createComponent)(d,{segments:a,commands:o,route:s})]}})}function d(r){let{commands:a,route:o}=r,s=(0,i.usePowerlines)();return(0,e.createComponent)(t.Show,{get when(){return a&&Object.keys(a).length>0},get children(){return(0,e.createComponent)(n.IfStatement,{condition:t.code`!command.startsWith("-")`,get children(){return[(0,e.createComponent)(t.For,{get each(){return Object.values(a??{})},children:(r,i)=>(0,e.createComponent)(c.CommandContext.Provider,{value:r,get children(){return(0,e.createComponent)(t.Show,{get when(){return!!i},get fallback(){return(0,e.createComponent)(n.IfStatement,{get condition(){return t.code`${s.config.isCaseSensitive?`command`:`command.toLowerCase().replaceAll("-", "").replaceAll("_", "")`} === "${s.config.isCaseSensitive?r.name:r.name.toLowerCase().replaceAll(`-`,``).replaceAll(`_`,``)}"${r.alias&&r.alias.length>0?` || ${r.alias.map(e=>`${s.config.isCaseSensitive?`command`:`command.toLowerCase().replaceAll("-", "").replaceAll("_", "")`} === "${s.config.isCaseSensitive?e:e.toLowerCase().replaceAll(`-`,``).replaceAll(`_`,``)}"`).join(` || `)}`:``}`},get children(){return(0,e.createComponent)(t.Show,{get when(){return!!o},get fallback(){return(0,e.createComponent)(l,{})},children:o})}})},get children(){return(0,e.createComponent)(n.ElseIfClause,{get condition(){return t.code`${s.config.isCaseSensitive?`command`:`command.toLowerCase().replaceAll("-", "").replaceAll("_", "")`} === "${s.config.isCaseSensitive?r.name:r.name.toLowerCase().replaceAll(`-`,``).replaceAll(`_`,``)}"${r.alias&&r.alias.length>0?` || ${r.alias.map(e=>`${s.config.isCaseSensitive?`command`:`command.toLowerCase().replaceAll("-", "").replaceAll("_", "")`} === "${s.config.isCaseSensitive?e:e.toLowerCase().replaceAll(`-`,``).replaceAll(`_`,``)}"`).join(` || `)}`:``}`},get children(){return(0,e.createComponent)(t.Show,{get when(){return!!o},get fallback(){return(0,e.createComponent)(l,{})},children:o})}})}})}})}),(0,e.createComponent)(n.ElseIfClause,{condition:t.code`Boolean(command) && !command.startsWith("-")`,get children(){return t.code`const suggestions = findSuggestions(command, [${Object.values(a??{}).map(e=>`"${e.name}"${(e.alias??[]).map(e=>`, "${e}"`).join(``)}`).join(`, `)}]).slice(0, 3);
2
- error(\`Unknown command: "\${command}"\${suggestions && suggestions.length > 0 ? \`, did you mean: \${suggestions.length === 1 ? \`"\${suggestions[0]}"\` : suggestions.map((suggestion, i) => i < suggestions.length - 1 ? \`"\${suggestion}", \` : \`or "\${suggestion}"\`)}?\` : ""} \`);`}})]}})}})}exports.CommandRouter=u,exports.CommandRouterBody=d,exports.CommandRouterRoute=l;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.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 _alloy_js_typescript = require("@alloy-js/typescript");
6
+ let _powerlines_plugin_alloy_core_components_spacing = require("@powerlines/plugin-alloy/core/components/spacing");
7
+ let _powerlines_plugin_alloy_core_contexts_context = require("@powerlines/plugin-alloy/core/contexts/context");
8
+ let _shell_shock_core_plugin_utils = require("@shell-shock/core/plugin-utils");
9
+ let _stryke_string_format_pascal_case = require("@stryke/string-format/pascal-case");
10
+ let _powerlines_plugin_alloy_typescript_components_dynamic_import_statement = require("@powerlines/plugin-alloy/typescript/components/dynamic-import-statement");
11
+ let _shell_shock_core_contexts_command = require("@shell-shock/core/contexts/command");
12
+
13
+ //#region src/components/command-router.tsx
14
+ function CommandRouterRoute() {
15
+ const command = (0, _shell_shock_core_contexts_command.useCommand)();
16
+ return [
17
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
18
+ get when() {
19
+ return !command.isVirtual;
20
+ },
21
+ get children() {
22
+ return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_dynamic_import_statement.DynamicImportStatement, {
23
+ get name() {
24
+ return `handle${(0, _stryke_string_format_pascal_case.pascalCase)(command.name)}`;
25
+ },
26
+ get importPath() {
27
+ return `./${command.segments.filter((segment) => !(0, _shell_shock_core_plugin_utils.isDynamicPathSegment)(segment))[command.segments.filter((segment) => !(0, _shell_shock_core_plugin_utils.isDynamicPathSegment)(segment)).length - 1]}`;
28
+ },
29
+ exportName: "handler"
30
+ });
31
+ }
32
+ }),
33
+ (0, _alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
34
+ (0, _alloy_js_core_jsx_runtime.memo)(() => _alloy_js_core.code`return handle${(0, _stryke_string_format_pascal_case.pascalCase)(command.name)}(args);`)
35
+ ];
36
+ }
37
+ /**
38
+ * The command router component.
39
+ */
40
+ function CommandRouter(props) {
41
+ const { segments, commands, route } = props;
42
+ const index = (0, _alloy_js_core.computed)(() => 2 + (segments.length ?? 0));
43
+ return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
44
+ get when() {
45
+ return commands && Object.keys(commands).length > 0;
46
+ },
47
+ get children() {
48
+ return [
49
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
50
+ "let": true,
51
+ name: "command",
52
+ type: "string",
53
+ initializer: _alloy_js_core.code`"";`
54
+ }),
55
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
56
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
57
+ get when() {
58
+ return commands && Object.keys(commands).length > 0;
59
+ },
60
+ get children() {
61
+ return [(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.IfStatement, {
62
+ get condition() {
63
+ return _alloy_js_core.code`args.length > ${index.value} && args[${index.value}]`;
64
+ },
65
+ get children() {
66
+ return _alloy_js_core.code`command = args[${index.value}];`;
67
+ }
68
+ }), (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {})];
69
+ }
70
+ }),
71
+ (0, _alloy_js_core_jsx_runtime.createComponent)(CommandRouterBody, {
72
+ segments,
73
+ commands,
74
+ route
75
+ })
76
+ ];
77
+ }
78
+ });
79
+ }
80
+ /**
81
+ * The internal command router body logic component.
82
+ */
83
+ function CommandRouterBody(props) {
84
+ const { commands, route } = props;
85
+ const context = (0, _powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
86
+ return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
87
+ get when() {
88
+ return commands && Object.keys(commands).length > 0;
89
+ },
90
+ get children() {
91
+ return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.IfStatement, {
92
+ condition: _alloy_js_core.code`!command.startsWith("-")`,
93
+ get children() {
94
+ return [(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.For, {
95
+ get each() {
96
+ return Object.values(commands ?? {});
97
+ },
98
+ children: (subcommand, idx) => (0, _alloy_js_core_jsx_runtime.createComponent)(_shell_shock_core_contexts_command.CommandContext.Provider, {
99
+ value: subcommand,
100
+ get children() {
101
+ return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
102
+ get when() {
103
+ return Boolean(idx);
104
+ },
105
+ get fallback() {
106
+ return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.IfStatement, {
107
+ get condition() {
108
+ return _alloy_js_core.code`${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${context.config.isCaseSensitive ? subcommand.name : subcommand.name.toLowerCase().replaceAll("-", "").replaceAll("_", "")}"${subcommand.alias && subcommand.alias.length > 0 ? ` || ${subcommand.alias.map((alias) => `${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${context.config.isCaseSensitive ? alias : alias.toLowerCase().replaceAll("-", "").replaceAll("_", "")}"`).join(" || ")}` : ""}`;
109
+ },
110
+ get children() {
111
+ return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
112
+ get when() {
113
+ return Boolean(route);
114
+ },
115
+ get fallback() {
116
+ return (0, _alloy_js_core_jsx_runtime.createComponent)(CommandRouterRoute, {});
117
+ },
118
+ children: route
119
+ });
120
+ }
121
+ });
122
+ },
123
+ get children() {
124
+ return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.ElseIfClause, {
125
+ get condition() {
126
+ return _alloy_js_core.code`${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${context.config.isCaseSensitive ? subcommand.name : subcommand.name.toLowerCase().replaceAll("-", "").replaceAll("_", "")}"${subcommand.alias && subcommand.alias.length > 0 ? ` || ${subcommand.alias.map((alias) => `${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${context.config.isCaseSensitive ? alias : alias.toLowerCase().replaceAll("-", "").replaceAll("_", "")}"`).join(" || ")}` : ""}`;
127
+ },
128
+ get children() {
129
+ return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
130
+ get when() {
131
+ return Boolean(route);
132
+ },
133
+ get fallback() {
134
+ return (0, _alloy_js_core_jsx_runtime.createComponent)(CommandRouterRoute, {});
135
+ },
136
+ children: route
137
+ });
138
+ }
139
+ });
140
+ }
141
+ });
142
+ }
143
+ })
144
+ }), (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.ElseIfClause, {
145
+ condition: _alloy_js_core.code`Boolean(command) && !command.startsWith("-")`,
146
+ get children() {
147
+ return _alloy_js_core.code`const suggestions = findSuggestions(command, [${Object.values(commands ?? {}).map((cmd) => `"${cmd.name}"${(cmd.alias ?? []).map((alias) => `, "${alias}"`).join("")}`).join(", ")}]).slice(0, 3);
148
+ error(\`Unknown command: "\${command}"\${suggestions && suggestions.length > 0 ? \`, did you mean: \${suggestions.length === 1 ? \`"\${suggestions[0]}"\` : suggestions.map((suggestion, i) => i < suggestions.length - 1 ? \`"\${suggestion}", \` : \`or "\${suggestion}"\`)}?\` : ""} \`);`;
149
+ }
150
+ })];
151
+ }
152
+ });
153
+ }
154
+ });
155
+ }
156
+
157
+ //#endregion
158
+ exports.CommandRouter = CommandRouter;
159
+ exports.CommandRouterBody = CommandRouterBody;
160
+ exports.CommandRouterRoute = CommandRouterRoute;
@@ -1,3 +1,157 @@
1
- import{createComponent as e,createIntrinsic as t,memo as n}from"@alloy-js/core/jsx-runtime";import{For as r,Show as i,code as a,computed as o}from"@alloy-js/core";import{ElseIfClause as s,IfStatement as c,VarDeclaration as l}from"@alloy-js/typescript";import{Spacing as u}from"@powerlines/plugin-alloy/core/components/spacing";import{usePowerlines as d}from"@powerlines/plugin-alloy/core/contexts/context";import{isDynamicPathSegment as f}from"@shell-shock/core/plugin-utils";import{pascalCase as p}from"@stryke/string-format/pascal-case";import{DynamicImportStatement as m}from"@powerlines/plugin-alloy/typescript/components/dynamic-import-statement";import{CommandContext as h,useCommand as g}from"@shell-shock/core/contexts/command";function _(){let r=g();return[e(i,{get when(){return!r.isVirtual},get children(){return e(m,{get name(){return`handle${p(r.name)}`},get importPath(){return`./${r.segments.filter(e=>!f(e))[r.segments.filter(e=>!f(e)).length-1]}`},exportName:`handler`})}}),t(`hbr`,{}),n(()=>a`return handle${p(r.name)}(args);`)]}function v(t){let{segments:n,commands:r,route:s}=t,d=o(()=>2+(n.length??0));return e(i,{get when(){return r&&Object.keys(r).length>0},get children(){return[e(l,{let:!0,name:`command`,type:`string`,initializer:a`"";`}),e(u,{}),e(i,{get when(){return r&&Object.keys(r).length>0},get children(){return[e(c,{get condition(){return a`args.length > ${d.value} && args[${d.value}]`},get children(){return a`command = args[${d.value}];`}}),e(u,{})]}}),e(y,{segments:n,commands:r,route:s})]}})}function y(t){let{commands:n,route:o}=t,l=d();return e(i,{get when(){return n&&Object.keys(n).length>0},get children(){return e(c,{condition:a`!command.startsWith("-")`,get children(){return[e(r,{get each(){return Object.values(n??{})},children:(t,n)=>e(h.Provider,{value:t,get children(){return e(i,{get when(){return!!n},get fallback(){return e(c,{get condition(){return a`${l.config.isCaseSensitive?`command`:`command.toLowerCase().replaceAll("-", "").replaceAll("_", "")`} === "${l.config.isCaseSensitive?t.name:t.name.toLowerCase().replaceAll(`-`,``).replaceAll(`_`,``)}"${t.alias&&t.alias.length>0?` || ${t.alias.map(e=>`${l.config.isCaseSensitive?`command`:`command.toLowerCase().replaceAll("-", "").replaceAll("_", "")`} === "${l.config.isCaseSensitive?e:e.toLowerCase().replaceAll(`-`,``).replaceAll(`_`,``)}"`).join(` || `)}`:``}`},get children(){return e(i,{get when(){return!!o},get fallback(){return e(_,{})},children:o})}})},get children(){return e(s,{get condition(){return a`${l.config.isCaseSensitive?`command`:`command.toLowerCase().replaceAll("-", "").replaceAll("_", "")`} === "${l.config.isCaseSensitive?t.name:t.name.toLowerCase().replaceAll(`-`,``).replaceAll(`_`,``)}"${t.alias&&t.alias.length>0?` || ${t.alias.map(e=>`${l.config.isCaseSensitive?`command`:`command.toLowerCase().replaceAll("-", "").replaceAll("_", "")`} === "${l.config.isCaseSensitive?e:e.toLowerCase().replaceAll(`-`,``).replaceAll(`_`,``)}"`).join(` || `)}`:``}`},get children(){return e(i,{get when(){return!!o},get fallback(){return e(_,{})},children:o})}})}})}})}),e(s,{condition:a`Boolean(command) && !command.startsWith("-")`,get children(){return a`const suggestions = findSuggestions(command, [${Object.values(n??{}).map(e=>`"${e.name}"${(e.alias??[]).map(e=>`, "${e}"`).join(``)}`).join(`, `)}]).slice(0, 3);
2
- error(\`Unknown command: "\${command}"\${suggestions && suggestions.length > 0 ? \`, did you mean: \${suggestions.length === 1 ? \`"\${suggestions[0]}"\` : suggestions.map((suggestion, i) => i < suggestions.length - 1 ? \`"\${suggestion}", \` : \`or "\${suggestion}"\`)}?\` : ""} \`);`}})]}})}})}export{v as CommandRouter,y as CommandRouterBody,_ as CommandRouterRoute};
1
+ import { createComponent, createIntrinsic, memo } from "@alloy-js/core/jsx-runtime";
2
+ import { For, Show, code, computed } from "@alloy-js/core";
3
+ import { ElseIfClause, IfStatement, VarDeclaration } from "@alloy-js/typescript";
4
+ import { Spacing } from "@powerlines/plugin-alloy/core/components/spacing";
5
+ import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
6
+ import { isDynamicPathSegment } from "@shell-shock/core/plugin-utils";
7
+ import { pascalCase } from "@stryke/string-format/pascal-case";
8
+ import { DynamicImportStatement } from "@powerlines/plugin-alloy/typescript/components/dynamic-import-statement";
9
+ import { CommandContext, useCommand } from "@shell-shock/core/contexts/command";
10
+
11
+ //#region src/components/command-router.tsx
12
+ function CommandRouterRoute() {
13
+ const command = useCommand();
14
+ return [
15
+ createComponent(Show, {
16
+ get when() {
17
+ return !command.isVirtual;
18
+ },
19
+ get children() {
20
+ return createComponent(DynamicImportStatement, {
21
+ get name() {
22
+ return `handle${pascalCase(command.name)}`;
23
+ },
24
+ get importPath() {
25
+ return `./${command.segments.filter((segment) => !isDynamicPathSegment(segment))[command.segments.filter((segment) => !isDynamicPathSegment(segment)).length - 1]}`;
26
+ },
27
+ exportName: "handler"
28
+ });
29
+ }
30
+ }),
31
+ createIntrinsic("hbr", {}),
32
+ memo(() => code`return handle${pascalCase(command.name)}(args);`)
33
+ ];
34
+ }
35
+ /**
36
+ * The command router component.
37
+ */
38
+ function CommandRouter(props) {
39
+ const { segments, commands, route } = props;
40
+ const index = computed(() => 2 + (segments.length ?? 0));
41
+ return createComponent(Show, {
42
+ get when() {
43
+ return commands && Object.keys(commands).length > 0;
44
+ },
45
+ get children() {
46
+ return [
47
+ createComponent(VarDeclaration, {
48
+ "let": true,
49
+ name: "command",
50
+ type: "string",
51
+ initializer: code`"";`
52
+ }),
53
+ createComponent(Spacing, {}),
54
+ createComponent(Show, {
55
+ get when() {
56
+ return commands && Object.keys(commands).length > 0;
57
+ },
58
+ get children() {
59
+ return [createComponent(IfStatement, {
60
+ get condition() {
61
+ return code`args.length > ${index.value} && args[${index.value}]`;
62
+ },
63
+ get children() {
64
+ return code`command = args[${index.value}];`;
65
+ }
66
+ }), createComponent(Spacing, {})];
67
+ }
68
+ }),
69
+ createComponent(CommandRouterBody, {
70
+ segments,
71
+ commands,
72
+ route
73
+ })
74
+ ];
75
+ }
76
+ });
77
+ }
78
+ /**
79
+ * The internal command router body logic component.
80
+ */
81
+ function CommandRouterBody(props) {
82
+ const { commands, route } = props;
83
+ const context = usePowerlines();
84
+ return createComponent(Show, {
85
+ get when() {
86
+ return commands && Object.keys(commands).length > 0;
87
+ },
88
+ get children() {
89
+ return createComponent(IfStatement, {
90
+ condition: code`!command.startsWith("-")`,
91
+ get children() {
92
+ return [createComponent(For, {
93
+ get each() {
94
+ return Object.values(commands ?? {});
95
+ },
96
+ children: (subcommand, idx) => createComponent(CommandContext.Provider, {
97
+ value: subcommand,
98
+ get children() {
99
+ return createComponent(Show, {
100
+ get when() {
101
+ return Boolean(idx);
102
+ },
103
+ get fallback() {
104
+ return createComponent(IfStatement, {
105
+ get condition() {
106
+ return code`${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${context.config.isCaseSensitive ? subcommand.name : subcommand.name.toLowerCase().replaceAll("-", "").replaceAll("_", "")}"${subcommand.alias && subcommand.alias.length > 0 ? ` || ${subcommand.alias.map((alias) => `${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${context.config.isCaseSensitive ? alias : alias.toLowerCase().replaceAll("-", "").replaceAll("_", "")}"`).join(" || ")}` : ""}`;
107
+ },
108
+ get children() {
109
+ return createComponent(Show, {
110
+ get when() {
111
+ return Boolean(route);
112
+ },
113
+ get fallback() {
114
+ return createComponent(CommandRouterRoute, {});
115
+ },
116
+ children: route
117
+ });
118
+ }
119
+ });
120
+ },
121
+ get children() {
122
+ return createComponent(ElseIfClause, {
123
+ get condition() {
124
+ return code`${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${context.config.isCaseSensitive ? subcommand.name : subcommand.name.toLowerCase().replaceAll("-", "").replaceAll("_", "")}"${subcommand.alias && subcommand.alias.length > 0 ? ` || ${subcommand.alias.map((alias) => `${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${context.config.isCaseSensitive ? alias : alias.toLowerCase().replaceAll("-", "").replaceAll("_", "")}"`).join(" || ")}` : ""}`;
125
+ },
126
+ get children() {
127
+ return createComponent(Show, {
128
+ get when() {
129
+ return Boolean(route);
130
+ },
131
+ get fallback() {
132
+ return createComponent(CommandRouterRoute, {});
133
+ },
134
+ children: route
135
+ });
136
+ }
137
+ });
138
+ }
139
+ });
140
+ }
141
+ })
142
+ }), createComponent(ElseIfClause, {
143
+ condition: code`Boolean(command) && !command.startsWith("-")`,
144
+ get children() {
145
+ return code`const suggestions = findSuggestions(command, [${Object.values(commands ?? {}).map((cmd) => `"${cmd.name}"${(cmd.alias ?? []).map((alias) => `, "${alias}"`).join("")}`).join(", ")}]).slice(0, 3);
146
+ error(\`Unknown command: "\${command}"\${suggestions && suggestions.length > 0 ? \`, did you mean: \${suggestions.length === 1 ? \`"\${suggestions[0]}"\` : suggestions.map((suggestion, i) => i < suggestions.length - 1 ? \`"\${suggestion}", \` : \`or "\${suggestion}"\`)}?\` : ""} \`);`;
147
+ }
148
+ })];
149
+ }
150
+ });
151
+ }
152
+ });
153
+ }
154
+
155
+ //#endregion
156
+ export { CommandRouter, CommandRouterBody, CommandRouterRoute };
3
157
  //# sourceMappingURL=command-router.mjs.map