@shell-shock/preset-script 0.1.2 → 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 (44) hide show
  1. package/dist/components/args-parser-logic.d.cts +7 -7
  2. package/dist/components/args-parser-logic.d.cts.map +1 -1
  3. package/dist/components/bin-entry.cjs +15 -6
  4. package/dist/components/bin-entry.cjs.map +1 -1
  5. package/dist/components/bin-entry.d.cts +3 -3
  6. package/dist/components/bin-entry.d.cts.map +1 -1
  7. package/dist/components/bin-entry.d.mts +3 -3
  8. package/dist/components/bin-entry.d.mts.map +1 -1
  9. package/dist/components/bin-entry.mjs +15 -6
  10. package/dist/components/bin-entry.mjs.map +1 -1
  11. package/dist/components/command-entry.d.cts +4 -4
  12. package/dist/components/command-router.cjs +63 -38
  13. package/dist/components/command-router.cjs.map +1 -1
  14. package/dist/components/command-router.d.cts.map +1 -1
  15. package/dist/components/command-router.d.mts.map +1 -1
  16. package/dist/components/command-router.mjs +63 -38
  17. package/dist/components/command-router.mjs.map +1 -1
  18. package/dist/components/console-builtin.cjs +9 -6
  19. package/dist/components/console-builtin.cjs.map +1 -1
  20. package/dist/components/console-builtin.d.cts.map +1 -1
  21. package/dist/components/console-builtin.d.mts.map +1 -1
  22. package/dist/components/console-builtin.mjs +9 -6
  23. package/dist/components/console-builtin.mjs.map +1 -1
  24. package/dist/components/help.d.cts +5 -5
  25. package/dist/components/index.cjs +1 -1
  26. package/dist/components/index.d.cts +2 -2
  27. package/dist/components/index.d.mts +2 -2
  28. package/dist/components/index.mjs +2 -2
  29. package/dist/components/utils-builtin.d.cts +7 -7
  30. package/dist/components/virtual-command-entry.cjs +8 -1
  31. package/dist/components/virtual-command-entry.cjs.map +1 -1
  32. package/dist/components/virtual-command-entry.d.cts +3 -3
  33. package/dist/components/virtual-command-entry.d.cts.map +1 -1
  34. package/dist/components/virtual-command-entry.mjs +8 -1
  35. package/dist/components/virtual-command-entry.mjs.map +1 -1
  36. package/dist/index.cjs +3 -0
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.d.cts.map +1 -1
  39. package/dist/index.d.mts.map +1 -1
  40. package/dist/index.mjs +3 -0
  41. package/dist/index.mjs.map +1 -1
  42. package/dist/types/plugin.d.cts.map +1 -1
  43. package/dist/types/plugin.d.mts.map +1 -1
  44. package/package.json +10 -10
@@ -1,16 +1,16 @@
1
- import * as _alloy_js_core14 from "@alloy-js/core";
1
+ import * as _alloy_js_core9 from "@alloy-js/core";
2
2
  import { CommandOption, CommandParam, CommandTree, CommandTreePath } from "@shell-shock/core/types/command";
3
3
 
4
4
  //#region src/components/args-parser-logic.d.ts
5
5
  declare function VariablePathsParserLogic(props: {
6
6
  path: CommandTreePath;
7
- }): _alloy_js_core14.Children;
7
+ }): _alloy_js_core9.Children;
8
8
  /**
9
9
  * The command parameter parser logic.
10
10
  */
11
11
  declare function ParamsParserLogic(props: {
12
12
  params: CommandParam[];
13
- }): _alloy_js_core14.Children;
13
+ }): _alloy_js_core9.Children;
14
14
  /**
15
15
  * The command option interface property.
16
16
  */
@@ -20,7 +20,7 @@ declare function OptionsMember({
20
20
  }: {
21
21
  name: string;
22
22
  option: CommandOption;
23
- }): _alloy_js_core14.Children;
23
+ }): _alloy_js_core9.Children;
24
24
  /**
25
25
  * The command option property parser logic.
26
26
  */
@@ -30,16 +30,16 @@ declare function OptionsMemberParserLogic({
30
30
  }: {
31
31
  name: string;
32
32
  option: CommandOption;
33
- }): _alloy_js_core14.Children;
33
+ }): _alloy_js_core9.Children;
34
34
  declare function OptionsInterfaceDeclaration(props: {
35
35
  command: CommandTree;
36
- }): _alloy_js_core14.Children;
36
+ }): _alloy_js_core9.Children;
37
37
  /**
38
38
  * The command options parser logic.
39
39
  */
