@shell-shock/core 0.6.0 → 0.8.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 +1 -1
- package/dist/components/docs.cjs.map +1 -1
- package/dist/components/docs.d.cts +5 -5
- package/dist/components/docs.d.mts +5 -5
- package/dist/components/docs.mjs +1 -1
- package/dist/components/docs.mjs.map +1 -1
- package/dist/components/helpers.cjs +15 -0
- package/dist/components/helpers.cjs.map +1 -0
- package/dist/components/helpers.d.cts +13 -0
- package/dist/components/helpers.d.cts.map +1 -0
- package/dist/components/helpers.d.mts +13 -0
- package/dist/components/helpers.d.mts.map +1 -0
- package/dist/components/helpers.mjs +14 -0
- package/dist/components/helpers.mjs.map +1 -0
- package/dist/components/index.cjs +5 -1
- package/dist/components/index.d.cts +3 -2
- package/dist/components/index.d.mts +3 -2
- package/dist/components/index.mjs +3 -2
- package/dist/components/options-parser-logic.cjs +156 -31
- package/dist/components/options-parser-logic.cjs.map +1 -1
- package/dist/components/options-parser-logic.d.cts +47 -8
- package/dist/components/options-parser-logic.d.cts.map +1 -1
- package/dist/components/options-parser-logic.d.mts +53 -14
- package/dist/components/options-parser-logic.d.mts.map +1 -1
- package/dist/components/options-parser-logic.mjs +154 -31
- package/dist/components/options-parser-logic.mjs.map +1 -1
- package/dist/components/usage.cjs +38 -5
- package/dist/components/usage.cjs.map +1 -1
- package/dist/components/usage.d.cts +2 -4
- package/dist/components/usage.d.cts.map +1 -1
- package/dist/components/usage.d.mts +2 -4
- package/dist/components/usage.d.mts.map +1 -1
- package/dist/components/usage.mjs +40 -7
- package/dist/components/usage.mjs.map +1 -1
- package/dist/helpers/persistence.cjs +31 -3
- package/dist/helpers/persistence.cjs.map +1 -1
- package/dist/helpers/persistence.mjs +31 -3
- package/dist/helpers/persistence.mjs.map +1 -1
- package/dist/helpers/resolve-command.cjs +68 -47
- package/dist/helpers/resolve-command.cjs.map +1 -1
- package/dist/helpers/resolve-command.mjs +70 -49
- package/dist/helpers/resolve-command.mjs.map +1 -1
- package/dist/helpers/validations.cjs +13 -36
- package/dist/helpers/validations.cjs.map +1 -1
- package/dist/helpers/validations.mjs +12 -36
- package/dist/helpers/validations.mjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/plugin-utils/context-helpers.cjs +3 -45
- package/dist/plugin-utils/context-helpers.cjs.map +1 -1
- package/dist/plugin-utils/context-helpers.d.cts +1 -37
- package/dist/plugin-utils/context-helpers.d.cts.map +1 -1
- package/dist/plugin-utils/context-helpers.d.mts +1 -37
- package/dist/plugin-utils/context-helpers.d.mts.map +1 -1
- package/dist/plugin-utils/context-helpers.mjs +4 -44
- package/dist/plugin-utils/context-helpers.mjs.map +1 -1
- package/dist/plugin-utils/index.cjs +0 -2
- package/dist/plugin-utils/index.d.cts +2 -2
- package/dist/plugin-utils/index.d.mts +2 -2
- package/dist/plugin-utils/index.mjs +2 -2
- package/dist/plugin.cjs +9 -15
- 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 +9 -15
- package/dist/plugin.mjs.map +1 -1
- package/dist/types/command.d.cts +206 -33
- package/dist/types/command.d.cts.map +1 -1
- package/dist/types/command.d.mts +206 -33
- package/dist/types/command.d.mts.map +1 -1
- package/dist/types/index.d.cts +3 -2
- package/dist/types/index.d.mts +3 -2
- package/dist/types/runtime.d.cts +5 -15
- package/dist/types/runtime.d.cts.map +1 -1
- package/dist/types/runtime.d.mts +5 -15
- package/dist/types/runtime.d.mts.map +1 -1
- package/package.json +25 -11
|
@@ -2,6 +2,7 @@ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
|
2
2
|
const require_plugin_utils_context_helpers = require('../plugin-utils/context-helpers.cjs');
|
|
3
3
|
let __alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
4
4
|
let __alloy_js_core = require("@alloy-js/core");
|
|
5
|
+
let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
5
6
|
let __stryke_string_format_snake_case = require("@stryke/string-format/snake-case");
|
|
6
7
|
|
|
7
8
|
//#region src/components/usage.tsx
|
|
@@ -14,6 +15,10 @@ function Usage(props) {
|
|
|
14
15
|
__alloy_js_core.code`$ `,
|
|
15
16
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Switch, { get children() {
|
|
16
17
|
return [
|
|
18
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Match, {
|
|
19
|
+
when: packageManager === "npm",
|
|
20
|
+
children: `npx `
|
|
21
|
+
}),
|
|
17
22
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Match, {
|
|
18
23
|
when: packageManager === "yarn",
|
|
19
24
|
children: `yarn exec `
|
|
@@ -25,14 +30,42 @@ function Usage(props) {
|
|
|
25
30
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Match, {
|
|
26
31
|
when: packageManager === "bun",
|
|
27
32
|
children: `bun x `
|
|
28
|
-
}),
|
|
29
|
-
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Match, {
|
|
30
|
-
"else": true,
|
|
31
|
-
children: `npx `
|
|
32
33
|
})
|
|
33
34
|
];
|
|
34
35
|
} }),
|
|
35
|
-
(0, __alloy_js_core_jsx_runtime.memo)(() => __alloy_js_core.code`${bin} ${command.
|
|
36
|
+
(0, __alloy_js_core_jsx_runtime.memo)(() => __alloy_js_core.code`${bin}${command.segments.length > 0 ? ` ${command.segments.map((segment) => require_plugin_utils_context_helpers.isDynamicPathSegment(segment) ? `[${(0, __stryke_string_format_snake_case.snakeCase)(require_plugin_utils_context_helpers.getDynamicPathSegmentName(segment))}]` : segment).join(" ")}` : ""}${Object.values(command.children).length > 0 ? " [commands]" : ""}${command.arguments.length > 0 ? ` ${command.arguments.map((param) => `<${(0, __stryke_string_format_snake_case.snakeCase)(param.name)}${(param.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string || param.kind === __powerlines_deepkit_vendor_type.ReflectionKind.number) && param.variadic ? "..." : ""}>`).join(" ")}` : ""} [options]`),
|
|
37
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
|
|
38
|
+
get when() {
|
|
39
|
+
return command.arguments.length > 0;
|
|
40
|
+
},
|
|
41
|
+
get children() {
|
|
42
|
+
return [
|
|
43
|
+
(0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
44
|
+
__alloy_js_core.code`$ `,
|
|
45
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Switch, { get children() {
|
|
46
|
+
return [
|
|
47
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Match, {
|
|
48
|
+
when: packageManager === "npm",
|
|
49
|
+
children: `npx `
|
|
50
|
+
}),
|
|
51
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Match, {
|
|
52
|
+
when: packageManager === "yarn",
|
|
53
|
+
children: `yarn exec `
|
|
54
|
+
}),
|
|
55
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Match, {
|
|
56
|
+
when: packageManager === "pnpm",
|
|
57
|
+
children: `pnpm exec `
|
|
58
|
+
}),
|
|
59
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Match, {
|
|
60
|
+
when: packageManager === "bun",
|
|
61
|
+
children: `bun x `
|
|
62
|
+
})
|
|
63
|
+
];
|
|
64
|
+
} }),
|
|
65
|
+
(0, __alloy_js_core_jsx_runtime.memo)(() => __alloy_js_core.code`${bin}${command.segments.length > 0 ? ` ${command.segments.map((segment) => require_plugin_utils_context_helpers.isDynamicPathSegment(segment) ? `[${(0, __stryke_string_format_snake_case.snakeCase)(require_plugin_utils_context_helpers.getDynamicPathSegmentName(segment))}]` : segment).join(" ")}` : ""}${Object.values(command.children).length > 0 ? " [commands]" : ""} [options] ${command.arguments.length > 0 ? ` ${command.arguments.map((param) => `<${(0, __stryke_string_format_snake_case.snakeCase)(param.name)}${(param.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string || param.kind === __powerlines_deepkit_vendor_type.ReflectionKind.number) && param.variadic ? "..." : ""}>`).join(" ")}` : ""}`)
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
})
|
|
36
69
|
];
|
|
37
70
|
}
|
|
38
71
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.cjs","names":["code","Match","Switch","snakeCase","getDynamicPathSegmentName","isDynamicPathSegment","Usage","props","command","bin","packageManager","_$createComponent","children","when","_$memo","
|
|
1
|
+
{"version":3,"file":"usage.cjs","names":["code","Match","Show","Switch","ReflectionKind","snakeCase","getDynamicPathSegmentName","isDynamicPathSegment","Usage","props","command","bin","packageManager","_$createComponent","children","when","_$memo","segments","length","map","segment","join","Object","values","arguments","param","name","kind","string","number","variadic","_$createIntrinsic"],"sources":["../../src/components/usage.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { code, Match, Show, Switch } from \"@alloy-js/core\";\nimport { ReflectionKind } from \"@powerlines/deepkit/vendor/type\";\nimport { snakeCase } from \"@stryke/string-format/snake-case\";\nimport {\n getDynamicPathSegmentName,\n isDynamicPathSegment\n} from \"../plugin-utils/context-helpers\";\nimport type { CommandTree } from \"../types/command\";\n\nexport interface UsageProps {\n /**\n * The command to generate help for.\n */\n command: CommandTree;\n\n /**\n * The package manager to generate the usage example for.\n *\n * @remarks\n * If not specified, examples for all supported package managers will be generated.\n */\n packageManager?: \"npm\" | \"yarn\" | \"pnpm\" | \"bun\";\n\n /**\n * The bin name to use in the usage display.\n */\n bin: string;\n}\n\n/**\n * A component that generates the usage display for a command.\n */\nexport function Usage(props: UsageProps) {\n const { command, bin, packageManager } = props;\n\n return (\n <>\n {code`$ `}\n <Switch>\n <Match when={packageManager === \"npm\"}>{`npx `}</Match>\n <Match when={packageManager === \"yarn\"}>{`yarn exec `}</Match>\n <Match when={packageManager === \"pnpm\"}>{`pnpm exec `}</Match>\n <Match when={packageManager === \"bun\"}>{`bun x `}</Match>\n </Switch>\n {code`${bin}${\n command.segments.length > 0\n ? ` ${command.segments\n .map(segment =>\n isDynamicPathSegment(segment)\n ? `[${snakeCase(getDynamicPathSegmentName(segment))}]`\n : segment\n )\n .join(\" \")}`\n : \"\"\n }${Object.values(command.children).length > 0 ? \" [commands]\" : \"\"}${\n command.arguments.length > 0\n ? ` ${command.arguments\n .map(\n param =>\n `<${snakeCase(param.name)}${\n (param.kind === ReflectionKind.string ||\n param.kind === ReflectionKind.number) &&\n param.variadic\n ? \"...\"\n : \"\"\n }>`\n )\n .join(\" \")}`\n : \"\"\n } [options]`}\n <Show when={command.arguments.length > 0}>\n <hbr />\n {code`$ `}\n <Switch>\n <Match when={packageManager === \"npm\"}>{`npx `}</Match>\n <Match when={packageManager === \"yarn\"}>{`yarn exec `}</Match>\n <Match when={packageManager === \"pnpm\"}>{`pnpm exec `}</Match>\n <Match when={packageManager === \"bun\"}>{`bun x `}</Match>\n </Switch>\n {code`${bin}${\n command.segments.length > 0\n ? ` ${command.segments\n .map(segment =>\n isDynamicPathSegment(segment)\n ? `[${snakeCase(getDynamicPathSegmentName(segment))}]`\n : segment\n )\n .join(\" \")}`\n : \"\"\n }${Object.values(command.children).length > 0 ? \" [commands]\" : \"\"} [options] ${\n command.arguments.length > 0\n ? ` ${command.arguments\n .map(\n param =>\n `<${snakeCase(param.name)}${\n (param.kind === ReflectionKind.string ||\n param.kind === ReflectionKind.number) &&\n param.variadic\n ? \"...\"\n : \"\"\n }>`\n )\n .join(\" \")}`\n : \"\"\n }`}\n </Show>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;AAkDA,SAAgBQ,MAAMC,OAAmB;CACvC,MAAM,EAAEC,SAASC,KAAKC,mBAAmBH;AAEzC,QAAA;EAEKT,oBAAI;mDACJG,wBAAM,EAAA,IAAAW,WAAA;AAAA,UAAA;qDACJb,uBAAK;KAACc,MAAMH,mBAAmB;KAAKE,UAAG;KAAM,CAAA;qDAC7Cb,uBAAK;KAACc,MAAMH,mBAAmB;KAAME,UAAG;KAAY,CAAA;qDACpDb,uBAAK;KAACc,MAAMH,mBAAmB;KAAME,UAAG;KAAY,CAAA;qDACpDb,uBAAK;KAACc,MAAMH,mBAAmB;KAAKE,UAAG;KAAQ,CAAA;IAAA;KAAA,CAAA;8CAEjDd,oBAAI,GAAGW,MACND,QAAQO,SAASC,SAAS,IACtB,IAAIR,QAAQO,SACTE,KAAIC,YACHb,0DAAqBa,QAAQ,GACzB,qDAAcd,+DAA0Bc,QAAQ,CAAC,CAAA,KACjDA,QACL,CACAC,KAAK,IAAI,KACZ,KACHC,OAAOC,OAAOb,QAAQI,SAAS,CAACI,SAAS,IAAI,gBAAgB,KAC9DR,QAAQc,UAAUN,SAAS,IACvB,IAAIR,QAAQc,UACTL,KACCM,UACE,qDAAcA,MAAMC,KAAK,IACtBD,MAAME,SAASvB,gDAAewB,UAC7BH,MAAME,SAASvB,gDAAeyB,WAChCJ,MAAMK,WACF,QACA,GAAE,GAEX,CACAT,KAAK,IAAI,KACZ,GAAE,YACI;mDACXnB,sBAAI;GAAA,IAACa,OAAI;AAAA,WAAEL,QAAQc,UAAUN,SAAS;;GAAC,IAAAJ,WAAA;AAAA,WAAA;sDAAA,OAAA,EAAA,CAAA;KAErCd,oBAAI;sDACJG,wBAAM,EAAA,IAAAW,WAAA;AAAA,aAAA;wDACJb,uBAAK;QAACc,MAAMH,mBAAmB;QAAKE,UAAG;QAAM,CAAA;wDAC7Cb,uBAAK;QAACc,MAAMH,mBAAmB;QAAME,UAAG;QAAY,CAAA;wDACpDb,uBAAK;QAACc,MAAMH,mBAAmB;QAAME,UAAG;QAAY,CAAA;wDACpDb,uBAAK;QAACc,MAAMH,mBAAmB;QAAKE,UAAG;QAAQ,CAAA;OAAA;QAAA,CAAA;iDAEjDd,oBAAI,GAAGW,MACND,QAAQO,SAASC,SAAS,IACtB,IAAIR,QAAQO,SACTE,KAAIC,YACHb,0DAAqBa,QAAQ,GACzB,qDAAcd,+DAA0Bc,QAAQ,CAAC,CAAA,KACjDA,QACL,CACAC,KAAK,IAAI,KACZ,KACHC,OAAOC,OAAOb,QAAQI,SAAS,CAACI,SAAS,IAAI,gBAAgB,GAAE,aAChER,QAAQc,UAAUN,SAAS,IACvB,IAAIR,QAAQc,UACTL,KACCM,UACE,qDAAcA,MAAMC,KAAK,IACtBD,MAAME,SAASvB,gDAAewB,UAC7BH,MAAME,SAASvB,gDAAeyB,WAChCJ,MAAMK,WACF,QACA,GAAE,GAEX,CACAT,KAAK,IAAI,KACZ,KACJ;KAAA;;GAAA,CAAA;EAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommandTree } from "../types/command.cjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _alloy_js_core12 from "@alloy-js/core";
|
|
3
3
|
|
|
4
4
|
//#region src/components/usage.d.ts
|
|
5
5
|
interface UsageProps {
|
|
@@ -12,8 +12,6 @@ interface UsageProps {
|
|
|
12
12
|
*
|
|
13
13
|
* @remarks
|
|
14
14
|
* If not specified, examples for all supported package managers will be generated.
|
|
15
|
-
*
|
|
16
|
-
* @defaultValue "npm"
|
|
17
15
|
*/
|
|
18
16
|
packageManager?: "npm" | "yarn" | "pnpm" | "bun";
|
|
19
17
|
/**
|
|
@@ -24,7 +22,7 @@ interface UsageProps {
|
|
|
24
22
|
/**
|
|
25
23
|
* A component that generates the usage display for a command.
|
|
26
24
|
*/
|
|
27
|
-
declare function Usage(props: UsageProps):
|
|
25
|
+
declare function Usage(props: UsageProps): _alloy_js_core12.Children;
|
|
28
26
|
//#endregion
|
|
29
27
|
export { Usage, UsageProps };
|
|
30
28
|
//# sourceMappingURL=usage.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.d.cts","names":[],"sources":["../../src/components/usage.tsx"],"sourcesContent":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"usage.d.cts","names":[],"sources":["../../src/components/usage.tsx"],"sourcesContent":[],"mappings":";;;;UA2BiB,UAAA;;;AAAjB;EAuBgB,OAAA,EAnBL,WAmBkB;;;;;;;;;;;;;;;;iBAAb,KAAA,QAAa,aAAU,gBAAA,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommandTree } from "../types/command.mjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _alloy_js_core12 from "@alloy-js/core";
|
|
3
3
|
|
|
4
4
|
//#region src/components/usage.d.ts
|
|
5
5
|
interface UsageProps {
|
|
@@ -12,8 +12,6 @@ interface UsageProps {
|
|
|
12
12
|
*
|
|
13
13
|
* @remarks
|
|
14
14
|
* If not specified, examples for all supported package managers will be generated.
|
|
15
|
-
*
|
|
16
|
-
* @defaultValue "npm"
|
|
17
15
|
*/
|
|
18
16
|
packageManager?: "npm" | "yarn" | "pnpm" | "bun";
|
|
19
17
|
/**
|
|
@@ -24,7 +22,7 @@ interface UsageProps {
|
|
|
24
22
|
/**
|
|
25
23
|
* A component that generates the usage display for a command.
|
|
26
24
|
*/
|
|
27
|
-
declare function Usage(props: UsageProps):
|
|
25
|
+
declare function Usage(props: UsageProps): _alloy_js_core12.Children;
|
|
28
26
|
//#endregion
|
|
29
27
|
export { Usage, UsageProps };
|
|
30
28
|
//# sourceMappingURL=usage.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.d.mts","names":[],"sources":["../../src/components/usage.tsx"],"sourcesContent":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"usage.d.mts","names":[],"sources":["../../src/components/usage.tsx"],"sourcesContent":[],"mappings":";;;;UA2BiB,UAAA;;;AAAjB;EAuBgB,OAAA,EAnBL,WAmBkB;;;;;;;;;;;;;;;;iBAAb,KAAA,QAAa,aAAU,gBAAA,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getDynamicPathSegmentName, isDynamicPathSegment } from "../plugin-utils/context-helpers.mjs";
|
|
2
|
-
import { createComponent, memo } from "@alloy-js/core/jsx-runtime";
|
|
3
|
-
import { Match, Switch, code } from "@alloy-js/core";
|
|
2
|
+
import { createComponent, createIntrinsic, memo } from "@alloy-js/core/jsx-runtime";
|
|
3
|
+
import { Match, Show, Switch, code } from "@alloy-js/core";
|
|
4
|
+
import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
|
|
4
5
|
import { snakeCase } from "@stryke/string-format/snake-case";
|
|
5
6
|
|
|
6
7
|
//#region src/components/usage.tsx
|
|
@@ -13,6 +14,10 @@ function Usage(props) {
|
|
|
13
14
|
code`$ `,
|
|
14
15
|
createComponent(Switch, { get children() {
|
|
15
16
|
return [
|
|
17
|
+
createComponent(Match, {
|
|
18
|
+
when: packageManager === "npm",
|
|
19
|
+
children: `npx `
|
|
20
|
+
}),
|
|
16
21
|
createComponent(Match, {
|
|
17
22
|
when: packageManager === "yarn",
|
|
18
23
|
children: `yarn exec `
|
|
@@ -24,14 +29,42 @@ function Usage(props) {
|
|
|
24
29
|
createComponent(Match, {
|
|
25
30
|
when: packageManager === "bun",
|
|
26
31
|
children: `bun x `
|
|
27
|
-
}),
|
|
28
|
-
createComponent(Match, {
|
|
29
|
-
"else": true,
|
|
30
|
-
children: `npx `
|
|
31
32
|
})
|
|
32
33
|
];
|
|
33
34
|
} }),
|
|
34
|
-
memo(() => code`${bin} ${command.
|
|
35
|
+
memo(() => code`${bin}${command.segments.length > 0 ? ` ${command.segments.map((segment) => isDynamicPathSegment(segment) ? `[${snakeCase(getDynamicPathSegmentName(segment))}]` : segment).join(" ")}` : ""}${Object.values(command.children).length > 0 ? " [commands]" : ""}${command.arguments.length > 0 ? ` ${command.arguments.map((param) => `<${snakeCase(param.name)}${(param.kind === ReflectionKind.string || param.kind === ReflectionKind.number) && param.variadic ? "..." : ""}>`).join(" ")}` : ""} [options]`),
|
|
36
|
+
createComponent(Show, {
|
|
37
|
+
get when() {
|
|
38
|
+
return command.arguments.length > 0;
|
|
39
|
+
},
|
|
40
|
+
get children() {
|
|
41
|
+
return [
|
|
42
|
+
createIntrinsic("hbr", {}),
|
|
43
|
+
code`$ `,
|
|
44
|
+
createComponent(Switch, { get children() {
|
|
45
|
+
return [
|
|
46
|
+
createComponent(Match, {
|
|
47
|
+
when: packageManager === "npm",
|
|
48
|
+
children: `npx `
|
|
49
|
+
}),
|
|
50
|
+
createComponent(Match, {
|
|
51
|
+
when: packageManager === "yarn",
|
|
52
|
+
children: `yarn exec `
|
|
53
|
+
}),
|
|
54
|
+
createComponent(Match, {
|
|
55
|
+
when: packageManager === "pnpm",
|
|
56
|
+
children: `pnpm exec `
|
|
57
|
+
}),
|
|
58
|
+
createComponent(Match, {
|
|
59
|
+
when: packageManager === "bun",
|
|
60
|
+
children: `bun x `
|
|
61
|
+
})
|
|
62
|
+
];
|
|
63
|
+
} }),
|
|
64
|
+
memo(() => code`${bin}${command.segments.length > 0 ? ` ${command.segments.map((segment) => isDynamicPathSegment(segment) ? `[${snakeCase(getDynamicPathSegmentName(segment))}]` : segment).join(" ")}` : ""}${Object.values(command.children).length > 0 ? " [commands]" : ""} [options] ${command.arguments.length > 0 ? ` ${command.arguments.map((param) => `<${snakeCase(param.name)}${(param.kind === ReflectionKind.string || param.kind === ReflectionKind.number) && param.variadic ? "..." : ""}>`).join(" ")}` : ""}`)
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
})
|
|
35
68
|
];
|
|
36
69
|
}
|
|
37
70
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.mjs","names":["code","Match","Switch","snakeCase","getDynamicPathSegmentName","isDynamicPathSegment","Usage","props","command","bin","packageManager","_$createComponent","children","when","_$memo","
|
|
1
|
+
{"version":3,"file":"usage.mjs","names":["code","Match","Show","Switch","ReflectionKind","snakeCase","getDynamicPathSegmentName","isDynamicPathSegment","Usage","props","command","bin","packageManager","_$createComponent","children","when","_$memo","segments","length","map","segment","join","Object","values","arguments","param","name","kind","string","number","variadic","_$createIntrinsic"],"sources":["../../src/components/usage.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { code, Match, Show, Switch } from \"@alloy-js/core\";\nimport { ReflectionKind } from \"@powerlines/deepkit/vendor/type\";\nimport { snakeCase } from \"@stryke/string-format/snake-case\";\nimport {\n getDynamicPathSegmentName,\n isDynamicPathSegment\n} from \"../plugin-utils/context-helpers\";\nimport type { CommandTree } from \"../types/command\";\n\nexport interface UsageProps {\n /**\n * The command to generate help for.\n */\n command: CommandTree;\n\n /**\n * The package manager to generate the usage example for.\n *\n * @remarks\n * If not specified, examples for all supported package managers will be generated.\n */\n packageManager?: \"npm\" | \"yarn\" | \"pnpm\" | \"bun\";\n\n /**\n * The bin name to use in the usage display.\n */\n bin: string;\n}\n\n/**\n * A component that generates the usage display for a command.\n */\nexport function Usage(props: UsageProps) {\n const { command, bin, packageManager } = props;\n\n return (\n <>\n {code`$ `}\n <Switch>\n <Match when={packageManager === \"npm\"}>{`npx `}</Match>\n <Match when={packageManager === \"yarn\"}>{`yarn exec `}</Match>\n <Match when={packageManager === \"pnpm\"}>{`pnpm exec `}</Match>\n <Match when={packageManager === \"bun\"}>{`bun x `}</Match>\n </Switch>\n {code`${bin}${\n command.segments.length > 0\n ? ` ${command.segments\n .map(segment =>\n isDynamicPathSegment(segment)\n ? `[${snakeCase(getDynamicPathSegmentName(segment))}]`\n : segment\n )\n .join(\" \")}`\n : \"\"\n }${Object.values(command.children).length > 0 ? \" [commands]\" : \"\"}${\n command.arguments.length > 0\n ? ` ${command.arguments\n .map(\n param =>\n `<${snakeCase(param.name)}${\n (param.kind === ReflectionKind.string ||\n param.kind === ReflectionKind.number) &&\n param.variadic\n ? \"...\"\n : \"\"\n }>`\n )\n .join(\" \")}`\n : \"\"\n } [options]`}\n <Show when={command.arguments.length > 0}>\n <hbr />\n {code`$ `}\n <Switch>\n <Match when={packageManager === \"npm\"}>{`npx `}</Match>\n <Match when={packageManager === \"yarn\"}>{`yarn exec `}</Match>\n <Match when={packageManager === \"pnpm\"}>{`pnpm exec `}</Match>\n <Match when={packageManager === \"bun\"}>{`bun x `}</Match>\n </Switch>\n {code`${bin}${\n command.segments.length > 0\n ? ` ${command.segments\n .map(segment =>\n isDynamicPathSegment(segment)\n ? `[${snakeCase(getDynamicPathSegmentName(segment))}]`\n : segment\n )\n .join(\" \")}`\n : \"\"\n }${Object.values(command.children).length > 0 ? \" [commands]\" : \"\"} [options] ${\n command.arguments.length > 0\n ? ` ${command.arguments\n .map(\n param =>\n `<${snakeCase(param.name)}${\n (param.kind === ReflectionKind.string ||\n param.kind === ReflectionKind.number) &&\n param.variadic\n ? \"...\"\n : \"\"\n }>`\n )\n .join(\" \")}`\n : \"\"\n }`}\n </Show>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;AAkDA,SAAgBQ,MAAMC,OAAmB;CACvC,MAAM,EAAEC,SAASC,KAAKC,mBAAmBH;AAEzC,QAAA;E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QAAME,UAAG;QAAY,CAAA;OAAAD,gBACpDZ,OAAK;QAACc,MAAMH,mBAAmB;QAAKE,UAAG;QAAQ,CAAA;OAAA;QAAA,CAAA;KAAAE,WAEjDhB,IAAI,GAAGW,MACND,QAAQO,SAASC,SAAS,IACtB,IAAIR,QAAQO,SACTE,KAAIC,YACHb,qBAAqBa,QAAQ,GACzB,IAAIf,UAAUC,0BAA0Bc,QAAQ,CAAC,CAAA,KACjDA,QACL,CACAC,KAAK,IAAI,KACZ,KACHC,OAAOC,OAAOb,QAAQI,SAAS,CAACI,SAAS,IAAI,gBAAgB,GAAE,aAChER,QAAQc,UAAUN,SAAS,IACvB,IAAIR,QAAQc,UACTL,KACCM,UACE,IAAIpB,UAAUoB,MAAMC,KAAK,IACtBD,MAAME,SAASvB,eAAewB,UAC7BH,MAAME,SAASvB,eAAeyB,WAChCJ,MAAMK,WACF,QACA,GAAE,GAEX,CACAT,KAAK,IAAI,KACZ,KACJ;KAAA;;GAAA,CAAA;EAAA"}
|
|
@@ -1,16 +1,24 @@
|
|
|
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");
|
|
3
5
|
|
|
4
6
|
//#region src/helpers/persistence.ts
|
|
5
7
|
function getCommandsPersistencePath(context) {
|
|
6
|
-
return (0, __stryke_path_join_paths.joinPaths)(context.dataPath,
|
|
8
|
+
return (0, __stryke_path_join_paths.joinPaths)(context.dataPath, "reflections", "commands.json");
|
|
7
9
|
}
|
|
8
10
|
function serializedCommandTree(commands) {
|
|
9
11
|
const serialize = (node, parent = null) => {
|
|
10
12
|
const serializedNode = {
|
|
11
13
|
...node,
|
|
14
|
+
options: Object.entries(node.options).reduce((ret, [key, option]) => {
|
|
15
|
+
ret[key] = { ...(0, __stryke_helpers_omit.omit)(option, ["reflection"]) };
|
|
16
|
+
return ret;
|
|
17
|
+
}, {}),
|
|
18
|
+
arguments: node.arguments.map((arg) => ({ ...(0, __stryke_helpers_omit.omit)(arg, ["reflection"]) })),
|
|
12
19
|
parent,
|
|
13
|
-
children: {}
|
|
20
|
+
children: {},
|
|
21
|
+
reflection: node.reflection ? (0, __powerlines_deepkit_vendor_type.serializeType)(node.reflection.type) : void 0
|
|
14
22
|
};
|
|
15
23
|
for (const [key, child] of Object.entries(node.children || {})) serializedNode.children[key] = serialize(child, node.id);
|
|
16
24
|
return serializedNode;
|
|
@@ -21,10 +29,30 @@ function serializedCommandTree(commands) {
|
|
|
21
29
|
}
|
|
22
30
|
function deserializeCommandTree(serializedCommands) {
|
|
23
31
|
const deserialize = (node, parent = null) => {
|
|
32
|
+
const type = (0, __powerlines_deepkit_vendor_type.deserializeType)(node.reflection);
|
|
33
|
+
if (type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.function) throw new Error(`Failed to deserialize persisted data - invalid command handler reflection type for command ${node.id}`);
|
|
34
|
+
const reflection = new __powerlines_deepkit_vendor_type.ReflectionFunction(type);
|
|
35
|
+
let optionsReflection;
|
|
36
|
+
if (reflection.getParameters().length > 0 && reflection.getParameters()[0]) {
|
|
37
|
+
const optionsType = reflection.getParameters()[0].type;
|
|
38
|
+
if (optionsType.kind === __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral) optionsReflection = (0, __powerlines_deepkit_vendor_type.resolveClassType)(optionsType);
|
|
39
|
+
}
|
|
24
40
|
const deserializedNode = {
|
|
25
41
|
...node,
|
|
42
|
+
options: optionsReflection ? Object.entries(node.options).reduce((ret, [key, option]) => {
|
|
43
|
+
ret[key] = {
|
|
44
|
+
...option,
|
|
45
|
+
reflection: optionsReflection.getProperty(option.name)
|
|
46
|
+
};
|
|
47
|
+
return ret;
|
|
48
|
+
}, {}) : {},
|
|
49
|
+
arguments: node.arguments.map((arg, i) => ({
|
|
50
|
+
...arg,
|
|
51
|
+
reflection: reflection.getParameters().length > i + 1 ? reflection.getParameters()[i + 1] : reflection.getParameterOrUndefined(arg.name)
|
|
52
|
+
})),
|
|
26
53
|
parent,
|
|
27
|
-
children: {}
|
|
54
|
+
children: {},
|
|
55
|
+
reflection
|
|
28
56
|
};
|
|
29
57
|
for (const [key, child] of Object.entries(node.children || {})) deserializedNode.children[key] = deserialize(child, deserializedNode);
|
|
30
58
|
return deserializedNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistence.cjs","names":["joinPaths","getCommandsPersistencePath","context","dataPath","serializedCommandTree","commands","serialize","node","parent","serializedNode","
|
|
1
|
+
{"version":3,"file":"persistence.cjs","names":["deserializeType","ReflectionFunction","ReflectionKind","resolveClassType","serializeType","omit","joinPaths","getCommandsPersistencePath","context","dataPath","serializedCommandTree","commands","serialize","node","parent","serializedNode","options","Object","entries","reduce","ret","key","option","arguments","map","arg","children","reflection","type","undefined","child","id","result","deserializeCommandTree","serializedCommands","deserialize","kind","function","Error","optionsReflection","getParameters","length","optionsType","objectLiteral","deserializedNode","getProperty","name","i","getParameterOrUndefined","readCommandsPersistence","reflections","fs","read","JSON","parse","writeCommandsPersistence","filePath","write","stringify","config","mode"],"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 type { ReflectionClass } from \"@powerlines/deepkit/vendor/type\";\nimport {\n deserializeType,\n ReflectionFunction,\n ReflectionKind,\n resolveClassType,\n serializeType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport type {\n CommandArgument,\n CommandOption,\n CommandTree,\n SerializedCommandOption,\n SerializedCommandTree\n} from \"../types\";\nimport type { Context } from \"../types/context\";\n\nexport function getCommandsPersistencePath(context: Context): string {\n return joinPaths(context.dataPath, \"reflections\", \"commands.json\");\n}\n\nexport function serializedCommandTree(\n commands: Record<string, CommandTree>\n): Record<string, SerializedCommandTree> {\n const serialize = (\n node: CommandTree,\n parent: string | null = null\n ): SerializedCommandTree => {\n const serializedNode: SerializedCommandTree = {\n ...node,\n options: Object.entries(node.options).reduce(\n (ret, [key, option]) => {\n ret[key] = {\n ...omit(option, [\"reflection\"])\n };\n return ret;\n },\n {} as Record<string, SerializedCommandOption>\n ),\n arguments: node.arguments.map(arg => ({\n ...omit(arg, [\"reflection\"])\n })),\n parent,\n children: {},\n reflection: node.reflection\n ? serializeType(node.reflection.type)\n : undefined\n };\n\n for (const [key, child] of Object.entries(node.children || {})) {\n serializedNode.children[key] = serialize(child, node.id);\n }\n\n return serializedNode;\n };\n\n const result: Record<string, SerializedCommandTree> = {};\n for (const [key, child] of Object.entries(commands)) {\n result[key] = serialize(child, null);\n }\n\n return result;\n}\n\nexport function deserializeCommandTree(\n serializedCommands: Record<string, SerializedCommandTree>\n): Record<string, CommandTree> {\n const deserialize = (\n node: SerializedCommandTree,\n parent: CommandTree | null = null\n ): CommandTree => {\n const type = deserializeType(node.reflection);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `Failed to deserialize persisted data - invalid command handler reflection type for command ${node.id}`\n );\n }\n\n const reflection = new ReflectionFunction(type);\n\n let optionsReflection: ReflectionClass<any> | undefined;\n if (\n reflection.getParameters().length > 0 &&\n reflection.getParameters()[0]\n ) {\n const optionsType = reflection.getParameters()[0]!.type;\n if (optionsType.kind === ReflectionKind.objectLiteral) {\n optionsReflection = resolveClassType(optionsType);\n }\n }\n\n const deserializedNode: CommandTree = {\n ...node,\n options: optionsReflection\n ? Object.entries(node.options).reduce(\n (ret, [key, option]) => {\n ret[key] = {\n ...option,\n reflection: optionsReflection.getProperty(option.name)\n } as CommandOption;\n return ret;\n },\n {} as Record<string, CommandOption>\n )\n : {},\n arguments: node.arguments.map((arg, i) => ({\n ...arg,\n reflection:\n reflection.getParameters().length > i + 1\n ? reflection.getParameters()[i + 1]\n : reflection.getParameterOrUndefined(arg.name)\n })) as CommandArgument[],\n parent,\n children: {},\n reflection\n };\n\n for (const [key, child] of Object.entries(node.children || {})) {\n deserializedNode.children[key] = deserialize(child, deserializedNode);\n }\n\n return deserializedNode;\n };\n\n const result: Record<string, CommandTree> = {};\n for (const [key, child] of Object.entries(serializedCommands)) {\n result[key] = deserialize(child, null);\n }\n\n return result;\n}\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 = deserializeCommandTree(JSON.parse(reflections));\n}\n\nexport async function writeCommandsPersistence(context: Context) {\n const filePath = getCommandsPersistencePath(context);\n\n await context.fs.write(\n filePath,\n JSON.stringify(\n serializedCommandTree(context.commands),\n null,\n context.config.mode === \"development\" ? 2 : 0\n )\n );\n}\n"],"mappings":";;;;;;AAqCA,SAAgBO,2BAA2BC,SAA0B;AACnE,gDAAiBA,QAAQC,UAAU,eAAe,gBAAgB;;AAGpE,SAAgBC,sBACdC,UACuC;CACvC,MAAMC,aACJC,MACAC,SAAwB,SACE;EAC1B,MAAMC,iBAAwC;GAC5C,GAAGF;GACHG,SAASC,OAAOC,QAAQL,KAAKG,QAAQ,CAACG,QACnCC,KAAK,CAACC,KAAKC,YAAY;AACtBF,QAAIC,OAAO,EACT,mCAAQC,QAAQ,CAAC,aAAa,CAAA,EAC/B;AACD,WAAOF;MAET,EACF,CAAC;GACDG,WAAWV,KAAKU,UAAUC,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,SAASM,IAAI,IACpCpB,WAAWa,eAAe,CAACO,IAAI,KAC/BpB,WAAWqB,wBAAwBvB,IAAIqB,KAAI;IAClD,EAAuB;GACxBhC;GACAY,UAAU,EAAE;GACZC;GACD;AAED,OAAK,MAAM,CAACN,KAAKS,UAAUb,OAAOC,QAAQL,KAAKa,YAAY,EAAE,CAAC,CAC5DkB,kBAAiBlB,SAASL,OAAOc,YAAYL,OAAOc,iBAAiB;AAGvE,SAAOA;;CAGT,MAAMZ,SAAsC,EAAE;AAC9C,MAAK,MAAM,CAACX,KAAKS,UAAUb,OAAOC,QAAQgB,mBAAmB,CAC3DF,QAAOX,OAAOc,YAAYL,OAAO,KAAK;AAGxC,QAAOE;;AAGT,eAAsBiB,wBAAwBzC,SAAkB;CAC9D,MAAM0C,cAAc,MAAM1C,QAAQ2C,GAAGC,KACnC7C,2BAA2BC,QAC7B,CAAC;AACD,KAAI,CAAC0C,eAAe,CAACA,YAAYT,OAC/B,OAAM,IAAIH,MACR,+BAA+B/B,2BAA2BC,QAAQ,CAAA,WACnE;AAGHA,SAAQG,WAAWsB,uBAAuBoB,KAAKC,MAAMJ,YAAY,CAAC;;AAGpE,eAAsBK,yBAAyB/C,SAAkB;CAC/D,MAAMgD,WAAWjD,2BAA2BC,QAAQ;AAEpD,OAAMA,QAAQ2C,GAAGM,MACfD,UACAH,KAAKK,UACHhD,sBAAsBF,QAAQG,SAAS,EACvC,MACAH,QAAQmD,OAAOC,SAAS,gBAAgB,IAAI,EAEhD,CAAC"}
|
|
@@ -1,15 +1,23 @@
|
|
|
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";
|
|
2
4
|
|
|
3
5
|
//#region src/helpers/persistence.ts
|
|
4
6
|
function getCommandsPersistencePath(context) {
|
|
5
|
-
return joinPaths(context.dataPath,
|
|
7
|
+
return joinPaths(context.dataPath, "reflections", "commands.json");
|
|
6
8
|
}
|
|
7
9
|
function serializedCommandTree(commands) {
|
|
8
10
|
const serialize = (node, parent = null) => {
|
|
9
11
|
const serializedNode = {
|
|
10
12
|
...node,
|
|
13
|
+
options: Object.entries(node.options).reduce((ret, [key, option]) => {
|
|
14
|
+
ret[key] = { ...omit(option, ["reflection"]) };
|
|
15
|
+
return ret;
|
|
16
|
+
}, {}),
|
|
17
|
+
arguments: node.arguments.map((arg) => ({ ...omit(arg, ["reflection"]) })),
|
|
11
18
|
parent,
|
|
12
|
-
children: {}
|
|
19
|
+
children: {},
|
|
20
|
+
reflection: node.reflection ? serializeType(node.reflection.type) : void 0
|
|
13
21
|
};
|
|
14
22
|
for (const [key, child] of Object.entries(node.children || {})) serializedNode.children[key] = serialize(child, node.id);
|
|
15
23
|
return serializedNode;
|
|
@@ -20,10 +28,30 @@ function serializedCommandTree(commands) {
|
|
|
20
28
|
}
|
|
21
29
|
function deserializeCommandTree(serializedCommands) {
|
|
22
30
|
const deserialize = (node, parent = null) => {
|
|
31
|
+
const type = deserializeType(node.reflection);
|
|
32
|
+
if (type.kind !== ReflectionKind.function) throw new Error(`Failed to deserialize persisted data - invalid command handler reflection type for command ${node.id}`);
|
|
33
|
+
const reflection = new ReflectionFunction(type);
|
|
34
|
+
let optionsReflection;
|
|
35
|
+
if (reflection.getParameters().length > 0 && reflection.getParameters()[0]) {
|
|
36
|
+
const optionsType = reflection.getParameters()[0].type;
|
|
37
|
+
if (optionsType.kind === ReflectionKind.objectLiteral) optionsReflection = resolveClassType(optionsType);
|
|
38
|
+
}
|
|
23
39
|
const deserializedNode = {
|
|
24
40
|
...node,
|
|
41
|
+
options: optionsReflection ? Object.entries(node.options).reduce((ret, [key, option]) => {
|
|
42
|
+
ret[key] = {
|
|
43
|
+
...option,
|
|
44
|
+
reflection: optionsReflection.getProperty(option.name)
|
|
45
|
+
};
|
|
46
|
+
return ret;
|
|
47
|
+
}, {}) : {},
|
|
48
|
+
arguments: node.arguments.map((arg, i) => ({
|
|
49
|
+
...arg,
|
|
50
|
+
reflection: reflection.getParameters().length > i + 1 ? reflection.getParameters()[i + 1] : reflection.getParameterOrUndefined(arg.name)
|
|
51
|
+
})),
|
|
25
52
|
parent,
|
|
26
|
-
children: {}
|
|
53
|
+
children: {},
|
|
54
|
+
reflection
|
|
27
55
|
};
|
|
28
56
|
for (const [key, child] of Object.entries(node.children || {})) deserializedNode.children[key] = deserialize(child, deserializedNode);
|
|
29
57
|
return deserializedNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistence.mjs","names":["joinPaths","getCommandsPersistencePath","context","dataPath","serializedCommandTree","commands","serialize","node","parent","serializedNode","
|
|
1
|
+
{"version":3,"file":"persistence.mjs","names":["deserializeType","ReflectionFunction","ReflectionKind","resolveClassType","serializeType","omit","joinPaths","getCommandsPersistencePath","context","dataPath","serializedCommandTree","commands","serialize","node","parent","serializedNode","options","Object","entries","reduce","ret","key","option","arguments","map","arg","children","reflection","type","undefined","child","id","result","deserializeCommandTree","serializedCommands","deserialize","kind","function","Error","optionsReflection","getParameters","length","optionsType","objectLiteral","deserializedNode","getProperty","name","i","getParameterOrUndefined","readCommandsPersistence","reflections","fs","read","JSON","parse","writeCommandsPersistence","filePath","write","stringify","config","mode"],"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 type { ReflectionClass } from \"@powerlines/deepkit/vendor/type\";\nimport {\n deserializeType,\n ReflectionFunction,\n ReflectionKind,\n resolveClassType,\n serializeType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport type {\n CommandArgument,\n CommandOption,\n CommandTree,\n SerializedCommandOption,\n SerializedCommandTree\n} from \"../types\";\nimport type { Context } from \"../types/context\";\n\nexport function getCommandsPersistencePath(context: Context): string {\n return joinPaths(context.dataPath, \"reflections\", \"commands.json\");\n}\n\nexport function serializedCommandTree(\n commands: Record<string, CommandTree>\n): Record<string, SerializedCommandTree> {\n const serialize = (\n node: CommandTree,\n parent: string | null = null\n ): SerializedCommandTree => {\n const serializedNode: SerializedCommandTree = {\n ...node,\n options: Object.entries(node.options).reduce(\n (ret, [key, option]) => {\n ret[key] = {\n ...omit(option, [\"reflection\"])\n };\n return ret;\n },\n {} as Record<string, SerializedCommandOption>\n ),\n arguments: node.arguments.map(arg => ({\n ...omit(arg, [\"reflection\"])\n })),\n parent,\n children: {},\n reflection: node.reflection\n ? serializeType(node.reflection.type)\n : undefined\n };\n\n for (const [key, child] of Object.entries(node.children || {})) {\n serializedNode.children[key] = serialize(child, node.id);\n }\n\n return serializedNode;\n };\n\n const result: Record<string, SerializedCommandTree> = {};\n for (const [key, child] of Object.entries(commands)) {\n result[key] = serialize(child, null);\n }\n\n return result;\n}\n\nexport function deserializeCommandTree(\n serializedCommands: Record<string, SerializedCommandTree>\n): Record<string, CommandTree> {\n const deserialize = (\n node: SerializedCommandTree,\n parent: CommandTree | null = null\n ): CommandTree => {\n const type = deserializeType(node.reflection);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `Failed to deserialize persisted data - invalid command handler reflection type for command ${node.id}`\n );\n }\n\n const reflection = new ReflectionFunction(type);\n\n let optionsReflection: ReflectionClass<any> | undefined;\n if (\n reflection.getParameters().length > 0 &&\n reflection.getParameters()[0]\n ) {\n const optionsType = reflection.getParameters()[0]!.type;\n if (optionsType.kind === ReflectionKind.objectLiteral) {\n optionsReflection = resolveClassType(optionsType);\n }\n }\n\n const deserializedNode: CommandTree = {\n ...node,\n options: optionsReflection\n ? Object.entries(node.options).reduce(\n (ret, [key, option]) => {\n ret[key] = {\n ...option,\n reflection: optionsReflection.getProperty(option.name)\n } as CommandOption;\n return ret;\n },\n {} as Record<string, CommandOption>\n )\n : {},\n arguments: node.arguments.map((arg, i) => ({\n ...arg,\n reflection:\n reflection.getParameters().length > i + 1\n ? reflection.getParameters()[i + 1]\n : reflection.getParameterOrUndefined(arg.name)\n })) as CommandArgument[],\n parent,\n children: {},\n reflection\n };\n\n for (const [key, child] of Object.entries(node.children || {})) {\n deserializedNode.children[key] = deserialize(child, deserializedNode);\n }\n\n return deserializedNode;\n };\n\n const result: Record<string, CommandTree> = {};\n for (const [key, child] of Object.entries(serializedCommands)) {\n result[key] = deserialize(child, null);\n }\n\n return result;\n}\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 = deserializeCommandTree(JSON.parse(reflections));\n}\n\nexport async function writeCommandsPersistence(context: Context) {\n const filePath = getCommandsPersistencePath(context);\n\n await context.fs.write(\n filePath,\n JSON.stringify(\n serializedCommandTree(context.commands),\n null,\n context.config.mode === \"development\" ? 2 : 0\n )\n );\n}\n"],"mappings":";;;;;AAqCA,SAAgBO,2BAA2BC,SAA0B;AACnE,QAAOF,UAAUE,QAAQC,UAAU,eAAe,gBAAgB;;AAGpE,SAAgBC,sBACdC,UACuC;CACvC,MAAMC,aACJC,MACAC,SAAwB,SACE;EAC1B,MAAMC,iBAAwC;GAC5C,GAAGF;GACHG,SAASC,OAAOC,QAAQL,KAAKG,QAAQ,CAACG,QACnCC,KAAK,CAACC,KAAKC,YAAY;AACtBF,QAAIC,OAAO,EACT,GAAGhB,KAAKiB,QAAQ,CAAC,aAAa,CAA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