@shell-shock/preset-cli 0.2.0 → 0.3.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.
@@ -1,8 +1,8 @@
1
1
  import { BannerFunctionDeclaration } from "./banner-function-declaration.mjs";
2
2
  import { VirtualCommandEntry } from "./virtual-command-entry.mjs";
3
- import { createComponent, createIntrinsic, mergeProps } from "@alloy-js/core/jsx-runtime";
3
+ import { createComponent, createIntrinsic, memo, mergeProps } from "@alloy-js/core/jsx-runtime";
4
4
  import { For, Match, Show, Switch, code, computed } from "@alloy-js/core";
5
- import { ElseClause, ElseIfClause, IfStatement } from "@alloy-js/typescript";
5
+ import { ElseIfClause, IfStatement } from "@alloy-js/typescript";
6
6
  import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
7
7
  import { isDynamicPathSegment } from "@shell-shock/core/plugin-utils/context-helpers";
8
8
  import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
@@ -45,7 +45,6 @@ function CommandEntry(props) {
45
45
  return defu(builtinImports ?? {}, {
46
46
  env: [
47
47
  "env",
48
- "isCI",
49
48
  "isDevelopment",
50
49
  "isDebug"
51
50
  ],
@@ -60,15 +59,19 @@ function CommandEntry(props) {
60
59
  "splitText",
61
60
  "text",
62
61
  "confirm",
63
- "isCancel"
62
+ "isCancel",
63
+ "intro",
64
+ "outro"
64
65
  ],
65
66
  utils: [
66
- "getArgs",
67
+ "useApp",
68
+ "useArgs",
67
69
  "hasFlag",
68
70
  "isMinimal",
69
71
  "isInteractive",
72
+ "isHelp",
70
73
  "isUnicodeSupported",
71
- "internal_commandContextStore"
74
+ "internal_commandContext"
72
75
  ]
73
76
  });
74
77
  },
