@shell-shock/core 0.17.8 → 0.17.10

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 (141) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -1
  2. package/dist/api.cjs +148 -1
  3. package/dist/api.d.cts +6 -6
  4. package/dist/api.d.cts.map +1 -1
  5. package/dist/api.d.mts +6 -6
  6. package/dist/api.d.mts.map +1 -1
  7. package/dist/api.mjs +145 -1
  8. package/dist/api.mjs.map +1 -1
  9. package/dist/components/command-validation-logic.cjs +292 -1
  10. package/dist/components/command-validation-logic.mjs +289 -1
  11. package/dist/components/command-validation-logic.mjs.map +1 -1
  12. package/dist/components/docs.cjs +265 -1
  13. package/dist/components/docs.mjs +256 -1
  14. package/dist/components/docs.mjs.map +1 -1
  15. package/dist/components/exec-builtin.cjs +429 -13
  16. package/dist/components/exec-builtin.mjs +425 -13
  17. package/dist/components/exec-builtin.mjs.map +1 -1
  18. package/dist/components/helpers.cjs +120 -1
  19. package/dist/components/helpers.mjs +112 -1
  20. package/dist/components/helpers.mjs.map +1 -1
  21. package/dist/components/index.cjs +58 -1
  22. package/dist/components/index.mjs +10 -1
  23. package/dist/components/options-parser-logic.cjs +960 -5
  24. package/dist/components/options-parser-logic.d.cts +1 -1
  25. package/dist/components/options-parser-logic.mjs +945 -5
  26. package/dist/components/options-parser-logic.mjs.map +1 -1
  27. package/dist/components/state-builtin.cjs +629 -8
  28. package/dist/components/state-builtin.mjs +622 -8
  29. package/dist/components/state-builtin.mjs.map +1 -1
  30. package/dist/components/usage.cjs +117 -1
  31. package/dist/components/usage.mjs +114 -1
  32. package/dist/components/usage.mjs.map +1 -1
  33. package/dist/components/utils-builtin.cjs +838 -33
  34. package/dist/components/utils-builtin.mjs +828 -33
  35. package/dist/components/utils-builtin.mjs.map +1 -1
  36. package/dist/config.cjs +31 -1
  37. package/dist/config.mjs +29 -1
  38. package/dist/config.mjs.map +1 -1
  39. package/dist/contexts/command.cjs +26 -1
  40. package/dist/contexts/command.mjs +23 -1
  41. package/dist/contexts/command.mjs.map +1 -1
  42. package/dist/contexts/index.cjs +9 -1
  43. package/dist/contexts/index.mjs +4 -1
  44. package/dist/contexts/options.cjs +63 -1
  45. package/dist/contexts/options.mjs +58 -1
  46. package/dist/contexts/options.mjs.map +1 -1
  47. package/dist/helpers/automd.cjs +71 -1
  48. package/dist/helpers/automd.mjs +70 -1
  49. package/dist/helpers/automd.mjs.map +1 -1
  50. package/dist/helpers/docs-helpers.cjs +23 -1
  51. package/dist/helpers/docs-helpers.mjs +22 -1
  52. package/dist/helpers/docs-helpers.mjs.map +1 -1
  53. package/dist/helpers/paths.cjs +137 -1
  54. package/dist/helpers/paths.mjs +133 -1
  55. package/dist/helpers/paths.mjs.map +1 -1
  56. package/dist/helpers/persistence.cjs +115 -1
  57. package/dist/helpers/persistence.mjs +112 -1
  58. package/dist/helpers/persistence.mjs.map +1 -1
  59. package/dist/helpers/update-package-json.cjs +65 -1
  60. package/dist/helpers/update-package-json.mjs +63 -1
  61. package/dist/helpers/update-package-json.mjs.map +1 -1
  62. package/dist/helpers/utilities.cjs +95 -1
  63. package/dist/helpers/utilities.mjs +93 -1
  64. package/dist/helpers/utilities.mjs.map +1 -1
  65. package/dist/helpers/validations.cjs +71 -1
  66. package/dist/helpers/validations.mjs +71 -1
  67. package/dist/helpers/validations.mjs.map +1 -1
  68. package/dist/index.cjs +53 -1
  69. package/dist/index.d.cts +3 -3
  70. package/dist/index.d.mts +3 -3
  71. package/dist/index.mjs +7 -1
  72. package/dist/plugin-utils/compute-bin.cjs +50 -1
  73. package/dist/plugin-utils/compute-bin.mjs +49 -1
  74. package/dist/plugin-utils/compute-bin.mjs.map +1 -1
  75. package/dist/plugin-utils/context-helpers.cjs +231 -1
  76. package/dist/plugin-utils/context-helpers.mjs +221 -1
  77. package/dist/plugin-utils/context-helpers.mjs.map +1 -1
  78. package/dist/plugin-utils/deepkit.cjs +71 -1
  79. package/dist/plugin-utils/deepkit.mjs +69 -1
  80. package/dist/plugin-utils/deepkit.mjs.map +1 -1
  81. package/dist/plugin-utils/description-helpers.cjs +111 -2
  82. package/dist/plugin-utils/description-helpers.mjs +107 -2
  83. package/dist/plugin-utils/description-helpers.mjs.map +1 -1
  84. package/dist/plugin-utils/get-command-tree.cjs +117 -1
  85. package/dist/plugin-utils/get-command-tree.mjs +114 -1
  86. package/dist/plugin-utils/get-command-tree.mjs.map +1 -1
  87. package/dist/plugin-utils/index.cjs +39 -1
  88. package/dist/plugin-utils/index.mjs +10 -1
  89. package/dist/plugin-utils/reflect.cjs +52 -1
  90. package/dist/plugin-utils/reflect.mjs +52 -1
  91. package/dist/plugin-utils/reflect.mjs.map +1 -1
  92. package/dist/plugin-utils/traverse-command-tree.cjs +64 -1
  93. package/dist/plugin-utils/traverse-command-tree.mjs +62 -1
  94. package/dist/plugin-utils/traverse-command-tree.mjs.map +1 -1
  95. package/dist/plugin-utils/type-checks.cjs +93 -1
  96. package/dist/plugin-utils/type-checks.mjs +88 -1
  97. package/dist/plugin-utils/type-checks.mjs.map +1 -1
  98. package/dist/plugin.cjs +471 -4
  99. package/dist/plugin.d.cts.map +1 -1
  100. package/dist/plugin.d.mts.map +1 -1
  101. package/dist/plugin.mjs +465 -4
  102. package/dist/plugin.mjs.map +1 -1
  103. package/dist/resolver/deepkit.cjs +135 -1
  104. package/dist/resolver/deepkit.mjs +134 -1
  105. package/dist/resolver/deepkit.mjs.map +1 -1
  106. package/dist/resolver/helpers.cjs +173 -1
  107. package/dist/resolver/helpers.mjs +168 -1
  108. package/dist/resolver/helpers.mjs.map +1 -1
  109. package/dist/resolver/module.cjs +145 -1
  110. package/dist/resolver/module.mjs +144 -1
  111. package/dist/resolver/module.mjs.map +1 -1
  112. package/dist/resolver/resolve.cjs +222 -1
  113. package/dist/resolver/resolve.mjs +221 -1
  114. package/dist/resolver/resolve.mjs.map +1 -1
  115. package/dist/types/command.cjs +441 -1
  116. package/dist/types/command.d.cts +1 -1
  117. package/dist/types/command.d.mts +2 -2
  118. package/dist/types/command.mjs +405 -1
  119. package/dist/types/command.mjs.map +1 -1
  120. package/dist/types/config.cjs +134 -1
  121. package/dist/types/config.d.cts +10 -8
  122. package/dist/types/config.d.cts.map +1 -1
  123. package/dist/types/config.d.mts +10 -8
  124. package/dist/types/config.d.mts.map +1 -1
  125. package/dist/types/config.mjs +127 -1
  126. package/dist/types/config.mjs.map +1 -1
  127. package/dist/types/context.cjs +37 -1
  128. package/dist/types/context.mjs +34 -1
  129. package/dist/types/context.mjs.map +1 -1
  130. package/dist/types/env.cjs +52 -1
  131. package/dist/types/env.d.cts +1 -1
  132. package/dist/types/env.d.mts +1 -1
  133. package/dist/types/env.mjs +50 -1
  134. package/dist/types/env.mjs.map +1 -1
  135. package/dist/types/index.cjs +50 -1
  136. package/dist/types/index.d.cts +2 -2
  137. package/dist/types/index.d.mts +2 -2
  138. package/dist/types/index.mjs +6 -1
  139. package/dist/types/options.cjs +12 -1
  140. package/dist/types/options.mjs +10 -1
  141. package/package.json +22 -21
