@shell-shock/preset-script 0.1.2 → 0.2.1

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 (46) hide show
  1. package/README.md +2 -2
  2. package/dist/components/bin-entry.cjs +15 -6
  3. package/dist/components/bin-entry.cjs.map +1 -1
  4. package/dist/components/bin-entry.d.cts +3 -3
  5. package/dist/components/bin-entry.d.cts.map +1 -1
  6. package/dist/components/bin-entry.d.mts +3 -3
  7. package/dist/components/bin-entry.d.mts.map +1 -1
  8. package/dist/components/bin-entry.mjs +15 -6
  9. package/dist/components/bin-entry.mjs.map +1 -1
  10. package/dist/components/command-router.cjs +61 -38
  11. package/dist/components/command-router.cjs.map +1 -1
  12. package/dist/components/command-router.d.cts.map +1 -1
  13. package/dist/components/command-router.d.mts.map +1 -1
  14. package/dist/components/command-router.mjs +61 -38
  15. package/dist/components/command-router.mjs.map +1 -1
  16. package/dist/components/console-builtin.cjs +74 -51
  17. package/dist/components/console-builtin.cjs.map +1 -1
  18. package/dist/components/console-builtin.d.cts.map +1 -1
  19. package/dist/components/console-builtin.d.mts.map +1 -1
  20. package/dist/components/console-builtin.mjs +74 -51
  21. package/dist/components/console-builtin.mjs.map +1 -1
  22. package/dist/components/help.cjs +33 -21
  23. package/dist/components/help.cjs.map +1 -1
  24. package/dist/components/help.d.cts +16 -8
  25. package/dist/components/help.d.cts.map +1 -1
  26. package/dist/components/help.d.mts +19 -11
  27. package/dist/components/help.d.mts.map +1 -1
  28. package/dist/components/help.mjs +34 -22
  29. package/dist/components/help.mjs.map +1 -1
  30. package/dist/components/index.cjs +1 -1
  31. package/dist/components/index.d.cts +3 -3
  32. package/dist/components/index.d.mts +3 -3
  33. package/dist/components/index.mjs +2 -2
  34. package/dist/components/utils-builtin.d.mts +7 -7
  35. package/dist/components/virtual-command-entry.cjs +8 -1
  36. package/dist/components/virtual-command-entry.cjs.map +1 -1
  37. package/dist/components/virtual-command-entry.mjs +8 -1
  38. package/dist/components/virtual-command-entry.mjs.map +1 -1
  39. package/dist/index.cjs +94 -71
  40. package/dist/index.cjs.map +1 -1
  41. package/dist/index.d.cts.map +1 -1
  42. package/dist/index.d.mts.map +1 -1
  43. package/dist/index.mjs +95 -72
  44. package/dist/index.mjs.map +1 -1
  45. package/dist/types/plugin.d.cts.map +1 -1
  46. package/package.json +10 -10
package/README.md CHANGED
@@ -27,7 +27,7 @@ This package is part of the ⚡<b>Shell Shock</b> monorepo. The Shell Shock pack
27
27
 
28
28
  <h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
29
29
 