@@ -85,31 +88,39 @@ function CommandEntry(props) {
85
88
  get children() {
86
89
  return createComponent(CommandValidationLogic, { command });
87
90
  }
88
- }), createComponent(ElseClause, { get children() {
89
- return [
90
- createIntrinsic("hbr", {}),
91
- createComponent(For, {
92
- get each() {
93
- return Object.values(command.options ?? {});
94
- },
95
- doubleHardline: true,
96
- children: (option) => [createComponent(Show, {
97
- get when() {
98
- return !option.optional;
91
+ }), createComponent(ElseIfClause, {
92
+ get condition() {
93
+ return code`!isHelp && (${Object.values(command.options ?? {}).filter((option) => !option.optional).map((option) => (option.kind === ReflectionKind.string || option.kind === ReflectionKind.number) && option.variadic ? `(!options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`} || options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`}.length === 0)` : `options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`} === undefined`).join(" || ")}${Object.values(command.options ?? {}).filter((option) => !option.optional).length > 0 && Object.values(command.arguments ?? {}).filter((argument) => !argument.optional).length > 0 ? " || " : ""}${Object.values(command.arguments ?? {}).filter((argument) => !argument.optional).map((argument) => (argument.kind === ReflectionKind.string || argument.kind === ReflectionKind.number) && argument.variadic ? `(!${camelCase(argument.name)} || ${camelCase(argument.name)}.length === 0)` : `${camelCase(argument.name)} === undefined`).join(" || ")}) `;
94
+ },
95
+ get children() {
96
+ return [
97
+ code`writeLine("");
98
+
99
+ intro("Select required input parameters"); `,
100
+ createIntrinsic("hbr", {}),
101
+ createIntrinsic("hbr", {}),
102
+ createComponent(For, {
103
+ get each() {
104
+ return Object.values(command.options ?? {});
99
105
  },
100
- get children() {
101
- return [createComponent(IfStatement, {
102
- get condition() {
103
- return code`!options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`}`;
104
- },
105
- get children() {
106
- return createComponent(Switch, { get children() {
107
- return [createComponent(Match, {
108
- get when() {
109
- return option.kind === ReflectionKind.string || option.kind === ReflectionKind.number;
110
- },
111
- get children() {
112
- return code`
106
+ doubleHardline: true,
107
+ children: (option) => [createComponent(Show, {
108
+ get when() {
109
+ return !option.optional;
110
+ },
111
+ get children() {
112
+ return [createComponent(IfStatement, {
113
+ get condition() {
114
+ return code`!options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`}`;
115
+ },
116
+ get children() {
117
+ return createComponent(Switch, { get children() {
118
+ return [createComponent(Match, {
119
+ get when() {
120
+ return option.kind === ReflectionKind.string || option.kind === ReflectionKind.number;
121
+ },
122
+ get children() {
123
+ return code`
113
124
  const value = await text({
114
125
  message: 'Please provide a value for the ${option.title} option:',
115
126
  validate(value) {
@@ -131,32 +142,32 @@ function CommandEntry(props) {
131
142
 
132
143
  options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`} = ${option.kind === ReflectionKind.number ? `Number(value)` : "value"};
133
144
  `;
134
- }
135
- }), createComponent(Match, {
136
- get when() {
137
- return option.kind === ReflectionKind.boolean;
138
- },
139
- get children() {
140
- return code`
145
+ }
146
+ }), createComponent(Match, {
147
+ get when() {
148
+ return option.kind === ReflectionKind.boolean;
149
+ },
150
+ get children() {
151
+ return code`
141
152
  options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`} = await confirm({
142
153
  message: 'Please select a value for the ${option.title} option:'
143
154
  });
144
155
  `;
145
- }
146
- })];
147
- } });
148
- }
149
- }), createComponent(Show, {
150
- get when() {
151
- return (option.kind === ReflectionKind.string || option.kind === ReflectionKind.number) && option.variadic;
152
- },
153
- get children() {
154
- return createComponent(ElseIfClause, {
155
- get condition() {
156
- return code`options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`}.length === 0`;
157
- },
158
- get children() {
159
- return code`
156
+ }
157
+ })];
158
+ } });
159
+ }
160
+ }), createComponent(Show, {
161
+ get when() {
162
+ return (option.kind === ReflectionKind.string || option.kind === ReflectionKind.number) && option.variadic;
163
+ },
164
+ get children() {
165
+ return createComponent(ElseIfClause, {
166
+ get condition() {
167
+ return code`options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`}.length === 0`;
168
+ },
169
+ get children() {
170
+ return code`
160
171
  const value = await text({
161
172
  message: 'Please provide one or more values for the ${option.title} option (values are separated by a "," character):',
162
173
  validate(value) {
@@ -182,37 +193,37 @@ function CommandEntry(props) {
182
193
 
183
194
  options${option.name.includes("?") ? `["${option.name}"]` : `.${camelCase(option.name)}`} = value.split(",").map(value => value.trim()).filter(Boolean)${option.kind === ReflectionKind.number ? `.map(Number)` : ""} ;
184
195
  `;
185
- }
186
- });
187
- }
188
- })];
189
- }
190
- })]
191
- }),
192
- createIntrinsic("hbr", {}),
193
- createIntrinsic("hbr", {}),
194
- createComponent(For, {
195
- get each() {
196
- return command.arguments;
197
- },
198
- doubleHardline: true,
199
- children: (argument) => [createComponent(Show, {
200
- get when() {
201
- return !argument.optional;
196
+ }
197
+ });
198
+ }
199
+ })];
200
+ }
201
+ })]
202
+ }),
203
+ createIntrinsic("hbr", {}),
204
+ createIntrinsic("hbr", {}),
205
+ createComponent(For, {
206
+ get each() {
207
+ return command.arguments;
202
208
  },
203
- get children() {
204
- return [createComponent(IfStatement, {
205
- get condition() {
206
- return code`!${camelCase(argument.name)}`;
207
- },
208
- get children() {
209
- return createComponent(Switch, { get children() {
210
- return [createComponent(Match, {
211
- get when() {
212
- return argument.kind === ReflectionKind.string || argument.kind === ReflectionKind.number;
213
- },
214
- get children() {
215
- return code`
209
+ doubleHardline: true,
210
+ children: (argument) => [createComponent(Show, {
211
+ get when() {
212
+ return !argument.optional;
213
+ },
214
+ get children() {
215
+ return [createComponent(IfStatement, {
216
+ get condition() {
217
+ return code`!${camelCase(argument.name)}`;
218
+ },
219
+ get children() {
220
+ return createComponent(Switch, { get children() {
221
+ return [createComponent(Match, {
222
+ get when() {
223
+ return argument.kind === ReflectionKind.string || argument.kind === ReflectionKind.number;
224
+ },
225
+ get children() {
226
+ return code`
216
227
  const value = await text({
217
228
  message: 'Please provide a value for the ${argument.title} positional argument:',
218
229
  validate(value) {
@@ -234,32 +245,32 @@ function CommandEntry(props) {
234
245
 
235
246
  ${camelCase(argument.name)} = ${argument.kind === ReflectionKind.number ? `Number(value)` : "value"};
236
247
  `;
237
- }
238
- }), createComponent(Match, {
239
- get when() {
240
- return argument.kind === ReflectionKind.boolean;
241
- },
242
- get children() {
243
- return code`
248
+ }
249
+ }), createComponent(Match, {
250
+ get when() {
251
+ return argument.kind === ReflectionKind.boolean;
252
+ },
253
+ get children() {
254
+ return code`
244
255
  ${camelCase(argument.name)} = await confirm({
245
256
  message: 'Please select a value for the ${argument.title} positional argument:'
246
257
  });
247
258
  `;
248
- }
249
- })];
250
- } });
251
- }
252
- }), createComponent(Show, {
253
- get when() {
254
- return (argument.kind === ReflectionKind.string || argument.kind === ReflectionKind.number) && argument.variadic;
255
- },
256
- get children() {
257
- return createComponent(ElseIfClause, {
258
- get condition() {
259
- return code`${camelCase(argument.name)}.length === 0`;
260
- },
261
- get children() {
262
- return code`
259
+ }
260
+ })];
261
+ } });
262
+ }
263
+ }), createComponent(Show, {
264
+ get when() {
265
+ return (argument.kind === ReflectionKind.string || argument.kind === ReflectionKind.number) && argument.variadic;
266
+ },
267
+ get children() {
268
+ return createComponent(ElseIfClause, {
269
+ get condition() {
270
+ return code`${camelCase(argument.name)}.length === 0`;
271
+ },
272
+ get children() {
273
+ return code`
263
274
  const value = await text({
264
275
  message: 'Please provide one or more values for the ${argument.title} option (values are separated by a "," character):',
265
276
  validate(value) {
@@ -286,15 +297,21 @@ function CommandEntry(props) {
286
297
 
287
298
  ${camelCase(argument.name)} = value.split(",").map(value => value.trim()).filter(Boolean)${argument.kind === ReflectionKind.number ? `.map(Number)` : ""} ;
288
299
  `;
289
- }
290
- });
291
- }
292
- })];
293
- }
294
- })]
295
- })
296
- ];
297
- } })];
300
+ }
301
+ });
302
+ }
303
+ })];
304
+ }
305
+ })]
306
+ }),
307
+ code`outro("Completed providing all required input parameters");
308
+
309
+ writeLine(""); `,
310
+ createIntrinsic("hbr", {}),
311
+ createIntrinsic("hbr", {})
312
+ ];
313
+ }
314
+ })];
298
315
  }
299
316
  })
300
317
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"command-entry.mjs","names":["code","computed","For","Match","Show","Switch","ElseClause","ElseIfClause","IfStatement","ReflectionKind","usePowerlines","EntryFile","isDynamicPathSegment","CommandHandlerDeclaration","CommandValidationLogic","findFilePath","relativePath","joinPaths","replaceExtension","camelCase","pascalCase","defu","BannerFunctionDeclaration","VirtualCommandEntry","CommandEntry","props","command","imports","builtinImports","rest","context","filePath","segments","filter","segment","join","commandSourcePath","entryPath","value","entry","input","file","typeDefinition","output","id","_$createComponent","_$mergeProps","path","name","prompts","env","console","utils","children","_$createIntrinsic","condition","each","Object","values","options","doubleHardline","option","when","optional","includes","kind","string","number","title","boolean","variadic","arguments","argument","child","isVirtual","fallback"],"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 { code, computed, For, Match, Show, Switch } from \"@alloy-js/core\";\nimport { ElseClause, ElseIfClause, IfStatement } from \"@alloy-js/typescript\";\nimport { ReflectionKind } from \"@powerlines/deepkit/vendor/type\";\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 { isDynamicPathSegment } from \"@shell-shock/core/plugin-utils/context-helpers\";\nimport type { CommandTree } from \"@shell-shock/core/types/command\";\nimport {\n CommandHandlerDeclaration,\n CommandValidationLogic\n} from \"@shell-shock/preset-script/components/command-entry\";\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 { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport defu from \"defu\";\nimport type { CLIPresetContext } from \"../types/plugin\";\nimport { BannerFunctionDeclaration } from \"./banner-function-declaration\";\nimport { VirtualCommandEntry } from \"./virtual-command-entry\";\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<CLIPresetContext>();\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]: `handle${pascalCase(command.name)}`,\n prompts: \"prompts\"\n })}\n builtinImports={defu(builtinImports ?? {}, {\n env: [\"env\", \"isCI\", \"isDevelopment\", \"isDebug\"],\n console: [\n \"debug\",\n \"warn\",\n \"error\",\n \"table\",\n \"colors\",\n \"stripAnsi\",\n \"writeLine\",\n \"splitText\",\n \"text\",\n \"confirm\",\n \"isCancel\"\n ],\n utils: [\n \"getArgs\",\n \"hasFlag\",\n \"isMinimal\",\n \"isInteractive\",\n \"isUnicodeSupported\",\n \"internal_commandContextStore\"\n ]\n })}>\n <BannerFunctionDeclaration command={command} />\n <hbr />\n <hbr />\n <CommandHandlerDeclaration command={command}>\n <IfStatement condition={code`!isInteractive`}>\n <CommandValidationLogic command={command} />\n </IfStatement>\n <ElseClause>\n <hbr />\n <For each={Object.values(command.options ?? {})} doubleHardline>\n {option => (\n <>\n <Show when={!option.optional}>\n <IfStatement\n condition={code`!options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }`}>\n <Switch>\n <Match\n when={\n option.kind === ReflectionKind.string ||\n option.kind === ReflectionKind.number\n }>{code`\n const value = await text({\n message: 'Please provide a value for the ${option.title} option:',\n validate(value) {\n if (isCancel(value)) {\n return true;\n }\n if (!value || value.trim() === \"\") {\n return \"A value is required for this option\";\n }\n ${\n option.kind === ReflectionKind.number\n ? `if (Number.isNaN(Number(value))) {\n return \"The value provided must be a valid number\";\n }`\n : \"\"\n }\n return undefined;\n }\n });\n if (isCancel(value)) {\n return;\n }\n\n options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } = ${\n option.kind === ReflectionKind.number\n ? `Number(value)`\n : \"value\"\n };\n `}</Match>\n <Match\n when={option.kind === ReflectionKind.boolean}>{code`\n options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } = await confirm({\n message: 'Please select a value for the ${option.title} option:'\n });\n `}</Match>\n </Switch>\n </IfStatement>\n <Show\n when={\n (option.kind === ReflectionKind.string ||\n option.kind === ReflectionKind.number) &&\n option.variadic\n }>\n <ElseIfClause\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.length === 0`}>\n {code`\n const value = await text({\n message: 'Please provide one or more values for the ${\n option.title\n } option (values are separated by a \",\" character):',\n validate(value) {\n if (isCancel(value)) {\n return true;\n }\n if (!value || value.trim() === \"\") {\n return \"A value is required for this option\";\n }\n if (value.split(\",\").map(value => value.trim()).filter(Boolean).length === 0) {\n return \"At least one value is required for this option\";\n }\n ${\n option.kind === ReflectionKind.number\n ? `const invalidIndex = value.split(\",\").map(value => value.trim()).filter(Boolean).findIndex(value => Number.isNaN(Number(value));\n if (invalidIndex !== -1) {\n return \\`Invalid numeric value provided for item #\\${invalidIndex + 1} - all provided items must be a valid number\\`;\n } `\n : \"\"\n }\n return undefined;\n }\n });\n if (isCancel(value)) {\n return;\n }\n\n options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } = value.split(\",\").map(value => value.trim()).filter(Boolean)${\n option.kind === ReflectionKind.number\n ? `.map(Number)`\n : \"\"\n } ;\n `}\n </ElseIfClause>\n </Show>\n </Show>\n </>\n )}\n </For>\n <hbr />\n <hbr />\n <For each={command.arguments} doubleHardline>\n {argument => (\n <>\n <Show when={!argument.optional}>\n <IfStatement condition={code`!${camelCase(argument.name)}`}>\n <Switch>\n <Match\n when={\n argument.kind === ReflectionKind.string ||\n argument.kind === ReflectionKind.number\n }>{code`\n const value = await text({\n message: 'Please provide a value for the ${argument.title} positional argument:',\n validate(value) {\n if (isCancel(value)) {\n return true;\n }\n if (!value || value.trim() === \"\") {\n return \"A value is required for this positional argument\";\n }\n ${\n argument.kind === ReflectionKind.number\n ? `if (Number.isNaN(Number(value))) {\n return \"The value provided must be a valid number\";\n }`\n : \"\"\n }\n return undefined;\n }\n });\n if (isCancel(value)) {\n return;\n }\n\n ${camelCase(argument.name)} = ${\n argument.kind === ReflectionKind.number\n ? `Number(value)`\n : \"value\"\n };\n `}</Match>\n <Match\n when={argument.kind === ReflectionKind.boolean}>{code`\n ${camelCase(argument.name)} = await confirm({\n message: 'Please select a value for the ${argument.title} positional argument:'\n });\n `}</Match>\n </Switch>\n </IfStatement>\n <Show\n when={\n (argument.kind === ReflectionKind.string ||\n argument.kind === ReflectionKind.number) &&\n argument.variadic\n }>\n <ElseIfClause\n condition={code`${camelCase(argument.name)}.length === 0`}>\n {code`\n const value = await text({\n message: 'Please provide one or more values for the ${\n argument.title\n } option (values are separated by a \",\" character):',\n validate(value) {\n if (isCancel(value)) {\n return true;\n }\n if (!value || value.trim() === \"\") {\n return \"A value is required for this option\";\n }\n if (value.split(\",\").map(value => value.trim()).filter(Boolean).length === 0) {\n return \"At least one value is required for this option\";\n }\n ${\n argument.kind === ReflectionKind.number\n ? `const invalidIndex = value.split(\",\").map(value => value.trim()).filter(Boolean).findIndex(value => Number.isNaN(Number(value));\n if (invalidIndex !== -1) {\n return \\`Invalid numeric value provided for item #\\${invalidIndex + 1} - all provided items must be a valid number\\`;\n } `\n : \"\"\n }\n\n return undefined;\n }\n });\n if (isCancel(value)) {\n return;\n }\n\n ${camelCase(argument.name)} = value.split(\",\").map(value => value.trim()).filter(Boolean)${\n argument.kind === ReflectionKind.number\n ? `.map(Number)`\n : \"\"\n } ;\n `}\n </ElseIfClause>\n </Show>\n </Show>\n </>\n )}\n </For>\n </ElseClause>\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":";;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgBwB,aAAaC,OAA0B;CACrD,MAAM,EAAEC,SAASC,SAASC,gBAAgB,GAAGC,SAASJ;CAEtD,MAAMK,UAAUpB,eAAiC;CACjD,MAAMqB,WAAW9B,eACfgB,UACES,QAAQM,SACLC,QAAOC,YAAW,CAACtB,qBAAqBsB,QAAQ,CAAC,CACjDC,KAAK,IAAI,EACZ,WAEJ,CAAC;CACD,MAAMC,oBAAoBnC,eACxBiB,iBACEF,aACEC,UAAUa,QAAQO,WAAWtB,aAAagB,SAASO,MAAM,CAAC,EAC1DZ,QAAQa,MAAMC,OAAOC,QAAQf,QAAQa,MAAME,KAE/C,CACF,CAAC;CACD,MAAMC,iBAAiBzC,gBAAgB;EACrC,GAAGyB,QAAQa;EACXI,QAAQjB,QAAQkB;EACjB,EAAE;AAEH,QAAA,CAAAC,gBAEKlC,WAASmC,WACJjB,MAAI;EAAA,IACRkB,OAAI;AAAA,UAAEhB,SAASO;;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AA;wEACkBwB,SAASJ,MAAK;;;;eAE3D,CAAA,CAAA;gBAAA,CAAA;;YAAA,CAAA,EAAAvB,gBAGNzC,MAAI;YAAA,IACH0D,OAAI;AAAA,qBACDU,SAASP,SAASxD,eAAeyD,UAChCM,SAASP,SAASxD,eAAe0D,WACnCK,SAASF;;YAAQ,IAAAjB,WAAA;AAAA,oBAAAR,gBAElBtC,cAAY;cAAA,IACXgD,YAAS;AAAA,sBAAEvD,IAAI,GAAGmB,UAAUqD,SAASxB,KAAK,CAAA;;cAAe,IAAAK,WAAA;AAAA,sBACxDrD,IAAI;;oFAGGwE,SAASJ,MAAK;;;;;;;;;;;kCAaZI,SAASP,SAASxD,eAAe0D,SAC7B;;;0CAIA,GAAE;;;;;;;;;8BAUVhD,UAAUqD,SAASxB,KAAK,CAAA,gEACxBwB,SAASP,SAASxD,eAAe0D,SAC7B,iBACA,GAAE;;;cAET,CAAA;;YAAA,CAAA,CAAA;;UAAA,CAAA,CAAA;SAKZ,CAAA;QAAA;SAAA,CAAA,CAAA;;KAAA,CAAA;IAAA;;EAAA,CAAA,CAAA,EAAAtB,gBAKR3C,KAAG;EAAA,IAACsD,OAAI;AAAA,UAAEC,OAAOC,OAAOhC,QAAQ2B,SAAS;;EAAAA,WACvCoB,UAAK5B,gBACHzC,MAAI;GAAA,IACH0D,OAAI;AAAA,WAAEW,MAAMC;;GAAS,IACrBC,WAAQ;AAAA,WAAA9B,gBAAGrB,cAAY,EAACE,SAAS+C,OAAK,CAAA;;GAAA,IAAApB,WAAA;AAAA,WAAAR,gBACrCtB,qBAAmB,EAACG,SAAS+C,OAAK,CAAA;;GAAA,CAAA;EAEtC,CAAA,CAAA"}
1
+ {"version":3,"file":"command-entry.mjs","names":["code","computed","For","Match","Show","Switch","ElseIfClause","IfStatement","ReflectionKind","usePowerlines","EntryFile","isDynamicPathSegment","CommandHandlerDeclaration","CommandValidationLogic","findFilePath","relativePath","joinPaths","replaceExtension","camelCase","pascalCase","defu","BannerFunctionDeclaration","VirtualCommandEntry","CommandEntry","props","command","imports","builtinImports","rest","context","filePath","segments","filter","segment","join","commandSourcePath","entryPath","value","entry","input","file","typeDefinition","output","id","_$createComponent","_$mergeProps","path","name","prompts","env","console","utils","children","_$createIntrinsic","condition","Object","values","options","option","optional","map","kind","string","number","variadic","includes","length","arguments","argument","each","doubleHardline","when","title","boolean","child","isVirtual","fallback"],"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 { code, computed, For, Match, Show, Switch } from \"@alloy-js/core\";\nimport { ElseIfClause, IfStatement } from \"@alloy-js/typescript\";\nimport { ReflectionKind } from \"@powerlines/deepkit/vendor/type\";\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 { isDynamicPathSegment } from \"@shell-shock/core/plugin-utils/context-helpers\";\nimport type { CommandTree } from \"@shell-shock/core/types/command\";\nimport {\n CommandHandlerDeclaration,\n CommandValidationLogic\n} from \"@shell-shock/preset-script/components/command-entry\";\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 { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport defu from \"defu\";\nimport type { CLIPresetContext } from \"../types/plugin\";\nimport { BannerFunctionDeclaration } from \"./banner-function-declaration\";\nimport { VirtualCommandEntry } from \"./virtual-command-entry\";\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<CLIPresetContext>();\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]: `handle${pascalCase(command.name)}`,\n prompts: \"prompts\"\n })}\n builtinImports={defu(builtinImports ?? {}, {\n env: [\"env\", \"isDevelopment\", \"isDebug\"],\n console: [\n \"debug\",\n \"warn\",\n \"error\",\n \"table\",\n \"colors\",\n \"stripAnsi\",\n \"writeLine\",\n \"splitText\",\n \"text\",\n \"confirm\",\n \"isCancel\",\n \"intro\",\n \"outro\"\n ],\n utils: [\n \"useApp\",\n \"useArgs\",\n \"hasFlag\",\n \"isMinimal\",\n \"isInteractive\",\n \"isHelp\",\n \"isUnicodeSupported\",\n \"internal_commandContext\"\n ]\n })}>\n <BannerFunctionDeclaration command={command} />\n <hbr />\n <hbr />\n <CommandHandlerDeclaration command={command}>\n <IfStatement condition={code`!isInteractive`}>\n <CommandValidationLogic command={command} />\n </IfStatement>\n <ElseIfClause\n condition={code`!isHelp && (${Object.values(command.options ?? {})\n .filter(option => !option.optional)\n .map(option =>\n (option.kind === ReflectionKind.string ||\n option.kind === ReflectionKind.number) &&\n option.variadic\n ? `(!options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } || options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.length === 0)`\n : `options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } === undefined`\n )\n .join(\" || \")}${\n Object.values(command.options ?? {}).filter(\n option => !option.optional\n ).length > 0 &&\n Object.values(command.arguments ?? {}).filter(\n argument => !argument.optional\n ).length > 0\n ? \" || \"\n : \"\"\n }${Object.values(command.arguments ?? {})\n .filter(argument => !argument.optional)\n .map(argument =>\n (argument.kind === ReflectionKind.string ||\n argument.kind === ReflectionKind.number) &&\n argument.variadic\n ? `(!${camelCase(\n argument.name\n )} || ${camelCase(argument.name)}.length === 0)`\n : `${camelCase(argument.name)} === undefined`\n )\n .join(\" || \")}) `}>\n {code`writeLine(\"\");\n\n intro(\"Select required input parameters\"); `}\n <hbr />\n <hbr />\n <For each={Object.values(command.options ?? {})} doubleHardline>\n {option => (\n <>\n <Show when={!option.optional}>\n <IfStatement\n condition={code`!options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }`}>\n <Switch>\n <Match\n when={\n option.kind === ReflectionKind.string ||\n option.kind === ReflectionKind.number\n }>{code`\n const value = await text({\n message: 'Please provide a value for the ${\n option.title\n } option:',\n validate(value) {\n if (isCancel(value)) {\n return true;\n }\n if (!value || value.trim() === \"\") {\n return \"A value is required for this option\";\n }\n ${\n option.kind === ReflectionKind.number\n ? `if (Number.isNaN(Number(value))) {\n return \"The value provided must be a valid number\";\n }`\n : \"\"\n }\n return undefined;\n }\n });\n if (isCancel(value)) {\n return;\n }\n\n options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } = ${\n option.kind === ReflectionKind.number\n ? `Number(value)`\n : \"value\"\n };\n `}</Match>\n <Match\n when={option.kind === ReflectionKind.boolean}>{code`\n options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } = await confirm({\n message: 'Please select a value for the ${option.title} option:'\n });\n `}</Match>\n </Switch>\n </IfStatement>\n <Show\n when={\n (option.kind === ReflectionKind.string ||\n option.kind === ReflectionKind.number) &&\n option.variadic\n }>\n <ElseIfClause\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.length === 0`}>\n {code`\n const value = await text({\n message: 'Please provide one or more values for the ${\n option.title\n } option (values are separated by a \",\" character):',\n validate(value) {\n if (isCancel(value)) {\n return true;\n }\n if (!value || value.trim() === \"\") {\n return \"A value is required for this option\";\n }\n if (value.split(\",\").map(value => value.trim()).filter(Boolean).length === 0) {\n return \"At least one value is required for this option\";\n }\n ${\n option.kind === ReflectionKind.number\n ? `const invalidIndex = value.split(\",\").map(value => value.trim()).filter(Boolean).findIndex(value => Number.isNaN(Number(value));\n if (invalidIndex !== -1) {\n return \\`Invalid numeric value provided for item #\\${invalidIndex + 1} - all provided items must be a valid number\\`;\n } `\n : \"\"\n }\n return undefined;\n }\n });\n if (isCancel(value)) {\n return;\n }\n\n options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } = value.split(\",\").map(value => value.trim()).filter(Boolean)${\n option.kind === ReflectionKind.number\n ? `.map(Number)`\n : \"\"\n } ;\n `}\n </ElseIfClause>\n </Show>\n </Show>\n </>\n )}\n </For>\n <hbr />\n <hbr />\n <For each={command.arguments} doubleHardline>\n {argument => (\n <>\n <Show when={!argument.optional}>\n <IfStatement condition={code`!${camelCase(argument.name)}`}>\n <Switch>\n <Match\n when={\n argument.kind === ReflectionKind.string ||\n argument.kind === ReflectionKind.number\n }>{code`\n const value = await text({\n message: 'Please provide a value for the ${argument.title} positional argument:',\n validate(value) {\n if (isCancel(value)) {\n return true;\n }\n if (!value || value.trim() === \"\") {\n return \"A value is required for this positional argument\";\n }\n ${\n argument.kind === ReflectionKind.number\n ? `if (Number.isNaN(Number(value))) {\n return \"The value provided must be a valid number\";\n }`\n : \"\"\n }\n return undefined;\n }\n });\n if (isCancel(value)) {\n return;\n }\n\n ${camelCase(argument.name)} = ${\n argument.kind === ReflectionKind.number\n ? `Number(value)`\n : \"value\"\n };\n `}</Match>\n <Match\n when={argument.kind === ReflectionKind.boolean}>{code`\n ${camelCase(argument.name)} = await confirm({\n message: 'Please select a value for the ${argument.title} positional argument:'\n });\n `}</Match>\n </Switch>\n </IfStatement>\n <Show\n when={\n (argument.kind === ReflectionKind.string ||\n argument.kind === ReflectionKind.number) &&\n argument.variadic\n }>\n <ElseIfClause\n condition={code`${camelCase(argument.name)}.length === 0`}>\n {code`\n const value = await text({\n message: 'Please provide one or more values for the ${\n argument.title\n } option (values are separated by a \",\" character):',\n validate(value) {\n if (isCancel(value)) {\n return true;\n }\n if (!value || value.trim() === \"\") {\n return \"A value is required for this option\";\n }\n if (value.split(\",\").map(value => value.trim()).filter(Boolean).length === 0) {\n return \"At least one value is required for this option\";\n }\n ${\n argument.kind === ReflectionKind.number\n ? `const invalidIndex = value.split(\",\").map(value => value.trim()).filter(Boolean).findIndex(value => Number.isNaN(Number(value));\n if (invalidIndex !== -1) {\n return \\`Invalid numeric value provided for item #\\${invalidIndex + 1} - all provided items must be a valid number\\`;\n } `\n : \"\"\n }\n\n return undefined;\n }\n });\n if (isCancel(value)) {\n return;\n }\n\n ${camelCase(argument.name)} = value.split(\",\").map(value => value.trim()).filter(Boolean)${\n argument.kind === ReflectionKind.number\n ? `.map(Number)`\n : \"\"\n } ;\n `}\n </ElseIfClause>\n </Show>\n </Show>\n </>\n )}\n </For>\n {code`outro(\"Completed providing all required input parameters\");\n\n writeLine(\"\"); `}\n <hbr />\n <hbr />\n </ElseIfClause>\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":";;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgBuB,aAAaC,OAA0B;CACrD,MAAM,EAAEC,SAASC,SAASC,gBAAgB,GAAGC,SAASJ;CAEtD,MAAMK,UAAUpB,eAAiC;CACjD,MAAMqB,WAAW7B,eACfe,UACES,QAAQM,SACLC,QAAOC,YAAW,CAACtB,qBAAqBsB,QAAQ,CAAC,CACjDC,KAAK,IAAI,EACZ,WAEJ,CAAC;CACD,MAAMC,oBAAoBlC,eACxBgB,iBACEF,aACEC,UAAUa,QAAQO,WAAWtB,aAAagB,SAASO,MAAM,CAAC,EAC1DZ,QAAQa,MAAMC,OAAOC,QAAQf,QAAQa,MAAME,KAE/C,CACF,CAAC;CACD,MAAMC,iBAAiBxC,gBAAgB;EACrC,GAAGwB,QAAQa;EACXI,QAAQjB,QAAQkB;EACjB,EAAE;AAEH,QAAA,CAAAC,gBAEKlC,WAASmC,WACJjB,MAAI;EAAA,IACRkB,OAAI;AAAA,UAAEhB,SAASO;;EAAK,IACpBI,iBAAc;AAAA,UAAEA,eAAeJ;;EAAK,IACpCX,UAAO;AAAA,UAAEN,KAAKM,WAAW,EAAE,EAAE;KAC1BS,kBAAkBE,QAAQ,SAASlB,WAAWM,QAAQsB,KAAK;IAC5DC,SAAS;IACV,CAAC;;EAAA,IACFrB,iBAAc;AAAA,UAAEP,KAAKO,kBAAkB,EAAE,EAAE;IACzCsB,KAAK;KAAC;KAAO;KAAiB;KAAU;IACxCC,SAAS;KACP;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KACD;IACDC,OAAO;KACL;KACA;KACA;KACA;KACA;KACA;KACA;KACA;KAAyB;IAE5B,CAAC;;EAAA,IAAAC,WAAA;AAAA,UAAA;IAAAR,gBACDvB,2BAAyB,EAAUI,SAAO,CAAA;IAAA4B,gBAAA,OAAA,EAAA,CA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AAA,CAAA;UAKZ,CAAA;SAEF/D,IAAI;;;SAEWqD,gBAAA,OAAA,EAAA,CAAA;SAAAA,gBAAA,OAAA,EAAA,CAAA;SAAA;;OAAA,CAAA,CAAA;;KAAA,CAAA;IAAA;;EAAA,CAAA,CAAA,EAAAT,gBAMrB1C,KAAG;EAAA,IAACmE,OAAI;AAAA,UAAEd,OAAOC,OAAO/B,QAAQ2B,SAAS;;EAAAA,WACvCsB,UAAK9B,gBACHxC,MAAI;GAAA,IACHmE,OAAI;AAAA,WAAEG,MAAMC;;GAAS,IACrBC,WAAQ;AAAA,WAAAhC,gBAAGrB,cAAY,EAACE,SAASiD,OAAK,CAAA;;GAAA,IAAAtB,WAAA;AAAA,WAAAR,gBACrCtB,qBAAmB,EAACG,SAASiD,OAAK,CAAA;;GAAA,CAAA;EAEtC,CAAA,CAAA"}
@@ -0,0 +1,87 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ let __alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
3
+ let __alloy_js_core = require("@alloy-js/core");
4
+ let __alloy_js_typescript = require("@alloy-js/typescript");
5
+ let __shell_shock_preset_script_components_command_router = require("@shell-shock/preset-script/components/command-router");
6
+
7
+ //#region src/components/command-router.tsx
8
+ function CommandRouterSelectOptions(props) {
9
+ const { commands } = props;
10
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.For, {
11
+ get each() {
12
+ return Object.values(commands ?? {});
13
+ },
14
+ joiner: ",",
15
+ hardline: true,
16
+ children: (command) => command.isVirtual ? (0, __alloy_js_core_jsx_runtime.createComponent)(CommandRouterSelectOptions, { get commands() {
17
+ return command.children ?? {};
18
+ } }) : __alloy_js_core.code`{ value: [${command.segments.map((segment) => `"${segment}"`).join(", ")}], label: "${command.icon ? `${command.icon} ` : ""}${command.title}", hint: "${command.description}" }`
19
+ });
20
+ }
21
+ /**
22
+ * A component that renders a command router interface, allowing users to select and execute commands from a provided list of commands and segments. This component serves as a wrapper around the base CommandRouter, adding additional UI elements and logic for command selection.
23
+ */
24
+ function CommandRouter(props) {
25
+ const { segments, commands } = props;
26
+ return [
27
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__shell_shock_preset_script_components_command_router.CommandRouter, (0, __alloy_js_core_jsx_runtime.mergeProps)(props, {
28
+ segments,
29
+ commands
30
+ })),
31
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
32
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
33
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
34
+ condition: __alloy_js_core.code`isInteractive && !isHelp`,
35
+ get children() {
36
+ return [
37
+ __alloy_js_core.code`
38
+ banner();
39
+ writeLine("");
40
+
41
+ intro("Command selection");
42
+
43
+ let segments = await select({
44
+ message: "Please select a command to execute:",
45
+ options: [ `,
46
+ (0, __alloy_js_core_jsx_runtime.createComponent)(CommandRouterSelectOptions, { commands }),
47
+ (0, __alloy_js_core_jsx_runtime.memo)(() => ` ],
48
+ });
49
+ if (isCancel(segments)) {
50
+ return;
51
+ }
52
+
53
+ let dynamics = {} as Record<string, string>;
54
+ for (const dynamic of segments.filter(segment => segment.startsWith("[") && segment.endsWith("]"))) {
55
+ const value = await text({
56
+ message: \`Please provide a value for \${dynamic.replace(/^\[+/, "").replace(/\]+$/, "")}:\`,
57
+ });
58
+ if (isCancel(value)) {
59
+ return;
60
+ }
61
+ dynamics[dynamic] = value;
62
+ }
63
+
64
+ segments = segments.map(segment => dynamics[segment] || segment);
65
+ const context = useApp();
66
+ context.set("args", [args[0], ...segments, ...args.slice(${segments.length + 2})]);
67
+
68
+ outro(\`Executing \${segments.join(" ")} command\`);
69
+
70
+ command = segments[0];
71
+ args = context.get("args");
72
+ `),
73
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__shell_shock_preset_script_components_command_router.CommandRouterBody, (0, __alloy_js_core_jsx_runtime.mergeProps)(props, {
74
+ segments,
75
+ commands
76
+ }))
77
+ ];
78
+ }
79
+ }),
80
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
81
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {})
82
+ ];
83
+ }
84
+
85
+ //#endregion
86
+ exports.CommandRouter = CommandRouter;
87
+ exports.CommandRouterSelectOptions = CommandRouterSelectOptions;
@@ -0,0 +1,16 @@
1
+ import * as _alloy_js_core0 from "@alloy-js/core";
2
+ import { CommandTree } from "@shell-shock/core/types/command";
3
+ import { CommandRouterProps } from "@shell-shock/preset-script/components/command-router";
4
+
5
+ //#region src/components/command-router.d.ts
6
+ interface CommandRouterSelectOptionsProps {
7
+ commands?: Record<string, CommandTree>;
8
+ }
9
+ declare function CommandRouterSelectOptions(props: CommandRouterSelectOptionsProps): _alloy_js_core0.Children;
10
+ /**
11
+ * A component that renders a command router interface, allowing users to select and execute commands from a provided list of commands and segments. This component serves as a wrapper around the base CommandRouter, adding additional UI elements and logic for command selection.
12
+ */
13
+ declare function CommandRouter(props: CommandRouterProps): _alloy_js_core0.Children;
14
+ //#endregion
15
+ export { CommandRouter, CommandRouterSelectOptions, CommandRouterSelectOptionsProps };
16
+ //# sourceMappingURL=command-router.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-router.d.cts","names":[],"sources":["../../src/components/command-router.tsx"],"sourcesContent":[],"mappings":";;;;;UA2BiB,+BAAA;aACJ,eAAe;;AADX,iBAID,0BAAA,CAHY,KAAA,EAInB,+BAJU,CAAA,EAIqB,eAAA,CAAA,QAJrB;AAGnB;AA2BA;;iBAAgB,aAAA,QAAqB,qBAAkB,eAAA,CAAA"}
@@ -0,0 +1,16 @@
1
+ import * as _alloy_js_core0 from "@alloy-js/core";
2
+ import { CommandRouterProps } from "@shell-shock/preset-script/components/command-router";
3
+ import { CommandTree } from "@shell-shock/core/types/command";
4
+
5
+ //#region src/components/command-router.d.ts
6
+ interface CommandRouterSelectOptionsProps {
7
+ commands?: Record<string, CommandTree>;
8
+ }
9
+ declare function CommandRouterSelectOptions(props: CommandRouterSelectOptionsProps): _alloy_js_core0.Children;
10
+ /**
11
+ * A component that renders a command router interface, allowing users to select and execute commands from a provided list of commands and segments. This component serves as a wrapper around the base CommandRouter, adding additional UI elements and logic for command selection.
12
+ */
13
+ declare function CommandRouter(props: CommandRouterProps): _alloy_js_core0.Children;
14
+ //#endregion
15
+ export { CommandRouter, CommandRouterSelectOptions, CommandRouterSelectOptionsProps };
16
+ //# sourceMappingURL=command-router.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-router.d.mts","names":[],"sources":["../../src/components/command-router.tsx"],"sourcesContent":[],"mappings":";;;;;UA2BiB,+BAAA;aACJ,eAAe;;AADX,iBAID,0BAAA,CAHY,KAAA,EAInB,+BAJU,CAAA,EAIqB,eAAA,CAAA,QAJrB;AAGnB;AA2BA;;iBAAgB,aAAA,QAAqB,qBAAkB,eAAA,CAAA"}