@@ -1,2 +1,134 @@
1
- import{getDynamicPathSegmentName as e,isDynamicPathSegment as t,isPathSegmentGroup as n}from"../plugin-utils/context-helpers.mjs";import{appendPath as r}from"@stryke/path/append";import{findFilePath as i,findFolderName as a}from"@stryke/path/file-path-fns";import{joinPaths as o}from"@stryke/path/join-paths";import{replacePath as s}from"@stryke/path/replace";import{resolveParentPath as c}from"@stryke/path/resolve-parent-path";import{isSetString as l}from"@stryke/type-checks/is-set-string";import{isTypeDefinition as u}from"powerlines/utils";import{isSetObject as d}from"@stryke/type-checks/is-set-object";import{listFiles as f}from"@stryke/fs/list-files";import{commonPath as p}from"@stryke/path/common";import{existsSync as m}from"node:fs";function h(e,t){return e.__type=t,e}function g(e,n){return s(i(n),e.commandsPath).split(`/`).filter(h(e=>!!e&&!t(e),[`p`,``,`P"2!"/"`])).join(`/`).replaceAll(/^\/+/g,``).replaceAll(/\/+$/g,``).replaceAll(`/`,`-`)}g.__type=[`Context`,`context`,`file`,`resolveCommandId`,`P"w!2"&2#&/$`];function _(e){let n=i(e),r=a(e,{requireExtension:!0});for(;t(r);)n=c(n),r=a(n,{requireExtension:!0});return r}_.__type=[`file`,`resolveCommandName`,`Finds the command name from the given file path.`,`P&2!"/"?#`];function v(e,t){return s(i(t),e.commandsPath).replaceAll(/^\/+/g,``).replaceAll(/\/+$/g,``).split(`/`).filter(h(e=>e&&!n(e),[`path`,``,`P"2!"/"`])).join(`/`)}v.__type=[`Context`,`context`,`file`,`resolveCommandPath`,`P"w!2"&2#&/$`];function y(n,r){return s(i(r),n.commandsPath).split(`/`).filter(h(e=>!!e&&t(e),[`path`,``,`P"2!"/"`])).map(h(t=>e(t),[`path`,``,`P"2!"/"`]))}y.__type=[`Context`,`context`,`file`,`resolveCommandDynamicPathSegments`,`P"w!2"&2#&F/$`];async function b(e){let t=[];if(l(e.config.input)?t=await f(r(r(e.config.input,e.config.root),e.config.cwd)):u(e.config.input)?t=await f(r(r(e.config.input.file,e.config.root),e.config.cwd)):Array.isArray(e.config.input)&&e.config.input.length>0?t=(await Promise.all(e.config.input.map(h(async t=>f(r(r(l(t)?t:t.file,e.config.root),e.config.cwd)),[`input`,``,`P"2!"/"`])))).flat():d(e.config.input)&&(t=(await Promise.all(Object.values(e.config.input).map(h(async t=>Array.isArray(t)?(await Promise.all(t.map(h(async t=>f(r(r(l(t)?t:t.file,e.config.root),e.config.cwd)),[`i`,``,`P"2!"/"`])))).flat():f(r(r(l(t)?t:t.file,e.config.root),e.config.cwd)),[`input`,``,`P"2!"/"`])))).flat()),t.length>0)return p(t.map(h(e=>i(e),[`p`,``,`P"2!"/"`])));let n=o(e.config.root,`src/commands`);return m(n)||(n=o(e.config.root,`commands`),m(n)||(n=o(e.config.root,`src`),m(n)||(n=e.config.root))),t=(await Promise.all([f(o(r(n,e.config.cwd),`**/command.ts`)),f(o(r(n,e.config.cwd),`**/command.tsx`))])).flat(),t.length>0?p(t.map(h(e=>i(e),[`p`,``,`P"2!"/"`]))):r(n,e.config.cwd)}b.__type=[`Context`,`context`,`findCommandsRoot`,'P"w!2"&`/#'];export{b as findCommandsRoot,g as resolveCommandId,_ as resolveCommandName,v as resolveCommandPath};
1
+ import { getDynamicPathSegmentName, isDynamicPathSegment, isPathSegmentGroup } from "../plugin-utils/context-helpers.mjs";
2
+ import { appendPath } from "@stryke/path/append";
3
+ import { findFilePath, findFolderName } from "@stryke/path/file-path-fns";
4
+ import { joinPaths } from "@stryke/path/join-paths";
5
+ import { replacePath } from "@stryke/path/replace";
6
+ import { resolveParentPath } from "@stryke/path/resolve-parent-path";
7
+ import { isSetString } from "@stryke/type-checks/is-set-string";
8
+ import { isTypeDefinition } from "powerlines/utils";
9
+ import { isSetObject } from "@stryke/type-checks/is-set-object";
10
+ import { listFiles } from "@stryke/fs/list-files";
11
+ import { commonPath } from "@stryke/path/common";
12
+ import { existsSync } from "node:fs";
13
+
14
+ //#region src/helpers/paths.ts
15
+ function __assignType(fn, args) {
16
+ fn.__type = args;
17
+ return fn;
18
+ }
19
+ function resolveCommandId(context, file) {
20
+ return replacePath(findFilePath(file), context.commandsPath).split("/").filter(__assignType((p) => Boolean(p) && !isDynamicPathSegment(p), [
21
+ "p",
22
+ "",
23
+ "P\"2!\"/\""
24
+ ])).join("/").replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "").replaceAll("/", "-");
25
+ }
26
+ resolveCommandId.__type = [
27
+ "Context",
28
+ "context",
29
+ "file",
30
+ "resolveCommandId",
31
+ "P\"w!2\"&2#&/$"
32
+ ];
33
+ /**
34
+ * Finds the command name from the given file path.
35
+ *
36
+ * @param file - The file path to extract the command name from.
37
+ * @returns The command name.
38
+ */
39
+ function resolveCommandName(file) {
40
+ let path = findFilePath(file);
41
+ let name = findFolderName(file, { requireExtension: true });
42
+ while (isDynamicPathSegment(name)) {
43
+ path = resolveParentPath(path);
44
+ name = findFolderName(path, { requireExtension: true });
45
+ }
46
+ return name;
47
+ }
48
+ resolveCommandName.__type = [
49
+ "file",
50
+ "resolveCommandName",
51
+ "Finds the command name from the given file path.",
52
+ "P&2!\"/\"?#"
53
+ ];
54
+ function resolveCommandPath(context, file) {
55
+ return replacePath(findFilePath(file), context.commandsPath).replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "").split("/").filter(__assignType((path) => path && !isPathSegmentGroup(path), [
56
+ "path",
57
+ "",
58
+ "P\"2!\"/\""
59
+ ])).join("/");
60
+ }
61
+ resolveCommandPath.__type = [
62
+ "Context",
63
+ "context",
64
+ "file",
65
+ "resolveCommandPath",
66
+ "P\"w!2\"&2#&/$"
67
+ ];
68
+ function resolveCommandDynamicPathSegments(context, file) {
69
+ return replacePath(findFilePath(file), context.commandsPath).split("/").filter(__assignType((path) => Boolean(path) && isDynamicPathSegment(path), [
70
+ "path",
71
+ "",
72
+ "P\"2!\"/\""
73
+ ])).map(__assignType((path) => getDynamicPathSegmentName(path), [
74
+ "path",
75
+ "",
76
+ "P\"2!\"/\""
77
+ ]));
78
+ }
79
+ resolveCommandDynamicPathSegments.__type = [
80
+ "Context",
81
+ "context",
82
+ "file",
83
+ "resolveCommandDynamicPathSegments",
84
+ "P\"w!2\"&2#&F/$"
85
+ ];
86
+ async function findCommandsRoot(context) {
87
+ let paths = [];
88
+ if (isSetString(context.config.input)) paths = await listFiles(appendPath(appendPath(context.config.input, context.config.root), context.config.cwd));
89
+ else if (isTypeDefinition(context.config.input)) paths = await listFiles(appendPath(appendPath(context.config.input.file, context.config.root), context.config.cwd));
90
+ else if (Array.isArray(context.config.input) && context.config.input.length > 0) paths = (await Promise.all(context.config.input.map(__assignType(async (input) => listFiles(appendPath(appendPath(isSetString(input) ? input : input.file, context.config.root), context.config.cwd)), [
91
+ "input",
92
+ "",
93
+ "P\"2!\"/\""
94
+ ])))).flat();
95
+ else if (isSetObject(context.config.input)) paths = (await Promise.all(Object.values(context.config.input).map(__assignType(async (input) => Array.isArray(input) ? (await Promise.all(input.map(__assignType(async (i) => listFiles(appendPath(appendPath(isSetString(i) ? i : i.file, context.config.root), context.config.cwd)), [
96
+ "i",
97
+ "",
98
+ "P\"2!\"/\""
99
+ ])))).flat() : listFiles(appendPath(appendPath(isSetString(input) ? input : input.file, context.config.root), context.config.cwd)), [
100
+ "input",
101
+ "",
102
+ "P\"2!\"/\""
103
+ ])))).flat();
104
+ if (paths.length > 0) return commonPath(paths.map(__assignType((p) => findFilePath(p), [
105
+ "p",
106
+ "",
107
+ "P\"2!\"/\""
108
+ ])));
109
+ let commandsPath = joinPaths(context.config.root, "src/commands");
110
+ if (!existsSync(commandsPath)) {
111
+ commandsPath = joinPaths(context.config.root, "commands");
112
+ if (!existsSync(commandsPath)) {
113
+ commandsPath = joinPaths(context.config.root, "src");
114
+ if (!existsSync(commandsPath)) commandsPath = context.config.root;
115
+ }
116
+ }
117
+ paths = (await Promise.all([listFiles(joinPaths(appendPath(commandsPath, context.config.cwd), "**/command.ts")), listFiles(joinPaths(appendPath(commandsPath, context.config.cwd), "**/command.tsx"))])).flat();
118
+ if (paths.length > 0) return commonPath(paths.map(__assignType((p) => findFilePath(p), [
119
+ "p",
120
+ "",
121
+ "P\"2!\"/\""
122
+ ])));
123
+ return appendPath(commandsPath, context.config.cwd);
124
+ }
125
+ findCommandsRoot.__type = [
126
+ "Context",
127
+ "context",
128
+ "findCommandsRoot",
129
+ "P\"w!2\"&`/#"
130
+ ];
131
+
132
+ //#endregion
133
+ export { findCommandsRoot, resolveCommandId, resolveCommandName, resolveCommandPath };
2
134
  //# sourceMappingURL=paths.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"paths.mjs","names":[],"sources":["../../src/helpers/paths.ts"],"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 { listFiles } from \"@stryke/fs/list-files\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { commonPath } from \"@stryke/path/common\";\nimport { findFilePath, findFolderName } from \"@stryke/path/file-path-fns\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { existsSync } from \"node:fs\";\nimport { isTypeDefinition } from \"powerlines/utils\";\nimport {\n getDynamicPathSegmentName,\n isDynamicPathSegment,\n isPathSegmentGroup\n} from \"../plugin-utils/context-helpers\";\nimport type { Context } from \"../types/context\";\n\nexport function resolveCommandId(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(p => Boolean(p) && !isDynamicPathSegment(p))\n .join(\"/\")\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .replaceAll(\"/\", \"-\");\n}\n\n/**\n * Finds the command name from the given file path.\n *\n * @param file - The file path to extract the command name from.\n * @returns The command name.\n */\nexport function resolveCommandName(file: string) {\n let path = findFilePath(file);\n let name = findFolderName(file, {\n requireExtension: true\n });\n\n while (isDynamicPathSegment(name)) {\n path = resolveParentPath(path);\n name = findFolderName(path, {\n requireExtension: true\n });\n }\n\n return name;\n}\n\nexport function resolveCommandPath(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .split(\"/\")\n .filter(path => path && !isPathSegmentGroup(path))\n .join(\"/\");\n}\n\nexport function resolveCommandDynamicPathSegments(\n context: Context,\n file: string\n): string[] {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(path => Boolean(path) && isDynamicPathSegment(path))\n .map(path => getDynamicPathSegmentName(path));\n}\n\nexport async function findCommandsRoot(context: Context): Promise<string> {\n let paths = [] as string[];\n if (isSetString(context.config.input)) {\n paths = await listFiles(\n appendPath(\n appendPath(context.config.input, context.config.root),\n context.config.cwd\n )\n );\n } else if (isTypeDefinition(context.config.input)) {\n paths = await listFiles(\n appendPath(\n appendPath(context.config.input.file, context.config.root),\n context.config.cwd\n )\n );\n } else if (\n Array.isArray(context.config.input) &&\n context.config.input.length > 0\n ) {\n paths = (\n await Promise.all(\n context.config.input.map(async input =>\n listFiles(\n appendPath(\n appendPath(\n isSetString(input) ? input : input.file,\n context.config.root\n ),\n context.config.cwd\n )\n )\n )\n )\n ).flat();\n } else if (isSetObject(context.config.input)) {\n paths = (\n await Promise.all(\n Object.values(context.config.input).map(async input =>\n Array.isArray(input)\n ? (\n await Promise.all(\n input.map(async i =>\n listFiles(\n appendPath(\n appendPath(\n isSetString(i) ? i : i.file,\n context.config.root\n ),\n context.config.cwd\n )\n )\n )\n )\n ).flat()\n : listFiles(\n appendPath(\n appendPath(\n isSetString(input) ? input : input.file,\n context.config.root\n ),\n context.config.cwd\n )\n )\n )\n )\n ).flat();\n }\n\n if (paths.length > 0) {\n return commonPath(paths.map(p => findFilePath(p)));\n }\n\n let commandsPath = joinPaths(context.config.root, \"src/commands\");\n if (!existsSync(commandsPath)) {\n commandsPath = joinPaths(context.config.root, \"commands\");\n if (!existsSync(commandsPath)) {\n commandsPath = joinPaths(context.config.root, \"src\");\n if (!existsSync(commandsPath)) {\n commandsPath = context.config.root;\n }\n }\n }\n\n paths = (\n await Promise.all([\n listFiles(\n joinPaths(appendPath(commandsPath, context.config.cwd), \"**/command.ts\")\n ),\n listFiles(\n joinPaths(\n appendPath(commandsPath, context.config.cwd),\n \"**/command.tsx\"\n )\n )\n ])\n ).flat();\n if (paths.length > 0) {\n return commonPath(paths.map(p => findFilePath(p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C,IAAI,EAAE,EAAA,EAAA,OAAA,KAAA,eAAA,CAcN,OAbC,EAAS,EAAA,GACV,EAAO,EAAY,EAAa,OAAO,KAAQ,WAAY,CACxD,EAAS,EAAA,GACT,EAAe,EAAQ,EAAS,OAAA,KAAA,MAAqB,CACjD,EAAQ,EAAA,GACjB,EAAA,EAAA,OAAA,QAIE,GAAI,MAAW,QAAQ,IAAC,CAAA,EAAc,EAAC,EAAA,EAAA,EAAA,OAAA,IAAA,CAAA,gBAAA,CAAA,CAAA,EAAA,EAAA,EAAA,EAAA,EAAA,OAAA,IAAA,CAAA,iBAAA,CAAA,CAAA,CAAA,EAAA,MAAA,CACrC,EAAQ,OAAM,EACZ,EAAU,EAAA,IAAA,EAAA,GAAA,EAAA,EAAA,CAAA,CAAA,IAAA,GAAA,UAAA,CAAA,CAAA,CAAA,CAER,EAAQ,EAAO,EAAA,OAAA,IAAA,CAEvB,EAAK,OAAA,CAAA,UAAA,UAAA,mBAAA,aAAA"}