40
40
  declare function OptionsParserLogic(props: {
41
41
  command: CommandTree;
42
- }): _alloy_js_core14.Children;
42
+ }): _alloy_js_core9.Children;
43
43
  //#endregion
44
44
  export { OptionsInterfaceDeclaration, OptionsMember, OptionsMemberParserLogic, OptionsParserLogic, ParamsParserLogic, VariablePathsParserLogic };
45
45
  //# sourceMappingURL=args-parser-logic.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"args-parser-logic.d.cts","names":[],"sources":["../../src/components/args-parser-logic.tsx"],"sourcesContent":[],"mappings":";;;;iBAiDgB,wBAAA;QAAwC;IAAe,gBAAA,CAAE;AAAzE;AAsDA;AA4EA;AACE,iBA7Ec,iBAAA,CA6Ed,KAAA,EAAA;EACA,MAAA,EA9EiD,YA8EjD,EAAA;CAGQ,CAAA,EAjFqD,gBAAA,CAAI,QAiFzD;;;AAoEV;AACE,iBA1Ec,aAAA,CA0Ed;EAAA,IAAA;EAAA;CAAA,EAAA;EACA,IAAA,EAAA,MAAA;EAGQ,MAAA,EAzEA,aAyEA;CAAa,CAAA,EAzEA,gBAAA,CACtB,QAyEA;;AAuND;AAeA;iBA5OgB,wBAAA;;;;;UAKN;IAAa,gBAAA,CACtB;iBAuNe,2BAAA;WAA8C;IAAW,gBAAA,CAAE;;;;iBAe3D,kBAAA;WAAqC;IAAW,gBAAA,CAAE"}
1
+ {"version":3,"file":"args-parser-logic.d.cts","names":[],"sources":["../../src/components/args-parser-logic.tsx"],"sourcesContent":[],"mappings":";;;;iBAiDgB,wBAAA;QAAwC;IAAe,eAAA,CAAE;AAAzE;AAsDA;AA4EA;AACE,iBA7Ec,iBAAA,CA6Ed,KAAA,EAAA;EACA,MAAA,EA9EiD,YA8EjD,EAAA;CAGQ,CAAA,EAjFqD,eAAA,CAAI,QAiFzD;;;AAoEV;AACE,iBA1Ec,aAAA,CA0Ed;EAAA,IAAA;EAAA;CAAA,EAAA;EACA,IAAA,EAAA,MAAA;EAGQ,MAAA,EAzEA,aAyEA;CAAa,CAAA,EAzEA,eAAA,CACtB,QAyEA;;AAuND;AAeA;iBA5OgB,wBAAA;;;;;UAKN;IAAa,eAAA,CACtB;iBAuNe,2BAAA;WAA8C;IAAW,eAAA,CAAE;;;;iBAe3D,kBAAA;WAAqC;IAAW,eAAA,CAAE"}
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mDAuDJ,OAAA,EAAA,CAAA;EAAA;;;;;AAkBP,SAAgBiB,SAASC,OAAsB;CAC7C,MAAM,EAAEC,QAAQC,SAASC,gBAAgBC,SAASC,UAAU,GAAGC,SAASN;CAExE,MAAMO,8EAA8C;CACpD,MAAMC,sFAAgCC,OAAOC,OAAOH,QAAQI,OAAOC,IAAI,CAAC,CAAC;AAEzE,yDACG5B,qBAAG;EAAA,IAAC8B,OAAI;AAAA,UAAEN,KAAKO;;EAAKV,WAClBO,yDACEvB,kHACKiB,MAAI;GAAA,IACRW,OAAI;AAAA,qGAAgCL,IAAI,CAAC;;GACzCM,gBAAgB;IACd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AAI;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 <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;mDAAA,OAAA,EAAA,CAAA;mDAAA,OAAA,EAAA,CAAA;EAIKf,oBAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mDAwDJ,OAAA,EAAA,CAAA;EAAA;;;;;AAkBP,SAAgBiB,SAASC,OAAsB;CAC7C,MAAM,EAAEC,QAAQC,SAASC,g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AI;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,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YgB,QAAQ,CAAA;QAAmB,CAAA;KAAAM,gBAC/E3B,qBAAmB;MAACiD,OAAK;MAACC,YAAU;MAAOR,MAAI;MAAA,IAAAvB,WAAA;AAAA,cAAA;QAAAQ,gBAC7C1B,aAAW;SAACkD,WAAWvD,IAAI;SAA2B,IAAAuB,WAAA;AAAA,iBACpDvB,IAAI,eAAeyB,SAAS+B,YAAYC,UAAU,IAAIhC,SAAS+B,YAAYC,QAAO,KAAM,QAAO;;;SAC5F,CAAA;QAAAzC,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,IAAC+C,OAAI;AAAA,cAAEC,QAAQ/B,QAAQ;;MAAA,IAAEsC,WAAQ;AAAA,cAAA3B,gBAAGhB,mBAAiB,EAAA,CAAA;;MAAAQ,UACvDH;MAAO,CAAA;KAAAJ,gBAAA,OAAA,EAAA,CAAA;KAAA;;GAAA,CAAA,CAAA;EAIb,CAAA"}
1
+ {"version":3,"file":"bin-entry.mjs","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 <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;;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,KACP,EACEyB,aAAa;KACX;MAAEC,MAAM;MAAcC,SAAS;MAAM;KACrC,EAAED,MAAM,mBAAmB;KAC3B,EAAEA,MAAM,sBAAsB;KAAA,EAEjC,EACDlB,WAAW,EAAE,EACbK,OAAOe,QAAQjB,QAAQkB,SAAS,CAC7BC,QAAQ,GAAGC,aAAaA,QAAQC,UA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IAAEwC,WAAQ;AAAA,cAAA7B,gBAAGhB,gBAAc,EAAA,CAAA;;MAAAQ,UACpDH;MAAO,CAAA;KAAAJ,gBAAA,OAAA,EAAA,CAAA;KAAA;;GAAA,CAAA,CAAA;EAIb,CAAA"}
@@ -1,24 +1,24 @@
1
- import * as _alloy_js_core11 from "@alloy-js/core";
1
+ import * as _alloy_js_core15 from "@alloy-js/core";
2
2
  import { CommandTree } from "@shell-shock/core/types/command";
