@shell-shock/preset-script 0.1.1 → 0.2.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.
Files changed (134) hide show
  1. package/README.md +1 -1
  2. package/dist/components/args-parser-logic.cjs +678 -0
  3. package/dist/components/args-parser-logic.cjs.map +1 -0
  4. package/dist/components/args-parser-logic.d.cts +45 -0
  5. package/dist/components/args-parser-logic.d.cts.map +1 -0
  6. package/dist/components/args-parser-logic.d.mts +45 -0
  7. package/dist/components/args-parser-logic.d.mts.map +1 -0
  8. package/dist/components/args-parser-logic.mjs +672 -0
  9. package/dist/components/args-parser-logic.mjs.map +1 -0
  10. package/dist/components/bin-entry.cjs +188 -0
  11. package/dist/components/bin-entry.cjs.map +1 -0
  12. package/dist/components/{entry/bin.d.cts → bin-entry.d.cts} +9 -3
  13. package/dist/components/bin-entry.d.cts.map +1 -0
  14. package/dist/components/{entry/bin.d.mts → bin-entry.d.mts} +9 -3
  15. package/dist/components/bin-entry.d.mts.map +1 -0
  16. package/dist/components/bin-entry.mjs +185 -0
  17. package/dist/components/bin-entry.mjs.map +1 -0
  18. package/dist/components/command-entry.cjs +162 -0
  19. package/dist/components/command-entry.cjs.map +1 -0
  20. package/dist/components/command-entry.d.cts +24 -0
  21. package/dist/components/command-entry.d.cts.map +1 -0
  22. package/dist/components/command-entry.d.mts +24 -0
  23. package/dist/components/command-entry.d.mts.map +1 -0
  24. package/dist/components/command-entry.mjs +158 -0
  25. package/dist/components/command-entry.mjs.map +1 -0
  26. package/dist/components/command-router.cjs +129 -74
  27. package/dist/components/command-router.cjs.map +1 -1
  28. package/dist/components/command-router.d.cts +13 -4
  29. package/dist/components/command-router.d.cts.map +1 -0
  30. package/dist/components/command-router.d.mts +13 -4
  31. package/dist/components/command-router.d.mts.map +1 -0
  32. package/dist/components/command-router.mjs +128 -73
  33. package/dist/components/command-router.mjs.map +1 -1
  34. package/dist/components/console-builtin.cjs +2086 -0
  35. package/dist/components/console-builtin.cjs.map +1 -0
  36. package/dist/components/console-builtin.d.cts +56 -0
  37. package/dist/components/console-builtin.d.cts.map +1 -0
  38. package/dist/components/console-builtin.d.mts +56 -0
  39. package/dist/components/console-builtin.d.mts.map +1 -0
  40. package/dist/components/console-builtin.mjs +2077 -0
  41. package/dist/components/console-builtin.mjs.map +1 -0
  42. package/dist/components/help.cjs +130 -0
  43. package/dist/components/help.cjs.map +1 -0
  44. package/dist/components/help.d.cts +57 -0
  45. package/dist/components/help.d.cts.map +1 -0
  46. package/dist/components/help.d.mts +57 -0
  47. package/dist/components/help.d.mts.map +1 -0
  48. package/dist/components/help.mjs +126 -0
  49. package/dist/components/help.mjs.map +1 -0
  50. package/dist/components/index.cjs +39 -15
  51. package/dist/components/index.d.cts +9 -7
  52. package/dist/components/index.d.mts +9 -7
  53. package/dist/components/index.mjs +8 -6
  54. package/dist/components/utils-builtin.cjs +612 -0
  55. package/dist/components/utils-builtin.cjs.map +1 -0
  56. package/dist/components/utils-builtin.d.cts +32 -0
  57. package/dist/components/utils-builtin.d.cts.map +1 -0
  58. package/dist/components/utils-builtin.d.mts +32 -0
  59. package/dist/components/utils-builtin.d.mts.map +1 -0
  60. package/dist/components/utils-builtin.mjs +605 -0
  61. package/dist/components/utils-builtin.mjs.map +1 -0
  62. package/dist/components/virtual-command-entry.cjs +140 -0
  63. package/dist/components/virtual-command-entry.cjs.map +1 -0
  64. package/dist/components/virtual-command-entry.d.cts +21 -0
  65. package/dist/components/virtual-command-entry.d.cts.map +1 -0
  66. package/dist/components/virtual-command-entry.d.mts +21 -0
  67. package/dist/components/virtual-command-entry.d.mts.map +1 -0
  68. package/dist/components/virtual-command-entry.mjs +137 -0
  69. package/dist/components/virtual-command-entry.mjs.map +1 -0
  70. package/dist/contexts/index.cjs +4 -0
  71. package/dist/contexts/index.d.cts +2 -0
  72. package/dist/contexts/index.d.mts +2 -0
  73. package/dist/contexts/index.mjs +3 -0
  74. package/dist/contexts/theme.d.cts +20 -0
  75. package/dist/contexts/theme.d.cts.map +1 -0
  76. package/dist/contexts/theme.d.mts +20 -0
  77. package/dist/contexts/theme.d.mts.map +1 -0
  78. package/dist/helpers/ansi-utils.cjs +28 -4
  79. package/dist/helpers/ansi-utils.cjs.map +1 -1
  80. package/dist/helpers/ansi-utils.d.cts +68 -0
  81. package/dist/helpers/ansi-utils.d.cts.map +1 -0
  82. package/dist/helpers/ansi-utils.d.mts +68 -0
  83. package/dist/helpers/ansi-utils.d.mts.map +1 -0
  84. package/dist/helpers/ansi-utils.mjs +28 -4
  85. package/dist/helpers/ansi-utils.mjs.map +1 -1
  86. package/dist/helpers/get-default-options.cjs +6 -13
  87. package/dist/helpers/get-default-options.cjs.map +1 -1
  88. package/dist/helpers/get-default-options.mjs +6 -13
  89. package/dist/helpers/get-default-options.mjs.map +1 -1
  90. package/dist/index.cjs +117 -29
  91. package/dist/index.cjs.map +1 -1
  92. package/dist/index.d.cts.map +1 -0
  93. package/dist/index.d.mts.map +1 -0
  94. package/dist/index.mjs +118 -28
  95. package/dist/index.mjs.map +1 -1
  96. package/dist/types/plugin.d.cts +1 -6
  97. package/dist/types/plugin.d.cts.map +1 -0
  98. package/dist/types/plugin.d.mts +1 -6
  99. package/dist/types/plugin.d.mts.map +1 -0
  100. package/package.json +163 -71
  101. package/dist/components/builtin/console.cjs +0 -1232
  102. package/dist/components/builtin/console.cjs.map +0 -1
  103. package/dist/components/builtin/console.d.cts +0 -37
  104. package/dist/components/builtin/console.d.mts +0 -37
  105. package/dist/components/builtin/console.mjs +0 -1225
  106. package/dist/components/builtin/console.mjs.map +0 -1
  107. package/dist/components/builtin/index.cjs +0 -9
  108. package/dist/components/builtin/index.d.cts +0 -2
  109. package/dist/components/builtin/index.d.mts +0 -2
  110. package/dist/components/builtin/index.mjs +0 -3
  111. package/dist/components/entry/bin.cjs +0 -92
  112. package/dist/components/entry/bin.cjs.map +0 -1
  113. package/dist/components/entry/bin.mjs +0 -91
  114. package/dist/components/entry/bin.mjs.map +0 -1
  115. package/dist/components/entry/command.cjs +0 -54
  116. package/dist/components/entry/command.cjs.map +0 -1
  117. package/dist/components/entry/command.d.cts +0 -15
  118. package/dist/components/entry/command.d.mts +0 -15
  119. package/dist/components/entry/command.mjs +0 -53
  120. package/dist/components/entry/command.mjs.map +0 -1
  121. package/dist/components/entry/index.cjs +0 -3
  122. package/dist/components/entry/index.d.cts +0 -2
  123. package/dist/components/entry/index.d.mts +0 -2
  124. package/dist/components/entry/index.mjs +0 -3
  125. package/dist/components/shutdown.cjs +0 -93
  126. package/dist/components/shutdown.cjs.map +0 -1
  127. package/dist/components/shutdown.d.cts +0 -14
  128. package/dist/components/shutdown.d.mts +0 -14
  129. package/dist/components/shutdown.mjs +0 -91
  130. package/dist/components/shutdown.mjs.map +0 -1
  131. package/dist/contexts/command.cjs +0 -21
  132. package/dist/contexts/command.cjs.map +0 -1
  133. package/dist/contexts/command.mjs +0 -19
  134. package/dist/contexts/command.mjs.map +0 -1