1
+ {"version":3,"file":"paths.mjs","names":[],"sources":["../../src/helpers/paths.ts"],"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 { listFiles } from \"@stryke/fs/list-files\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { commonPath } from \"@stryke/path/common\";\nimport { findFilePath, findFolderName } from \"@stryke/path/file-path-fns\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { existsSync } from \"node:fs\";\nimport { isTypeDefinition } from \"powerlines/utils\";\nimport {\n getDynamicPathSegmentName,\n isDynamicPathSegment,\n isPathSegmentGroup\n} from \"../plugin-utils/context-helpers\";\nimport type { Context } from \"../types/context\";\n\nexport function resolveCommandId(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(p => Boolean(p) && !isDynamicPathSegment(p))\n .join(\"/\")\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .replaceAll(\"/\", \"-\");\n}\n\n/**\n * Finds the command name from the given file path.\n *\n * @param file - The file path to extract the command name from.\n * @returns The command name.\n */\nexport function resolveCommandName(file: string) {\n let path = findFilePath(file);\n let name = findFolderName(file, {\n requireExtension: true\n });\n\n while (isDynamicPathSegment(name)) {\n path = resolveParentPath(path);\n name = findFolderName(path, {\n requireExtension: true\n });\n }\n\n return name;\n}\n\nexport function resolveCommandPath(context: Context, file: string): string {\n return replacePath(findFilePath(file), context.commandsPath)\n .replaceAll(/^\\/+/g, \"\")\n .replaceAll(/\\/+$/g, \"\")\n .split(\"/\")\n .filter(path => path && !isPathSegmentGroup(path))\n .join(\"/\");\n}\n\nexport function resolveCommandDynamicPathSegments(\n context: Context,\n file: string\n): string[] {\n return replacePath(findFilePath(file), context.commandsPath)\n .split(\"/\")\n .filter(path => Boolean(path) && isDynamicPathSegment(path))\n .map(path => getDynamicPathSegmentName(path));\n}\n\nexport async function findCommandsRoot(context: Context): Promise<string> {\n let paths = [] as string[];\n if (isSetString(context.config.input)) {\n paths = await listFiles(\n appendPath(\n appendPath(context.config.input, context.config.root),\n context.config.cwd\n )\n );\n } else if (isTypeDefinition(context.config.input)) {\n paths = await listFiles(\n appendPath(\n appendPath(context.config.input.file, context.config.root),\n context.config.cwd\n )\n );\n } else if (\n Array.isArray(context.config.input) &&\n context.config.input.length > 0\n ) {\n paths = (\n await Promise.all(\n context.config.input.map(async input =>\n listFiles(\n appendPath(\n appendPath(\n isSetString(input) ? input : input.file,\n context.config.root\n ),\n context.config.cwd\n )\n )\n )\n )\n ).flat();\n } else if (isSetObject(context.config.input)) {\n paths = (\n await Promise.all(\n Object.values(context.config.input).map(async input =>\n Array.isArray(input)\n ? (\n await Promise.all(\n input.map(async i =>\n listFiles(\n appendPath(\n appendPath(\n isSetString(i) ? i : i.file,\n context.config.root\n ),\n context.config.cwd\n )\n )\n )\n )\n ).flat()\n : listFiles(\n appendPath(\n appendPath(\n isSetString(input) ? input : input.file,\n context.config.root\n ),\n context.config.cwd\n )\n )\n )\n )\n ).flat();\n }\n\n if (paths.length > 0) {\n return commonPath(paths.map(p => findFilePath(p)));\n }\n\n let commandsPath = joinPaths(context.config.root, \"src/commands\");\n if (!existsSync(commandsPath)) {\n commandsPath = joinPaths(context.config.root, \"commands\");\n if (!existsSync(commandsPath)) {\n commandsPath = joinPaths(context.config.root, \"src\");\n if (!existsSync(commandsPath)) {\n commandsPath = context.config.root;\n }\n }\n }\n\n paths = (\n await Promise.all([\n listFiles(\n joinPaths(appendPath(commandsPath, context.config.cwd), \"**/command.ts\")\n ),\n listFiles(\n joinPaths(\n appendPath(commandsPath, context.config.cwd),\n \"**/command.tsx\"\n )\n )\n ])\n ).flat();\n if (paths.length > 0) {\n return commonPath(paths.map(p => findFilePath(p)));\n }\n\n return appendPath(commandsPath, context.config.cwd);\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE9B,QAAO;;AA+BT,SAAW,iBAAqB,SAAQ,MAAA;AACxC,QAAO,YAAc,aAAY,KAAM,EAAA,QAAQ,aAAA,CAAA,MAAA,IAAA,CAAA,OAAA,cAAA,MAAA,QAAA,EAAA,IAAA,CAAA,qBAAA,EAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA,KAAA,IAAA,CAAA,WAAA,SAAA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,IAAC,CAAA,UAAc,UAAC,WAAA,cAAA,QAAA,OAAA,IAAA,EAAA,gBAAA,CAAA,EAAA,UAAA,UAAA,WAAA,cAAA,QAAA,OAAA,IAAA,EAAA,iBAAA,CAAA,CAAA,CAAA,EAAA,MAAA;AACvC,KAAE,MAAQ,SAAM,EACd,QAAE,WAAU,MAAA,IAAA,cAAA,MAAA,aAAA,EAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA;AAEd,QAAM,WAAQ,cAAO,QAAA,OAAA,IAAA;;AAEvB,iBAAK,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
@@ -1 +1,115 @@
1
- require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`@powerlines/plugin-env/helpers`),t=require(`@stryke/path/join-paths`);function n(e,t){return e.__type=t,e}function r(e){return{...e,parent:e.parent?.name?e.parent.name:null,children:Object.fromEntries(Object.entries(e.children||{}).map(n(([e,t])=>[e,r(t)],[`param0`,``,`P"2!"/"`])))}}r.__type=[`CommandTree`,`command`,`SerializedCommandTree`,`serialize`,`P"w!2""w#/$`];function i(e,t=null){let r={...e,parent:t??null,children:{}};return r.children=Object.fromEntries(Object.entries(e.children||{}).map(n(([e,t])=>[e,i(t,r)],[`param0`,``,`P"2!"/"`]))),r}i.__type=[`SerializedCommandTree`,`command`,`CommandTree`,`parent`,()=>null,`deserialize`,`P"w!2"P"w#,J2$>%"w#/&`];function a(e){return(0,t.joinPaths)(e.dataPath,`reflections`,`commands.json`)}a.__type=[`Context`,`context`,`getCommandsPersistencePath`,`Gets the file path for persisting CLI command reflections.`,`P"w!2"&/#?$`];async function o(e){let t=await e.fs.read(a(e));if(!t||!t.length)throw Error(`CLI Command reflection file ${a(e)} is empty`);e.commands=Object.fromEntries(Object.entries(JSON.parse(t)??{}).map(n(([e,t])=>[e,i(t)],[`param0`,``,`P"2!"/"`])))}o.__type=[`Context`,`context`,`readCommandsPersistence`,`Reads the persisted CLI command reflections from the file system and populates the context's commands.`,`P"w!2""/#?$`];async function s(t){let i=a(t);await(0,e.writeEnvTypeReflection)(t,t.env.types.env,`env`),await t.fs.write(i,JSON.stringify(Object.fromEntries(Object.entries(t.commands).map(n(([e,t])=>[e,r(t)],[`param0`,``,`P"2!"/"`]))),null,t.config.mode===`production`?0:2))}s.__type=[`Context`,`context`,`writeCommandsPersistence`,`Writes the current CLI command reflections from the context to the file system for persistence.`,`P"w!2""/#?$`],exports.getCommandsPersistencePath=a,exports.readCommandsPersistence=o,exports.writeCommandsPersistence=s;
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ let _powerlines_plugin_env_helpers = require("@powerlines/plugin-env/helpers");
3
+ let _stryke_path_join_paths = require("@stryke/path/join-paths");
4
+
5
+ //#region src/helpers/persistence.ts
6
+ function __assignType(fn, args) {
7
+ fn.__type = args;
8
+ return fn;
9
+ }
10
+ function serialize(command) {
11
+ return {
12
+ ...command,
13
+ parent: command.parent?.name ? command.parent.name : null,
14
+ children: Object.fromEntries(Object.entries(command.children || {}).map(__assignType(([name, child]) => [name, serialize(child)], [
15
+ "param0",
16
+ "",
17
+ "P\"2!\"/\""
18
+ ])))
19
+ };
20
+ }
21
+ serialize.__type = [
22
+ "CommandTree",
23
+ "command",
24
+ "SerializedCommandTree",
25
+ "serialize",
26
+ "P\"w!2\"\"w#/$"
27
+ ];
28
+ function deserialize(command, parent = null) {
29
+ const result = {
30
+ ...command,
31
+ parent: parent ?? null,
32
+ children: {}
33
+ };
34
+ result.children = Object.fromEntries(Object.entries(command.children || {}).map(__assignType(([name, child]) => [name, deserialize(child, result)], [
35
+ "param0",
36
+ "",
37
+ "P\"2!\"/\""
38
+ ])));
39
+ return result;
40
+ }
41
+ deserialize.__type = [
42
+ "SerializedCommandTree",
43
+ "command",
44
+ "CommandTree",
45
+ "parent",
46
+ () => null,
47
+ "deserialize",
48
+ "P\"w!2\"P\"w#,J2$>%\"w#/&"
49
+ ];
50
+ /**
51
+ * Gets the file path for persisting CLI command reflections.
52
+ *
53
+ * @param context - The Shell Shock context.
54
+ * @returns The file path for persisting CLI command reflections.
55
+ */
56
+ function getCommandsPersistencePath(context) {
57
+ return (0, _stryke_path_join_paths.joinPaths)(context.dataPath, "reflections", "commands.json");
58
+ }
59
+ getCommandsPersistencePath.__type = [
60
+ "Context",
61
+ "context",
62
+ "getCommandsPersistencePath",
63
+ "Gets the file path for persisting CLI command reflections.",
64
+ "P\"w!2\"&/#?$"
65
+ ];
66
+ /**
67
+ * Reads the persisted CLI command reflections from the file system and populates the context's commands.
68
+ *
69
+ * @param context - The Shell Shock context.
70
+ * @throws Will throw an error if the reflections file is empty or cannot be read.
71
+ */
72
+ async function readCommandsPersistence(context) {
73
+ const reflections = await context.fs.read(getCommandsPersistencePath(context));
74
+ if (!reflections || !reflections.length) throw new Error(`CLI Command reflection file ${getCommandsPersistencePath(context)} is empty`);
75
+ context.commands = Object.fromEntries(Object.entries(JSON.parse(reflections) ?? {}).map(__assignType(([name, command]) => [name, deserialize(command)], [
76
+ "param0",
77
+ "",
78
+ "P\"2!\"/\""
79
+ ])));
80
+ }
81
+ readCommandsPersistence.__type = [
82
+ "Context",
83
+ "context",
84
+ "readCommandsPersistence",
85
+ "Reads the persisted CLI command reflections from the file system and populates the context's commands.",
86
+ "P\"w!2\"\"/#?$"
87
+ ];
88
+ /**
89
+ * Writes the current CLI command reflections from the context to the file system for persistence.
90
+ *
91
+ * @param context - The Shell Shock context.
92
+ * @returns A promise that resolves when the reflections have been successfully written to the file system.
93
+ * @throws Will throw an error if there is an issue writing the reflections to the file system.
94
+ */
95
+ async function writeCommandsPersistence(context) {
96
+ const filePath = getCommandsPersistencePath(context);
97
+ await (0, _powerlines_plugin_env_helpers.writeEnvTypeReflection)(context, context.env.types.env, "env");
98
+ await context.fs.write(filePath, JSON.stringify(Object.fromEntries(Object.entries(context.commands).map(__assignType(([name, command]) => [name, serialize(command)], [
99
+ "param0",
100
+ "",
101
+ "P\"2!\"/\""
102
+ ]))), null, context.config.mode === "production" ? 0 : 2));
103
+ }
104
+ writeCommandsPersistence.__type = [
105
+ "Context",
106
+ "context",
107
+ "writeCommandsPersistence",
108
+ "Writes the current CLI command reflections from the context to the file system for persistence.",
109
+ "P\"w!2\"\"/#?$"
110
+ ];
111
+
112
+ //#endregion
113
+ exports.getCommandsPersistencePath = getCommandsPersistencePath;
114
+ exports.readCommandsPersistence = readCommandsPersistence;
115
+ exports.writeCommandsPersistence = writeCommandsPersistence;
@@ -1,2 +1,113 @@
1
- import{writeEnvTypeReflection as e}from"@powerlines/plugin-env/helpers";import{joinPaths as t}from"@stryke/path/join-paths";function n(e,t){return e.__type=t,e}function r(e){return{...e,parent:e.parent?.name?e.parent.name:null,children:Object.fromEntries(Object.entries(e.children||{}).map(n(([e,t])=>[e,r(t)],[`param0`,``,`P"2!"/"`])))}}r.__type=[`CommandTree`,`command`,`SerializedCommandTree`,`serialize`,`P"w!2""w#/$`];function i(e,t=null){let r={...e,parent:t??null,children:{}};return r.children=Object.fromEntries(Object.entries(e.children||{}).map(n(([e,t])=>[e,i(t,r)],[`param0`,``,`P"2!"/"`]))),r}i.__type=[`SerializedCommandTree`,`command`,`CommandTree`,`parent`,()=>null,`deserialize`,`P"w!2"P"w#,J2$>%"w#/&`];function a(e){return t(e.dataPath,`reflections`,`commands.json`)}a.__type=[`Context`,`context`,`getCommandsPersistencePath`,`Gets the file path for persisting CLI command reflections.`,`P"w!2"&/#?$`];async function o(e){let t=await e.fs.read(a(e));if(!t||!t.length)throw Error(`CLI Command reflection file ${a(e)} is empty`);e.commands=Object.fromEntries(Object.entries(JSON.parse(t)??{}).map(n(([e,t])=>[e,i(t)],[`param0`,``,`P"2!"/"`])))}o.__type=[`Context`,`context`,`readCommandsPersistence`,`Reads the persisted CLI command reflections from the file system and populates the context's commands.`,`P"w!2""/#?$`];async function s(t){let i=a(t);await e(t,t.env.types.env,`env`),await t.fs.write(i,JSON.stringify(Object.fromEntries(Object.entries(t.commands).map(n(([e,t])=>[e,r(t)],[`param0`,``,`P"2!"/"`]))),null,t.config.mode===`production`?0:2))}s.__type=[`Context`,`context`,`writeCommandsPersistence`,`Writes the current CLI command reflections from the context to the file system for persistence.`,`P"w!2""/#?$`];export{a as getCommandsPersistencePath,o as readCommandsPersistence,s as writeCommandsPersistence};
1
+ import { writeEnvTypeReflection } from "@powerlines/plugin-env/helpers";
2
+ import { joinPaths } from "@stryke/path/join-paths";
3
+
4
+ //#region src/helpers/persistence.ts
5
+ function __assignType(fn, args) {
6
+ fn.__type = args;
7
+ return fn;
8
+ }
9
+ function serialize(command) {
10
+ return {
11
+ ...command,
12
+ parent: command.parent?.name ? command.parent.name : null,
13
+ children: Object.fromEntries(Object.entries(command.children || {}).map(__assignType(([name, child]) => [name, serialize(child)], [
14
+ "param0",
15
+ "",
16
+ "P\"2!\"/\""
17
+ ])))
18
+ };
19
+ }
20
+ serialize.__type = [
21
+ "CommandTree",
22
+ "command",
23
+ "SerializedCommandTree",
24
+ "serialize",
25
+ "P\"w!2\"\"w#/$"
26
+ ];
27
+ function deserialize(command, parent = null) {
28
+ const result = {
29
+ ...command,
30
+ parent: parent ?? null,
31
+ children: {}
32
+ };
33
+ result.children = Object.fromEntries(Object.entries(command.children || {}).map(__assignType(([name, child]) => [name, deserialize(child, result)], [
34
+ "param0",
35
+ "",
36
+ "P\"2!\"/\""
37
+ ])));
38
+ return result;
39
+ }
40
+ deserialize.__type = [
41
+ "SerializedCommandTree",
42
+ "command",
43
+ "CommandTree",
44
+ "parent",
45
+ () => null,
46
+ "deserialize",
47
+ "P\"w!2\"P\"w#,J2$>%\"w#/&"
48
+ ];
49
+ /**
50
+ * Gets the file path for persisting CLI command reflections.
51
+ *
52
+ * @param context - The Shell Shock context.
53
+ * @returns The file path for persisting CLI command reflections.
54
+ */
55
+ function getCommandsPersistencePath(context) {
56
+ return joinPaths(context.dataPath, "reflections", "commands.json");
57
+ }
58
+ getCommandsPersistencePath.__type = [
59
+ "Context",
60
+ "context",
61
+ "getCommandsPersistencePath",
62
+ "Gets the file path for persisting CLI command reflections.",
63
+ "P\"w!2\"&/#?$"
64
+ ];
65
+ /**
66
+ * Reads the persisted CLI command reflections from the file system and populates the context's commands.
67
+ *
68
+ * @param context - The Shell Shock context.
69
+ * @throws Will throw an error if the reflections file is empty or cannot be read.
70
+ */
71
+ async function readCommandsPersistence(context) {
72
+ const reflections = await context.fs.read(getCommandsPersistencePath(context));
73
+ if (!reflections || !reflections.length) throw new Error(`CLI Command reflection file ${getCommandsPersistencePath(context)} is empty`);
74
+ context.commands = Object.fromEntries(Object.entries(JSON.parse(reflections) ?? {}).map(__assignType(([name, command]) => [name, deserialize(command)], [
75
+ "param0",
76
+ "",
77
+ "P\"2!\"/\""
78
+ ])));
79
+ }
80
+ readCommandsPersistence.__type = [
81
+ "Context",
82
+ "context",
83
+ "readCommandsPersistence",
84
+ "Reads the persisted CLI command reflections from the file system and populates the context's commands.",
85
+ "P\"w!2\"\"/#?$"
86
+ ];
87
+ /**
88
+ * Writes the current CLI command reflections from the context to the file system for persistence.
89
+ *
90
+ * @param context - The Shell Shock context.
91
+ * @returns A promise that resolves when the reflections have been successfully written to the file system.
92
+ * @throws Will throw an error if there is an issue writing the reflections to the file system.
93
+ */
94
+ async function writeCommandsPersistence(context) {
95
+ const filePath = getCommandsPersistencePath(context);
96
+ await writeEnvTypeReflection(context, context.env.types.env, "env");
97
+ await context.fs.write(filePath, JSON.stringify(Object.fromEntries(Object.entries(context.commands).map(__assignType(([name, command]) => [name, serialize(command)], [
98
+ "param0",
99
+ "",
100
+ "P\"2!\"/\""
101
+ ]))), null, context.config.mode === "production" ? 0 : 2));
102
+ }
103
+ writeCommandsPersistence.__type = [
104
+ "Context",
105
+ "context",
106
+ "writeCommandsPersistence",
107
+ "Writes the current CLI command reflections from the context to the file system for persistence.",
108
+ "P\"w!2\"\"/#?$"
109
+ ];
110
+
111
+ //#endregion
112
+ export { getCommandsPersistencePath, readCommandsPersistence, writeCommandsPersistence };
2
113
  //# sourceMappingURL=persistence.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"persistence.mjs","names":[],"sources":["../../src/helpers/persistence.ts"],"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 { writeEnvTypeReflection } from \"@powerlines/plugin-env/helpers\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport type { CommandTree, SerializedCommandTree } from \"../types\";\nimport type { Context } from \"../types/context\";\n\nfunction serialize(command: CommandTree): SerializedCommandTree {\n return {\n ...command,\n parent: command.parent?.name ? command.parent.name : null,\n children: Object.fromEntries(\n Object.entries(command.children || {}).map(([name, child]) => [\n name,\n serialize(child)\n ])\n )\n };\n}\n\nfunction deserialize(\n command: SerializedCommandTree,\n parent: CommandTree | null = null\n): CommandTree {\n const result: CommandTree = {\n ...command,\n parent: parent ?? null,\n children: {}\n };\n\n result.children = Object.fromEntries(\n Object.entries(command.children || {}).map(([name, child]) => [\n name,\n deserialize(child, result)\n ])\n );\n\n return result;\n}\n\n/**\n * Gets the file path for persisting CLI command reflections.\n *\n * @param context - The Shell Shock context.\n * @returns The file path for persisting CLI command reflections.\n */\nexport function getCommandsPersistencePath(context: Context): string {\n return joinPaths(context.dataPath, \"reflections\", \"commands.json\");\n}\n\n/**\n * Reads the persisted CLI command reflections from the file system and populates the context's commands.\n *\n * @param context - The Shell Shock context.\n * @throws Will throw an error if the reflections file is empty or cannot be read.\n */\nexport async function readCommandsPersistence(context: Context) {\n const reflections = await context.fs.read(\n getCommandsPersistencePath(context)\n );\n if (!reflections || !reflections.length) {\n throw new Error(\n `CLI Command reflection file ${getCommandsPersistencePath(context)} is empty`\n );\n }\n\n context.commands = Object.fromEntries(\n Object.entries(\n (JSON.parse(reflections) ?? {}) as Record<string, SerializedCommandTree>\n ).map(([name, command]) => [name, deserialize(command)])\n );\n}\n\n/**\n * Writes the current CLI command reflections from the context to the file system for persistence.\n *\n * @param context - The Shell Shock context.\n * @returns A promise that resolves when the reflections have been successfully written to the file system.\n * @throws Will throw an error if there is an issue writing the reflections to the file system.\n */\nexport async function writeCommandsPersistence(context: Context) {\n const filePath = getCommandsPersistencePath(context);\n\n // Also update the environment type reflections whenever we write the command reflections, to ensure they stay in sync.\n await writeEnvTypeReflection(context, context.env.types.env, \"env\");\n\n await context.fs.write(\n filePath,\n JSON.stringify(\n Object.fromEntries(\n Object.entries(context.commands).map(([name, command]) => [\n name,\n serialize(command)\n ])\n ),\n null,\n context.config.mode === \"production\" ? 0 : 2\n )\n );\n}\n"],"mappings":"4HAAA,SAAS,EAAa,EAAI,EAAM,CAE9B,kBAAO,EAqBT,SAAS,EAAU,EAAS,CAC1B,MAAO,CACL,GAAG,EACH,OAAQ,EAAQ,QAAQ,KAAO,EAAQ,OAAO,KAAO,KACrD,SAAU,OAAO,YAAW,OAAA,QAAA,EAAA,UAAA,EAAA,CAAA,CAAA,IAAA,GAAA,CAAA,EAAA,KAAA,CAAA,EAAA,EAAA,EAAA,CAAA,CAAA,CAAA,SAAA,GAAA,UAAA,CAAA,CAAA,CAAA,CAC7B,CAEH,EAAQ,OAAU,CAAA,cAAK,UAAA,wBAAA,YAAA,cAAA,CACvB,SAAO,EAAA,EAAA,EAAA,KAAA,CACL,IAAE,EAAA,CACD,GAAA,EACH,OAAA,GAAA,iBAEA,CAEE,MADA,GAAO,SAAE,OAAA,YAAqB,OAAA,QAAA,EAAA,UAAA,EAAA,CAAA,CAAA,IAAA,GAAA,CAAA,EAAA,KAAA,CAAA,EAAA,EAAA,EAAA,EAAA,CAAA,CAAA,CAAA,SAAA,GAAA,UAAA,CAAA,CAAA,CAAA,CACvB,EAET,EAAQ,OAAQ,CAAA,wBAAc,UAAA,cAAA,aAAA,KAAA,cAAA,wBAAA,CAO9B,SAAW,EAAgC,EAAM,CAC/C,OAAI,EAAI,EAAA,SAAA,cAAA,gBAAA,CAEV,EAAK,OAAA,CAAA,UAAA,UAAA,6BAAA,6DAAA,cAAA,CAOL,eAAsB,EAAmB,EAAQ,CAChD,IAAA,EAAA,MAAA,EAAA,GAAA,KAAA,EAAA,EAAA,CAAA,CACC,GAAE,CAAA,GAAgB,CAAG,EAAY,OAC/B,MAAQ,MAAQ,+BAAyB,EAAmB,EAAA,CAAA,WAAA,CAEhE,EAAO,SAAS,OAAA,YAAA,OAA2B,QAAS,KAAQ,MAAE,EAAO,EAAA,EAAA,CAAA,CAAA,IAAA,GAAA,CAAA,EAAA,KAAA,CAAA,EAAA,EAAA,EAAA,CAAA,CAAA,CAAA,SAAA,GAAA,UAAA,CAAA,CAAA,CAAA,CAErE,EAAA,OAAA,CAAA,UAAA,UAAA,0BAAA,yGAAA,cAAA,CAQA,eAAsB,EAAwB,EAAS,CACrD,IAAM,EAAW,EAAwB,EAAA,CAEzC,MAAC,EAAA,EAAA,EAAA,IAAA,MAAA,IAAA,MAAA,CACD,MAAK,EAAA,GAAY,MAAI,EAAY,KAAA,UAAQ,OAAA,YAAA,OAAA,QAAA,EAAA,SAAA,CAAA,IAAA,GAAA,CAAA,EAAA,KAAA,CAAA,EAAA,EAAA,EAAA,CAAA,CAAA,CAAA,SAAA,GAAA,UAAA,CAAA,CAAA,CAAA,CAAA,KAAA,EAAA,OAAA,OAAA,aAAA,EAAA,EAAA,CAAA,CAE3C,EAAmB,OAAe,CAAC,UAAE,UAAA,2BAA6C,kGAAA,cAAA"}
