@shell-shock/core 0.10.0 → 0.12.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.
- package/dist/components/docs.cjs +4 -4
- package/dist/components/docs.cjs.map +1 -1
- package/dist/components/docs.d.cts +5 -5
- package/dist/components/docs.d.cts.map +1 -1
- package/dist/components/docs.d.mts +5 -5
- package/dist/components/docs.d.mts.map +1 -1
- package/dist/components/helpers.cjs +9 -0
- package/dist/components/helpers.cjs.map +1 -1
- package/dist/components/helpers.d.cts +15 -7
- package/dist/components/helpers.d.cts.map +1 -1
- package/dist/components/helpers.d.mts +15 -7
- package/dist/components/helpers.d.mts.map +1 -1
- package/dist/components/helpers.mjs +9 -1
- package/dist/components/helpers.mjs.map +1 -1
- package/dist/components/index.cjs +1 -0
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.mts +2 -2
- package/dist/components/index.mjs +2 -2
- package/dist/components/options-parser-logic.cjs +167 -87
- package/dist/components/options-parser-logic.cjs.map +1 -1
- package/dist/components/options-parser-logic.d.cts +15 -15
- package/dist/components/options-parser-logic.d.cts.map +1 -1
- package/dist/components/options-parser-logic.d.mts +15 -15
- package/dist/components/options-parser-logic.d.mts.map +1 -1
- package/dist/components/options-parser-logic.mjs +163 -83
- package/dist/components/options-parser-logic.mjs.map +1 -1
- package/dist/components/usage.cjs +5 -5
- package/dist/components/usage.cjs.map +1 -1
- package/dist/components/usage.d.cts +2 -2
- package/dist/components/usage.d.cts.map +1 -1
- package/dist/components/usage.d.mts +2 -2
- package/dist/components/usage.mjs +4 -4
- package/dist/components/usage.mjs.map +1 -1
- package/dist/components/utils-builtin.cjs +2 -2
- package/dist/components/utils-builtin.cjs.map +1 -1
- package/dist/components/utils-builtin.d.cts +9 -9
- package/dist/components/utils-builtin.d.cts.map +1 -1
- package/dist/components/utils-builtin.d.mts +9 -9
- package/dist/components/utils-builtin.d.mts.map +1 -1
- package/dist/components/utils-builtin.mjs +5 -5
- package/dist/components/utils-builtin.mjs.map +1 -1
- package/dist/contexts/options.cjs +2 -2
- package/dist/contexts/options.cjs.map +1 -1
- package/dist/contexts/options.d.cts +1 -1
- package/dist/contexts/options.d.cts.map +1 -1
- package/dist/contexts/options.d.mts +1 -1
- package/dist/contexts/options.d.mts.map +1 -1
- package/dist/contexts/options.mjs +4 -4
- package/dist/contexts/options.mjs.map +1 -1
- package/dist/helpers/automd.cjs +2 -2
- package/dist/helpers/automd.cjs.map +1 -1
- package/dist/helpers/automd.mjs.map +1 -1
- package/dist/helpers/paths.cjs +125 -0
- package/dist/helpers/paths.cjs.map +1 -0
- package/dist/helpers/paths.mjs +121 -0
- package/dist/helpers/paths.mjs.map +1 -0
- package/dist/helpers/persistence.cjs +68 -116
- package/dist/helpers/persistence.cjs.map +1 -1
- package/dist/helpers/persistence.mjs +68 -116
- package/dist/helpers/persistence.mjs.map +1 -1
- package/dist/helpers/update-package-json.cjs +4 -4
- package/dist/helpers/update-package-json.cjs.map +1 -1
- package/dist/helpers/utilities.cjs +1 -1
- package/dist/helpers/utilities.mjs +1 -1
- package/dist/helpers/validations.cjs +2 -3
- package/dist/helpers/validations.cjs.map +1 -1
- package/dist/helpers/validations.mjs +2 -2
- package/dist/helpers/validations.mjs.map +1 -1
- package/dist/index.cjs +14 -11
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +3 -3
- package/dist/plugin-utils/deepkit.cjs +72 -0
- package/dist/plugin-utils/deepkit.cjs.map +1 -0
- package/dist/plugin-utils/deepkit.d.cts +24 -0
- package/dist/plugin-utils/deepkit.d.cts.map +1 -0
- package/dist/plugin-utils/deepkit.d.mts +24 -0
- package/dist/plugin-utils/deepkit.d.mts.map +1 -0
- package/dist/plugin-utils/deepkit.mjs +70 -0
- package/dist/plugin-utils/deepkit.mjs.map +1 -0
- package/dist/plugin-utils/description-helpers.cjs +105 -0
- package/dist/plugin-utils/description-helpers.cjs.map +1 -0
- package/dist/plugin-utils/description-helpers.d.cts +44 -0
- package/dist/plugin-utils/description-helpers.d.cts.map +1 -0
- package/dist/plugin-utils/description-helpers.d.mts +44 -0
- package/dist/plugin-utils/description-helpers.d.mts.map +1 -0
- package/dist/plugin-utils/description-helpers.mjs +101 -0
- package/dist/plugin-utils/description-helpers.mjs.map +1 -0
- package/dist/plugin-utils/get-command-tree.cjs +2 -2
- package/dist/plugin-utils/get-command-tree.cjs.map +1 -1
- package/dist/plugin-utils/index.cjs +32 -18
- package/dist/plugin-utils/index.d.cts +4 -1
- package/dist/plugin-utils/index.d.mts +4 -1
- package/dist/plugin-utils/index.mjs +4 -1
- package/dist/plugin-utils/reflect.cjs +4 -5
- package/dist/plugin-utils/reflect.cjs.map +1 -1
- package/dist/plugin-utils/reflect.mjs +4 -4
- package/dist/plugin-utils/reflect.mjs.map +1 -1
- package/dist/plugin-utils/type-checks.cjs +89 -0
- package/dist/plugin-utils/type-checks.cjs.map +1 -0
- package/dist/plugin-utils/type-checks.d.cts +42 -0
- package/dist/plugin-utils/type-checks.d.cts.map +1 -0
- package/dist/plugin-utils/type-checks.d.mts +42 -0
- package/dist/plugin-utils/type-checks.d.mts.map +1 -0
- package/dist/plugin-utils/type-checks.mjs +84 -0
- package/dist/plugin-utils/type-checks.mjs.map +1 -0
- package/dist/plugin.cjs +31 -29
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +15 -13
- package/dist/plugin.mjs.map +1 -1
- package/dist/resolver/deepkit.cjs +132 -0
- package/dist/resolver/deepkit.cjs.map +1 -0
- package/dist/resolver/deepkit.mjs +131 -0
- package/dist/resolver/deepkit.mjs.map +1 -0
- package/dist/resolver/helpers.cjs +167 -0
- package/dist/resolver/helpers.cjs.map +1 -0
- package/dist/resolver/helpers.mjs +162 -0
- package/dist/resolver/helpers.mjs.map +1 -0
- package/dist/resolver/module.cjs +144 -0
- package/dist/resolver/module.cjs.map +1 -0
- package/dist/resolver/module.mjs +143 -0
- package/dist/resolver/module.mjs.map +1 -0
- package/dist/resolver/resolve.cjs +209 -0
- package/dist/resolver/resolve.cjs.map +1 -0
- package/dist/resolver/resolve.mjs +208 -0
- package/dist/resolver/resolve.mjs.map +1 -0
- package/dist/types/command.cjs +127 -104
- package/dist/types/command.cjs.map +1 -1
- package/dist/types/command.d.cts +39 -78
- package/dist/types/command.d.cts.map +1 -1
- package/dist/types/command.d.mts +39 -78
- package/dist/types/command.d.mts.map +1 -1
- package/dist/types/command.mjs +115 -95
- package/dist/types/command.mjs.map +1 -1
- package/dist/types/config.cjs +5 -3
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.cts +7 -3
- package/dist/types/config.d.cts.map +1 -1
- package/dist/types/config.d.mts +7 -3
- package/dist/types/config.d.mts.map +1 -1
- package/dist/types/config.mjs +5 -3
- package/dist/types/config.mjs.map +1 -1
- package/dist/types/context.cjs +1 -1
- package/dist/types/context.cjs.map +1 -1
- package/dist/types/context.d.cts +2 -2
- package/dist/types/context.d.cts.map +1 -1
- package/dist/types/context.d.mts +2 -2
- package/dist/types/context.d.mts.map +1 -1
- package/dist/types/context.mjs +1 -1
- package/dist/types/context.mjs.map +1 -1
- package/dist/types/index.cjs +13 -10
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.mts +2 -2
- package/dist/types/index.mjs +2 -2
- package/package.json +24 -75
- package/dist/helpers/resolve-command.cjs +0 -430
- package/dist/helpers/resolve-command.cjs.map +0 -1
- package/dist/helpers/resolve-command.mjs +0 -425
- package/dist/helpers/resolve-command.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.cjs","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 { 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 { stripStars } from \"@stryke/path/normalize\";\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 function findCommandsRoot(context: Context): string {\n if (isSetString(context.config.input)) {\n return appendPath(\n appendPath(stripStars(context.config.input), context.config.root),\n context.workspaceConfig.workspaceRoot\n );\n } else if (isTypeDefinition(context.config.input)) {\n return appendPath(\n appendPath(stripStars(context.config.input.file), context.config.root),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n Array.isArray(context.config.input) &&\n context.config.input.length > 0\n ) {\n return commonPath(\n context.config.input.map(input =>\n appendPath(\n appendPath(\n stripStars(isSetString(input) ? input : input.file),\n context.config.root\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\n } else if (isSetObject(context.config.input)) {\n return commonPath(\n Object.values(context.config.input).map(input =>\n Array.isArray(input)\n ? commonPath(\n input.map(i =>\n appendPath(\n appendPath(\n stripStars(isSetString(i) ? i : i.file),\n context.config.root\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n )\n : appendPath(\n appendPath(\n stripStars(isSetString(input) ? input : input.file),\n context.config.root\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\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 return appendPath(commandsPath, context.workspaceConfig.workspaceRoot);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;AA+BX,SAAgB,iBAAiB,SAAO,MAAA;AACpC,6FAAgC,KAAK,EAAE,QAAI,aAAA,YAEtC,OAAO,cAAa,MAAK,QAAQ,EAAE,IAAI,CAAC,6CAAqB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M,SAAS,EAC9B,6CAAkB,QAAQ,OAAO,MAAA,IAAA,cAAA,gLAAA,MAAA,GAAA,QAAA,MAAA,KAAA,EAAA,QAAA,OAAA,KAAA,EAAA,QAAA,gBAAA,cAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA;8DAEhB,QAAQ,OAAO,MAAM,CACtC,6CAAkB,OAAO,OAAO,QAAE,OAAA,MAAA,CAAA,IAAA,cAAA,UAAA,MAAA,QAAA,MAAA,wCACrC,MAAA,IAAA,cAAA,4KAAA,EAAA,GAAA,IAAA,EAAA,KAAA,EAAA,QAAA,OAAA,KAAA,EAAA,QAAA,gBAAA,cAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA,yKACgD,MAAA,GAAA,QAAA,MAAA,KAAA,EAAA,QAAA,OAAA,KAAA,EAAA,QAAA,gBAAA,cAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA;CAEjD,IAAI,uDAAyB,QAAQ,OAAO,MAAM,eAAe;AACjE,KAAI,yBAAY,aAAa,EAAE;AAC9B,yDAAA,QAAA,OAAA,MAAA,WAAA;AACG,MAAI,yBAAA,aAAA,EAAA;AACA,0DAAyB,QAAI,OAAA,MAAA,MAAA;AAC7B,OAAI,yBAAY,aAAM,CAC9B,gBAAA,QAAA,OAAA;;;AAIA,6CAAgB,cAAA,QAAA,gBAAA,cAAA;;AAEpB,iBAAiB,SAAS;CAAC;CAAG;CAAA;CAAA;CAAA"}
|
|
@@ -0,0 +1,121 @@
|
|
|
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 { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
8
|
+
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
9
|
+
import { isTypeDefinition } from "powerlines/utils";
|
|
10
|
+
import { commonPath } from "@stryke/path/common";
|
|
11
|
+
import { stripStars } from "@stryke/path/normalize";
|
|
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
|
+
"P&2!\"/\""
|
|
52
|
+
];
|
|
53
|
+
function resolveCommandPath(context, file) {
|
|
54
|
+
return replacePath(findFilePath(file), context.commandsPath).replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "").split("/").filter(__assignType((path) => path && !isPathSegmentGroup(path), [
|
|
55
|
+
"path",
|
|
56
|
+
"",
|
|
57
|
+
"P\"2!\"/\""
|
|
58
|
+
])).join("/");
|
|
59
|
+
}
|
|
60
|
+
resolveCommandPath.__type = [
|
|
61
|
+
"Context",
|
|
62
|
+
"context",
|
|
63
|
+
"file",
|
|
64
|
+
"resolveCommandPath",
|
|
65
|
+
"P\"w!2\"&2#&/$"
|
|
66
|
+
];
|
|
67
|
+
function resolveCommandDynamicPathSegments(context, file) {
|
|
68
|
+
return replacePath(findFilePath(file), context.commandsPath).split("/").filter(__assignType((path) => Boolean(path) && isDynamicPathSegment(path), [
|
|
69
|
+
"path",
|
|
70
|
+
"",
|
|
71
|
+
"P\"2!\"/\""
|
|
72
|
+
])).map(__assignType((path) => getDynamicPathSegmentName(path), [
|
|
73
|
+
"path",
|
|
74
|
+
"",
|
|
75
|
+
"P\"2!\"/\""
|
|
76
|
+
]));
|
|
77
|
+
}
|
|
78
|
+
resolveCommandDynamicPathSegments.__type = [
|
|
79
|
+
"Context",
|
|
80
|
+
"context",
|
|
81
|
+
"file",
|
|
82
|
+
"resolveCommandDynamicPathSegments",
|
|
83
|
+
"P\"w!2\"&2#&F/$"
|
|
84
|
+
];
|
|
85
|
+
function findCommandsRoot(context) {
|
|
86
|
+
if (isSetString(context.config.input)) return appendPath(appendPath(stripStars(context.config.input), context.config.root), context.workspaceConfig.workspaceRoot);
|
|
87
|
+
else if (isTypeDefinition(context.config.input)) return appendPath(appendPath(stripStars(context.config.input.file), context.config.root), context.workspaceConfig.workspaceRoot);
|
|
88
|
+
else if (Array.isArray(context.config.input) && context.config.input.length > 0) return commonPath(context.config.input.map(__assignType((input) => appendPath(appendPath(stripStars(isSetString(input) ? input : input.file), context.config.root), context.workspaceConfig.workspaceRoot), [
|
|
89
|
+
"input",
|
|
90
|
+
"",
|
|
91
|
+
"P\"2!\"/\""
|
|
92
|
+
])));
|
|
93
|
+
else if (isSetObject(context.config.input)) return commonPath(Object.values(context.config.input).map(__assignType((input) => Array.isArray(input) ? commonPath(input.map(__assignType((i) => appendPath(appendPath(stripStars(isSetString(i) ? i : i.file), context.config.root), context.workspaceConfig.workspaceRoot), [
|
|
94
|
+
"i",
|
|
95
|
+
"",
|
|
96
|
+
"P\"2!\"/\""
|
|
97
|
+
]))) : appendPath(appendPath(stripStars(isSetString(input) ? input : input.file), context.config.root), context.workspaceConfig.workspaceRoot), [
|
|
98
|
+
"input",
|
|
99
|
+
"",
|
|
100
|
+
"P\"2!\"/\""
|
|
101
|
+
])));
|
|
102
|
+
let commandsPath = joinPaths(context.config.root, "src/commands");
|
|
103
|
+
if (!existsSync(commandsPath)) {
|
|
104
|
+
commandsPath = joinPaths(context.config.root, "commands");
|
|
105
|
+
if (!existsSync(commandsPath)) {
|
|
106
|
+
commandsPath = joinPaths(context.config.root, "src");
|
|
107
|
+
if (!existsSync(commandsPath)) commandsPath = context.config.root;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return appendPath(commandsPath, context.workspaceConfig.workspaceRoot);
|
|
111
|
+
}
|
|
112
|
+
findCommandsRoot.__type = [
|
|
113
|
+
"Context",
|
|
114
|
+
"context",
|
|
115
|
+
"findCommandsRoot",
|
|
116
|
+
"P\"w!2\"&/#"
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
//#endregion
|
|
120
|
+
export { findCommandsRoot, resolveCommandId, resolveCommandName, resolveCommandPath };
|
|
121
|
+
//# sourceMappingURL=paths.mjs.map
|
|
@@ -0,0 +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 { 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 { stripStars } from \"@stryke/path/normalize\";\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 function findCommandsRoot(context: Context): string {\n if (isSetString(context.config.input)) {\n return appendPath(\n appendPath(stripStars(context.config.input), context.config.root),\n context.workspaceConfig.workspaceRoot\n );\n } else if (isTypeDefinition(context.config.input)) {\n return appendPath(\n appendPath(stripStars(context.config.input.file), context.config.root),\n context.workspaceConfig.workspaceRoot\n );\n } else if (\n Array.isArray(context.config.input) &&\n context.config.input.length > 0\n ) {\n return commonPath(\n context.config.input.map(input =>\n appendPath(\n appendPath(\n stripStars(isSetString(input) ? input : input.file),\n context.config.root\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\n } else if (isSetObject(context.config.input)) {\n return commonPath(\n Object.values(context.config.input).map(input =>\n Array.isArray(input)\n ? commonPath(\n input.map(i =>\n appendPath(\n appendPath(\n stripStars(isSetString(i) ? i : i.file),\n context.config.root\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n )\n : appendPath(\n appendPath(\n stripStars(isSetString(input) ? input : input.file),\n context.config.root\n ),\n context.workspaceConfig.workspaceRoot\n )\n )\n );\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 return appendPath(commandsPath, context.workspaceConfig.workspaceRoot);\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;AA+BX,SAAgB,iBAAiB,SAAO,MAAA;AACpC,QAAO,YAAY,a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
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
let __stryke_path_join_paths = require("@stryke/path/join-paths");
|
|
3
|
-
let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
4
|
-
let __stryke_helpers_omit = require("@stryke/helpers/omit");
|
|
5
3
|
|
|
6
4
|
//#region src/helpers/persistence.ts
|
|
7
|
-
const __ΩRecord = [
|
|
8
|
-
"K",
|
|
9
|
-
"T",
|
|
10
|
-
"Record",
|
|
11
|
-
"l'e#\"Rb!b\"Pde\"!N#!w#y"
|
|
12
|
-
];
|
|
13
5
|
function __assignType(fn, args) {
|
|
14
6
|
fn.__type = args;
|
|
15
7
|
return fn;
|
|
16
8
|
}
|
|
17
|
-
function
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
]
|
|
26
|
-
|
|
27
|
-
const serialize = __assignType((node, parent = null) => {
|
|
28
|
-
const serializedNode = {
|
|
29
|
-
...node,
|
|
30
|
-
options: Object.entries(node.options).reduce(__assignType((ret, [key, option]) => {
|
|
31
|
-
ret[key] = { ...(0, __stryke_helpers_omit.omit)(option, ["reflection"]) };
|
|
32
|
-
return ret;
|
|
33
|
-
}, [
|
|
34
|
-
"ret",
|
|
35
|
-
"param1",
|
|
36
|
-
"",
|
|
37
|
-
"P\"2!\"2\"\"/#"
|
|
38
|
-
]), {}),
|
|
39
|
-
arguments: node.arguments.map(__assignType((arg) => ({ ...(0, __stryke_helpers_omit.omit)(arg, ["reflection"]) }), [
|
|
40
|
-
"arg",
|
|
41
|
-
"",
|
|
42
|
-
"P\"2!\"/\""
|
|
43
|
-
])),
|
|
44
|
-
parent,
|
|
45
|
-
children: {},
|
|
46
|
-
reflection: node.reflection ? (0, __powerlines_deepkit_vendor_type.serializeType)(node.reflection.type) : void 0
|
|
47
|
-
};
|
|
48
|
-
for (const [key, child] of Object.entries(node.children || {})) serializedNode.children[key] = serialize(child, node.id);
|
|
49
|
-
return serializedNode;
|
|
50
|
-
}, [
|
|
51
|
-
"CommandTree",
|
|
52
|
-
"node",
|
|
53
|
-
"parent",
|
|
54
|
-
() => null,
|
|
55
|
-
"SerializedCommandTree",
|
|
56
|
-
"",
|
|
57
|
-
"P\"w!2\"P&,J2#>$\"w%/&"
|
|
58
|
-
]);
|
|
59
|
-
const result = {};
|
|
60
|
-
for (const [key, child] of Object.entries(commands)) result[key] = serialize(child, null);
|
|
61
|
-
return result;
|
|
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
|
+
};
|
|
62
19
|
}
|
|
63
|
-
|
|
64
|
-
() => __ΩRecord,
|
|
20
|
+
serialize.__type = [
|
|
65
21
|
"CommandTree",
|
|
66
|
-
"
|
|
67
|
-
() => __ΩRecord,
|
|
22
|
+
"command",
|
|
68
23
|
"SerializedCommandTree",
|
|
69
|
-
"
|
|
70
|
-
"P
|
|
24
|
+
"serialize",
|
|
25
|
+
"P\"w!2\"\"w#/$"
|
|
71
26
|
];
|
|
72
|
-
function
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (optionsType.kind === __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral) optionsReflection = (0, __powerlines_deepkit_vendor_type.resolveClassType)(optionsType);
|
|
81
|
-
}
|
|
82
|
-
const deserializedNode = {
|
|
83
|
-
...node,
|
|
84
|
-
options: optionsReflection ? Object.entries(node.options).reduce(__assignType((ret, [key, option]) => {
|
|
85
|
-
ret[key] = {
|
|
86
|
-
...option,
|
|
87
|
-
reflection: optionsReflection.getProperty(option.name)
|
|
88
|
-
};
|
|
89
|
-
return ret;
|
|
90
|
-
}, [
|
|
91
|
-
"ret",
|
|
92
|
-
"param1",
|
|
93
|
-
"",
|
|
94
|
-
"P\"2!\"2\"\"/#"
|
|
95
|
-
]), {}) : {},
|
|
96
|
-
arguments: node.arguments.map(__assignType((arg, i) => ({
|
|
97
|
-
...arg,
|
|
98
|
-
reflection: reflection.getParameters().length > i + 1 ? reflection.getParameters()[i + 1] : reflection.getParameterOrUndefined(arg.name)
|
|
99
|
-
}), [
|
|
100
|
-
"arg",
|
|
101
|
-
"i",
|
|
102
|
-
"",
|
|
103
|
-
"P\"2!\"2\"\"/#"
|
|
104
|
-
])),
|
|
105
|
-
parent,
|
|
106
|
-
children: {},
|
|
107
|
-
reflection
|
|
108
|
-
};
|
|
109
|
-
for (const [key, child] of Object.entries(node.children || {})) deserializedNode.children[key] = deserialize(child, deserializedNode);
|
|
110
|
-
return deserializedNode;
|
|
111
|
-
}, [
|
|
112
|
-
"SerializedCommandTree",
|
|
113
|
-
"node",
|
|
114
|
-
"CommandTree",
|
|
115
|
-
"parent",
|
|
116
|
-
() => null,
|
|
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",
|
|
117
35
|
"",
|
|
118
|
-
"P\"
|
|
119
|
-
]);
|
|
120
|
-
const result = {};
|
|
121
|
-
for (const [key, child] of Object.entries(serializedCommands)) result[key] = deserialize(child, null);
|
|
36
|
+
"P\"2!\"/\""
|
|
37
|
+
])));
|
|
122
38
|
return result;
|
|
123
39
|
}
|
|
124
|
-
|
|
125
|
-
() => __ΩRecord,
|
|
40
|
+
deserialize.__type = [
|
|
126
41
|
"SerializedCommandTree",
|
|
127
|
-
"
|
|
128
|
-
() => __ΩRecord,
|
|
42
|
+
"command",
|
|
129
43
|
"CommandTree",
|
|
130
|
-
"
|
|
131
|
-
|
|
44
|
+
"parent",
|
|
45
|
+
() => null,
|
|
46
|
+
"deserialize",
|
|
47
|
+
"P\"w!2\"P\"w#,J2$>%\"w#/&"
|
|
132
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 (0, __stryke_path_join_paths.joinPaths)(context.dataPath, "reflections", "commands.json");
|
|
57
|
+
}
|
|
58
|
+
getCommandsPersistencePath.__type = [
|
|
59
|
+
"Context",
|
|
60
|
+
"context",
|
|
61
|
+
"getCommandsPersistencePath",
|
|
62
|
+
"P\"w!2\"&/#"
|
|
63
|
+
];
|
|
64
|
+
/**
|
|
65
|
+
* Reads the persisted CLI command reflections from the file system and populates the context's commands.
|
|
66
|
+
*
|
|
67
|
+
* @param context - The Shell Shock context.
|
|
68
|
+
* @throws Will throw an error if the reflections file is empty or cannot be read.
|
|
69
|
+
*/
|
|
133
70
|
async function readCommandsPersistence(context) {
|
|
134
71
|
const reflections = await context.fs.read(getCommandsPersistencePath(context));
|
|
135
72
|
if (!reflections || !reflections.length) throw new Error(`CLI Command reflection file ${getCommandsPersistencePath(context)} is empty`);
|
|
136
|
-
context.commands =
|
|
73
|
+
context.commands = Object.fromEntries(Object.entries(JSON.parse(reflections) ?? {}).map(__assignType(([name, command]) => [name, deserialize(command)], [
|
|
74
|
+
"param0",
|
|
75
|
+
"",
|
|
76
|
+
"P\"2!\"/\""
|
|
77
|
+
])));
|
|
137
78
|
}
|
|
138
79
|
readCommandsPersistence.__type = [
|
|
139
80
|
"Context",
|
|
@@ -141,9 +82,20 @@ readCommandsPersistence.__type = [
|
|
|
141
82
|
"readCommandsPersistence",
|
|
142
83
|
"P\"w!2\"\"/#"
|
|
143
84
|
];
|
|
85
|
+
/**
|
|
86
|
+
* Writes the current CLI command reflections from the context to the file system for persistence.
|
|
87
|
+
*
|
|
88
|
+
* @param context - The Shell Shock context.
|
|
89
|
+
* @returns A promise that resolves when the reflections have been successfully written to the file system.
|
|
90
|
+
* @throws Will throw an error if there is an issue writing the reflections to the file system.
|
|
91
|
+
*/
|
|
144
92
|
async function writeCommandsPersistence(context) {
|
|
145
93
|
const filePath = getCommandsPersistencePath(context);
|
|
146
|
-
await context.fs.write(filePath, JSON.stringify(
|
|
94
|
+
await context.fs.write(filePath, JSON.stringify(Object.fromEntries(Object.entries(context.commands).map(__assignType(([name, command]) => [name, serialize(command)], [
|
|
95
|
+
"param0",
|
|
96
|
+
"",
|
|
97
|
+
"P\"2!\"/\""
|
|
98
|
+
]))), null, context.config.mode === "production" ? 0 : 2));
|
|
147
99
|
}
|
|
148
100
|
writeCommandsPersistence.__type = [
|
|
149
101
|
"Context",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistence.cjs","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
|
|
1
|
+
{"version":3,"file":"persistence.cjs","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 { 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 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;;AAE5B,QAAO;;AAoBX,SAAS,UAAU,SAAS;AACxB,QAAK;EACD,GAAG;EACH,QAAQ,QAAQ,QAAQ,OAAO,QAAQ,OAAO,OAAO;EACrD,UAAU,OAAO,YAAO,OAAA,QAAA,QAAA,YAAA,EAAA,CAAA,CAAA,IAAA,cAAA,CAAA,MAAA,WAAA,CACpB,MACA,UAAA,MAAA,CACH,EAAE;GAAC;GAAU;GAAC;GAAA,CAAA,CAAA,CAAA;EAClB;;AAEL,UAAG,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;AACH,SAAA,YAAA,SAAA,SAAA,MAAA;;EAEQ,GAAG;EACH,QAAQ,UAAU;EAClB,UAAU,EAAC;EACd;AACD,QAAO,WAAW,OAAO,YAAC,OAAA,QAAA,QAAA,YAAA,EAAA,CAAA,CAAA,IAAA,cAAA,CAAA,MAAA,WAAA,CACtB,MACA,YAAY,OAAM,OAAA,CACrB,EAAE;EAAC;EAAO;EAAA;EAAA,CAAA,CAAA,CAAA;AACZ,QAAA;;AAEH,YAAY,SAAS;CAAC;CAAgB;CAAA;CAAA;OAAA;CAAA;CAAA;CAAA;;;;;;;AAOtC,SAAe,2BAAA,SAAA;AACf,gDAAA,QAAA,UAAA,eAAA,gBAAA;;AAEA,2BAAE,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;AAOF,eAAsB,wBAAwB,SAAS;CACvD,MAAA,cAAA,MAAA,QAAA,GAAA,KAAA,2BAAA,QAAA,CAAA;yCAEE,OAAA,IAAA,MAAA,+BAAA,2BAAA,QAAA,CAAA,WAAA;AAED,SAAA,WAAA,OAAA,YAAA,OAAA,QAAA,KAAA,MAAA,YAAA,IAAA,EAAA,CAAA,CAAA,IAAA,cAAA,CAAA,MAAA,aAAA,CAAA,MAAA,YAAA,QAAA,CAAA,EAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA;;AAED,wBAAwB,SAAS;CAAC;CAAW;CAAW;CAAyB;CAAA;;;;;;;;AAQjF,eAAsB,yBAAyB,SAAS;CACpD,MAAC,WAAA,2BAAA,QAAA;AACH,OAAA,QAAA,GAAA,MAAA,UAAA,KAAA,UAAA,OAAA,YAAA,OAAA,QAAA,QAAA,SAAA,CAAA,IAAA,cAAA,CAAA,MAAA,aAAA,OAEM,UAAU,QAAQ,CACrB,EAAE;EAAC;EAAU;EAAA;EAAA,CAAA,CAAA,CAAA,EAAA,MAAA,QAAA,OAAA,SAAA,eAAA,IAAA,EAAA,CAAA;;AAElB,yBAAyB,SAAS;CAAC;CAAW;CAAW;CAAE;CAAA"}
|
|
@@ -1,138 +1,79 @@
|
|
|
1
1
|
import { joinPaths } from "@stryke/path/join-paths";
|
|
2
|
-
import { ReflectionFunction, ReflectionKind, deserializeType, resolveClassType, serializeType } from "@powerlines/deepkit/vendor/type";
|
|
3
|
-
import { omit } from "@stryke/helpers/omit";
|
|
4
2
|
|
|
5
3
|
//#region src/helpers/persistence.ts
|
|
6
|
-
const __ΩRecord = [
|
|
7
|
-
"K",
|
|
8
|
-
"T",
|
|
9
|
-
"Record",
|
|
10
|
-
"l'e#\"Rb!b\"Pde\"!N#!w#y"
|
|
11
|
-
];
|
|
12
4
|
function __assignType(fn, args) {
|
|
13
5
|
fn.__type = args;
|
|
14
6
|
return fn;
|
|
15
7
|
}
|
|
16
|
-
function
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
]
|
|
25
|
-
|
|
26
|
-
const serialize = __assignType((node, parent = null) => {
|
|
27
|
-
const serializedNode = {
|
|
28
|
-
...node,
|
|
29
|
-
options: Object.entries(node.options).reduce(__assignType((ret, [key, option]) => {
|
|
30
|
-
ret[key] = { ...omit(option, ["reflection"]) };
|
|
31
|
-
return ret;
|
|
32
|
-
}, [
|
|
33
|
-
"ret",
|
|
34
|
-
"param1",
|
|
35
|
-
"",
|
|
36
|
-
"P\"2!\"2\"\"/#"
|
|
37
|
-
]), {}),
|
|
38
|
-
arguments: node.arguments.map(__assignType((arg) => ({ ...omit(arg, ["reflection"]) }), [
|
|
39
|
-
"arg",
|
|
40
|
-
"",
|
|
41
|
-
"P\"2!\"/\""
|
|
42
|
-
])),
|
|
43
|
-
parent,
|
|
44
|
-
children: {},
|
|
45
|
-
reflection: node.reflection ? serializeType(node.reflection.type) : void 0
|
|
46
|
-
};
|
|
47
|
-
for (const [key, child] of Object.entries(node.children || {})) serializedNode.children[key] = serialize(child, node.id);
|
|
48
|
-
return serializedNode;
|
|
49
|
-
}, [
|
|
50
|
-
"CommandTree",
|
|
51
|
-
"node",
|
|
52
|
-
"parent",
|
|
53
|
-
() => null,
|
|
54
|
-
"SerializedCommandTree",
|
|
55
|
-
"",
|
|
56
|
-
"P\"w!2\"P&,J2#>$\"w%/&"
|
|
57
|
-
]);
|
|
58
|
-
const result = {};
|
|
59
|
-
for (const [key, child] of Object.entries(commands)) result[key] = serialize(child, null);
|
|
60
|
-
return result;
|
|
8
|
+
function serialize(command) {
|
|
9
|
+
return {
|
|
10
|
+
...command,
|
|
11
|
+
parent: command.parent?.name ? command.parent.name : null,
|
|
12
|
+
children: Object.fromEntries(Object.entries(command.children || {}).map(__assignType(([name, child]) => [name, serialize(child)], [
|
|
13
|
+
"param0",
|
|
14
|
+
"",
|
|
15
|
+
"P\"2!\"/\""
|
|
16
|
+
])))
|
|
17
|
+
};
|
|
61
18
|
}
|
|
62
|
-
|
|
63
|
-
() => __ΩRecord,
|
|
19
|
+
serialize.__type = [
|
|
64
20
|
"CommandTree",
|
|
65
|
-
"
|
|
66
|
-
() => __ΩRecord,
|
|
21
|
+
"command",
|
|
67
22
|
"SerializedCommandTree",
|
|
68
|
-
"
|
|
69
|
-
"P
|
|
23
|
+
"serialize",
|
|
24
|
+
"P\"w!2\"\"w#/$"
|
|
70
25
|
];
|
|
71
|
-
function
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (optionsType.kind === ReflectionKind.objectLiteral) optionsReflection = resolveClassType(optionsType);
|
|
80
|
-
}
|
|
81
|
-
const deserializedNode = {
|
|
82
|
-
...node,
|
|
83
|
-
options: optionsReflection ? Object.entries(node.options).reduce(__assignType((ret, [key, option]) => {
|
|
84
|
-
ret[key] = {
|
|
85
|
-
...option,
|
|
86
|
-
reflection: optionsReflection.getProperty(option.name)
|
|
87
|
-
};
|
|
88
|
-
return ret;
|
|
89
|
-
}, [
|
|
90
|
-
"ret",
|
|
91
|
-
"param1",
|
|
92
|
-
"",
|
|
93
|
-
"P\"2!\"2\"\"/#"
|
|
94
|
-
]), {}) : {},
|
|
95
|
-
arguments: node.arguments.map(__assignType((arg, i) => ({
|
|
96
|
-
...arg,
|
|
97
|
-
reflection: reflection.getParameters().length > i + 1 ? reflection.getParameters()[i + 1] : reflection.getParameterOrUndefined(arg.name)
|
|
98
|
-
}), [
|
|
99
|
-
"arg",
|
|
100
|
-
"i",
|
|
101
|
-
"",
|
|
102
|
-
"P\"2!\"2\"\"/#"
|
|
103
|
-
])),
|
|
104
|
-
parent,
|
|
105
|
-
children: {},
|
|
106
|
-
reflection
|
|
107
|
-
};
|
|
108
|
-
for (const [key, child] of Object.entries(node.children || {})) deserializedNode.children[key] = deserialize(child, deserializedNode);
|
|
109
|
-
return deserializedNode;
|
|
110
|
-
}, [
|
|
111
|
-
"SerializedCommandTree",
|
|
112
|
-
"node",
|
|
113
|
-
"CommandTree",
|
|
114
|
-
"parent",
|
|
115
|
-
() => null,
|
|
26
|
+
function deserialize(command, parent = null) {
|
|
27
|
+
const result = {
|
|
28
|
+
...command,
|
|
29
|
+
parent: parent ?? null,
|
|
30
|
+
children: {}
|
|
31
|
+
};
|
|
32
|
+
result.children = Object.fromEntries(Object.entries(command.children || {}).map(__assignType(([name, child]) => [name, deserialize(child, result)], [
|
|
33
|
+
"param0",
|
|
116
34
|
"",
|
|
117
|
-
"P\"
|
|
118
|
-
]);
|
|
119
|
-
const result = {};
|
|
120
|
-
for (const [key, child] of Object.entries(serializedCommands)) result[key] = deserialize(child, null);
|
|
35
|
+
"P\"2!\"/\""
|
|
36
|
+
])));
|
|
121
37
|
return result;
|
|
122
38
|
}
|
|
123
|
-
|
|
124
|
-
() => __ΩRecord,
|
|
39
|
+
deserialize.__type = [
|
|
125
40
|
"SerializedCommandTree",
|
|
126
|
-
"
|
|
127
|
-
() => __ΩRecord,
|
|
41
|
+
"command",
|
|
128
42
|
"CommandTree",
|
|
129
|
-
"
|
|
130
|
-
|
|
43
|
+
"parent",
|
|
44
|
+
() => null,
|
|
45
|
+
"deserialize",
|
|
46
|
+
"P\"w!2\"P\"w#,J2$>%\"w#/&"
|
|
131
47
|
];
|
|
48
|
+
/**
|
|
49
|
+
* Gets the file path for persisting CLI command reflections.
|
|
50
|
+
*
|
|
51
|
+
* @param context - The Shell Shock context.
|
|
52
|
+
* @returns The file path for persisting CLI command reflections.
|
|
53
|
+
*/
|
|
54
|
+
function getCommandsPersistencePath(context) {
|
|
55
|
+
return joinPaths(context.dataPath, "reflections", "commands.json");
|
|
56
|
+
}
|
|
57
|
+
getCommandsPersistencePath.__type = [
|
|
58
|
+
"Context",
|
|
59
|
+
"context",
|
|
60
|
+
"getCommandsPersistencePath",
|
|
61
|
+
"P\"w!2\"&/#"
|
|
62
|
+
];
|
|
63
|
+
/**
|
|
64
|
+
* Reads the persisted CLI command reflections from the file system and populates the context's commands.
|
|
65
|
+
*
|
|
66
|
+
* @param context - The Shell Shock context.
|
|
67
|
+
* @throws Will throw an error if the reflections file is empty or cannot be read.
|
|
68
|
+
*/
|
|
132
69
|
async function readCommandsPersistence(context) {
|
|
133
70
|
const reflections = await context.fs.read(getCommandsPersistencePath(context));
|
|
134
71
|
if (!reflections || !reflections.length) throw new Error(`CLI Command reflection file ${getCommandsPersistencePath(context)} is empty`);
|
|
135
|
-
context.commands =
|
|
72
|
+
context.commands = Object.fromEntries(Object.entries(JSON.parse(reflections) ?? {}).map(__assignType(([name, command]) => [name, deserialize(command)], [
|
|
73
|
+
"param0",
|
|
74
|
+
"",
|
|
75
|
+
"P\"2!\"/\""
|
|
76
|
+
])));
|
|
136
77
|
}
|
|
137
78
|
readCommandsPersistence.__type = [
|
|
138
79
|
"Context",
|
|
@@ -140,9 +81,20 @@ readCommandsPersistence.__type = [
|
|
|
140
81
|
"readCommandsPersistence",
|
|
141
82
|
"P\"w!2\"\"/#"
|
|
142
83
|
];
|
|
84
|
+
/**
|
|
85
|
+
* Writes the current CLI command reflections from the context to the file system for persistence.
|
|
86
|
+
*
|
|
87
|
+
* @param context - The Shell Shock context.
|
|
88
|
+
* @returns A promise that resolves when the reflections have been successfully written to the file system.
|
|
89
|
+
* @throws Will throw an error if there is an issue writing the reflections to the file system.
|
|
90
|
+
*/
|
|
143
91
|
async function writeCommandsPersistence(context) {
|
|
144
92
|
const filePath = getCommandsPersistencePath(context);
|
|
145
|
-
await context.fs.write(filePath, JSON.stringify(
|
|
93
|
+
await context.fs.write(filePath, JSON.stringify(Object.fromEntries(Object.entries(context.commands).map(__assignType(([name, command]) => [name, serialize(command)], [
|
|
94
|
+
"param0",
|
|
95
|
+
"",
|
|
96
|
+
"P\"2!\"/\""
|
|
97
|
+
]))), null, context.config.mode === "production" ? 0 : 2));
|
|
146
98
|
}
|
|
147
99
|
writeCommandsPersistence.__type = [
|
|
148
100
|
"Context",
|