@@ -1,100 +1,155 @@
1
1
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
- const require_command = require('../contexts/command.cjs');
3
2
  let __alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
4
3
  let __alloy_js_core = require("@alloy-js/core");
5
4
  let __alloy_js_typescript = require("@alloy-js/typescript");
5
+ let __shell_shock_core_plugin_utils_context_helpers = require("@shell-shock/core/plugin-utils/context-helpers");
6
6
  let __powerlines_plugin_alloy_core_contexts_context = require("@powerlines/plugin-alloy/core/contexts/context");
7
- let __powerlines_plugin_alloy_typescript_components_dynamic_import_statement = require("@powerlines/plugin-alloy/typescript/components/dynamic-import-statement");
8
7
  let __stryke_string_format_pascal_case = require("@stryke/string-format/pascal-case");
8
+ let __powerlines_plugin_alloy_typescript_components_dynamic_import_statement = require("@powerlines/plugin-alloy/typescript/components/dynamic-import-statement");
9
+ let __shell_shock_core_contexts_command = require("@shell-shock/core/contexts/command");
9
10
 
10
11
  //#region src/components/command-router.tsx
11
12
  function CommandRouterRoute() {
12
- const command = require_command.useCommand();
13
- return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
14
- get when() {
15
- return !command.isVirtual;
16
- },
17
- get fallback() {
18
- return __alloy_js_core.code`return handle${(0, __stryke_string_format_pascal_case.pascalCase)(command.name)}(args);`;
19
- },
20
- get children() {
21
- return [
22
- (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_dynamic_import_statement.DynamicImportStatement, {
13
+ const command = (0, __shell_shock_core_contexts_command.useCommand)();
14
+ return [
15
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
16
+ get when() {
17
+ return !command.isVirtual;
18
+ },
19
+ get children() {
20
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_dynamic_import_statement.DynamicImportStatement, {
23
21
  get name() {
24
22
  return `handle${(0, __stryke_string_format_pascal_case.pascalCase)(command.name)}`;
25
23
  },
26
24
  get importPath() {
27
- return `./${command.entry.output}`;
25
+ return `./${command.path.segments.filter((segment) => !(0, __shell_shock_core_plugin_utils_context_helpers.isVariableCommandPath)(segment))[command.path.segments.filter((segment) => !(0, __shell_shock_core_plugin_utils_context_helpers.isVariableCommandPath)(segment)).length - 1]}`;
28
26
  },
29
27
  exportName: "handler"
30
- }),
31
- (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
32
- (0, __alloy_js_core_jsx_runtime.memo)(() => __alloy_js_core.code`return handle${(0, __stryke_string_format_pascal_case.pascalCase)(command.name)}(args);`)
33
- ];
34
- }
35
- });
36
- }
37
- function CommandRouter() {
38
- const context = (0, __powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
39
- const command = require_command.useCommand();
40
- const index = (0, __alloy_js_core.computed)(() => 2 + (command?.path.length ?? 0));
41
- return [
42
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
43
- "let": true,
44
- name: "command",
45
- type: "string",
46
- initializer: __alloy_js_core.code`"";`
47
- }),
48
- (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
49
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
50
- get condition() {
51
- return __alloy_js_core.code`args.length > ${index.value} && args[${index.value}]`;
52
- },
53
- get children() {
54
- return __alloy_js_core.code`command = args[${index.value}];`;
28
+ });
55
29
  }
56
30
  }),
