@shell-shock/preset-script 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/components/banner-function-declaration.cjs +4 -2
- package/dist/components/banner-function-declaration.cjs.map +1 -1
- package/dist/components/banner-function-declaration.mjs +4 -2
- package/dist/components/banner-function-declaration.mjs.map +1 -1
- package/dist/components/bin-entry.cjs +9 -5
- package/dist/components/bin-entry.cjs.map +1 -1
- package/dist/components/bin-entry.d.cts.map +1 -1
- package/dist/components/bin-entry.d.mts.map +1 -1
- package/dist/components/bin-entry.mjs +9 -5
- package/dist/components/bin-entry.mjs.map +1 -1
- package/dist/components/command-entry.cjs +4 -8
- package/dist/components/command-entry.cjs.map +1 -1
- package/dist/components/command-entry.d.cts.map +1 -1
- package/dist/components/command-entry.d.mts.map +1 -1
- package/dist/components/command-entry.mjs +4 -8
- package/dist/components/command-entry.mjs.map +1 -1
- package/dist/components/command-router.cjs +90 -61
- package/dist/components/command-router.cjs.map +1 -1
- package/dist/components/command-router.d.cts +5 -1
- package/dist/components/command-router.d.cts.map +1 -1
- package/dist/components/command-router.d.mts +5 -1
- package/dist/components/command-router.d.mts.map +1 -1
- package/dist/components/command-router.mjs +90 -62
- package/dist/components/command-router.mjs.map +1 -1
- package/dist/components/console-builtin.cjs +1 -2
- package/dist/components/console-builtin.cjs.map +1 -1
- package/dist/components/console-builtin.mjs +1 -2
- package/dist/components/console-builtin.mjs.map +1 -1
- package/dist/components/help.d.cts +7 -7
- package/dist/components/help.d.cts.map +1 -1
- package/dist/components/help.d.mts +7 -7
- package/dist/components/help.d.mts.map +1 -1
- package/dist/components/helpers.d.cts +5 -5
- package/dist/components/helpers.d.mts +5 -5
- package/dist/components/index.cjs +1 -0
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.mts +2 -2
- package/dist/components/index.mjs +2 -2
- package/dist/components/utils-builtin.cjs +53 -9
- package/dist/components/utils-builtin.cjs.map +1 -1
- package/dist/components/utils-builtin.d.cts +8 -8
- package/dist/components/utils-builtin.d.cts.map +1 -1
- package/dist/components/utils-builtin.d.mts +8 -8
- package/dist/components/utils-builtin.d.mts.map +1 -1
- package/dist/components/utils-builtin.mjs +54 -10
- package/dist/components/utils-builtin.mjs.map +1 -1
- package/dist/components/virtual-command-entry.cjs +16 -12
- package/dist/components/virtual-command-entry.cjs.map +1 -1
- package/dist/components/virtual-command-entry.d.cts.map +1 -1
- package/dist/components/virtual-command-entry.d.mts.map +1 -1
- package/dist/components/virtual-command-entry.mjs +16 -12
- package/dist/components/virtual-command-entry.mjs.map +1 -1
- package/dist/index.cjs +2 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -13,7 +13,6 @@ import { replaceExtension } from "@stryke/path/replace";
|
|
|
13
13
|
import { pascalCase } from "@stryke/string-format/pascal-case";
|
|
14
14
|
import defu from "defu";
|
|
15
15
|
import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
|
|
16
|
-
import { SingleLineComment } from "@powerlines/plugin-alloy/core/components/single-line-comment";
|
|
17
16
|
import { CommandParserLogic, OptionsInterfaceDeclaration } from "@shell-shock/core/components/options-parser-logic";
|
|
18
17
|
import { findFilePath, relativePath } from "@stryke/path/find";
|
|
19
18
|
import { joinPaths } from "@stryke/path/join";
|
|
@@ -35,7 +34,7 @@ function CommandInvocation(props) {
|
|
|
35
34
|
createIntrinsic("hbr", {}),
|
|
36
35
|
memo(() => code`
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
internal_commandContext.run(__context, () => {
|
|
39
38
|
return Promise.resolve(Reflect.apply(handle${pascalCase(command.name)}, __context, [options${command.arguments.length > 0 ? `, ${command.arguments.map((argument) => camelCase(argument.name)).join(", ")}` : ""}]));
|
|
40
39
|
});
|
|
41
40
|
|
|
@@ -80,7 +79,7 @@ function CommandHandlerDeclaration(props) {
|
|
|
80
79
|
parameters: [{
|
|
81
80
|
name: "args",
|
|
82
81
|
type: "string[]",
|
|
83
|
-
default: "
|
|
82
|
+
default: "useArgs()"
|
|
84
83
|
}],
|
|
85
84
|
get children() {
|
|
86
85
|
return [
|
|
@@ -311,7 +310,6 @@ function CommandEntry(props) {
|
|
|
311
310
|
return defu(builtinImports ?? {}, {
|
|
312
311
|
env: [
|
|
313
312
|
"env",
|
|
314
|
-
"isCI",
|
|
315
313
|
"isDevelopment",
|
|
316
314
|
"isDebug"
|
|
317
315
|
],
|
|
@@ -326,11 +324,11 @@ function CommandEntry(props) {
|
|
|
326
324
|
"splitText"
|
|
327
325
|
],
|
|
328
326
|
utils: [
|
|
329
|
-
"
|
|
327
|
+
"useArgs",
|
|
330
328
|
"hasFlag",
|
|
331
329
|
"isMinimal",
|
|
332
330
|
"isUnicodeSupported",
|
|
333
|
-
"
|
|
331
|
+
"internal_commandContext"
|
|
334
332
|
]
|
|
335
333
|
});
|
|
336
334
|
},
|
|
@@ -342,8 +340,6 @@ function CommandEntry(props) {
|
|
|
342
340
|
createComponent(OptionsInterfaceDeclaration, { command }),
|
|
343
341
|
createIntrinsic("hbr", {}),
|
|
344
342
|
createIntrinsic("hbr", {}),
|
|
345
|
-
createComponent(SingleLineComment, { children: code`Validate required options and arguments` }),
|
|
346
|
-
createIntrinsic("hbr", {}),
|
|
347
343
|
createComponent(CommandHandlerDeclaration, {
|
|
348
344
|
command,
|
|
349
345
|
get children() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-entry.mjs","names":["code","computed","For","Show","ElseClause","ElseIfClause","FunctionDeclaration","IfStatement","VarDeclaration","ReflectionKind","SingleLineComment","usePowerlines","EntryFile","TSDoc","TSDocParam","TSDocRemarks","TSDocTitle","CommandParserLogic","OptionsInterfaceDeclaration","getAppBin","getDynamicPathSegmentName","isDynamicPathSegment","findFilePath","relativePath","joinPaths","replaceExtension","camelCase","constantCase","kebabCase","pascalCase","defu","BannerFunctionDeclaration","CommandHelp","IsDebug","VirtualCommandEntry","CommandInvocation","props","command","_$createComponent","name","initializer","segments","map","segment","join","_$createIntrinsic","_$memo","arguments","length","argument","CommandHandlerDeclaration","children","context","heading","title","description","replace","async","parameters","type","default","envPrefix","config","isCaseSensitive","condition","Object","values","options","option","CommandValidationLogic","each","doubleHardline","when","optional","includes","kind","string","number","variadic","fallback","CommandEntry","imports","builtinImports","rest","filePath","filter","commandSourcePath","entryPath","value","entry","input","file","typeDefinition","output","id","_$mergeProps","path","env","console","utils","child","isVirtual"],"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 ElseIfClause,\n FunctionDeclaration,\n IfStatement,\n VarDeclaration\n} from \"@alloy-js/typescript\";\nimport { ReflectionKind } from \"@powerlines/deepkit/vendor/type\";\nimport { SingleLineComment } from \"@powerlines/plugin-alloy/core/components/single-line-comment\";\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 {\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/context-helpers\";\nimport type {\n CommandTree,\n NumberCommandArgument,\n NumberCommandOption\n} from \"@shell-shock/core/types/command\";\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 { BannerFunctionDeclaration } from \"./banner-function-declaration\";\nimport { CommandHelp } from \"./help\";\nimport { IsDebug } from \"./helpers\";\nimport { VirtualCommandEntry } from \"./virtual-command-entry\";\n\nexport function CommandInvocation(props: { command: CommandTree }) {\n const { command } = props;\n\n return (\n <>\n <VarDeclaration\n name=\"__context\"\n initializer={code`{ path: \\`${command.segments\n .map(segment =>\n isDynamicPathSegment(segment)\n ? `\\${${camelCase(getDynamicPathSegmentName(segment))}}`\n : segment\n )\n .join(\"/\")}\\`, segments: [${command.segments\n .map(segment =>\n isDynamicPathSegment(segment)\n ? camelCase(getDynamicPathSegmentName(segment))\n : `\"${segment}\"`\n )\n .join(\", \")}] }`}\n />\n <hbr />\n <hbr />\n {code`\n\n internal_commandContextStore.run(__context, () => {\n return Promise.resolve(Reflect.apply(handle${pascalCase(\n command.name\n )}, __context, [options${\n command.arguments.length > 0\n ? `, ${command.arguments\n .map(argument => camelCase(argument.name))\n .join(\", \")}`\n : \"\"\n }]));\n });\n\n `}\n <hbr />\n </>\n );\n}\n\nexport interface CommandHandlerDeclarationProps {\n command: CommandTree;\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, children } = props;\n\n const context = usePowerlines<ScriptPresetContext>();\n\n return (\n <>\n <OptionsInterfaceDeclaration command={command} />\n <hbr />\n <hbr />\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: \"getArgs()\" }]}>\n <CommandParserLogic\n command={command}\n envPrefix={context.config.envPrefix}\n isCaseSensitive={context.config.isCaseSensitive}\n />\n <hbr />\n <hbr />\n {code`writeLine(\"\");\n banner(); `}\n <hbr />\n <hbr />\n <IfStatement condition={<IsDebug />}>\n {code`\n writeLine(\"\");\n writeLine(colors.text.body.tertiary(\"Debug mode is enabled. Additional debug information may be logged to the console.\"));\n\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.arguments.length > 0\n ? ` \\\\n\\\\nArguments: \\\\n${command.arguments\n .map(\n argument =>\n ` - ${kebabCase(argument.name)}: \\${${camelCase(\n argument.name\n )} === undefined ? \"\" : JSON.stringify(${camelCase(\n argument.name\n )})}`\n )\n .join(\"\\\\n\")}`\n : \"\"\n }\\`);\n writeLine(\"\"); `}\n </IfStatement>\n <hbr />\n <hbr />\n {children}\n <hbr />\n <hbr />\n <IfStatement condition={code`options.help`}>\n <CommandHelp command={command} />\n </IfStatement>\n <ElseClause>\n <hbr />\n <CommandInvocation command={command} />\n </ElseClause>\n </FunctionDeclaration>\n </>\n );\n}\n\nexport interface CommandValidationLogicProps {\n command: CommandTree;\n}\n\n/**\n * A component that generates command validation logic for required options and arguments.\n */\nexport function CommandValidationLogic(props: CommandValidationLogicProps) {\n const { command } = props;\n\n return (\n <>\n <VarDeclaration name=\"failures\" type=\"string[]\" initializer={code`[];`} />\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 {code`failures.push(\"Missing required \\\\\"${option.name}\\\\\" option\");`}\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`failures.push(\"No values were provided to the required \\\\\"${\n option.name\n }\\\\\" array option\");`}\n </ElseIfClause>\n </Show>\n </Show>\n <Show when={option.kind === ReflectionKind.number}>\n <Show\n when={(option as NumberCommandOption).variadic}\n fallback={\n <IfStatement\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } && Number.isNaN(options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n })`}>\n {code`failures.push(\"Invalid numeric value provided for the \\\\\"${\n option.name\n }\\\\\" option\");`}\n </IfStatement>\n }>\n <IfStatement\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.some(value => Number.isNaN(value))`}>\n {code`failures.push(\"Invalid numeric value provided in the \\\\\"${\n option.name\n }\\\\\" array option\");`}\n </IfStatement>\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 {code`failures.push(\"Missing required \\\\\"${\n argument.name\n }\\\\\" positional argument\");`}\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`failures.push(\"No values were provided to the required \\\\\"${\n argument.name\n }\\\\\" array positional argument\");`}\n </ElseIfClause>\n </Show>\n </Show>\n <Show when={argument.kind === ReflectionKind.number}>\n <Show\n when={(argument as NumberCommandArgument).variadic}\n fallback={\n <IfStatement\n condition={code`${camelCase(\n argument.name\n )} && Number.isNaN(${camelCase(argument.name)})`}>\n {code`failures.push(\"Invalid numeric value provided for the \\\\\"${\n argument.name\n }\\\\\" positional argument\");`}\n </IfStatement>\n }>\n <IfStatement\n condition={code`${camelCase(argument.name)}.some(value => Number.isNaN(value))`}>\n {code`failures.push(\"Invalid numeric value provided in the \\\\\"${\n argument.name\n }\\\\\" array positional argument\");`}\n </IfStatement>\n </Show>\n </Show>\n </>\n )}\n </For>\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 command line process can be executed: \\\\n\\\\n\" + failures.map(failure => \" - \" + failure).join(\"\\\\n\"));\n options.help = true; `}\n </IfStatement>\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]: `handle${pascalCase(command.name)}`\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 ],\n utils: [\n \"getArgs\",\n \"hasFlag\",\n \"isMinimal\",\n \"isUnicodeSupported\",\n \"internal_commandContextStore\"\n ]\n })}>\n <BannerFunctionDeclaration command={command} />\n <hbr />\n <hbr />\n <OptionsInterfaceDeclaration command={command} />\n <hbr />\n <hbr />\n <SingleLineComment>{code`Validate required options and arguments`}</SingleLineComment>\n <hbr />\n <CommandHandlerDeclaration command={command}>\n <CommandValidationLogic command={command} />\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":";;;;;;;;;;;;;;;;;;;;;;;;AAkEA,SAAgBmC,kBAAkBC,OAAiC;CACjE,MAAM,EAAEC,YAAYD;AAEpB,QAAA;EAAAE,gBAEK9B,gBAAc;GACb+B,MAAI;GAAA,IACJC,cAAW;AAAA,WAAExC,IAAI,aAAaqC,QAAQI,SACnCC,KAAIC,YACHtB,qBAAqBsB,QAAQ,GACzB,MAAMjB,UAAUN,0BAA0BuB,Q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A;KACA;KACA;KACA;KACA;KACA;KACA;KACD;IACDC,OAAO;KACL;KACA;KACA;KACA;KACA;KAA8B;IAEjC,CAAC;;EAAA,IAAAhD,WAAA;AAAA,UAAA;IAAAb,gBACDP,2BAAyB,EAAUM,SAAO,CAAA;IAAAQ,gBAAA,OAAA,EAAA,CAAA;IAAAA,gBAAA,OAAA,EAAA,CAAA;IAAAP,gBAG1CpB,6BAA2B,EAAUmB,SAAO,CAAA;IAAAQ,gBAAA,OAAA,EAAA,CAAA;IAAAA,gBAAA,OAAA,EAAA,CAAA;IAAAP,gBAG5C5B,mBAAiB,EAAAyC,UAAEnD,IAAI,2CAAyC,CAAA;IAAA6C,gBAAA,OAAA,EAAA,CAAA;IAAAP,gBAEhEY,2BAAyB;KAAUb;KAAO,IAAAc,WAAA;AAAA,aAAAb,gBACxC+B,wBAAsB,EAAUhC,SAAO,CAAA;;KAAA,CAAA;IAAA;;EAAA,CAAA,CAAA,EAAAC,gBAG3CpC,KAAG;EAAA,IAACoE,OAAI;AAAA,UAAEL,OAAOC,OAAO7B,QAAQc,SAAS;;EAAAA,WACvCiD,UAAK9D,gBACHnC,MAAI;GAAA,IACHqE,OAAI;AAAA,WAAE4B,MAAMC;;GAAS,IACrBtB,WAAQ;AAAA,WAAAzC,gBAAG0C,cAAY,EAAC3C,SAAS+D,OAAK,CAAA;;GAAA,IAAAjD,WAAA;AAAA,WAAAb,gBACrCJ,qBAAmB,EAACG,SAAS+D,OAAK,CAAA;;GAAA,CAAA;EAEtC,CAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"command-entry.mjs","names":["code","computed","For","Show","ElseClause","ElseIfClause","FunctionDeclaration","IfStatement","VarDeclaration","ReflectionKind","usePowerlines","EntryFile","TSDoc","TSDocParam","TSDocRemarks","TSDocTitle","CommandParserLogic","OptionsInterfaceDeclaration","getAppBin","getDynamicPathSegmentName","isDynamicPathSegment","findFilePath","relativePath","joinPaths","replaceExtension","camelCase","constantCase","kebabCase","pascalCase","defu","BannerFunctionDeclaration","CommandHelp","IsDebug","VirtualCommandEntry","CommandInvocation","props","command","_$createComponent","name","initializer","segments","map","segment","join","_$createIntrinsic","_$memo","arguments","length","argument","CommandHandlerDeclaration","children","context","heading","title","description","replace","async","parameters","type","default","envPrefix","config","isCaseSensitive","condition","Object","values","options","option","CommandValidationLogic","each","doubleHardline","when","optional","includes","kind","string","number","variadic","fallback","CommandEntry","imports","builtinImports","rest","filePath","filter","commandSourcePath","entryPath","value","entry","input","file","typeDefinition","output","id","_$mergeProps","path","env","console","utils","child","isVirtual"],"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 ElseIfClause,\n FunctionDeclaration,\n IfStatement,\n VarDeclaration\n} 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 {\n TSDoc,\n TSDocParam,\n TSDocRemarks,\n TSDocTitle\n} from \"@powerlines/plugin-alloy/typescript/components/tsdoc\";\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/context-helpers\";\nimport type {\n CommandTree,\n NumberCommandArgument,\n NumberCommandOption\n} from \"@shell-shock/core/types/command\";\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 { BannerFunctionDeclaration } from \"./banner-function-declaration\";\nimport { CommandHelp } from \"./help\";\nimport { IsDebug } from \"./helpers\";\nimport { VirtualCommandEntry } from \"./virtual-command-entry\";\n\nexport function CommandInvocation(props: { command: CommandTree }) {\n const { command } = props;\n\n return (\n <>\n <VarDeclaration\n name=\"__context\"\n initializer={code`{ path: \\`${command.segments\n .map(segment =>\n isDynamicPathSegment(segment)\n ? `\\${${camelCase(getDynamicPathSegmentName(segment))}}`\n : segment\n )\n .join(\"/\")}\\`, segments: [${command.segments\n .map(segment =>\n isDynamicPathSegment(segment)\n ? camelCase(getDynamicPathSegmentName(segment))\n : `\"${segment}\"`\n )\n .join(\", \")}] }`}\n />\n <hbr />\n <hbr />\n {code`\n\n internal_commandContext.run(__context, () => {\n return Promise.resolve(Reflect.apply(handle${pascalCase(\n command.name\n )}, __context, [options${\n command.arguments.length > 0\n ? `, ${command.arguments\n .map(argument => camelCase(argument.name))\n .join(\", \")}`\n : \"\"\n }]));\n });\n\n `}\n <hbr />\n </>\n );\n}\n\nexport interface CommandHandlerDeclarationProps {\n command: CommandTree;\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, children } = props;\n\n const context = usePowerlines<ScriptPresetContext>();\n\n return (\n <>\n <OptionsInterfaceDeclaration command={command} />\n <hbr />\n <hbr />\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 envPrefix={context.config.envPrefix}\n isCaseSensitive={context.config.isCaseSensitive}\n />\n <hbr />\n <hbr />\n {code`writeLine(\"\");\n banner(); `}\n <hbr />\n <hbr />\n <IfStatement condition={<IsDebug />}>\n {code`\n writeLine(\"\");\n writeLine(colors.text.body.tertiary(\"Debug mode is enabled. Additional debug information may be logged to the console.\"));\n\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.arguments.length > 0\n ? ` \\\\n\\\\nArguments: \\\\n${command.arguments\n .map(\n argument =>\n ` - ${kebabCase(argument.name)}: \\${${camelCase(\n argument.name\n )} === undefined ? \"\" : JSON.stringify(${camelCase(\n argument.name\n )})}`\n )\n .join(\"\\\\n\")}`\n : \"\"\n }\\`);\n writeLine(\"\"); `}\n </IfStatement>\n <hbr />\n <hbr />\n {children}\n <hbr />\n <hbr />\n <IfStatement condition={code`options.help`}>\n <CommandHelp command={command} />\n </IfStatement>\n <ElseClause>\n <hbr />\n <CommandInvocation command={command} />\n </ElseClause>\n </FunctionDeclaration>\n </>\n );\n}\n\nexport interface CommandValidationLogicProps {\n command: CommandTree;\n}\n\n/**\n * A component that generates command validation logic for required options and arguments.\n */\nexport function CommandValidationLogic(props: CommandValidationLogicProps) {\n const { command } = props;\n\n return (\n <>\n <VarDeclaration name=\"failures\" type=\"string[]\" initializer={code`[];`} />\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 {code`failures.push(\"Missing required \\\\\"${option.name}\\\\\" option\");`}\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`failures.push(\"No values were provided to the required \\\\\"${\n option.name\n }\\\\\" array option\");`}\n </ElseIfClause>\n </Show>\n </Show>\n <Show when={option.kind === ReflectionKind.number}>\n <Show\n when={(option as NumberCommandOption).variadic}\n fallback={\n <IfStatement\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } && Number.isNaN(options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n })`}>\n {code`failures.push(\"Invalid numeric value provided for the \\\\\"${\n option.name\n }\\\\\" option\");`}\n </IfStatement>\n }>\n <IfStatement\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.some(value => Number.isNaN(value))`}>\n {code`failures.push(\"Invalid numeric value provided in the \\\\\"${\n option.name\n }\\\\\" array option\");`}\n </IfStatement>\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 {code`failures.push(\"Missing required \\\\\"${\n argument.name\n }\\\\\" positional argument\");`}\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`failures.push(\"No values were provided to the required \\\\\"${\n argument.name\n }\\\\\" array positional argument\");`}\n </ElseIfClause>\n </Show>\n </Show>\n <Show when={argument.kind === ReflectionKind.number}>\n <Show\n when={(argument as NumberCommandArgument).variadic}\n fallback={\n <IfStatement\n condition={code`${camelCase(\n argument.name\n )} && Number.isNaN(${camelCase(argument.name)})`}>\n {code`failures.push(\"Invalid numeric value provided for the \\\\\"${\n argument.name\n }\\\\\" positional argument\");`}\n </IfStatement>\n }>\n <IfStatement\n condition={code`${camelCase(argument.name)}.some(value => Number.isNaN(value))`}>\n {code`failures.push(\"Invalid numeric value provided in the \\\\\"${\n argument.name\n }\\\\\" array positional argument\");`}\n </IfStatement>\n </Show>\n </Show>\n </>\n )}\n </For>\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 command line process can be executed: \\\\n\\\\n\" + failures.map(failure => \" - \" + failure).join(\"\\\\n\"));\n options.help = true; `}\n </IfStatement>\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]: `handle${pascalCase(command.name)}`\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 ],\n utils: [\n \"useArgs\",\n \"hasFlag\",\n \"isMinimal\",\n \"isUnicodeSupported\",\n \"internal_commandContext\"\n ]\n })}>\n <BannerFunctionDeclaration command={command} />\n <hbr />\n <hbr />\n <OptionsInterfaceDeclaration command={command} />\n <hbr />\n <hbr />\n <CommandHandlerDeclaration command={command}>\n <CommandValidationLogic command={command} />\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":";;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAgBkC,kBAAkBC,OAAiC;CACjE,MAAM,EAAEC,YAAYD;AAEpB,QAAA;EAAAE,gBAEK7B,gBAAc;GACb8B,MAAI;GAAA,IACJC,cAAW;AAAA,WAAEvC,IAAI,aAAaoC,QAAQI,SACnCC,KAAIC,YACHtB,qBAAqBsB,QAAQ,GACzB,MAAMjB,UAAUN,0BAA0BuB,QAAQ,CAAC,CAAA,KACnDA,QACL,CACAC,KAAK,IAAI,CAAA,iBAAkBP,QAAQI,SACnCC,KAAIC,YACHtB,qBAAqBsB,QAAQ,GACzBjB,UAAUN,0BAA0BuB,QAAQ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,SAAO,CAAA;IAAAQ,gBAAA,OAAA,EAAA,CAAA;IAAAA,gBAAA,OAAA,EAAA,CAAA;IAAAP,gBAG1CpB,6BAA2B,EAAUmB,SAAO,CAAA;IAAAQ,gBAAA,OAAA,EAAA,CAAA;IAAAA,gBAAA,OAAA,EAAA,CAAA;IAAAP,gBAG5CY,2BAAyB;KAAUb;KAAO,IAAAc,WAAA;AAAA,aAAAb,gBACxC+B,wBAAsB,EAAUhC,SAAO,CAAA;;KAAA,CAAA;IAAA;;EAAA,CAAA,CAAA,EAAAC,gBAG3CnC,KAAG;EAAA,IAACmE,OAAI;AAAA,UAAEL,OAAOC,OAAO7B,QAAQc,SAAS;;EAAAA,WACvCiD,UAAK9D,gBACHlC,MAAI;GAAA,IACHoE,OAAI;AAAA,WAAE4B,MAAMC;;GAAS,IACrBtB,WAAQ;AAAA,WAAAzC,gBAAG0C,cAAY,EAAC3C,SAAS+D,OAAK,CAAA;;GAAA,IAAAjD,WAAA;AAAA,WAAAb,gBACrCJ,qBAAmB,EAACG,SAAS+D,OAAK,CAAA;;GAAA,CAAA;EAEtC,CAAA,CAAA"}
|
|
@@ -37,7 +37,6 @@ function CommandRouterRoute() {
|
|
|
37
37
|
*/
|
|
38
38
|
function CommandRouter(props) {
|
|
39
39
|
const { segments, commands, route } = props;
|
|
40
|
-
const context = (0, __powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
|
|
41
40
|
const index = (0, __alloy_js_core.computed)(() => 2 + (segments.length ?? 0));
|
|
42
41
|
return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
|
|
43
42
|
get when() {
|
|
@@ -52,84 +51,114 @@ function CommandRouter(props) {
|
|
|
52
51
|
initializer: __alloy_js_core.code`"";`
|
|
53
52
|
}),
|
|
54
53
|
(0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
55
|
-
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
|
|
56
|
-
get condition() {
|
|
57
|
-
return __alloy_js_core.code`args.length > ${index.value} && args[${index.value}]`;
|
|
58
|
-
},
|
|
59
|
-
get children() {
|
|
60
|
-
return __alloy_js_core.code`command = args[${index.value}];`;
|
|
61
|
-
}
|
|
62
|
-
}),
|
|
63
54
|
(0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
64
|
-
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.
|
|
65
|
-
get
|
|
66
|
-
return Object.
|
|
55
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
|
|
56
|
+
get when() {
|
|
57
|
+
return commands && Object.keys(commands).length > 0;
|
|
67
58
|
},
|
|
68
|
-
children
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return Boolean(idx);
|
|
74
|
-
},
|
|
75
|
-
get fallback() {
|
|
76
|
-
return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
|
|
77
|
-
get condition() {
|
|
78
|
-
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(" || ")}` : ""}`;
|
|
79
|
-
},
|
|
80
|
-
get children() {
|
|
81
|
-
return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
|
|
82
|
-
get when() {
|
|
83
|
-
return Boolean(route);
|
|
84
|
-
},
|
|
85
|
-
get fallback() {
|
|
86
|
-
return (0, __alloy_js_core_jsx_runtime.createComponent)(CommandRouterRoute, {});
|
|
87
|
-
},
|
|
88
|
-
children: route
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
});
|
|
59
|
+
get children() {
|
|
60
|
+
return [
|
|
61
|
+
(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}]`;
|
|
92
64
|
},
|
|
93
65
|
get children() {
|
|
94
|
-
return
|
|
95
|
-
get condition() {
|
|
96
|
-
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(" || ")}` : ""}`;
|
|
97
|
-
},
|
|
98
|
-
get children() {
|
|
99
|
-
return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
|
|
100
|
-
get when() {
|
|
101
|
-
return Boolean(route);
|
|
102
|
-
},
|
|
103
|
-
get fallback() {
|
|
104
|
-
return (0, __alloy_js_core_jsx_runtime.createComponent)(CommandRouterRoute, {});
|
|
105
|
-
},
|
|
106
|
-
children: route
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
});
|
|
66
|
+
return __alloy_js_core.code`command = args[${index.value}];`;
|
|
110
67
|
}
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
|
|
68
|
+
}),
|
|
69
|
+
(0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
70
|
+
(0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {})
|
|
71
|
+
];
|
|
72
|
+
}
|
|
114
73
|
}),
|
|
115
|
-
(0, __alloy_js_core_jsx_runtime.createComponent)(
|
|
116
|
-
|
|
74
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(CommandRouterBody, {
|
|
75
|
+
segments,
|
|
76
|
+
commands,
|
|
77
|
+
route
|
|
78
|
+
})
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The internal command router body logic component.
|
|
85
|
+
*/
|
|
86
|
+
function CommandRouterBody(props) {
|
|
87
|
+
const { commands, route } = props;
|
|
88
|
+
const context = (0, __powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
|
|
89
|
+
return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
|
|
90
|
+
get when() {
|
|
91
|
+
return commands && Object.keys(commands).length > 0;
|
|
92
|
+
},
|
|
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,
|
|
117
100
|
get children() {
|
|
118
|
-
return
|
|
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 = didYouMean(command, [${Object.values(commands ?? {}).map((cmd) => `"${cmd.name}"${(cmd.alias ?? []).map((alias, i) => i === 0 ? `, "${alias}"` : ` "${alias}"`).join("")}`).join(", ")}], {
|
|
119
148
|
caseSensitive: ${JSON.stringify(context.config.isCaseSensitive)},
|
|
120
149
|
returnType: ReturnTypeEnums.ALL_CLOSEST_MATCHES,
|
|
121
150
|
thresholdType: ThresholdTypeEnums.SIMILARITY,
|
|
122
151
|
threshold: 0.75
|
|
123
152
|
});
|
|
124
153
|
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}"\`)}?\` : ""} \`);`;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
];
|
|
154
|
+
}
|
|
155
|
+
})];
|
|
128
156
|
}
|
|
129
157
|
});
|
|
130
158
|
}
|
|
131
159
|
|
|
132
160
|
//#endregion
|
|
133
161
|
exports.CommandRouter = CommandRouter;
|
|
162
|
+
exports.CommandRouterBody = CommandRouterBody;
|
|
134
163
|
exports.CommandRouterRoute = CommandRouterRoute;
|
|
135
164
|
//# sourceMappingURL=command-router.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-router.cjs","names":["code","computed","For","Show","ElseIfClause","IfStatement","VarDeclaration","usePowerlines","DynamicImportStatement","CommandContext","useCommand","isDynamicPathSegment","pascalCase","CommandRouterRoute","command","_$createComponent","when","isVirtual","children","name","importPath","segments","filter","segment","length","exportName","_$createIntrinsic","_$memo","CommandRouter","props","commands","route","context","index","Object","keys","type","initializer","condition","value","each","values","subcommand","idx","Provider","Boolean","fallback","config","isCaseSensitive","toLowerCase","replaceAll","alias","map","join","cmd","i","JSON","stringify"],"sources":["../../src/components/command-router.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 ElseIfClause,\n IfStatement,\n VarDeclaration\n} from \"@alloy-js/typescript\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport { DynamicImportStatement } from \"@powerlines/plugin-alloy/typescript/components/dynamic-import-statement\";\nimport { CommandContext, useCommand } from \"@shell-shock/core/contexts/command\";\nimport { isDynamicPathSegment } from \"@shell-shock/core/plugin-utils/context-helpers\";\nimport type { CommandTree } from \"@shell-shock/core/types/command\";\nimport { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport type { ScriptPresetContext } from \"../types/plugin\";\n\nexport function CommandRouterRoute() {\n const command = useCommand();\n\n return (\n <>\n <Show when={!command.isVirtual}>\n <DynamicImportStatement\n name={`handle${pascalCase(command.name)}`}\n importPath={`./${\n command.segments.filter(segment => !isDynamicPathSegment(segment))[\n command.segments.filter(segment => !isDynamicPathSegment(segment))\n .length - 1\n ]\n }`}\n exportName=\"handler\"\n />\n </Show>\n <hbr />\n {code`return handle${pascalCase(command.name)}(args);`}\n </>\n );\n}\n\nexport interface CommandRouterProps {\n segments: string[];\n commands?: Record<string, CommandTree>;\n route?: Children;\n}\n\n/**\n * The command router component.\n */\nexport function CommandRouter(props: CommandRouterProps) {\n const { segments, commands, route } = props;\n\n const context = usePowerlines<ScriptPresetContext>();\n const index = computed(() => 2 + (segments.length ?? 0));\n\n return (\n <Show when={commands && Object.keys(commands).length > 0}>\n <VarDeclaration\n let\n name=\"command\"\n type=\"string\"\n initializer={code`\"\";`}\n />\n <hbr />\n <IfStatement\n condition={code`args.length > ${\n index.value\n } && args[${index.value}]`}>{code`command = args[${\n index.value\n }];`}</IfStatement>\n <hbr />\n <For each={Object.values(commands ?? {})}>\n {(subcommand, idx) => (\n <CommandContext.Provider value={subcommand}>\n <Show\n when={Boolean(idx)}\n fallback={\n <IfStatement\n condition={code`${\n context.config.isCaseSensitive\n ? \"command\"\n : 'command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")'\n } === \"${\n context.config.isCaseSensitive\n ? subcommand.name\n : subcommand.name\n .toLowerCase()\n .replaceAll(\"-\", \"\")\n .replaceAll(\"_\", \"\")\n }\"${\n subcommand.alias && subcommand.alias.length > 0\n ? ` || ${subcommand.alias\n .map(\n alias =>\n `${context.config.isCaseSensitive ? \"command\" : 'command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")'} === \"${\n context.config.isCaseSensitive\n ? alias\n : alias\n .toLowerCase()\n .replaceAll(\"-\", \"\")\n .replaceAll(\"_\", \"\")\n }\"`\n )\n .join(\" || \")}`\n : \"\"\n }`}>\n <Show when={Boolean(route)} fallback={<CommandRouterRoute />}>\n {route}\n </Show>\n </IfStatement>\n }>\n <ElseIfClause\n condition={code`${\n context.config.isCaseSensitive\n ? \"command\"\n : 'command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")'\n } === \"${\n context.config.isCaseSensitive\n ? subcommand.name\n : subcommand.name\n .toLowerCase()\n .replaceAll(\"-\", \"\")\n .replaceAll(\"_\", \"\")\n }\"${\n subcommand.alias && subcommand.alias.length > 0\n ? ` || ${subcommand.alias\n .map(\n alias =>\n `${context.config.isCaseSensitive ? \"command\" : 'command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")'} === \"${\n context.config.isCaseSensitive\n ? alias\n : alias\n .toLowerCase()\n .replaceAll(\"-\", \"\")\n .replaceAll(\"_\", \"\")\n }\"`\n )\n .join(\" || \")}`\n : \"\"\n }`}>\n <Show when={Boolean(route)} fallback={<CommandRouterRoute />}>\n {route}\n </Show>\n </ElseIfClause>\n </Show>\n </CommandContext.Provider>\n )}\n </For>\n <ElseIfClause\n condition={code`Boolean(command)`}>{code`const suggestions = didYouMean(command, [${Object.values(\n commands ?? {}\n )\n .map(\n cmd =>\n `\"${cmd.name}\"${(cmd.alias ?? []).map((alias, i) => (i === 0 ? `, \"${alias}\"` : ` \"${alias}\"`)).join(\"\")}`\n )\n .join(\", \")}], {\n caseSensitive: ${JSON.stringify(context.config.isCaseSensitive)},\n returnType: ReturnTypeEnums.ALL_CLOSEST_MATCHES,\n thresholdType: ThresholdTypeEnums.SIMILARITY,\n threshold: 0.75\n });\n 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}\"\\`)}?\\` : \"\"} \\`);`}</ElseIfClause>\n </Show>\n );\n}\n"],"mappings":";;;;;;;;;;;AAiCA,SAAgBa,qBAAqB;CACnC,MAAMC,+DAAsB;AAE5B,QAAA;mDAEKX,sBAAI;GAAA,IAACa,OAAI;AAAA,WAAE,CAACF,QAAQG;;GAAS,IAAAC,WAAA;AAAA,4DAC3BV,iGAAsB;KAA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,WAAQ;AAAA,qEAAGjC,oBAAkB,EAAA,CAAA;;YAAAK,UACtDa;YAAK,CAAA;;UAAA,CAAA;;QAAA,CAAA;;MAAA,CAAA;KAKf,CAAA;qDAEF3B,oCAAY;KACXkC,WAAWtC,oBAAI;KAAkB,IAAAkB,WAAA;AAAA,aAAGlB,oBAAI,4CAA4CkC,OAAOO,OAC3FX,YAAY,EACd,CAAC,CACEsB,KACCE,QACE,IAAIA,IAAInC,KAAI,IAAKmC,IAAIH,SAAS,EAAE,EAAEC,KAAKD,OAAOI,MAAOA,MAAM,IAAI,MAAMJ,MAAK,KAAM,KAAKA,MAAK,GAAK,CAACE,KAAK,GAAG,GAC3G,CACAA,KAAK,KAAK,CAAA;2BACQG,KAAKC,UAAUzB,QAAQe,OAAOC,gBAAgB,CAAA;;;;;;;KAK4N,CAAA;IAAA;;EAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"command-router.cjs","names":["code","computed","For","Show","ElseIfClause","IfStatement","VarDeclaration","usePowerlines","DynamicImportStatement","CommandContext","useCommand","isDynamicPathSegment","pascalCase","CommandRouterRoute","command","_$createComponent","when","isVirtual","children","name","importPath","segments","filter","segment","length","exportName","_$createIntrinsic","_$memo","CommandRouter","props","commands","route","index","Object","keys","type","initializer","condition","value","CommandRouterBody","context","each","values","subcommand","idx","Provider","Boolean","fallback","config","isCaseSensitive","toLowerCase","replaceAll","alias","map","join","cmd","i","JSON","stringify"],"sources":["../../src/components/command-router.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 ElseIfClause,\n IfStatement,\n VarDeclaration\n} from \"@alloy-js/typescript\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport { DynamicImportStatement } from \"@powerlines/plugin-alloy/typescript/components/dynamic-import-statement\";\nimport { CommandContext, useCommand } from \"@shell-shock/core/contexts/command\";\nimport { isDynamicPathSegment } from \"@shell-shock/core/plugin-utils/context-helpers\";\nimport type { CommandTree } from \"@shell-shock/core/types/command\";\nimport { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport type { ScriptPresetContext } from \"../types/plugin\";\n\nexport function CommandRouterRoute() {\n const command = useCommand();\n\n return (\n <>\n <Show when={!command.isVirtual}>\n <DynamicImportStatement\n name={`handle${pascalCase(command.name)}`}\n importPath={`./${\n command.segments.filter(segment => !isDynamicPathSegment(segment))[\n command.segments.filter(segment => !isDynamicPathSegment(segment))\n .length - 1\n ]\n }`}\n exportName=\"handler\"\n />\n </Show>\n <hbr />\n {code`return handle${pascalCase(command.name)}(args);`}\n </>\n );\n}\n\nexport interface CommandRouterProps {\n segments: string[];\n commands?: Record<string, CommandTree>;\n route?: Children;\n}\n\n/**\n * The command router component.\n */\nexport function CommandRouter(props: CommandRouterProps) {\n const { segments, commands, route } = props;\n\n const index = computed(() => 2 + (segments.length ?? 0));\n\n return (\n <Show when={commands && Object.keys(commands).length > 0}>\n <VarDeclaration\n let\n name=\"command\"\n type=\"string\"\n initializer={code`\"\";`}\n />\n <hbr />\n <hbr />\n <Show when={commands && Object.keys(commands).length > 0}>\n <IfStatement\n condition={code`args.length > ${\n index.value\n } && args[${index.value}]`}>{code`command = args[${\n index.value\n }];`}</IfStatement>\n <hbr />\n <hbr />\n </Show>\n <CommandRouterBody\n segments={segments}\n commands={commands}\n route={route}\n />\n </Show>\n );\n}\n\n/**\n * The internal command router body logic component.\n */\nexport function CommandRouterBody(props: CommandRouterProps) {\n const { commands, route } = props;\n\n const context = usePowerlines<ScriptPresetContext>();\n\n return (\n <Show when={commands && Object.keys(commands).length > 0}>\n <For each={Object.values(commands ?? {})}>\n {(subcommand, idx) => (\n <CommandContext.Provider value={subcommand}>\n <Show\n when={Boolean(idx)}\n fallback={\n <IfStatement\n condition={code`${\n context.config.isCaseSensitive\n ? \"command\"\n : 'command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")'\n } === \"${\n context.config.isCaseSensitive\n ? subcommand.name\n : subcommand.name\n .toLowerCase()\n .replaceAll(\"-\", \"\")\n .replaceAll(\"_\", \"\")\n }\"${\n subcommand.alias && subcommand.alias.length > 0\n ? ` || ${subcommand.alias\n .map(\n alias =>\n `${context.config.isCaseSensitive ? \"command\" : 'command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")'} === \"${\n context.config.isCaseSensitive\n ? alias\n : alias\n .toLowerCase()\n .replaceAll(\"-\", \"\")\n .replaceAll(\"_\", \"\")\n }\"`\n )\n .join(\" || \")}`\n : \"\"\n }`}>\n <Show when={Boolean(route)} fallback={<CommandRouterRoute />}>\n {route}\n </Show>\n </IfStatement>\n }>\n <ElseIfClause\n condition={code`${\n context.config.isCaseSensitive\n ? \"command\"\n : 'command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")'\n } === \"${\n context.config.isCaseSensitive\n ? subcommand.name\n : subcommand.name\n .toLowerCase()\n .replaceAll(\"-\", \"\")\n .replaceAll(\"_\", \"\")\n }\"${\n subcommand.alias && subcommand.alias.length > 0\n ? ` || ${subcommand.alias\n .map(\n alias =>\n `${context.config.isCaseSensitive ? \"command\" : 'command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")'} === \"${\n context.config.isCaseSensitive\n ? alias\n : alias\n .toLowerCase()\n .replaceAll(\"-\", \"\")\n .replaceAll(\"_\", \"\")\n }\"`\n )\n .join(\" || \")}`\n : \"\"\n }`}>\n <Show when={Boolean(route)} fallback={<CommandRouterRoute />}>\n {route}\n </Show>\n </ElseIfClause>\n </Show>\n </CommandContext.Provider>\n )}\n </For>\n <ElseIfClause\n condition={code`Boolean(command) && !command.startsWith(\"-\")`}>{code`const suggestions = didYouMean(command, [${Object.values(\n commands ?? {}\n )\n .map(\n cmd =>\n `\"${cmd.name}\"${(cmd.alias ?? []).map((alias, i) => (i === 0 ? `, \"${alias}\"` : ` \"${alias}\"`)).join(\"\")}`\n )\n .join(\", \")}], {\n caseSensitive: ${JSON.stringify(context.config.isCaseSensitive)},\n returnType: ReturnTypeEnums.ALL_CLOSEST_MATCHES,\n thresholdType: ThresholdTypeEnums.SIMILARITY,\n threshold: 0.75\n });\n 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}\"\\`)}?\\` : \"\"} \\`);`}</ElseIfClause>\n </Show>\n );\n}\n"],"mappings":";;;;;;;;;;;AAiCA,SAAgBa,qBAAqB;CACnC,MAAMC,+DAAsB;AAE5B,QAAA;mDAEKX,sBAAI;GAAA,IAACa,OAAI;AAAA,WAAE,CAACF,QAAQG;;GAAS,IAAAC,WAAA;AAAA,4DAC3BV,iGAAsB;KAAA,IACrBW,OAAI;AAAA,aAAE,4DAAoBL,QAAQK,KAAK;;KAAE,IACzCC,aAAU;AAAA,aAAE,KACVN,QAAQO,SAASC,QAAOC,YAAW,2EAAsBA,QAAQ,CAAC,CAChET,QAAQO,SAASC,QAAOC,YAAW,2EAAsBA,QAAQ,CAAC,CAC/DC,SAAS;;KAGhBC,YAAU;KAAA,CAAA;;GAAA,CAAA;mDAAA,OAAA,EAAA,CAAA;8CAIbzB,oBAAI,mEAA2Bc,QAAQK,KAAK,CAAA,SAAS;EAAA;;;;;AAc5D,SAAgBS,cAAcC,OAA2B;CACvD,MAA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;AAAA,kEACDf,sBAAI;WAAA,IAACa,OAAI;AAAA,mBAAE8B,QAAQf,MAAM;;WAAA,IAAEgB,WAAQ;AAAA,oEAAGlC,oBAAkB,EAAA,CAAA;;WAAAK,UACtDa;WAAK,CAAA;;SAAA,CAAA;;OAAA,CAAA;;KAAA,CAAA;IAKf,CAAA,mDAEF3B,oCAAY;IACXiC,WAAWrC,oBAAI;IAA8C,IAAAkB,WAAA;AAAA,YAAGlB,oBAAI,4CAA4CiC,OAAOS,OACvHZ,YAAY,EACd,CAAC,CACEuB,KACCE,QACE,IAAIA,IAAIpC,KAAI,IAAKoC,IAAIH,SAAS,EAAE,EAAEC,KAAKD,OAAOI,MAAOA,MAAM,IAAI,MAAMJ,MAAK,KAAM,KAAKA,MAAK,GAAK,CAACE,KAAK,GAAG,GAC3G,CACAA,KAAK,KAAK,CAAA;2BACQG,KAAKC,UAAUlB,QAAQQ,OAAOC,gBAAgB,CAAA;;;;;;;IAK4N,CAAA,CAAA;;EAAA,CAAA"}
|
|
@@ -12,6 +12,10 @@ interface CommandRouterProps {
|
|
|
12
12
|
* The command router component.
|
|
13
13
|
*/
|
|
14
14
|
declare function CommandRouter(props: CommandRouterProps): Children;
|
|
15
|
+
/**
|
|
16
|
+
* The internal command router body logic component.
|
|
17
|
+
*/
|
|
18
|
+
declare function CommandRouterBody(props: CommandRouterProps): Children;
|
|
15
19
|
//#endregion
|
|
16
|
-
export { CommandRouter, CommandRouterProps, CommandRouterRoute };
|
|
20
|
+
export { CommandRouter, CommandRouterBody, CommandRouterProps, CommandRouterRoute };
|
|
17
21
|
//# sourceMappingURL=command-router.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-router.d.cts","names":[],"sources":["../../src/components/command-router.tsx"],"sourcesContent":[],"mappings":";;;;iBAiCgB,kBAAA,CAAA,GAAkB;UAuBjB,kBAAA;EAvBD,QAAA,EAAA,MAAA,EAAA;EAuBC,QAAA,CAAA,EAEJ,MAFI,CAAA,MAAkB,EAEP,WAFO,CAAA;EAEP,KAAA,CAAA,EAClB,QADkB;;;;AAO5B;
|
|
1
|
+
{"version":3,"file":"command-router.d.cts","names":[],"sources":["../../src/components/command-router.tsx"],"sourcesContent":[],"mappings":";;;;iBAiCgB,kBAAA,CAAA,GAAkB;UAuBjB,kBAAA;EAvBD,QAAA,EAAA,MAAA,EAAA;EAuBC,QAAA,CAAA,EAEJ,MAFI,CAAA,MAAkB,EAEP,WAFO,CAAA;EAEP,KAAA,CAAA,EAClB,QADkB;;;;AAO5B;AAqCgB,iBArCA,aAAA,CAqCyB,KAAA,EArCJ,kBAqCsB,CAAA,EArCJ,QAqCI;;;;iBAA3C,iBAAA,QAAyB,qBAAkB"}
|
|
@@ -12,6 +12,10 @@ interface CommandRouterProps {
|
|
|
12
12
|
* The command router component.
|
|
13
13
|
*/
|
|
14
14
|
declare function CommandRouter(props: CommandRouterProps): Children;
|
|
15
|
+
/**
|
|
16
|
+
* The internal command router body logic component.
|
|
17
|
+
*/
|
|
18
|
+
declare function CommandRouterBody(props: CommandRouterProps): Children;
|
|
15
19
|
//#endregion
|
|
16
|
-
export { CommandRouter, CommandRouterProps, CommandRouterRoute };
|
|
20
|
+
export { CommandRouter, CommandRouterBody, CommandRouterProps, CommandRouterRoute };
|
|
17
21
|
//# sourceMappingURL=command-router.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-router.d.mts","names":[],"sources":["../../src/components/command-router.tsx"],"sourcesContent":[],"mappings":";;;;iBAiCgB,kBAAA,CAAA,GAAkB;UAuBjB,kBAAA;EAvBD,QAAA,EAAA,MAAA,EAAA;EAuBC,QAAA,CAAA,EAEJ,MAFI,CAAA,MAAkB,EAEP,WAFO,CAAA;EAEP,KAAA,CAAA,EAClB,QADkB;;;;AAO5B;
|
|
1
|
+
{"version":3,"file":"command-router.d.mts","names":[],"sources":["../../src/components/command-router.tsx"],"sourcesContent":[],"mappings":";;;;iBAiCgB,kBAAA,CAAA,GAAkB;UAuBjB,kBAAA;EAvBD,QAAA,EAAA,MAAA,EAAA;EAuBC,QAAA,CAAA,EAEJ,MAFI,CAAA,MAAkB,EAEP,WAFO,CAAA;EAEP,KAAA,CAAA,EAClB,QADkB;;;;AAO5B;AAqCgB,iBArCA,aAAA,CAqCyB,KAAA,EArCJ,kBAqCsB,CAAA,EArCJ,QAqCI;;;;iBAA3C,iBAAA,QAAyB,qBAAkB"}
|