1
+ {"version":3,"file":"persistence.mjs","names":[],"sources":["../../src/helpers/persistence.ts"],"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 { writeEnvTypeReflection } from \"@powerlines/plugin-env/helpers\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport type { CommandTree, SerializedCommandTree } from \"../types\";\nimport type { Context } from \"../types/context\";\n\nfunction serialize(command: CommandTree): SerializedCommandTree {\n return {\n ...command,\n parent: command.parent?.name ? command.parent.name : null,\n children: Object.fromEntries(\n Object.entries(command.children || {}).map(([name, child]) => [\n name,\n serialize(child)\n ])\n )\n };\n}\n\nfunction deserialize(\n command: SerializedCommandTree,\n parent: CommandTree | null = null\n): CommandTree {\n const result: CommandTree = {\n ...command,\n parent: parent ?? null,\n children: {}\n };\n\n result.children = Object.fromEntries(\n Object.entries(command.children || {}).map(([name, child]) => [\n name,\n deserialize(child, result)\n ])\n );\n\n return result;\n}\n\n/**\n * Gets the file path for persisting CLI command reflections.\n *\n * @param context - The Shell Shock context.\n * @returns The file path for persisting CLI command reflections.\n */\nexport function getCommandsPersistencePath(context: Context): string {\n return joinPaths(context.dataPath, \"reflections\", \"commands.json\");\n}\n\n/**\n * Reads the persisted CLI command reflections from the file system and populates the context's commands.\n *\n * @param context - The Shell Shock context.\n * @throws Will throw an error if the reflections file is empty or cannot be read.\n */\nexport async function readCommandsPersistence(context: Context) {\n const reflections = await context.fs.read(\n getCommandsPersistencePath(context)\n );\n if (!reflections || !reflections.length) {\n throw new Error(\n `CLI Command reflection file ${getCommandsPersistencePath(context)} is empty`\n );\n }\n\n context.commands = Object.fromEntries(\n Object.entries(\n (JSON.parse(reflections) ?? {}) as Record<string, SerializedCommandTree>\n ).map(([name, command]) => [name, deserialize(command)])\n );\n}\n\n/**\n * Writes the current CLI command reflections from the context to the file system for persistence.\n *\n * @param context - The Shell Shock context.\n * @returns A promise that resolves when the reflections have been successfully written to the file system.\n * @throws Will throw an error if there is an issue writing the reflections to the file system.\n */\nexport async function writeCommandsPersistence(context: Context) {\n const filePath = getCommandsPersistencePath(context);\n\n // Also update the environment type reflections whenever we write the command reflections, to ensure they stay in sync.\n await writeEnvTypeReflection(context, context.env.types.env, \"env\");\n\n await context.fs.write(\n filePath,\n JSON.stringify(\n Object.fromEntries(\n Object.entries(context.commands).map(([name, command]) => [\n name,\n serialize(command)\n ])\n ),\n null,\n context.config.mode === \"production\" ? 0 : 2\n )\n );\n}\n"],"mappings":";;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE9B,QAAO;;AAqBT,SAAS,UAAU,SAAS;AAC1B,QAAO;EACL,GAAG;EACH,QAAQ,QAAQ,QAAQ,OAAO,QAAQ,OAAO,OAAO;EACrD,UAAU,OAAO,YAAW,OAAA,QAAA,QAAA,YAAA,EAAA,CAAA,CAAA,IAAA,cAAA,CAAA,MAAA,WAAA,CAAA,MAAA,UAAA,MAAA,CAAA,EAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA,CAAA;EAC7B;;AAEH,UAAQ,SAAU;CAAA;CAAK;CAAA;CAAA;CAAA;CAAA;AACvB,SAAO,YAAA,SAAA,SAAA,MAAA;CACL,MAAE,SAAA;EACD,GAAA;EACH,QAAA,UAAA;;EAEA;AACE,QAAO,WAAE,OAAA,YAAqB,OAAA,QAAA,QAAA,YAAA,EAAA,CAAA,CAAA,IAAA,cAAA,CAAA,MAAA,WAAA,CAAA,MAAA,YAAA,OAAA,OAAA,CAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA;AAC9B,QAAO;;AAET,YAAQ,SAAQ;CAAA;CAAc;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;;;;;;;AAO9B,SAAW,2BAAgC,SAAM;AAC/C,QAAI,UAAI,QAAA,UAAA,eAAA,gBAAA;;AAEV,2BAAK,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;AAOL,eAAsB,wBAAmB,SAAQ;CAChD,MAAA,cAAA,MAAA,QAAA,GAAA,KAAA,2BAAA,QAAA,CAAA;AACC,KAAE,CAAA,eAAgB,CAAG,YAAY,OAC/B,OAAA,IAAQ,MAAQ,+BAAyB,2BAAmB,QAAA,CAAA,WAAA;AAEhE,SAAO,WAAS,OAAA,YAAA,OAA2B,QAAS,KAAQ,MAAE,YAAO,IAAA,EAAA,CAAA,CAAA,IAAA,cAAA,CAAA,MAAA,aAAA,CAAA,MAAA,YAAA,QAAA,CAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA;;AAErE,wBAAA,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;AAQA,eAAsB,yBAAwB,SAAS;CACrD,MAAM,WAAW,2BAAwB,QAAA;AAEzC,OAAC,uBAAA,SAAA,QAAA,IAAA,MAAA,KAAA,MAAA;AACD,OAAK,QAAA,GAAY,MAAI,UAAY,KAAA,UAAQ,OAAA,YAAA,OAAA,QAAA,QAAA,SAAA,CAAA,IAAA,cAAA,CAAA,MAAA,aAAA,CAAA,MAAA,UAAA,QAAA,CAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA,EAAA,MAAA,QAAA,OAAA,SAAA,eAAA,IAAA,EAAA,CAAA;;AAE3C,yBAAmB,SAAe;CAAC;CAAE;CAAA;CAA6C;CAAA;CAAA"}
@@ -1 +1,65 @@
1
- require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../plugin-utils/context-helpers.cjs`);let t=require(`@stryke/convert/to-array`),n=require(`@stryke/path/join-paths`),r=require(`@stryke/string-format/kebab-case`),i=require(`@stryke/type-checks/is-set-object`),a=require(`@stryke/helpers/get-unique`),o=require(`@stryke/json/storm-json`);function s(e,t){return e.__type=t,e}function c(e){return`./dist/bin.${e===`cjs`||Array.isArray(e)&&e.includes(`cjs`)?`cjs`:`mjs`}`}c.__type=[`format`,`formatBinaryPath`,`PP&&F-J2!&/"`];async function l(l){let u=(0,n.joinPaths)(l.config.cwd||process.cwd(),l.config.root,`package.json`);if(l.config.bin&&Array.isArray(l.config.bin)&&l.config.bin.length>0?(l.packageJson.bin=Object.fromEntries((0,a.getUnique)((0,t.toArray)(l.config.bin)).map(s(e=>[e,c(l.config.output.format)],[`bin`,``,`P"2!"/"`]))),await l.fs.write(u,o.StormJSON.stringify(l.packageJson))):(Array.isArray(l.config.output.format)&&l.config.output.format.length>1?(l.packageJson.bin={[(0,r.kebabCase)(e.getAppName(l))]:c((0,t.toArray)(l.config.output.format)[0])},l.packageJson.bin=(0,t.toArray)(l.config.output.format).reduce(s((t,n)=>(t[`${(0,r.kebabCase)(e.getAppName(l))}-${n}`]=c(n),t),[`ret`,`format`,``,`P"2!"2""/#`]),l.packageJson.bin)):l.packageJson.bin={[(0,r.kebabCase)(e.getAppName(l))]:c(l.config.output.format)},await l.fs.write(u,o.StormJSON.stringify(l.packageJson))),!(0,i.isSetObject)(l.packageJson.bin))throw Error("Unable to determine the CLI binary name. Please specify the `bin` option in your Shell Shock configuration or ensure that the `name` field is set in your package.json.");l.config.bin=l.packageJson.bin}l.__type=[`Context`,`context`,`updatePackageJsonBinary`,'P"w!2"$`/#'],exports.formatBinaryPath=c,exports.updatePackageJsonBinary=l;
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ const require_context_helpers = require('../plugin-utils/context-helpers.cjs');
3
+ let _stryke_convert_to_array = require("@stryke/convert/to-array");
4
+ let _stryke_path_join_paths = require("@stryke/path/join-paths");
5
+ let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
6
+ let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
7
+ let _stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
8
+ let _stryke_json_storm_json = require("@stryke/json/storm-json");
9
+
10
+ //#region src/helpers/update-package-json.ts
11
+ function __assignType(fn, args) {
12
+ fn.__type = args;
13
+ return fn;
14
+ }
15
+ function formatBinaryPath(format) {
16
+ return `./dist/bin.${format === "cjs" || Array.isArray(format) && format.includes("cjs") ? "cjs" : "mjs"}`;
17
+ }
18
+ formatBinaryPath.__type = [
19
+ "format",
20
+ "formatBinaryPath",
21
+ "PP&&F-J2!&/\""
22
+ ];
23
+ async function updatePackageJsonBinary(context) {
24
+ const packageJsonPath = (0, _stryke_path_join_paths.joinPaths)(context.config.cwd, context.config.root, "package.json");
25
+ if (!context.packageJson) {
26
+ const packageJson = await context.fs.read(packageJsonPath);
27
+ if (packageJson) context.packageJson ??= JSON.parse(packageJson);
28
+ }
29
+ if (context.packageJson) {
30
+ if (context.config.bin && Array.isArray(context.config.bin) && context.config.bin.length > 0) {
31
+ context.packageJson.bin = Object.fromEntries((0, _stryke_helpers_get_unique.getUnique)((0, _stryke_convert_to_array.toArray)(context.config.bin)).map(__assignType((bin) => [bin, formatBinaryPath(context.config.output.format)], [
32
+ "bin",
33
+ "",
34
+ "P\"2!\"/\""
35
+ ])));
36
+ await context.fs.write(packageJsonPath, _stryke_json_storm_json.StormJSON.stringify(context.packageJson));
37
+ } else {
38
+ if (Array.isArray(context.config.output.format) && context.config.output.format.length > 1) {
39
+ context.packageJson.bin = { [(0, _stryke_string_format_kebab_case.kebabCase)(require_context_helpers.getAppName(context))]: formatBinaryPath((0, _stryke_convert_to_array.toArray)(context.config.output.format)[0]) };
40
+ context.packageJson.bin = (0, _stryke_convert_to_array.toArray)(context.config.output.format).reduce(__assignType((ret, format) => {
41
+ ret[`${(0, _stryke_string_format_kebab_case.kebabCase)(require_context_helpers.getAppName(context))}-${format}`] = formatBinaryPath(format);
42
+ return ret;
43
+ }, [
44
+ "ret",
45
+ "format",
46
+ "",
47
+ "P\"2!\"2\"\"/#"
48
+ ]), context.packageJson.bin);
49
+ } else context.packageJson.bin = { [(0, _stryke_string_format_kebab_case.kebabCase)(require_context_helpers.getAppName(context))]: formatBinaryPath(context.config.output.format) };
50
+ await context.fs.write(packageJsonPath, _stryke_json_storm_json.StormJSON.stringify(context.packageJson));
51
+ }
52
+ if (!(0, _stryke_type_checks_is_set_object.isSetObject)(context.packageJson.bin)) throw new Error("Unable to determine the CLI binary name. Please specify the `bin` option in your Shell Shock configuration or ensure that the `name` field is set in your package.json.");
53
+ context.config.bin = context.packageJson.bin;
54
+ }
55
+ }
56
+ updatePackageJsonBinary.__type = [
57
+ "Context",
58
+ "context",
59
+ "updatePackageJsonBinary",
60
+ "P\"w!2\"$`/#"
61
+ ];
62
+
63
+ //#endregion
64
+ exports.formatBinaryPath = formatBinaryPath;
65
+ exports.updatePackageJsonBinary = updatePackageJsonBinary;
@@ -1,2 +1,64 @@
1
- import{getAppName as e}from"../plugin-utils/context-helpers.mjs";import{toArray as t}from"@stryke/convert/to-array";import{joinPaths as n}from"@stryke/path/join-paths";import{kebabCase as r}from"@stryke/string-format/kebab-case";import{isSetObject as i}from"@stryke/type-checks/is-set-object";import{getUnique as a}from"@stryke/helpers/get-unique";import{StormJSON as o}from"@stryke/json/storm-json";function s(e,t){return e.__type=t,e}function c(e){return`./dist/bin.${e===`cjs`||Array.isArray(e)&&e.includes(`cjs`)?`cjs`:`mjs`}`}c.__type=[`format`,`formatBinaryPath`,`PP&&F-J2!&/"`];async function l(l){let u=n(l.config.cwd||process.cwd(),l.config.root,`package.json`);if(l.config.bin&&Array.isArray(l.config.bin)&&l.config.bin.length>0?(l.packageJson.bin=Object.fromEntries(a(t(l.config.bin)).map(s(e=>[e,c(l.config.output.format)],[`bin`,``,`P"2!"/"`]))),await l.fs.write(u,o.stringify(l.packageJson))):(Array.isArray(l.config.output.format)&&l.config.output.format.length>1?(l.packageJson.bin={[r(e(l))]:c(t(l.config.output.format)[0])},l.packageJson.bin=t(l.config.output.format).reduce(s((t,n)=>(t[`${r(e(l))}-${n}`]=c(n),t),[`ret`,`format`,``,`P"2!"2""/#`]),l.packageJson.bin)):l.packageJson.bin={[r(e(l))]:c(l.config.output.format)},await l.fs.write(u,o.stringify(l.packageJson))),!i(l.packageJson.bin))throw Error("Unable to determine the CLI binary name. Please specify the `bin` option in your Shell Shock configuration or ensure that the `name` field is set in your package.json.");l.config.bin=l.packageJson.bin}l.__type=[`Context`,`context`,`updatePackageJsonBinary`,'P"w!2"$`/#'];export{c as formatBinaryPath,l as updatePackageJsonBinary};
1
+ import { getAppName } from "../plugin-utils/context-helpers.mjs";
2
+ import { toArray } from "@stryke/convert/to-array";
3
+ import { joinPaths } from "@stryke/path/join-paths";
4
+ import { kebabCase } from "@stryke/string-format/kebab-case";
5
+ import { isSetObject } from "@stryke/type-checks/is-set-object";
6
+ import { getUnique } from "@stryke/helpers/get-unique";
7
+ import { StormJSON } from "@stryke/json/storm-json";
8
+
9
+ //#region src/helpers/update-package-json.ts
10
+ function __assignType(fn, args) {
11
+ fn.__type = args;
12
+ return fn;
13
+ }
14
+ function formatBinaryPath(format) {
15
+ return `./dist/bin.${format === "cjs" || Array.isArray(format) && format.includes("cjs") ? "cjs" : "mjs"}`;
16
+ }
17
+ formatBinaryPath.__type = [
18
+ "format",
19
+ "formatBinaryPath",
20
+ "PP&&F-J2!&/\""
21
+ ];
22
+ async function updatePackageJsonBinary(context) {
23
+ const packageJsonPath = joinPaths(context.config.cwd, context.config.root, "package.json");
24
+ if (!context.packageJson) {
25
+ const packageJson = await context.fs.read(packageJsonPath);
26
+ if (packageJson) context.packageJson ??= JSON.parse(packageJson);
27
+ }
28
+ if (context.packageJson) {
29
+ if (context.config.bin && Array.isArray(context.config.bin) && context.config.bin.length > 0) {
30
+ context.packageJson.bin = Object.fromEntries(getUnique(toArray(context.config.bin)).map(__assignType((bin) => [bin, formatBinaryPath(context.config.output.format)], [
31
+ "bin",
32
+ "",
33
+ "P\"2!\"/\""
34
+ ])));
35
+ await context.fs.write(packageJsonPath, StormJSON.stringify(context.packageJson));
36
+ } else {
37
+ if (Array.isArray(context.config.output.format) && context.config.output.format.length > 1) {
38
+ context.packageJson.bin = { [kebabCase(getAppName(context))]: formatBinaryPath(toArray(context.config.output.format)[0]) };
39
+ context.packageJson.bin = toArray(context.config.output.format).reduce(__assignType((ret, format) => {
40
+ ret[`${kebabCase(getAppName(context))}-${format}`] = formatBinaryPath(format);
41
+ return ret;
42
+ }, [
43
+ "ret",
44
+ "format",
45
+ "",
46
+ "P\"2!\"2\"\"/#"
47
+ ]), context.packageJson.bin);
48
+ } else context.packageJson.bin = { [kebabCase(getAppName(context))]: formatBinaryPath(context.config.output.format) };
49
+ await context.fs.write(packageJsonPath, StormJSON.stringify(context.packageJson));
50
+ }
51
+ if (!isSetObject(context.packageJson.bin)) throw new Error("Unable to determine the CLI binary name. Please specify the `bin` option in your Shell Shock configuration or ensure that the `name` field is set in your package.json.");
52
+ context.config.bin = context.packageJson.bin;
53
+ }
54
+ }
55
+ updatePackageJsonBinary.__type = [
56
+ "Context",
57
+ "context",
58
+ "updatePackageJsonBinary",
59
+ "P\"w!2\"$`/#"
60
+ ];
61
+
62
+ //#endregion
63
+ export { formatBinaryPath, updatePackageJsonBinary };
2
64
  //# sourceMappingURL=update-package-json.mjs.map