57
31
  (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
58
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.For, {
59
- get each() {
60
- return Object.values(command?.children ?? context?.commands ?? {});
61
- },
62
- children: (subcommand, idx) => (0, __alloy_js_core_jsx_runtime.createComponent)(require_command.CommandContext.Provider, {
63
- value: subcommand,
64
- get children() {
65
- return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
66
- get when() {
67
- return Boolean(idx);
68
- },
69
- get fallback() {
70
- return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
71
- get condition() {
72
- return __alloy_js_core.code`command.toLowerCase() === "${subcommand.name.toLowerCase()}"`;
73
- },
74
- get children() {
75
- return (0, __alloy_js_core_jsx_runtime.createComponent)(CommandRouterRoute, {});
76
- }
77
- });
78
- },
32
+ (0, __alloy_js_core_jsx_runtime.memo)(() => __alloy_js_core.code`return handle${(0, __stryke_string_format_pascal_case.pascalCase)(command.name)}(args);`)
33
+ ];
34
+ }
35
+ /**
36
+ * The command router component.
37
+ */
38
+ function CommandRouter(props) {
39
+ const { path, commands, route } = props;
40
+ const context = (0, __powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
41
+ const index = (0, __alloy_js_core.computed)(() => 2 + (path.length ?? 0));
42
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
43
+ get when() {
44
+ return commands && Object.keys(commands).length > 0;
45
+ },
46
+ get children() {
47
+ return [
48
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.VarDeclaration, {
49
+ "let": true,
50
+ name: "command",
51
+ type: "string",
52
+ initializer: __alloy_js_core.code`"";`
53
+ }),
54
+ (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
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
64
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.For, {
65
+ get each() {
66
+ return Object.values(commands ?? {});
67
+ },
68
+ children: (subcommand, idx) => (0, __alloy_js_core_jsx_runtime.createComponent)(__shell_shock_core_contexts_command.CommandContext.Provider, {
69
+ value: subcommand,
79
70
  get children() {
80
- return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.ElseIfClause, {
81
- get condition() {
82
- return __alloy_js_core.code`command.toLowerCase() === "${subcommand.name.toLowerCase()}"`;
71
+ return [(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
72
+ get when() {
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(/-/g, \"\")"} === "${context.config.isCaseSensitive ? subcommand.name : subcommand.name.toLowerCase().replaceAll(/-/g, "")}"`;
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
+ });
83
92
  },
84
93
  get children() {
85
- return (0, __alloy_js_core_jsx_runtime.createComponent)(CommandRouterRoute, {});
94
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.ElseIfClause, {
95
+ get condition() {
96
+ return __alloy_js_core.code`${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(/-/g, \"\")"} === "${context.config.isCaseSensitive ? subcommand.name : subcommand.name.toLowerCase().replaceAll(/-/g, "")}"`;
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
+ });
86
110
  }
87
- });
111
+ }), (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.For, {
112
+ get each() {
113
+ return subcommand.alias;
114
+ },
115
+ doubleHardline: true,
116
+ children: (alias) => (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.ElseIfClause, {
117
+ get condition() {
118
+ return __alloy_js_core.code`${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(/-/g, \"\")"} === "${context.config.isCaseSensitive ? alias : alias.toLowerCase().replaceAll(/-/g, "")}"`;
119
+ },
120
+ get children() {
121
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
122
+ get when() {
123
+ return Boolean(route);
124
+ },
125
+ get fallback() {
126
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(CommandRouterRoute, {});
127
+ },
128
+ children: route
129
+ });
130
+ }
131
+ })
132
+ })];
88
133
  }
89
- });
90
- }
91
- })
92
- }),
93
- (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.ElseIfClause, {
94
- condition: __alloy_js_core.code`Boolean(command)`,
95
- children: __alloy_js_core.code`error("Unknown command: " + command);`
96
- })
97
- ];
134
+ })
135
+ }),
136
+ (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.ElseIfClause, {
137
+ condition: __alloy_js_core.code`Boolean(command)`,
138
+ get children() {
139
+ return __alloy_js_core.code`const suggestions = didYouMean(command, [${Object.values(commands ?? {}).map((cmd) => `"${cmd.name}"${cmd.alias.map((alias) => `", "${alias}"`).join("")}`).join(", ")}], {
140
+ caseSensitive: false,
141
+ deburr: true,
142
+ trimSpaces: true,
143
+ returnType: ReturnTypeEnums.ALL_CLOSE_MATCHES,
144
+ thresholdType: ThresholdTypeEnums.RELATIVE_DISTANCE,
145
+ threshold: 0.75
146
+ });
147
+ 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}"\`)}?\` : ""} \`);`;
148
+ }
149
+ })
150
+ ];
151
+ }
152
+ });
98
153
  }
99
154
 
100
155
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"command-router.cjs","names":["code","computed","For","Show","ElseIfClause","IfStatement","VarDeclaration","usePowerlines","DynamicImportStatement","pascalCase","CommandContext","useCommand","CommandRouterRoute","command","_$createComponent","when","isVirtual","fallback","name","children","importPath","entry","output","exportName","_$createIntrinsic","_$memo","CommandRouter","context","index","path","length","type","initializer","condition","value","each","Object","values","commands","subcommand","idx","Provider","Boolean","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 { 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 { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport { CommandContext, useCommand } from \"../contexts/command\";\nimport type { ScriptPresetContext } from \"../types/plugin\";\n\nexport function CommandRouterRoute() {\n const command = useCommand();\n\n return (\n <Show\n when={!command.isVirtual}\n fallback={code`return handle${pascalCase(command.name)}(args);`}>\n <DynamicImportStatement\n name={`handle${pascalCase(command.name)}`}\n importPath={`./${command.entry.output}`}\n exportName=\"handler\"\n />\n <hbr />\n {code`return handle${pascalCase(command.name)}(args);`}\n </Show>\n );\n}\n\nexport function CommandRouter() {\n const context = usePowerlines<ScriptPresetContext>();\n\n const command = useCommand();\n const index = computed(() => 2 + (command?.path.length ?? 0));\n\n return (\n <>\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(command?.children ?? context?.commands ?? {})}>\n {(subcommand, idx) => (\n <CommandContext.Provider value={subcommand}>\n <Show\n when={Boolean(idx)}\n fallback={\n <IfStatement\n condition={code`command.toLowerCase() === \"${subcommand.name.toLowerCase()}\"`}>\n <CommandRouterRoute />\n </IfStatement>\n }>\n <ElseIfClause\n condition={code`command.toLowerCase() === \"${subcommand.name.toLowerCase()}\"`}>\n <CommandRouterRoute />\n </ElseIfClause>\n </Show>\n </CommandContext.Provider>\n )}\n </For>\n <ElseIfClause\n condition={code`Boolean(command)`}>{code`error(\"Unknown command: \" + command);`}</ElseI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MAAA,IAClBvB,WAAQ;AAAA,+DACLZ,mCAAW;QAAA,IACV4B,YAAS;AAAA,gBAAEjC,oBAAI,8BAA8BuC,WAAWrB,KAAKyB,aAAa,CAAA;;QAAG,IAAAxB,WAAA;AAAA,iEAC5EP,oBAAkB,EAAA,CAAA;;QAAA,CAAA;;MAAA,IAAAO,WAAA;AAAA,+DAGtBf,oCAAY;QAAA,IACX6B,YAAS;AAAA,gBAAEjC,oBAAI,8BAA8BuC,WAAWrB,KAAKyB,aAAa,CAAA;;QAAG,IAAAxB,WAAA;AAAA,iEAC5EP,oBAAkB,EAAA,CAAA;;QAAA,CAAA;;MAAA,CAAA;;IAAA,CAAA;GAI1B,CAAA;mDAEFR,oCAAY;GACX6B,WAAWjC,oBAAI;GAAkBmB,UAAGnB,oBAAI;GAAuC,CAAA;EAAA"}
1
+ {"version":3,"file":"command-router.cjs","names":["code","computed","For","Show","ElseIfClause","IfStatement","VarDeclaration","usePowerlines","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","context","index","Object","keys","type","initializer","condition","value","each","values","subcommand","idx","Provider","Boolean","fallback","config","isCaseSensitive","toLowerCase","replaceAll","alias","doubleHardline","map","cmd","join"],"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 { 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\";\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.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 context = usePowerlines<ScriptPresetContext>();\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\n when={Boolean(idx)}\n fallback={\n <IfStatement\n condition={code`${\n context.config.isCaseSensitive\n ? \"command\"\n : 'command.toLowerCase().replaceAll(/-/g, \"\")'\n } === \"${\n context.config.isCaseSensitive\n ? subcommand.name\n : subcommand.name.toLowerCase().replaceAll(/-/g, \"\")\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(/-/g, \"\")'\n } === \"${\n context.config.isCaseSensitive\n ? subcommand.name\n : subcommand.name.toLowerCase().replaceAll(/-/g, \"\")\n }\"`}>\n <Show when={Boolean(route)} fallback={<CommandRouterRoute />}>\n {route}\n </Show>\n </ElseIfClause>\n </Show>\n <For each={subcommand.alias} doubleHardline>\n {alias => (\n <ElseIfClause\n condition={code`${\n context.config.isCaseSensitive\n ? \"command\"\n : 'command.toLowerCase().replaceAll(/-/g, \"\")'\n } === \"${\n context.config.isCaseSensitive\n ? alias\n : alias.toLowerCase().replaceAll(/-/g, \"\")\n }\"`}>\n <Show when={Boolean(route)} fallback={<CommandRouterRoute />}>\n {route}\n </Show>\n </ElseIfClause>\n )}\n </For>\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 => `\", \"${alias}\"`).join(\"\")}`\n )\n .join(\", \")}], {\n caseSensitive: false,\n deburr: true,\n trimSpaces: true,\n returnType: ReturnTypeEnums.ALL_CLOSE_MATCHES,\n thresholdType: ThresholdTypeEnums.RELATIVE_DISTANCE,\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}\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;SAC3C,IAAAjC,WAAA;AAAA,kEACFf,sBAAI;WAAA,IAACa,OAAI;AAAA,mBAAE8B,QAAQd,MAAM;;WAAA,IAAEe,WAAQ;AAAA,oEAAGlC,oBAAkB,EAAA,CAAA;;WAAAK,UACtDc;WAAK,CAAA;;SAAA,CAAA;QAGX,CAAA,CAAA;;MAAA,CAAA;KAGN,CAAA;qDAEF5B,oCAAY;KACXmC,WAAWvC,oBAAI;KAAkB,IAAAkB,WAAA;AAAA,aAAGlB,oBAAI,4CAA4CmC,OAAOO,OAC3FX,YAAY,EACd,CAAC,CACEuB,KACCC,QACE,IAAIA,IAAIpC,KAAI,GAAIoC,IAAIH,MAAME,KAAIF,UAAS,OAAOA,MAAK,GAAI,CAACI,KAAK,GAAG,GACnE,CACAA,KAAK,KAAK,CAAA;;;;;;;;;;KAQkR,CAAA;IAAA;;EAAA,CAAA"}
@@ -1,8 +1,17 @@
1
- import * as _alloy_js_core2 from "@alloy-js/core";
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(): _alloy_js_core2.Children;
5
- declare function CommandRouter(): _alloy_js_core2.Children;
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":";;;;iBAiCgB,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 * as _alloy_js_core1 from "@alloy-js/core";
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(): _alloy_js_core1.Children;
5
- declare function CommandRouter(): _alloy_js_core1.Children;
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":";;;;iBAiCgB,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,154 @@
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";
4
+ import { isVariableCommandPath } from "@shell-shock/core/plugin-utils/context-helpers";
5
5
  import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
6
- import { DynamicImportStatement } from "@powerlines/plugin-alloy/typescript/components/dynamic-import-statement";
7
6
  import { pascalCase } from "@stryke/string-format/pascal-case";
7
+ import { DynamicImportStatement } from "@powerlines/plugin-alloy/typescript/components/dynamic-import-statement";
8
+ import { CommandContext, useCommand } from "@shell-shock/core/contexts/command";
8
9
 
9
10
  //#region src/components/command-router.tsx
10
11
  function CommandRouterRoute() {
11
12
  const command = useCommand();
12
- return createComponent(Show, {
13
- get when() {
14
- return !command.isVirtual;
15
- },
16
- get fallback() {
17
- return code`return handle${pascalCase(command.name)}(args);`;
18
- },
19
- get children() {
20
- return [
21
- createComponent(DynamicImportStatement, {
13
+ return [
14
+ createComponent(Show, {
15
+ get when() {
16
+ return !command.isVirtual;
17
+ },
18
+ get children() {
19
+ return createComponent(DynamicImportStatement, {
22
20
  get name() {
23
21
  return `handle${pascalCase(command.name)}`;
24
22
  },
25
23
  get importPath() {
26
- return `./${command.entry.output}`;
24
+ return `./${command.path.segments.filter((segment) => !isVariableCommandPath(segment))[command.path.segments.filter((segment) => !isVariableCommandPath(segment)).length - 1]}`;
27
25
  },
28
26
  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}];`;
27
+ });
54
28
  }
55
29
  }),
56
30
  createIntrinsic("hbr", {}),
57
- createComponent(For, {
58
- get each() {
59
- return Object.values(command?.children ?? context?.commands ?? {});
60
- },
61
- children: (subcommand, idx) => createComponent(CommandContext.Provider, {
62
- value: subcommand,
63
- get children() {
64
- return createComponent(Show, {
65
- get when() {
66
- return Boolean(idx);
67
- },
68
- get fallback() {
69
- return createComponent(IfStatement, {
70
- get condition() {
71
- return code`command.toLowerCase() === "${subcommand.name.toLowerCase()}"`;
72
- },
73
- get children() {
74
- return createComponent(CommandRouterRoute, {});
75
- }
76
- });
77
- },
31
+ memo(() => code`return handle${pascalCase(command.name)}(args);`)
32
+ ];
33
+ }
34
+ /**
35
+ * The command router component.
36
+ */
37
+ function CommandRouter(props) {
38
+ const { path, commands, route } = props;
39
+ const context = usePowerlines();
40
+ const index = computed(() => 2 + (path.length ?? 0));
41
+ return createComponent(Show, {
42
+ get when() {
43
+ return commands && Object.keys(commands).length > 0;
44
+ },
45
+ get children() {
46
+ return [
47
+ createComponent(VarDeclaration, {
48
+ "let": true,
49
+ name: "command",
50
+ type: "string",
51
+ initializer: code`"";`
52
+ }),
53
+ createIntrinsic("hbr", {}),
54
+ createComponent(IfStatement, {
55
+ get condition() {
56
+ return code`args.length > ${index.value} && args[${index.value}]`;
57
+ },
58
+ get children() {
59
+ return code`command = args[${index.value}];`;
60
+ }
61
+ }),
62
+ createIntrinsic("hbr", {}),
63
+ createComponent(For, {
64
+ get each() {
65
+ return Object.values(commands ?? {});
66
+ },
67
+ children: (subcommand, idx) => createComponent(CommandContext.Provider, {
68
+ value: subcommand,
78
69
  get children() {
79
- return createComponent(ElseIfClause, {
80
- get condition() {
81
- return code`command.toLowerCase() === "${subcommand.name.toLowerCase()}"`;
70
+ return [createComponent(Show, {
71
+ get when() {
72
+ return Boolean(idx);
73
+ },
74
+ get fallback() {
75
+ return createComponent(IfStatement, {
76
+ get condition() {
77
+ return code`${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(/-/g, \"\")"} === "${context.config.isCaseSensitive ? subcommand.name : subcommand.name.toLowerCase().replaceAll(/-/g, "")}"`;
78
+ },
79
+ get children() {
80
+ return createComponent(Show, {
81
+ get when() {
82
+ return Boolean(route);
83
+ },
84
+ get fallback() {
85
+ return createComponent(CommandRouterRoute, {});
86
+ },
87
+ children: route
88
+ });
89
+ }
90
+ });
82
91
  },
83
92
  get children() {
84
- return createComponent(CommandRouterRoute, {});
93
+ return createComponent(ElseIfClause, {
94
+ get condition() {
95
+ return code`${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(/-/g, \"\")"} === "${context.config.isCaseSensitive ? subcommand.name : subcommand.name.toLowerCase().replaceAll(/-/g, "")}"`;
96
+ },
97
+ get children() {
98
+ return createComponent(Show, {
99
+ get when() {
100
+ return Boolean(route);
101
+ },
102
+ get fallback() {
103
+ return createComponent(CommandRouterRoute, {});
104
+ },
105
+ children: route
106
+ });
107
+ }
108
+ });
85
109
  }
86
- });
110
+ }), createComponent(For, {
111
+ get each() {
112
+ return subcommand.alias;
113
+ },
114
+ doubleHardline: true,
115
+ children: (alias) => createComponent(ElseIfClause, {
116
+ get condition() {
117
+ return code`${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(/-/g, \"\")"} === "${context.config.isCaseSensitive ? alias : alias.toLowerCase().replaceAll(/-/g, "")}"`;
118
+ },
119
+ get children() {
120
+ return createComponent(Show, {
121
+ get when() {
122
+ return Boolean(route);
123
+ },
124
+ get fallback() {
125
+ return createComponent(CommandRouterRoute, {});
126
+ },
127
+ children: route
128
+ });
129
+ }
130
+ })
131
+ })];
87
132
  }
88
- });
89
- }
90
- })
91
- }),
92
- createComponent(ElseIfClause, {
93
- condition: code`Boolean(command)`,
94
- children: code`error("Unknown command: " + command);`
95
- })
96
- ];
133
+ })
134
+ }),
135
+ createComponent(ElseIfClause, {
136
+ condition: code`Boolean(command)`,
137
+ get children() {
138
+ return code`const suggestions = didYouMean(command, [${Object.values(commands ?? {}).map((cmd) => `"${cmd.name}"${cmd.alias.map((alias) => `", "${alias}"`).join("")}`).join(", ")}], {
139
+ caseSensitive: false,
140
+ deburr: true,
141
+ trimSpaces: true,
142
+ returnType: ReturnTypeEnums.ALL_CLOSE_MATCHES,
143
+ thresholdType: ThresholdTypeEnums.RELATIVE_DISTANCE,
144
+ threshold: 0.75
145
+ });
146
+ error(\`Unknown command: "\${command}"\${suggestions && suggestions.length > 0 ? \`, did you mean: \${suggestions.length === 1 ? \`"\${suggestions[0]}"\` : suggestions.map((suggestion, i) => i < suggestions.length - 1 ? \`"\${suggestion}", \` : \`or "\${suggestion}"\`)}?\` : ""} \`);`;
147
+ }
148
+ })
149
+ ];
150
+ }
151
+ });
97
152
  }
98
153
 
99
154
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"command-router.mjs","names":["code","computed","For","Show","ElseIfClause","IfStatement","VarDeclaration","usePowerlines","DynamicImportStatement","pascalCase","CommandContext","useCommand","CommandRouterRoute","command","_$createComponent","when","isVirtual","fallback","name","children","importPath","entry","output","exportName","_$createIntrinsic","_$memo","CommandRouter","context","index","path","length","type","initializer","condition","value","each","Object","values","commands","subcommand","idx","Provider","Boolean","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 { 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 { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport { CommandContext, useCommand } from \"../contexts/command\";\nimport type { ScriptPresetContext } from \"../types/plugin\";\n\nexport function CommandRouterRoute() {\n const command = useCommand();\n\n return (\n <Show\n when={!command.isVirtual}\n fallback={code`return handle${pascalCase(command.name)}(args);`}>\n <DynamicImportStatement\n name={`handle${pascalCase(command.name)}`}\n importPath={`./${command.entry.output}`}\n exportName=\"handler\"\n />\n <hbr />\n {code`return handle${pascalCase(command.name)}(args);`}\n </Show>\n );\n}\n\nexport function CommandRouter() {\n const context = usePowerlines<ScriptPresetContext>();\n\n const command = useCommand();\n const index = computed(() => 2 + (command?.path.length ?? 0));\n\n return (\n <>\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(command?.children ?? context?.commands ?? {})}>\n {(subcommand, idx) => (\n <CommandContext.Provider value={subcommand}>\n <Show\n when={Boolean(idx)}\n fallback={\n <IfStatement\n condition={code`command.toLowerCase() === \"${subcommand.name.toLowerCase()}\"`}>\n <CommandRouterRoute />\n </IfStatement>\n }>\n <ElseIfClause\n condition={code`command.toLowerCase() === \"${subcommand.name.toLowerCase()}\"`}>\n <CommandRouterRoute />\n </ElseIfClause>\n </Show>\n </CommandContext.Provider>\n )}\n </For>\n <ElseIfClause\n condition={code`Boolean(command)`}>{code`error(\"Unknown command: \" + command);`}</ElseIfClause>\n </>\n );\n}\n"],"mappings":";;;;;;;;;AA8BA,SAAgBY,qBAAqB;CACnC,MAAMC,UAAUF,YAAY;AAE5B,QAAAG,gBACGX,MAAI;EAAA,IACHY,OAAI;AAAA,UAAE,CAACF,QAAQG;;EAAS,IACxBC,WAAQ;AAAA,UAAEjB,IAAI,gBAAgBS,WAAWI,QAAQK,KAAK,CAAA;;EAAS,IAAAC,WAAA;AAAA,UAAA;IAAAL,gBAC9DN,wBAAsB;KAAA,IACrBU,OAAI;AAAA,aAAE,SAAST,WAAWI,QAAQK,KAA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;QAAA,IACX6B,YAAS;AAAA,gBAAEjC,IAAI,8BAA8BuC,WAAWrB,KAAKyB,aAAa,CAAA;;QAAG,IAAAxB,WAAA;AAAA,gBAAAL,gBAC5EF,oBAAkB,EAAA,CAAA;;QAAA,CAAA;;MAAA,CAAA;;IAAA,CAAA;GAI1B,CAAA;EAAAE,gBAEFV,cAAY;GACX6B,WAAWjC,IAAI;GAAkBmB,UAAGnB,IAAI;GAAuC,CAAA;EAAA"}
1
+ {"version":3,"file":"command-router.mjs","names":["code","computed","For","Show","ElseIfClause","IfStatement","VarDeclaration","usePowerlines","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","context","index","Object","keys","type","initializer","condition","value","each","values","subcommand","idx","Provider","Boolean","fallback","config","isCaseSensitive","toLowerCase","replaceAll","alias","doubleHardline","map","cmd","join"],"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 { 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\";\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.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 context = usePowerlines<ScriptPresetContext>();\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\n when={Boolean(idx)}\n fallback={\n <IfStatement\n condition={code`${\n context.config.isCaseSensitive\n ? \"command\"\n : 'command.toLowerCase().replaceAll(/-/g, \"\")'\n } === \"${\n context.config.isCaseSensitive\n ? subcommand.name\n : subcommand.name.toLowerCase().replaceAll(/-/g, \"\")\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(/-/g, \"\")'\n } === \"${\n context.config.isCaseSensitive\n ? subcommand.name\n : subcommand.name.toLowerCase().replaceAll(/-/g, \"\")\n }\"`}>\n <Show when={Boolean(route)} fallback={<CommandRouterRoute />}>\n {route}\n </Show>\n </ElseIfClause>\n </Show>\n <For each={subcommand.alias} doubleHardline>\n {alias => (\n <ElseIfClause\n condition={code`${\n context.config.isCaseSensitive\n ? \"command\"\n : 'command.toLowerCase().replaceAll(/-/g, \"\")'\n } === \"${\n context.config.isCaseSensitive\n ? alias\n : alias.toLowerCase().replaceAll(/-/g, \"\")\n }\"`}>\n <Show when={Boolean(route)} fallback={<CommandRouterRoute />}>\n {route}\n </Show>\n </ElseIfClause>\n )}\n </For>\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 => `\", \"${alias}\"`).join(\"\")}`\n )\n .join(\", \")}], {\n caseSensitive: false,\n deburr: true,\n trimSpaces: true,\n returnType: ReturnTypeEnums.ALL_CLOSE_MATCHES,\n thresholdType: ThresholdTypeEnums.RELATIVE_DISTANCE,\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,UAAUJ,YAAY;AAE5B,QAAA;EAAAK,gBAEKZ,MAAI;GAAA,IAACa,OAAI;AAAA,WAAE,CAACF,QAAQG;;GAAS,IAAAC,WAAA;AAAA,WAAAH,gBAC3BP,wBAAsB;KAAA,IACrBW,OAAI;AAA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