30
- [![Version](https://img.shields.io/badge/version-0.1.1-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://stormsoftware.com/projects/shell-shock/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/shell-shock/release.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
30
+ [![Version](https://img.shields.io/badge/version-0.1.2-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://stormsoftware.com/projects/shell-shock/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/shell-shock/release.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
31
31
 
32
32
  <!-- prettier-ignore-start -->
33
33
  <!-- markdownlint-disable -->
@@ -247,7 +247,7 @@ generation of development tools, please reach out on our
247
247
 
248
248
  <br />
249
249
 
250
- <div align="center"><a href="https://stormsoftware.com" target="_blank"><img src="https://public.storm-cdn.com/icon-fill.png" alt="Storm Software" width="200px"/></a></div>
250
+ <div align="center"><a href="https://stormsoftware.com" target="_blank"><img src="https://public.storm-cdn.com/storm-software/icon-circle-fill-dark.png" alt="Storm Software" width="200px"/></a></div>
251
251
  <br />
252
252
  <div align="center"><a href="https://stormsoftware.com" target="_blank"><img src="https://public.storm-cdn.com/visit-us-text.svg" alt="Visit us at stormsoftware.com" height="90px"/></a></div>
253
253
 
@@ -15,12 +15,14 @@ defu = require_rolldown_runtime.__toESM(defu);
15
15
 
16
16
  //#region src/components/bin-entry.tsx
17
17
  /**
18
- * The `exit` handler function usage code for the Shell Shock project.
18
+ * Runs the application main logic with proper exit handling.
19
19
  */
20
- function ExitFunctionUsage() {
20
+ function RunApplication() {
21
21
  return [
22
22
  (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
23
- __alloy_js_core.code`(async () => {
23
+ (0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
24
+ __alloy_js_core.code`// Run the application main logic inside an asynchronous IIFE
25
+ (async () => {
24
26
  try {
25
27
  process.on("exit", () => exit({
26
28
  skipExit: true,
@@ -99,7 +101,14 @@ function BinEntry(props) {
99
101
  output: "bin"
100
102
  },
101
103
  get imports() {
102
- return (0, defu.default)(imports ?? {}, Object.entries(context.commands).filter(([, command]) => command.isVirtual).reduce((ret, [name, command]) => {
104
+ return (0, defu.default)({ didyoumean2: [
105
+ {
106
+ name: "didYouMean",
107
+ default: true
108
+ },
109
+ { name: "ReturnTypeEnums" },
110
+ { name: "ThresholdTypeEnums" }
111
+ ] }, imports ?? {}, Object.entries(context.commands).filter(([, command]) => command.isVirtual).reduce((ret, [name, command]) => {
103
112
  ret[`./${command.name}`] = [{
104
113
  name: "handler",
105
114
  alias: `handle${(0, __stryke_string_format_pascal_case.pascalCase)(name)}`
@@ -162,7 +171,7 @@ function BinEntry(props) {
162
171
  return Boolean(postfix);
163
172
  },
164
173
  get fallback() {
165
- return (0, __alloy_js_core_jsx_runtime.createComponent)(ExitFunctionUsage, {});
174
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(RunApplication, {});
166
175
  },
167
176
  children: postfix
168
177
  }),
@@ -175,5 +184,5 @@ function BinEntry(props) {
175
184
 
176
185
  //#endregion
177
186
  exports.BinEntry = BinEntry;
178
- exports.ExitFunctionUsage = ExitFunctionUsage;
187
+ exports.RunApplication = RunApplication;
179
188
  //# sourceMappingURL=bin-entry.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"bin-entry.cjs","names":["code","computed","For","Show","FunctionDeclaration","IfStatement","usePowerlines","EntryFile","TSDoc","getAppTitle","getUnique","findFileName","replaceExtension","pascalCase","defu","ExitFunctionUsage","_$createIntrinsic","BinEntry","props","prefix","postfix","builtinImports","imports","children","rest","context","bins","Object","values","config","bin","_$createComponent","each","value","_$mergeProps","path","typeDefinition","file","output","entries","commands","filter","command","isVirtual","reduce","ret","name","alias","console","utils","when","Boolean","heading","async","returnType","condition","packageJson","version","fallback"],"sources":["../../src/components/bin-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 { FunctionDeclaration, IfStatement } from \"@alloy-js/typescript\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport type { TypescriptFileImports } from \"@powerlines/plugin-alloy/types/components\";\nimport type { EntryFileProps } from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport { EntryFile } from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport { TSDoc } from \"@powerlines/plugin-alloy/typescript/components/tsdoc\";\nimport { getAppTitle } from \"@shell-shock/core/plugin-utils/context-helpers\";\nimport { getUnique } from \"@stryke/helpers/get-unique\";\nimport { findFileName } from \"@stryke/path/file-path-fns\";\nimport { replaceExtension } from \"@stryke/path/replace\";\nimport { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport defu from \"defu\";\nimport type { ScriptPresetContext } from \"../types/plugin\";\n\n/**\n * The `exit` handler function usage code for the Shell Shock project.\n */\nexport function ExitFunctionUsage() {\n return (\n <>\n <hbr />\n {code`(async () => {\n try {\n process.on(\"exit\", () => exit({\n skipExit: true,\n isSynchronous: true,\n signal: 0\n }));\n process.on(\"beforeExit\", () => exit({\n signal: 0\n }));\n process.on(\"message\", message => {\n if (message === 'shutdown') {\n exit({\n isSynchronous: true,\n signal: -128\n });\n }\n });\n\n process.once(\"SIGTERM\", () => exit({\n signal: 15\n }));\n process.once(\"SIGINT\", () => exit({\n signal: 2\n }));\n process.once(\"SIGUSR2\", () => {\n verbose(\"The application was terminated by the user\");\n return exit({\n signal: 12\n });\n });\n process.once(\"SIGQUIT\", () => {\n verbose(\"The application was terminated by the user\");\n return exit({\n signal: 12\n });\n });\n\n for (const type of [\"unhandledRejection\", \"uncaughtException\"]) {\n process.on(type, err => exit({\n exception: err || new Error(\\`An \\${type === \"unhandledRejection\" ? \"unhandled promise rejection\" : \"uncaught exception\"} occurred during processing - the application is shutting down.\\`)\n }));\n }\n\n const result = await main();\n if (result?.error) {\n error(result.error);\n }\n\n exit();\n } catch (err) {\n verbose(\"An exception occurred during processing\");\n exit({ exception: err as Error });\n }\n })();\n `}\n <hbr />\n </>\n );\n}\n\nexport interface BinEntryProps extends Omit<\n EntryFileProps,\n \"path\" | \"hashbang\"\n> {\n prefix?: Children;\n postfix?: Children;\n children: Children;\n}\n\n/**\n * The binary entry point for the Shell Shock project.\n */\nexport function BinEntry(props: BinEntryProps) {\n const { prefix, postfix, builtinImports, imports, children, ...rest } = props;\n\n const context = usePowerlines<ScriptPresetContext>();\n const bins = computed(() => getUnique(Object.values(context.config.bin)));\n\n return (\n <For each={bins.value}>\n {bin => (\n <EntryFile\n {...rest}\n path={findFileName(replaceExtension(bin))}\n typeDefinition={{\n file: bin,\n output: \"bin\"\n }}\n imports={defu(\n imports ?? {},\n Object.entries(context.commands)\n .filter(([, command]) => command.isVirtual)\n .reduce((ret, [name, command]) => {\n ret[`./${command.name}`] = [\n { name: \"handler\", alias: `handle${pascalCase(name)}` }\n ];\n\n return ret;\n }, {} as TypescriptFileImports)\n )}\n builtinImports={defu(builtinImports ?? {}, {\n console: [\"error\", \"verbose\", \"table\"],\n utils: [\"hasFlag\", \"exit\"]\n })}>\n <Show when={Boolean(prefix)}>\n {prefix}\n <hbr />\n <hbr />\n </Show>\n <TSDoc\n heading={`Binary entry point for the ${getAppTitle(context)} CLI application.`}></TSDoc>\n <FunctionDeclaration async returnType=\"any\" name=\"main\">\n <IfStatement condition={code`hasFlag([\"version\", \"v\"])`}>\n {code`console.log(${context?.packageJson.version ? `\"${context?.packageJson.version}\"` : \"0.0.1\"});\n return;`}\n </IfStatement>\n <hbr />\n <hbr />\n {children}\n <hbr />\n </FunctionDeclaration>\n <hbr />\n <hbr />\n <hbr />\n <Show when={Boolean(postfix)} fallback={<ExitFunctionUsage />}>\n {postfix}\n </Show>\n <hbr />\n </EntryFile>\n )}\n </For>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqCA,SAAgBe,oBAAoB;AAClC,QAAA;mDAAA,OAAA,EAAA,CAAA;EAGKf,oBAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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vB,WAAA;AAAA,cAAA;yDAC7ClB,mCAAW;SAACkD,WAAWvD,oBAAI;SAA2B,IAAAuB,WAAA;AAAA,iBACpDvB,oBAAI,eAAeyB,SAAS+B,YAAYC,UAAU,IAAIhC,SAAS+B,YAAYC,QAAO,KAAM,QAAO;;;SAC5F,CAAA;yDAAA,OAAA,EAAA,CAAA;yDAAA,OAAA,EAAA,CAAA;QAILlC;yDAAQ,OAAA,EAAA,CAAA;QAAA;;MAAA,CAAA;sDAAA,OAAA,EAAA,CAAA;sDAAA,OAAA,EAAA,CAAA;sDAAA,OAAA,EAAA,CAAA;sDAMVpB,sBAAI;MAAA,IAAC+C,OAAI;AAAA,cAAEC,QAAQ/B,QAAQ;;MAAA,IAAEsC,WAAQ;AAAA,+DAAG3C,mBAAiB,EAAA,CAAA;;MAAAQ,UACvDH;MAAO,CAAA;sDAAA,OAAA,EAAA,CAAA;KAAA;;GAAA,CAAA,CAAA;EAIb,CAAA"}
1
+ {"version":3,"file":"bin-entry.cjs","names":["code","computed","For","Show","FunctionDeclaration","IfStatement","usePowerlines","EntryFile","TSDoc","getAppTitle","getUnique","findFileName","replaceExtension","pascalCase","defu","RunApplication","_$createIntrinsic","BinEntry","props","prefix","postfix","builtinImports","imports","children","rest","context","bins","Object","values","config","bin","_$createComponent","each","value","_$mergeProps","path","typeDefinition","file","output","didyoumean2","name","default","entries","commands","filter","command","isVirtual","reduce","ret","alias","console","utils","when","Boolean","heading","async","returnType","condition","packageJson","version","fallback"],"sources":["../../src/components/bin-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 { FunctionDeclaration, IfStatement } from \"@alloy-js/typescript\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport type { TypescriptFileImports } from \"@powerlines/plugin-alloy/types/components\";\nimport type { EntryFileProps } from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport { EntryFile } from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport { TSDoc } from \"@powerlines/plugin-alloy/typescript/components/tsdoc\";\nimport { getAppTitle } from \"@shell-shock/core/plugin-utils/context-helpers\";\nimport { getUnique } from \"@stryke/helpers/get-unique\";\nimport { findFileName } from \"@stryke/path/file-path-fns\";\nimport { replaceExtension } from \"@stryke/path/replace\";\nimport { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport defu from \"defu\";\nimport type { ScriptPresetContext } from \"../types/plugin\";\n\n/**\n * Runs the application main logic with proper exit handling.\n */\nexport function RunApplication() {\n return (\n <>\n <hbr />\n <hbr />\n {code`// Run the application main logic inside an asynchronous IIFE\n (async () => {\n try {\n process.on(\"exit\", () => exit({\n skipExit: true,\n isSynchronous: true,\n signal: 0\n }));\n process.on(\"beforeExit\", () => exit({\n signal: 0\n }));\n process.on(\"message\", message => {\n if (message === 'shutdown') {\n exit({\n isSynchronous: true,\n signal: -128\n });\n }\n });\n\n process.once(\"SIGTERM\", () => exit({\n signal: 15\n }));\n process.once(\"SIGINT\", () => exit({\n signal: 2\n }));\n process.once(\"SIGUSR2\", () => {\n verbose(\"The application was terminated by the user\");\n return exit({\n signal: 12\n });\n });\n process.once(\"SIGQUIT\", () => {\n verbose(\"The application was terminated by the user\");\n return exit({\n signal: 12\n });\n });\n\n for (const type of [\"unhandledRejection\", \"uncaughtException\"]) {\n process.on(type, err => exit({\n exception: err || new Error(\\`An \\${type === \"unhandledRejection\" ? \"unhandled promise rejection\" : \"uncaught exception\"} occurred during processing - the application is shutting down.\\`)\n }));\n }\n\n const result = await main();\n if (result?.error) {\n error(result.error);\n }\n\n exit();\n } catch (err) {\n verbose(\"An exception occurred during processing\");\n exit({ exception: err as Error });\n }\n })();\n `}\n <hbr />\n </>\n );\n}\n\nexport interface BinEntryProps extends Omit<\n EntryFileProps,\n \"path\" | \"hashbang\"\n> {\n prefix?: Children;\n postfix?: Children;\n children: Children;\n}\n\n/**\n * The binary entry point for the Shell Shock project.\n */\nexport function BinEntry(props: BinEntryProps) {\n const { prefix, postfix, builtinImports, imports, children, ...rest } = props;\n\n const context = usePowerlines<ScriptPresetContext>();\n const bins = computed(() => getUnique(Object.values(context.config.bin)));\n\n return (\n <For each={bins.value}>\n {bin => (\n <EntryFile\n {...rest}\n path={findFileName(replaceExtension(bin))}\n typeDefinition={{\n file: bin,\n output: \"bin\"\n }}\n imports={defu(\n {\n didyoumean2: [\n { name: \"didYouMean\", default: true },\n { name: \"ReturnTypeEnums\" },\n { name: \"ThresholdTypeEnums\" }\n ]\n },\n imports ?? {},\n Object.entries(context.commands)\n .filter(([, command]) => command.isVirtual)\n .reduce((ret, [name, command]) => {\n ret[`./${command.name}`] = [\n { name: \"handler\", alias: `handle${pascalCase(name)}` }\n ];\n\n return ret;\n }, {} as TypescriptFileImports)\n )}\n builtinImports={defu(builtinImports ?? {}, {\n console: [\"error\", \"verbose\", \"table\"],\n utils: [\"hasFlag\", \"exit\"]\n })}>\n <Show when={Boolean(prefix)}>\n {prefix}\n <hbr />\n <hbr />\n </Show>\n <TSDoc\n heading={`Binary entry point for the ${getAppTitle(context)} CLI application.`}></TSDoc>\n <FunctionDeclaration async returnType=\"any\" name=\"main\">\n <IfStatement condition={code`hasFlag([\"version\", \"v\"])`}>\n {code`console.log(${context?.packageJson.version ? `\"${context?.packageJson.version}\"` : \"0.0.1\"});\n return;`}\n </IfStatement>\n <hbr />\n <hbr />\n {children}\n <hbr />\n </FunctionDeclaration>\n <hbr />\n <hb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;MAAW;MAAQ;KACtCC,OAAO,CAAC,WAAW,OAAM;KAC1B,CAAC;;GAAA,IAAA5B,WAAA;AAAA,WAAA;sDACDpB,sBAAI;MAAA,IAACiD,OAAI;AAAA,cAAEC,QAAQlC,OAAO;;MAAA,IAAAI,WAAA;AAAA,cAAA;QACxBJ;yDAAM,OAAA,EAAA,CAAA;yDAAA,OAAA,EAAA,CAAA;QAAA;;MAAA,CAAA;sDAIRX,6DAAK,EAAA,IACJ8C,UAAO;AAAA,aAAE,+FAA0C7B,QAAQ,CAAA;QAAmB,CAAA;sDAC/ErB,2CAAmB;MAACmD,OAAK;MAACC,YAAU;MAAOhB,MAAI;MAAA,IAAAjB,WAAA;AAAA,cAAA;yDAC7ClB,mCAAW;SAACoD,WAAWzD,oBAAI;SAA2B,IAAAuB,WAAA;AAAA,iBACpDvB,oBAAI,eAAeyB,SAASiC,YAAYC,UAAU,IAAIlC,SAASiC,YAAYC,QAAO,KAAM,QAAO;;;SAC5F,CAAA;yDAAA,OAAA,EAAA,CAAA;yDAAA,OAAA,EAAA,CAAA;QAILpC;yDAAQ,OAAA,EAAA,CAAA;QAAA;;MAAA,CAAA;sDAAA,OAAA,EAAA,CAAA;sDAAA,OAAA,EAAA,CAAA;sDAAA,OAAA,EAAA,CAAA;sDAMVpB,sBAAI;MAAA,IAACiD,OAAI;AAAA,cAAEC,QAAQjC,QAAQ;;MAAA,IAAEwC,WAAQ;AAAA,+DAAG7C,gBAAc,EAAA,CAAA;;MAAAQ,UACpDH;MAAO,CAAA;sDAAA,OAAA,EAAA,CAAA;KAAA;;GAAA,CAAA,CAAA;EAIb,CAAA"}
@@ -4,9 +4,9 @@ import { EntryFileProps } from "@powerlines/plugin-alloy/typescript/components/e
4
4
  //#region src/components/bin-entry.d.ts
5
5
 
6
6
  /**
7
- * The `exit` handler function usage code for the Shell Shock project.
7
+ * Runs the application main logic with proper exit handling.
8
8
  */
9
- declare function ExitFunctionUsage(): Children;
9
+ declare function RunApplication(): Children;
10
10
  interface BinEntryProps extends Omit<EntryFileProps, "path" | "hashbang"> {
11
11
  prefix?: Children;
12
12
  postfix?: Children;
@@ -17,5 +17,5 @@ interface BinEntryProps extends Omit<EntryFileProps, "path" | "hashbang"> {
17
17
  */
18
18
  declare function BinEntry(props: BinEntryProps): Children;
19
19
  //#endregion
20
- export { BinEntry, BinEntryProps, ExitFunctionUsage };
20
+ export { BinEntry, BinEntryProps, RunApplication };
21
21
  //# sourceMappingURL=bin-entry.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bin-entry.d.cts","names":[],"sources":["../../src/components/bin-entry.tsx"],"sourcesContent":[],"mappings":";;;;;;;AAqCA;AAiEiB,iBAjED,iBAAA,CAAA,CAiEe,EAjEE,QAiEF;AAC7B,UADe,aAAA,SAAsB,IACrC,CAAA,cAAA,EAAA,MAAA,GAAA,UAAA,CAAA,CAAA;EAGS,MAAA,CAAA,EAAA,QAAA;EACC,OAAA,CAAA,EAAA,QAAA;EACA,QAAA,EAAA,QAAA;;;AAMZ;;iBAAgB,QAAA,QAAgB,gBAAa"}
1
+ {"version":3,"file":"bin-entry.d.cts","names":[],"sources":["../../src/components/bin-entry.tsx"],"sourcesContent":[],"mappings":";;;;;;;AAqCA;AAmEiB,iBAnED,cAAA,CAAA,CAmEe,EAnED,QAmEC;AAC7B,UADe,aAAA,SAAsB,IACrC,CAAA,cAAA,EAAA,MAAA,GAAA,UAAA,CAAA,CAAA;EAGS,MAAA,CAAA,EAAA,QAAA;EACC,OAAA,CAAA,EAAA,QAAA;EACA,QAAA,EAAA,QAAA;;;AAMZ;;iBAAgB,QAAA,QAAgB,gBAAa"}
@@ -4,9 +4,9 @@ import { EntryFileProps } from "@powerlines/plugin-alloy/typescript/components/e
4
4
  //#region src/components/bin-entry.d.ts
5
5
 
6
6
  /**
7
- * The `exit` handler function usage code for the Shell Shock project.
7
+ * Runs the application main logic with proper exit handling.
8
8
  */
9
- declare function ExitFunctionUsage(): Children;
9
+ declare function RunApplication(): Children;
10
10
  interface BinEntryProps extends Omit<EntryFileProps, "path" | "hashbang"> {
11
11
  prefix?: Children;
12
12
  postfix?: Children;
@@ -17,5 +17,5 @@ interface BinEntryProps extends Omit<EntryFileProps, "path" | "hashbang"> {
17
17
  */
18
18
  declare function BinEntry(props: BinEntryProps): Children;
19
19
  //#endregion
20
- export { BinEntry, BinEntryProps, ExitFunctionUsage };
20
+ export { BinEntry, BinEntryProps, RunApplication };
21
21
  //# sourceMappingURL=bin-entry.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bin-entry.d.mts","names":[],"sources":["../../src/components/bin-entry.tsx"],"sourcesContent":[],"mappings":";;;;;;;AAqCA;AAiEiB,iBAjED,iBAAA,CAAA,CAiEe,EAjEE,QAiEF;AAC7B,UADe,aAAA,SAAsB,IACrC,CAAA,cAAA,EAAA,MAAA,GAAA,UAAA,CAAA,CAAA;EAGS,MAAA,CAAA,EAAA,QAAA;EACC,OAAA,CAAA,EAAA,QAAA;EACA,QAAA,EAAA,QAAA;;;AAMZ;;iBAAgB,QAAA,QAAgB,gBAAa"}
1
+ {"version":3,"file":"bin-entry.d.mts","names":[],"sources":["../../src/components/bin-entry.tsx"],"sourcesContent":[],"mappings":";;;;;;;AAqCA;AAmEiB,iBAnED,cAAA,CAAA,CAmEe,EAnED,QAmEC;AAC7B,UADe,aAAA,SAAsB,IACrC,CAAA,cAAA,EAAA,MAAA,GAAA,UAAA,CAAA,CAAA;EAGS,MAAA,CAAA,EAAA,QAAA;EACC,OAAA,CAAA,EAAA,QAAA;EACA,QAAA,EAAA,QAAA;;;AAMZ;;iBAAgB,QAAA,QAAgB,gBAAa"}
@@ -13,12 +13,14 @@ import defu from "defu";
13
13
 
14
14
  //#region src/components/bin-entry.tsx
15
15
  /**
16
- * The `exit` handler function usage code for the Shell Shock project.
16
+ * Runs the application main logic with proper exit handling.
17
17
  */
18
- function ExitFunctionUsage() {
18
+ function RunApplication() {
19
19
  return [
20
20
  createIntrinsic("hbr", {}),
21
- code`(async () => {
21
+ createIntrinsic("hbr", {}),
22
+ code`// Run the application main logic inside an asynchronous IIFE
23
+ (async () => {
22
24
  try {
23
25
  process.on("exit", () => exit({
24
26
  skipExit: true,
@@ -97,7 +99,14 @@ function BinEntry(props) {
97
99
  output: "bin"
98
100
  },
99
101
  get imports() {
100
- return defu(imports ?? {}, Object.entries(context.commands).filter(([, command]) => command.isVirtual).reduce((ret, [name, command]) => {
102
+ return defu({ didyoumean2: [
103
+ {
104
+ name: "didYouMean",
105
+ default: true
106
+ },
107
+ { name: "ReturnTypeEnums" },
108
+ { name: "ThresholdTypeEnums" }
109
+ ] }, imports ?? {}, Object.entries(context.commands).filter(([, command]) => command.isVirtual).reduce((ret, [name, command]) => {
101
110
  ret[`./${command.name}`] = [{
102
111
  name: "handler",
103
112
  alias: `handle${pascalCase(name)}`
@@ -160,7 +169,7 @@ function BinEntry(props) {
160
169
  return Boolean(postfix);
161
170
  },
162
171
  get fallback() {
163
- return createComponent(ExitFunctionUsage, {});
172
+ return createComponent(RunApplication, {});
164
173
  },
165
174
  children: postfix
166
175
  }),
@@ -172,5 +181,5 @@ function BinEntry(props) {
172
181
  }
173
182
 
174
183
  //#endregion
175
- export { BinEntry, ExitFunctionUsage };
184
+ export { BinEntry, RunApplication };
176
185
  //# sourceMappingURL=bin-entry.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"bin-entry.mjs","names":["code","computed","For","Show","FunctionDeclaration","IfStatement","usePowerlines","EntryFile","TSDoc","getAppTitle","getUnique","findFileName","replaceExtension","pascalCase","defu","ExitFunctionUsage","_$createIntrinsic","BinEntry","props","prefix","postfix","builtinImports","imports","children","rest","context","bins","Object","values","config","bin","_$createComponent","each","value","_$mergeProps","path","typeDefinition","file","output","entries","commands","filter","command","isVirtual","reduce","ret","name","alias","console","utils","when","Boolean","heading","async","returnType","condition","packageJson","version","fallback"],"sources":["../../src/components/bin-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 { FunctionDeclaration, IfStatement } from \"@alloy-js/typescript\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport type { TypescriptFileImports } from \"@powerlines/plugin-alloy/types/components\";\nimport type { EntryFileProps } from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport { EntryFile } from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport { TSDoc } from \"@powerlines/plugin-alloy/typescript/components/tsdoc\";\nimport { getAppTitle } from \"@shell-shock/core/plugin-utils/context-helpers\";\nimport { getUnique } from \"@stryke/helpers/get-unique\";\nimport { findFileName } from \"@stryke/path/file-path-fns\";\nimport { replaceExtension } from \"@stryke/path/replace\";\nimport { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport defu from \"defu\";\nimport type { ScriptPresetContext } from \"../types/plugin\";\n\n/**\n * The `exit` handler function usage code for the Shell Shock project.\n */\nexport function ExitFunctionUsage() {\n return (\n <>\n <hbr />\n {code`(async () => {\n try {\n process.on(\"exit\", () => exit({\n skipExit: true,\n isSynchronous: true,\n signal: 0\n }));\n process.on(\"beforeExit\", () => exit({\n signal: 0\n }));\n process.on(\"message\", message => {\n if (message === 'shutdown') {\n exit({\n isSynchronous: true,\n signal: -128\n });\n }\n });\n\n process.once(\"SIGTERM\", () => exit({\n signal: 15\n }));\n process.once(\"SIGINT\", () => exit({\n signal: 2\n }));\n process.once(\"SIGUSR2\", () => {\n verbose(\"The application was terminated by the user\");\n return exit({\n signal: 12\n });\n });\n process.once(\"SIGQUIT\", () => {\n verbose(\"The application was terminated by the user\");\n return exit({\n signal: 12\n });\n });\n\n for (const type of [\"unhandledRejection\", \"uncaughtException\"]) {\n process.on(type, err => exit({\n exception: err || new Error(\\`An \\${type === \"unhandledRejection\" ? \"unhandled promise rejection\" : \"uncaught exception\"} occurred during processing - the application is shutting down.\\`)\n }));\n }\n\n const result = await main();\n if (result?.error) {\n error(result.error);\n }\n\n exit();\n } catch (err) {\n verbose(\"An exception occurred during processing\");\n exit({ exception: err as Error });\n }\n })();\n `}\n <hbr />\n </>\n );\n}\n\nexport interface BinEntryProps extends Omit<\n EntryFileProps,\n \"path\" | \"hashbang\"\n> {\n prefix?: Children;\n postfix?: Children;\n children: Children;\n}\n\n/**\n * The binary entry point for the Shell Shock project.\n */\nexport function BinEntry(props: BinEntryProps) {\n const { prefix, postfix, builtinImports, imports, children, ...rest } = props;\n\n const context = usePowerlines<ScriptPresetContext>();\n const bins = computed(() => getUnique(Object.values(context.config.bin)));\n\n return (\n <For each={bins.value}>\n {bin => (\n <EntryFile\n {...rest}\n path={findFileName(replaceExtension(bin))}\n typeDefinition={{\n file: bin,\n output: \"bin\"\n }}\n imports={defu(\n imports ?? {},\n Object.entries(context.commands)\n .filter(([, command]) => command.isVirtual)\n .reduce((ret, [name, command]) => {\n ret[`./${command.name}`] = [\n { name: \"handler\", alias: `handle${pascalCase(name)}` }\n ];\n\n return ret;\n }, {} as TypescriptFileImports)\n )}\n builtinImports={defu(builtinImports ?? {}, {\n console: [\"error\", \"verbose\", \"table\"],\n utils: [\"hasFlag\", \"exit\"]\n })}>\n <Show when={Boolean(prefix)}>\n {prefix}\n <hbr />\n <hbr />\n </Show>\n <TSDoc\n heading={`Binary entry point for the ${getAppTitle(context)} CLI application.`}></TSDoc>\n <FunctionDeclaration async returnType=\"any\" name=\"main\">\n <IfStatement condition={code`hasFlag([\"version\", \"v\"])`}>\n {code`console.log(${context?.packageJson.version ? `\"${context?.packageJson.version}\"` : \"0.0.1\"});\n return;`}\n </IfStatement>\n <hbr />\n <hbr />\n {children}\n <hbr />\n </FunctionDeclaration>\n <hbr />\n <hbr />\n <hbr />\n <Show when={Boolean(postfix)} fallback={<ExitFunctionUsage />}>\n {postfix}\n </Show>\n <hbr />\n </EntryFile>\n )}\n </For>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqCA,SAAgBe,oBAAoB;AAClC,QAAA;EAAAC,gBAAA,OAAA,EAAA,CAAA;EAGKhB,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuDJgB,gBAAA,OAAA,EAAA,CAAA;EAAA;;;;;AAkBP,SAAgBC,SAASC,OAAsB;CAC7C,MAAM,EAAEC,QAAQC,SAASC,gBAAgBC,SAASC,UAAU,GAAGC,SAASN;CAExE,MAAMO,UAAUnB,eAAoC;CACpD,MAAMoB,OAAOzB,eAAeS,UAAUiB,OAAOC,OAAOH,QAAQI,OAAOC,IAAI,CAAC,CAAC;AAEzE,QAAAC,gBACG7B,KAAG;EAAA,IAAC8B,OAAI;AAAA,UAAEN,KAAKO;;EAAKV,WAClBO,QAAGC,gBACDxB,WAAS2B,WACJV,MAAI;GAAA,IACRW,OAAI;AAAA,WAAExB,aAAaC,iBAAiBkB,IAAI,CAAC;;GACzCM,gBAAgB;IACdC,MAAMP;IACNQ,QAAQ;IACT;GAAA,IACDhB,UAAO;AAAA,WAAER,KACPQ,WAAW,EAAE,EACbK,OAAOY,QAAQd,QAAQe,SAAS,CAC7BC,QAAQ,GAAGC,aAAaA,QAAQC,UAAU,CAC1CC,QAAQC,KAAK,CAACC,MAAMJ,aAAa;AAChCG,SAAI,KAAKH,QAAQI,UAAU,CACzB;MAAEA,MAAM;MAAWC,OAAO,SAASlC,WAAWiC,KAAK;MAAI,CACxD;AAED,YAAOD;OACN,EAA2B,CAClC,CAAC;;GAAA,IACDxB,iBAAc;AAAA,WAAEP,KAAK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ration","IfStatement","usePowerlines","EntryFile","TSDoc","getAppTitle","getUnique","findFileName","replaceExtension","pascalCase","defu","RunApplication","_$createIntrinsic","BinEntry","props","prefix","postfix","builtinImports","imports","children","rest","context","bins","Object","values","config","bin","_$createComponent","each","value","_$mergeProps","path","typeDefinition","file","output","didyoumean2","name","default","entries","commands","filter","command","isVirtual","reduce","ret","alias","console","utils","when","Boolean","heading","async","returnType","condition","packageJson","version","fallback"],"sources":["../../src/components/bin-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 { FunctionDeclaration, IfStatement } from \"@alloy-js/typescript\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport type { TypescriptFileImports } from \"@powerlines/plugin-alloy/types/components\";\nimport type { EntryFileProps } from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport { EntryFile } from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport { TSDoc } from \"@powerlines/plugin-alloy/typescript/components/tsdoc\";\nimport { getAppTitle } from \"@shell-shock/core/plugin-utils/context-helpers\";\nimport { getUnique } from \"@stryke/helpers/get-unique\";\nimport { findFileName } from \"@stryke/path/file-path-fns\";\nimport { replaceExtension } from \"@stryke/path/replace\";\nimport { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport defu from \"defu\";\nimport type { ScriptPresetContext } from \"../types/plugin\";\n\n/**\n * Runs the application main logic with proper exit handling.\n */\nexport function RunApplication() {\n return (\n <>\n <hbr />\n <hbr />\n {code`// Run the application main logic inside an asynchronous IIFE\n (async () => {\n try {\n process.on(\"exit\", () => exit({\n skipExit: true,\n isSynchronous: true,\n signal: 0\n }));\n process.on(\"beforeExit\", () => exit({\n signal: 0\n }));\n process.on(\"message\", message => {\n if (message === 'shutdown') {\n exit({\n isSynchronous: true,\n signal: -128\n });\n }\n });\n\n process.once(\"SIGTERM\", () => exit({\n signal: 15\n }));\n process.once(\"SIGINT\", () => exit({\n signal: 2\n }));\n process.once(\"SIGUSR2\", () => {\n verbose(\"The application was terminated by the user\");\n return exit({\n signal: 12\n });\n });\n process.once(\"SIGQUIT\", () => {\n verbose(\"The application was terminated by the user\");\n return exit({\n signal: 12\n });\n });\n\n for (const type of [\"unhandledRejection\", \"uncaughtException\"]) {\n process.on(type, err => exit({\n exception: err || new Error(\\`An \\${type === \"unhandledRejection\" ? \"unhandled promise rejection\" : \"uncaught exception\"} occurred during processing - the application is shutting down.\\`)\n }));\n }\n\n const result = await main();\n if (result?.error) {\n error(result.error);\n }\n\n exit();\n } catch (err) {\n verbose(\"An exception occurred during processing\");\n exit({ exception: err as Error });\n }\n })();\n `}\n <hbr />\n </>\n );\n}\n\nexport interface BinEntryProps extends Omit<\n EntryFileProps,\n \"path\" | \"hashbang\"\n> {\n prefix?: Children;\n postfix?: Children;\n children: Children;\n}\n\n/**\n * The binary entry point for the Shell Shock project.\n */\nexport function BinEntry(props: BinEntryProps) {\n const { prefix, postfix, builtinImports, imports, children, ...rest } = props;\n\n const context = usePowerlines<ScriptPresetContext>();\n const bins = computed(() => getUnique(Object.values(context.config.bin)));\n\n return (\n <For each={bins.value}>\n {bin => (\n <EntryFile\n {...rest}\n path={findFileName(replaceExtension(bin))}\n typeDefinition={{\n file: bin,\n output: \"bin\"\n }}\n imports={defu(\n {\n didyoumean2: [\n { name: \"didYouMean\", default: true },\n { name: \"ReturnTypeEnums\" },\n { name: \"ThresholdTypeEnums\" }\n ]\n },\n imports ?? {},\n Object.entries(context.commands)\n .filter(([, command]) => command.isVirtual)\n .reduce((ret, [name, command]) => {\n ret[`./${command.name}`] = [\n { name: \"handler\", alias: `handle${pascalCase(name)}` }\n ];\n\n return ret;\n }, {} as TypescriptFileImports)\n )}\n builtinImports={defu(builtinImports ?? {}, {\n console: [\"error\", \"verbose\", \"table\"],\n utils: [\"hasFlag\", \"exit\"]\n })}>\n <Show when={Boolean(prefix)}>\n {prefix}\n <hbr />\n <hbr />\n </Show>\n <TSDoc\n heading={`Binary entry point for the ${getAppTitle(context)} CLI application.`}></TSDoc>\n <FunctionDeclaration async returnType=\"any\" name=\"main\">\n <IfStatement condition={code`hasFlag([\"version\", \"v\"])`}>\n {code`console.log(${context?.packageJson.version ? `\"${context?.packageJson.version}\"` : \"0.0.1\"});\n return;`}\n </IfStatement>\n <hbr />\n <hbr />\n {children}\n <hbr />\n </FunctionDeclaration>\n <hbr />\n <hbr />\n <hbr />\n <Show when={Boolean(postfix)} fallback={<RunApplication />}>\n {postfix}\n </Show>\n <hbr />\n </EntryFile>\n )}\n </For>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqCA,SAAgBe,iBAAiB;AAC/B,QAAA;EAAAC,gBAAA,OAAA,EAAA,CAAA;EAAAA,gBAAA,OAAA,EAAA,CAAA;EAIKhB,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwDJgB,gBAAA,OAAA,EAAA,CAAA;EAAA;;;;;AAkBP,SAAgBC,SAASC,OAAsB;CAC7C,MAAM,EAAEC,QAAQC,SAASC,gBAAgBC,SAASC,UAAU,GAAGC,SAASN;CAExE,MAAMO,UAAUnB,eAAoC;CACpD,MAAMoB,OAAOzB,eAAeS,UAAUiB,OAAOC,OAAOH,QAAQI,OAAOC,IAAI,CAAC,CAAC;AAEzE,QAAAC,gBACG7B,KAAG;EAAA,IAAC8B,OAAI;AAAA,UAAEN,KAAKO;;EAAK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AAAA,iBACpDvB,IAAI,eAAeyB,SAASiC,YAAYC,UAAU,IAAIlC,SAASiC,YAAYC,QAAO,KAAM,QAAO;;;SAC5F,CAAA;QAAA3C,gBAAA,OAAA,EAAA,CAAA;QAAAA,gBAAA,OAAA,EAAA,CAAA;QAILO;QAAQP,gBAAA,OAAA,EAAA,CAAA;QAAA;;MAAA,CAAA;KAAAA,gBAAA,OAAA,EAAA,CAAA;KAAAA,gBAAA,OAAA,EAAA,CAAA;KAAAA,gBAAA,OAAA,EAAA,CAAA;KAAAe,gBAMV5B,MAAI;MAAA,IAACiD,OAAI;AAAA,cAAEC,QAAQjC,QAAQ;;MAAA,IAAEwC,WAAQ;AAAA,cAAA7B,gBAAGhB,gBAAc,EAAA,CAAA;;MAAAQ,UACpDH;MAAO,CAAA;KAAAJ,gBAAA,OAAA,EAAA,CAAA;KAAA;;GAAA,CAAA,CAAA;EAIb,CAAA"}
@@ -3,6 +3,7 @@ let __alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
3
3
  let __alloy_js_core = require("@alloy-js/core");
4
4
  let __alloy_js_typescript = require("@alloy-js/typescript");
5
5
  let __shell_shock_core_plugin_utils_context_helpers = require("@shell-shock/core/plugin-utils/context-helpers");
6
+ let __powerlines_plugin_alloy_core_contexts_context = require("@powerlines/plugin-alloy/core/contexts/context");
6
7
  let __stryke_string_format_pascal_case = require("@stryke/string-format/pascal-case");
7
8
  let __powerlines_plugin_alloy_typescript_components_dynamic_import_statement = require("@powerlines/plugin-alloy/typescript/components/dynamic-import-statement");
8
9
  let __shell_shock_core_contexts_command = require("@shell-shock/core/contexts/command");
@@ -36,7 +37,7 @@ function CommandRouterRoute() {
36
37
  */
37
38
  function CommandRouter(props) {
38
39
  const { path, commands, route } = props;
39
- const command = (0, __shell_shock_core_contexts_command.useCommand)();
40
+ const context = (0, __powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
40
41
  const index = (0, __alloy_js_core.computed)(() => 2 + (path.length ?? 0));
41
42
  return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
42
43
  get when() {
@@ -67,60 +68,82 @@ function CommandRouter(props) {
67
68
  children: (subcommand, idx) => (0, __alloy_js_core_jsx_runtime.createComponent)(__shell_shock_core_contexts_command.CommandContext.Provider, {
68
69
  value: subcommand,
69
70
  get children() {
70
- return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
71
+ return [(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
71
72
  get when() {
72
- return subcommand.name !== command?.name;
73
+ return Boolean(idx);
73
74
  },
74
- get children() {
75
- return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
76
- get when() {
77
- return Boolean(idx);
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, "")}"`;
78
79
  },
79
- get fallback() {
80
- return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.IfStatement, {
81
- get condition() {
82
- return __alloy_js_core.code`command.toLowerCase() === "${subcommand.name.toLowerCase()}"`;
80
+ get children() {
81
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
82
+ get when() {
83
+ return Boolean(route);
83
84
  },
84
- get children() {
85
- return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
86
- get when() {
87
- return Boolean(route);
88
- },
89
- get fallback() {
90
- return (0, __alloy_js_core_jsx_runtime.createComponent)(CommandRouterRoute, {});
91
- },
92
- children: route
93
- });
94
- }
85
+ get fallback() {
86
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(CommandRouterRoute, {});
87
+ },
88
+ children: route
95
89
  });
90
+ }
91
+ });
92
+ },
93
+ get children() {
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, "")}"`;
96
97
  },
97
98
  get children() {
98
- return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.ElseIfClause, {
99
- get condition() {
100
- return __alloy_js_core.code`command.toLowerCase() === "${subcommand.name.toLowerCase()}"`;
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, {});
101
105
  },
102
- get children() {
103
- return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
104
- get when() {
105
- return Boolean(route);
106
- },
107
- get fallback() {
108
- return (0, __alloy_js_core_jsx_runtime.createComponent)(CommandRouterRoute, {});
109
- },
110
- children: route
111
- });
112
- }
106
+ children: route
113
107
  });
114
108
  }
115
109
  });
116
110
  }
117
- });
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
+ })];
118
133
  }
119
134
  })
120
135
  }),
121
136
  (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.ElseIfClause, {
122
137
  condition: __alloy_js_core.code`Boolean(command)`,
123
- children: __alloy_js_core.code`error("Unknown command: " + 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: ${JSON.stringify(context.config.isCaseSensitive)},
141
+ returnType: ReturnTypeEnums.ALL_CLOSEST_MATCHES,
142
+ thresholdType: ThresholdTypeEnums.SIMILARITY,
143
+ threshold: 0.75
144
+ });
145
+ 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}"\`)}?\` : ""} \`);`;
146
+ }
124
147
  })
125
148
  ];
126
149
  }
@@ -1 +1 @@
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);`}</ElseIfClause>\n </Show>\n );\n}\n"],"mappings":";;;;;;;;;;AA+BA,SAAgBY,qBAAqB;CACnC,MAAMC,+DAAsB;AAE5B,QAAA;mDAEKV,sBAAI;GAAA,IAACY,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,KAAKC,SAASC,QACpBC,YAAW,4EAAuBA,QACpC,CAAC,CACCV,QAAQO,KAAKC,SAASC,QACpBC,YAAW,4EAAuBA,QACpC,CAAC,CAACC,SAAS;;KAGfC,YAAU;KAAA,CAAA;;GAAA,CAAA;mDAAA,OAAA,EAAA,CAAA;8CAIbzB,oBAAI,mEAA2Ba,QAAQK,KAAK,CAAA,SAAS;EAAA;;;;;AAc5D,SAAgBU,cAAcC,OAA2B;CACvD,MAAM,EAAET,MAAMU,UAAUC,UAAUF;CAElC,MAAMhB,+DAAsB;CAC5B,MAAMmB,4CAAuB,KAAKZ,KAAKI,UAAU,GAAG;AAEpD,yDACGrB,sBAAI;EAAA,IAACY,OAAI;AAAA,UAAEe,YAAYG,OAAOC,KAAKJ,SAAS,CAACN,SAAS;;EAAC,IAAAP,WAAA;AAAA,UAAA;qDACrDX,sCAAc;KA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AAK,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
+ {"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","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 { 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: ${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,KAAKC,SAASC,QACpBC,YAAW,4EAAuBA,QACpC,CAAC,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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;2BACQC,KAAKC,UAAUzB,QAAQe,OAAOC,gBAAgB,CAAA;;;;;;;KAK4N,CAAA;IAAA;;EAAA,CAAA"}
@@ -1 +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
+ {"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 +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
+ {"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"}
@@ -2,6 +2,7 @@ import { createComponent, createIntrinsic, memo } from "@alloy-js/core/jsx-runti
2
2
  import { For, Show, code, computed } from "@alloy-js/core";
3
3
  import { ElseIfClause, IfStatement, VarDeclaration } from "@alloy-js/typescript";
4
4
  import { isVariableCommandPath } from "@shell-shock/core/plugin-utils/context-helpers";
5
+ import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
5
6
  import { pascalCase } from "@stryke/string-format/pascal-case";
6
7
  import { DynamicImportStatement } from "@powerlines/plugin-alloy/typescript/components/dynamic-import-statement";
7
8
  import { CommandContext, useCommand } from "@shell-shock/core/contexts/command";
@@ -35,7 +36,7 @@ function CommandRouterRoute() {
35
36
  */
36
37
  function CommandRouter(props) {
37
38
  const { path, commands, route } = props;
38
- const command = useCommand();
39
+ const context = usePowerlines();
39
40
  const index = computed(() => 2 + (path.length ?? 0));
40
41
  return createComponent(Show, {
41
42
  get when() {
@@ -66,60 +67,82 @@ function CommandRouter(props) {
66
67
  children: (subcommand, idx) => createComponent(CommandContext.Provider, {
67
68
  value: subcommand,
68
69
  get children() {
69
- return createComponent(Show, {
70
+ return [createComponent(Show, {
70
71
  get when() {
71
- return subcommand.name !== command?.name;
72
+ return Boolean(idx);
72
73
  },
73
- get children() {
74
- return createComponent(Show, {
75
- get when() {
76
- return Boolean(idx);
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, "")}"`;
77
78
  },
78
- get fallback() {
79
- return createComponent(IfStatement, {
80
- get condition() {
81
- return code`command.toLowerCase() === "${subcommand.name.toLowerCase()}"`;
79
+ get children() {
80
+ return createComponent(Show, {
81
+ get when() {
82
+ return Boolean(route);
82
83
  },
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
- }
84
+ get fallback() {
85
+ return createComponent(CommandRouterRoute, {});
86
+ },
87
+ children: route
94
88
  });
89
+ }
90
+ });
91
+ },
92
+ get children() {
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, "")}"`;
95
96
  },
96
97
  get children() {
97
- return createComponent(ElseIfClause, {
98
- get condition() {
99
- return code`command.toLowerCase() === "${subcommand.name.toLowerCase()}"`;
98
+ return createComponent(Show, {
99
+ get when() {
100
+ return Boolean(route);
101
+ },
102
+ get fallback() {
103
+ return createComponent(CommandRouterRoute, {});
100
104
  },
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
- }
105
+ children: route
112
106
  });
113
107
  }
114
108
  });
115
109
  }
116
- });
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
+ })];
117
132
  }
118
133
  })
119
134
  }),
120
135
  createComponent(ElseIfClause, {
121
136
  condition: code`Boolean(command)`,
122
- children: code`error("Unknown command: " + 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: ${JSON.stringify(context.config.isCaseSensitive)},
140
+ returnType: ReturnTypeEnums.ALL_CLOSEST_MATCHES,
141
+ thresholdType: ThresholdTypeEnums.SIMILARITY,
142
+ threshold: 0.75
143
+ });
144
+ 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}"\`)}?\` : ""} \`);`;
145
+ }
123
146
  })
124
147
  ];
125
148
  }