3
3
  import { EntryFileProps } from "@powerlines/plugin-alloy/typescript/components/entry-file";
4
4
 
5
5
  //#region src/components/command-entry.d.ts
6
6
  declare function CommandInvocation(props: {
7
7
  command: CommandTree;
8
- }): _alloy_js_core11.Children;
8
+ }): _alloy_js_core15.Children;
9
9
  /**
10
10
  * A component that generates the `handler` function declaration for a command.
11
11
  */
12
12
  declare function CommandHandlerDeclaration(props: {
13
13
  command: CommandTree;
14
- }): _alloy_js_core11.Children;
14
+ }): _alloy_js_core15.Children;
15
15
  interface CommandEntryProps extends Omit<EntryFileProps, "path" | "typeDefinition"> {
16
16
  command: CommandTree;
17
17
  }
18
18
  /**
19
19
  * The command entry point for the Shell Shock project.
20
20
  */
21
- declare function CommandEntry(props: CommandEntryProps): _alloy_js_core11.Children;
21
+ declare function CommandEntry(props: CommandEntryProps): _alloy_js_core15.Children;
22
22
  //#endregion
23
23
  export { CommandEntry, CommandEntryProps, CommandHandlerDeclaration, CommandInvocation };
24
24
  //# sourceMappingURL=command-entry.d.cts.map
@@ -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,84 @@ 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: 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
+ }
124
149
  })
125
150
  ];
126
151
  }
@@ -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,CA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jC,oBAAkB,EAAA,CAAA;;cAAAK,UAC5Bc;cAAK,CAAA;;YAAA,CAAA;;UAAA,IAAAd,WAAA;AAAA,mEAIXb,oCAAY;YAAA,IACXiC,YAAS;AAAA,oBAAErC,oBAAI,8BAA8ByC,WAAWvB,KAAK4B,aAAa,CAAA;;YAAG,IAAA7B,WAAA;AAAA,qEAC5Ed,sBAAI;cAAA,IAACY,OAAI;AAAA,sBAAE6B,QAAQb,MAAM;;cAAA,IAAEc,WAAQ;AAAA,uEAAGjC,oBAAkB,EAAA,CAAA;;cAAAK,UACtDc;cAAK,CAAA;;YAAA,CAAA;;UAAA,CAAA;;QAAA,CAAA;;MAAA,CAAA;KAMjB,CAAA;qDAEF3B,oCAAY;KACXiC,WAAWrC,oBAAI;KAAkBiB,UAAGjB,oBAAI;KAAuC,CAAA;IAAA;;EAAA,CAAA"}
1
+ {"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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AAM,GAAG,CAAA;;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 +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"}