@shell-shock/preset-script 0.1.1 → 0.1.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/args-parser-logic.cjs +678 -0
- package/dist/components/args-parser-logic.cjs.map +1 -0
- package/dist/components/args-parser-logic.d.cts +45 -0
- package/dist/components/args-parser-logic.d.cts.map +1 -0
- package/dist/components/args-parser-logic.d.mts +45 -0
- package/dist/components/args-parser-logic.d.mts.map +1 -0
- package/dist/components/args-parser-logic.mjs +672 -0
- package/dist/components/args-parser-logic.mjs.map +1 -0
- package/dist/components/bin-entry.cjs +179 -0
- package/dist/components/bin-entry.cjs.map +1 -0
- package/dist/components/{entry/bin.d.cts → bin-entry.d.cts} +9 -3
- package/dist/components/bin-entry.d.cts.map +1 -0
- package/dist/components/{entry/bin.d.mts → bin-entry.d.mts} +9 -3
- package/dist/components/bin-entry.d.mts.map +1 -0
- package/dist/components/bin-entry.mjs +176 -0
- package/dist/components/bin-entry.mjs.map +1 -0
- package/dist/components/command-entry.cjs +162 -0
- package/dist/components/command-entry.cjs.map +1 -0
- package/dist/components/command-entry.d.cts +24 -0
- package/dist/components/command-entry.d.cts.map +1 -0
- package/dist/components/command-entry.d.mts +24 -0
- package/dist/components/command-entry.d.mts.map +1 -0
- package/dist/components/command-entry.mjs +158 -0
- package/dist/components/command-entry.mjs.map +1 -0
- package/dist/components/command-router.cjs +104 -74
- package/dist/components/command-router.cjs.map +1 -1
- package/dist/components/command-router.d.cts +13 -4
- package/dist/components/command-router.d.cts.map +1 -0
- package/dist/components/command-router.d.mts +13 -4
- package/dist/components/command-router.d.mts.map +1 -0
- package/dist/components/command-router.mjs +103 -73
- package/dist/components/command-router.mjs.map +1 -1
- package/dist/components/console-builtin.cjs +2083 -0
- package/dist/components/console-builtin.cjs.map +1 -0
- package/dist/components/console-builtin.d.cts +56 -0
- package/dist/components/console-builtin.d.cts.map +1 -0
- package/dist/components/console-builtin.d.mts +56 -0
- package/dist/components/console-builtin.d.mts.map +1 -0
- package/dist/components/console-builtin.mjs +2074 -0
- package/dist/components/console-builtin.mjs.map +1 -0
- package/dist/components/help.cjs +130 -0
- package/dist/components/help.cjs.map +1 -0
- package/dist/components/help.d.cts +57 -0
- package/dist/components/help.d.cts.map +1 -0
- package/dist/components/help.d.mts +57 -0
- package/dist/components/help.d.mts.map +1 -0
- package/dist/components/help.mjs +126 -0
- package/dist/components/help.mjs.map +1 -0
- package/dist/components/index.cjs +39 -15
- package/dist/components/index.d.cts +9 -7
- package/dist/components/index.d.mts +9 -7
- package/dist/components/index.mjs +8 -6
- package/dist/components/utils-builtin.cjs +612 -0
- package/dist/components/utils-builtin.cjs.map +1 -0
- package/dist/components/utils-builtin.d.cts +32 -0
- package/dist/components/utils-builtin.d.cts.map +1 -0
- package/dist/components/utils-builtin.d.mts +32 -0
- package/dist/components/utils-builtin.d.mts.map +1 -0
- package/dist/components/utils-builtin.mjs +605 -0
- package/dist/components/utils-builtin.mjs.map +1 -0
- package/dist/components/virtual-command-entry.cjs +133 -0
- package/dist/components/virtual-command-entry.cjs.map +1 -0
- package/dist/components/virtual-command-entry.d.cts +21 -0
- package/dist/components/virtual-command-entry.d.cts.map +1 -0
- package/dist/components/virtual-command-entry.d.mts +21 -0
- package/dist/components/virtual-command-entry.d.mts.map +1 -0
- package/dist/components/virtual-command-entry.mjs +130 -0
- package/dist/components/virtual-command-entry.mjs.map +1 -0
- package/dist/contexts/index.cjs +4 -0
- package/dist/contexts/index.d.cts +2 -0
- package/dist/contexts/index.d.mts +2 -0
- package/dist/contexts/index.mjs +3 -0
- package/dist/contexts/theme.d.cts +20 -0
- package/dist/contexts/theme.d.cts.map +1 -0
- package/dist/contexts/theme.d.mts +20 -0
- package/dist/contexts/theme.d.mts.map +1 -0
- package/dist/helpers/ansi-utils.cjs +28 -4
- package/dist/helpers/ansi-utils.cjs.map +1 -1
- package/dist/helpers/ansi-utils.d.cts +68 -0
- package/dist/helpers/ansi-utils.d.cts.map +1 -0
- package/dist/helpers/ansi-utils.d.mts +68 -0
- package/dist/helpers/ansi-utils.d.mts.map +1 -0
- package/dist/helpers/ansi-utils.mjs +28 -4
- package/dist/helpers/ansi-utils.mjs.map +1 -1
- package/dist/helpers/get-default-options.cjs +6 -13
- package/dist/helpers/get-default-options.cjs.map +1 -1
- package/dist/helpers/get-default-options.mjs +6 -13
- package/dist/helpers/get-default-options.mjs.map +1 -1
- package/dist/index.cjs +114 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +115 -28
- package/dist/index.mjs.map +1 -1
- package/dist/types/plugin.d.cts +1 -6
- package/dist/types/plugin.d.cts.map +1 -0
- package/dist/types/plugin.d.mts +1 -6
- package/dist/types/plugin.d.mts.map +1 -0
- package/package.json +163 -71
- package/dist/components/builtin/console.cjs +0 -1232
- package/dist/components/builtin/console.cjs.map +0 -1
- package/dist/components/builtin/console.d.cts +0 -37
- package/dist/components/builtin/console.d.mts +0 -37
- package/dist/components/builtin/console.mjs +0 -1225
- package/dist/components/builtin/console.mjs.map +0 -1
- package/dist/components/builtin/index.cjs +0 -9
- package/dist/components/builtin/index.d.cts +0 -2
- package/dist/components/builtin/index.d.mts +0 -2
- package/dist/components/builtin/index.mjs +0 -3
- package/dist/components/entry/bin.cjs +0 -92
- package/dist/components/entry/bin.cjs.map +0 -1
- package/dist/components/entry/bin.mjs +0 -91
- package/dist/components/entry/bin.mjs.map +0 -1
- package/dist/components/entry/command.cjs +0 -54
- package/dist/components/entry/command.cjs.map +0 -1
- package/dist/components/entry/command.d.cts +0 -15
- package/dist/components/entry/command.d.mts +0 -15
- package/dist/components/entry/command.mjs +0 -53
- package/dist/components/entry/command.mjs.map +0 -1
- package/dist/components/entry/index.cjs +0 -3
- package/dist/components/entry/index.d.cts +0 -2
- package/dist/components/entry/index.d.mts +0 -2
- package/dist/components/entry/index.mjs +0 -3
- package/dist/components/shutdown.cjs +0 -93
- package/dist/components/shutdown.cjs.map +0 -1
- package/dist/components/shutdown.d.cts +0 -14
- package/dist/components/shutdown.d.mts +0 -14
- package/dist/components/shutdown.mjs +0 -91
- package/dist/components/shutdown.mjs.map +0 -1
- package/dist/contexts/command.cjs +0 -21
- package/dist/contexts/command.cjs.map +0 -1
- package/dist/contexts/command.mjs +0 -19
- package/dist/contexts/command.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-router.cjs","names":["code","computed","For","Show","ElseIfClause","IfStatement","VarDeclaration","
|
|
1
|
+
{"version":3,"file":"command-router.cjs","names":["code","computed","For","Show","ElseIfClause","IfStatement","VarDeclaration","DynamicImportStatement","CommandContext","useCommand","isVariableCommandPath","pascalCase","CommandRouterRoute","command","_$createComponent","when","isVirtual","children","name","importPath","path","segments","filter","segment","length","exportName","_$createIntrinsic","_$memo","CommandRouter","props","commands","route","index","Object","keys","type","initializer","condition","value","each","values","subcommand","idx","Provider","Boolean","fallback","toLowerCase"],"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 { DynamicImportStatement } from \"@powerlines/plugin-alloy/typescript/components/dynamic-import-statement\";\nimport { CommandContext, useCommand } from \"@shell-shock/core/contexts/command\";\nimport { isVariableCommandPath } 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\";\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.path.segments.filter(\n segment => !isVariableCommandPath(segment)\n )[\n command.path.segments.filter(\n segment => !isVariableCommandPath(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 path: 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 { path, commands, route } = props;\n\n const command = useCommand();\n const index = computed(() => 2 + (path.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 when={subcommand.name !== command?.name}>\n <Show\n when={Boolean(idx)}\n fallback={\n <IfStatement\n condition={code`command.toLowerCase() === \"${subcommand.name.toLowerCase()}\"`}>\n <Show\n when={Boolean(route)}\n fallback={<CommandRouterRoute />}>\n {route}\n </Show>\n </IfStatement>\n }>\n <ElseIfClause\n condition={code`command.toLowerCase() === \"${subcommand.name.toLowerCase()}\"`}>\n <Show when={Boolean(route)} fallback={<CommandRouterRoute />}>\n {route}\n </Show>\n </ElseIfClause>\n </Show>\n </Show>\n </CommandContext.Provider>\n )}\n </For>\n <ElseIfClause\n condition={code`Boolean(command)`}>{code`error(\"Unknown command: \" + command);`}</El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ACpCwB,YAAYC,yDACXlC,mDAAemC,UAAQ;MAACL,OAAOG;MAAU,IAAAxB,WAAA;AAAA,+DACvCd,sBAAI;QAAA,IAACY,OAAI;AAAA,gBAAE0B,WAAWvB,SAASL,SAASK;;QAAI,IAAAD,WAAA;AAAA,iEAC1Cd,sBAAI;UAAA,IACHY,OAAI;AAAA,kBAAE6B,QAAQF,IAAI;;UAAA,IAClBG,WAAQ;AAAA,mEACLxC,mCAAW;YAAA,IACVgC,YAAS;AAAA,oBAAErC,oBAAI,8BAA8ByC,WAAWvB,KAAK4B,aAAa,CAAA;;YAAG,IAAA7B,WAAA;AAAA,qEAC5Ed,sBAAI;cAAA,IACHY,OAAI;AAAA,sBAAE6B,QAAQb,MAAM;;cAAA,IACpBc,WAAQ;AAAA,uEAAGjC,oBAAkB,EAAA,CAAA;;cAAAK,UAC5Bc;cAAK,CAAA;;YAAA,CAAA;;UAAA,IAAAd,WAAA;AAAA,mEAIXb,oCAAY;YAAA,IACXiC,YAAS;AAAA,oBAAErC,oBAAI,8BAA8ByC,WAAWvB,KAAK4B,aAAa,CAAA;;YAAG,IAAA7B,WAAA;AAAA,qEAC5Ed,sBAAI;cAAA,IAACY,OAAI;AAAA,sBAAE6B,QAAQb,MAAM;;cAAA,IAAEc,WAAQ;AAAA,uEAAGjC,oBAAkB,EAAA,CAAA;;cAAAK,UACtDc;cAAK,CAAA;;YAAA,CAAA;;UAAA,CAAA;;QAAA,CAAA;;MAAA,CAAA;KAMjB,CAAA;qDAEF3B,oCAAY;KACXiC,WAAWrC,oBAAI;KAAkBiB,UAAGjB,oBAAI;KAAuC,CAAA;IAAA;;EAAA,CAAA"}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Children } from "@alloy-js/core";
|
|
2
|
+
import { CommandTree } from "@shell-shock/core/types/command";
|
|
2
3
|
|
|
3
4
|
//#region src/components/command-router.d.ts
|
|
4
|
-
declare function CommandRouterRoute():
|
|
5
|
-
|
|
5
|
+
declare function CommandRouterRoute(): Children;
|
|
6
|
+
interface CommandRouterProps {
|
|
7
|
+
path: string[];
|
|
8
|
+
commands?: Record<string, CommandTree>;
|
|
9
|
+
route?: Children;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The command router component.
|
|
13
|
+
*/
|
|
14
|
+
declare function CommandRouter(props: CommandRouterProps): Children;
|
|
6
15
|
//#endregion
|
|
7
|
-
export { CommandRouter, CommandRouterRoute };
|
|
16
|
+
export { CommandRouter, CommandRouterProps, CommandRouterRoute };
|
|
8
17
|
//# 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":";;;;iBA+BgB,kBAAA,CAAA,GAAkB;UA0BjB,kBAAA;EA1BD,IAAA,EAAA,MAAA,EAAA;EA0BC,QAAA,CAAA,EAEJ,MAFI,CAAA,MAAkB,EAEP,WAFO,CAAA;EAEP,KAAA,CAAA,EAClB,QADkB;;;;AAO5B;iBAAgB,aAAA,QAAqB,qBAAkB"}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Children } from "@alloy-js/core";
|
|
2
|
+
import { CommandTree } from "@shell-shock/core/types/command";
|
|
2
3
|
|
|
3
4
|
//#region src/components/command-router.d.ts
|
|
4
|
-
declare function CommandRouterRoute():
|
|
5
|
-
|
|
5
|
+
declare function CommandRouterRoute(): Children;
|
|
6
|
+
interface CommandRouterProps {
|
|
7
|
+
path: string[];
|
|
8
|
+
commands?: Record<string, CommandTree>;
|
|
9
|
+
route?: Children;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The command router component.
|
|
13
|
+
*/
|
|
14
|
+
declare function CommandRouter(props: CommandRouterProps): Children;
|
|
6
15
|
//#endregion
|
|
7
|
-
export { CommandRouter, CommandRouterRoute };
|
|
16
|
+
export { CommandRouter, CommandRouterProps, CommandRouterRoute };
|
|
8
17
|
//# 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":";;;;iBA+BgB,kBAAA,CAAA,GAAkB;UA0BjB,kBAAA;EA1BD,IAAA,EAAA,MAAA,EAAA;EA0BC,QAAA,CAAA,EAEJ,MAFI,CAAA,MAAkB,EAEP,WAFO,CAAA;EAEP,KAAA,CAAA,EAClB,QADkB;;;;AAO5B;iBAAgB,aAAA,QAAqB,qBAAkB"}
|
|
@@ -1,99 +1,129 @@
|
|
|
1
|
-
import { CommandContext, useCommand } from "../contexts/command.mjs";
|
|
2
1
|
import { createComponent, createIntrinsic, memo } from "@alloy-js/core/jsx-runtime";
|
|
3
2
|
import { For, Show, code, computed } from "@alloy-js/core";
|
|
4
3
|
import { ElseIfClause, IfStatement, VarDeclaration } from "@alloy-js/typescript";
|
|
5
|
-
import {
|
|
6
|
-
import { DynamicImportStatement } from "@powerlines/plugin-alloy/typescript/components/dynamic-import-statement";
|
|
4
|
+
import { isVariableCommandPath } from "@shell-shock/core/plugin-utils/context-helpers";
|
|
7
5
|
import { pascalCase } from "@stryke/string-format/pascal-case";
|
|
6
|
+
import { DynamicImportStatement } from "@powerlines/plugin-alloy/typescript/components/dynamic-import-statement";
|
|
7
|
+
import { CommandContext, useCommand } from "@shell-shock/core/contexts/command";
|
|
8
8
|
|
|
9
9
|
//#region src/components/command-router.tsx
|
|
10
10
|
function CommandRouterRoute() {
|
|
11
11
|
const command = useCommand();
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
get children() {
|
|
20
|
-
return [
|
|
21
|
-
createComponent(DynamicImportStatement, {
|
|
12
|
+
return [
|
|
13
|
+
createComponent(Show, {
|
|
14
|
+
get when() {
|
|
15
|
+
return !command.isVirtual;
|
|
16
|
+
},
|
|
17
|
+
get children() {
|
|
18
|
+
return createComponent(DynamicImportStatement, {
|
|
22
19
|
get name() {
|
|
23
20
|
return `handle${pascalCase(command.name)}`;
|
|
24
21
|
},
|
|
25
22
|
get importPath() {
|
|
26
|
-
return `./${command.
|
|
23
|
+
return `./${command.path.segments.filter((segment) => !isVariableCommandPath(segment))[command.path.segments.filter((segment) => !isVariableCommandPath(segment)).length - 1]}`;
|
|
27
24
|
},
|
|
28
25
|
exportName: "handler"
|
|
29
|
-
})
|
|
30
|
-
createIntrinsic("hbr", {}),
|
|
31
|
-
memo(() => code`return handle${pascalCase(command.name)}(args);`)
|
|
32
|
-
];
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
function CommandRouter() {
|
|
37
|
-
const context = usePowerlines();
|
|
38
|
-
const command = useCommand();
|
|
39
|
-
const index = computed(() => 2 + (command?.path.length ?? 0));
|
|
40
|
-
return [
|
|
41
|
-
createComponent(VarDeclaration, {
|
|
42
|
-
"let": true,
|
|
43
|
-
name: "command",
|
|
44
|
-
type: "string",
|
|
45
|
-
initializer: code`"";`
|
|
46
|
-
}),
|
|
47
|
-
createIntrinsic("hbr", {}),
|
|
48
|
-
createComponent(IfStatement, {
|
|
49
|
-
get condition() {
|
|
50
|
-
return code`args.length > ${index.value} && args[${index.value}]`;
|
|
51
|
-
},
|
|
52
|
-
get children() {
|
|
53
|
-
return code`command = args[${index.value}];`;
|
|
26
|
+
});
|
|
54
27
|
}
|
|
55
28
|
}),
|
|
56
29
|
createIntrinsic("hbr", {}),
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
30
|
+
memo(() => code`return handle${pascalCase(command.name)}(args);`)
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The command router component.
|
|
35
|
+
*/
|
|
36
|
+
function CommandRouter(props) {
|
|
37
|
+
const { path, commands, route } = props;
|
|
38
|
+
const command = useCommand();
|
|
39
|
+
const index = computed(() => 2 + (path.length ?? 0));
|
|
40
|
+
return createComponent(Show, {
|
|
41
|
+
get when() {
|
|
42
|
+
return commands && Object.keys(commands).length > 0;
|
|
43
|
+
},
|
|
44
|
+
get children() {
|
|
45
|
+
return [
|
|
46
|
+
createComponent(VarDeclaration, {
|
|
47
|
+
"let": true,
|
|
48
|
+
name: "command",
|
|
49
|
+
type: "string",
|
|
50
|
+
initializer: code`"";`
|
|
51
|
+
}),
|
|
52
|
+
createIntrinsic("hbr", {}),
|
|
53
|
+
createComponent(IfStatement, {
|
|
54
|
+
get condition() {
|
|
55
|
+
return code`args.length > ${index.value} && args[${index.value}]`;
|
|
56
|
+
},
|
|
57
|
+
get children() {
|
|
58
|
+
return code`command = args[${index.value}];`;
|
|
59
|
+
}
|
|
60
|
+
}),
|
|
61
|
+
createIntrinsic("hbr", {}),
|
|
62
|
+
createComponent(For, {
|
|
63
|
+
get each() {
|
|
64
|
+
return Object.values(commands ?? {});
|
|
65
|
+
},
|
|
66
|
+
children: (subcommand, idx) => createComponent(CommandContext.Provider, {
|
|
67
|
+
value: subcommand,
|
|
78
68
|
get children() {
|
|
79
|
-
return createComponent(
|
|
80
|
-
get
|
|
81
|
-
return
|
|
69
|
+
return createComponent(Show, {
|
|
70
|
+
get when() {
|
|
71
|
+
return subcommand.name !== command?.name;
|
|
82
72
|
},
|
|
83
73
|
get children() {
|
|
84
|
-
return createComponent(
|
|
74
|
+
return createComponent(Show, {
|
|
75
|
+
get when() {
|
|
76
|
+
return Boolean(idx);
|
|
77
|
+
},
|
|
78
|
+
get fallback() {
|
|
79
|
+
return createComponent(IfStatement, {
|
|
80
|
+
get condition() {
|
|
81
|
+
return code`command.toLowerCase() === "${subcommand.name.toLowerCase()}"`;
|
|
82
|
+
},
|
|
83
|
+
get children() {
|
|
84
|
+
return createComponent(Show, {
|
|
85
|
+
get when() {
|
|
86
|
+
return Boolean(route);
|
|
87
|
+
},
|
|
88
|
+
get fallback() {
|
|
89
|
+
return createComponent(CommandRouterRoute, {});
|
|
90
|
+
},
|
|
91
|
+
children: route
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
get children() {
|
|
97
|
+
return createComponent(ElseIfClause, {
|
|
98
|
+
get condition() {
|
|
99
|
+
return code`command.toLowerCase() === "${subcommand.name.toLowerCase()}"`;
|
|
100
|
+
},
|
|
101
|
+
get children() {
|
|
102
|
+
return createComponent(Show, {
|
|
103
|
+
get when() {
|
|
104
|
+
return Boolean(route);
|
|
105
|
+
},
|
|
106
|
+
get fallback() {
|
|
107
|
+
return createComponent(CommandRouterRoute, {});
|
|
108
|
+
},
|
|
109
|
+
children: route
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
});
|
|
85
115
|
}
|
|
86
116
|
});
|
|
87
117
|
}
|
|
88
|
-
})
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
118
|
+
})
|
|
119
|
+
}),
|
|
120
|
+
createComponent(ElseIfClause, {
|
|
121
|
+
condition: code`Boolean(command)`,
|
|
122
|
+
children: code`error("Unknown command: " + command);`
|
|
123
|
+
})
|
|
124
|
+
];
|
|
125
|
+
}
|
|
126
|
+
});
|
|
97
127
|
}
|
|
98
128
|
|
|
99
129
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-router.mjs","names":["code","computed","For","Show","ElseIfClause","IfStatement","VarDeclaration","
|
|
1
|
+
{"version":3,"file":"command-router.mjs","names":["code","computed","For","Show","ElseIfClause","IfStatement","VarDeclaration","DynamicImportStatement","CommandContext","useCommand","isVariableCommandPath","pascalCase","CommandRouterRoute","command","_$createComponent","when","isVirtual","children","name","importPath","path","segments","filter","segment","length","exportName","_$createIntrinsic","_$memo","CommandRouter","props","commands","route","index","Object","keys","type","initializer","condition","value","each","values","subcommand","idx","Provider","Boolean","fallback","toLowerCase"],"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 { DynamicImportStatement } from \"@powerlines/plugin-alloy/typescript/components/dynamic-import-statement\";\nimport { CommandContext, useCommand } from \"@shell-shock/core/contexts/command\";\nimport { isVariableCommandPath } 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\";\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.path.segments.filter(\n segment => !isVariableCommandPath(segment)\n )[\n command.path.segments.filter(\n segment => !isVariableCommandPath(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 path: 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 { path, commands, route } = props;\n\n const command = useCommand();\n const index = computed(() => 2 + (path.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 when={subcommand.name !== command?.name}>\n <Show\n when={Boolean(idx)}\n fallback={\n <IfStatement\n condition={code`command.toLowerCase() === \"${subcommand.name.toLowerCase()}\"`}>\n <Show\n when={Boolean(route)}\n fallback={<CommandRouterRoute />}>\n {route}\n </Show>\n </IfStatement>\n }>\n <ElseIfClause\n condition={code`command.toLowerCase() === \"${subcommand.name.toLowerCase()}\"`}>\n <Show when={Boolean(route)} fallback={<CommandRouterRoute />}>\n {route}\n </Show>\n </ElseIfClause>\n </Show>\n </Show>\n </CommandContext.Provider>\n )}\n </For>\n <ElseIfClause\n condition={code`Boolean(command)`}>{code`error(\"Unknown command: \" + command);`}</ElseIfClause>\n </Show>\n );\n}\n"],"mappings":";;;;;;;;;AA+BA,SAAgBY,qBAAqB;CACnC,MAAMC,UAAUJ,YAAY;AAE5B,QAAA;EAAAK,gBAEKX,MAAI;GAAA,IAACY,OAAI;AAAA,WAAE,CAACF,QAAQG;;GAAS,IAAAC,WAAA;AAAA,WAAAH,gBAC3BP,wBAAsB;KAAA,IACrBW,OAAI;AAAA,aAAE,SAASP,WAAWE,QAAQK,KAAK;;KAAE,IACzCC,aAAU;AAAA,aAAE,KACVN,QAAQO,KAAKC,SAASC,QACpBC,YAAW,CAACb,sBAAsBa,QACpC,CAAC,CACCV,QAAQO,KAAK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