@shell-shock/preset-script 0.6.61 → 0.6.63
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/README.md +1 -1
- package/dist/_virtual/_rolldown/runtime.cjs +1 -29
- package/dist/components/bin-entry.cjs +3 -149
- package/dist/components/bin-entry.d.cts.map +1 -1
- package/dist/components/bin-entry.d.mts.map +1 -1
- package/dist/components/bin-entry.mjs +3 -144
- package/dist/components/bin-entry.mjs.map +1 -1
- package/dist/components/command-entry.cjs +3 -203
- package/dist/components/command-entry.mjs +3 -197
- package/dist/components/command-entry.mjs.map +1 -1
- package/dist/components/command-router.cjs +2 -161
- package/dist/components/command-router.mjs +2 -156
- package/dist/components/command-router.mjs.map +1 -1
- package/dist/components/exit-function-declaration.cjs +6 -114
- package/dist/components/exit-function-declaration.mjs +6 -111
- package/dist/components/exit-function-declaration.mjs.map +1 -1
- package/dist/components/index.cjs +1 -18
- package/dist/components/index.mjs +1 -7
- package/dist/components/virtual-command-entry.cjs +1 -154
- package/dist/components/virtual-command-entry.mjs +1 -149
- package/dist/components/virtual-command-entry.mjs.map +1 -1
- package/dist/helpers/get-global-options.cjs +1 -76
- package/dist/helpers/get-global-options.mjs +1 -73
- package/dist/helpers/get-global-options.mjs.map +1 -1
- package/dist/index.cjs +1 -127
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -120
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.mjs +1 -1
- package/dist/types/plugin.mjs +1 -1
- package/package.json +15 -19
- package/dist/components/bin-entry.cjs.map +0 -1
- package/dist/components/command-entry.cjs.map +0 -1
- package/dist/components/command-router.cjs.map +0 -1
- package/dist/components/exit-function-declaration.cjs.map +0 -1
- package/dist/components/virtual-command-entry.cjs.map +0 -1
- package/dist/helpers/get-global-options.cjs.map +0 -1
- package/dist/index.cjs.map +0 -1
|
@@ -1,161 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
|
|
3
|
-
let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
4
|
-
let _alloy_js_core = require("@alloy-js/core");
|
|
5
|
-
let _alloy_js_typescript = require("@alloy-js/typescript");
|
|
6
|
-
let _powerlines_plugin_alloy_core_components_spacing = require("@powerlines/plugin-alloy/core/components/spacing");
|
|
7
|
-
let _powerlines_plugin_alloy_core_contexts_context = require("@powerlines/plugin-alloy/core/contexts/context");
|
|
8
|
-
let _shell_shock_core_plugin_utils = require("@shell-shock/core/plugin-utils");
|
|
9
|
-
let _stryke_string_format_pascal_case = require("@stryke/string-format/pascal-case");
|
|
10
|
-
let _powerlines_plugin_alloy_typescript_components_dynamic_import_statement = require("@powerlines/plugin-alloy/typescript/components/dynamic-import-statement");
|
|
11
|
-
let _shell_shock_core_contexts_command = require("@shell-shock/core/contexts/command");
|
|
12
|
-
|
|
13
|
-
//#region src/components/command-router.tsx
|
|
14
|
-
function CommandRouterRoute() {
|
|
15
|
-
const command = (0, _shell_shock_core_contexts_command.useCommand)();
|
|
16
|
-
return [
|
|
17
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
|
|
18
|
-
get when() {
|
|
19
|
-
return !command.isVirtual;
|
|
20
|
-
},
|
|
21
|
-
get children() {
|
|
22
|
-
return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_dynamic_import_statement.DynamicImportStatement, {
|
|
23
|
-
get name() {
|
|
24
|
-
return `handle${(0, _stryke_string_format_pascal_case.pascalCase)(command.name)}`;
|
|
25
|
-
},
|
|
26
|
-
get importPath() {
|
|
27
|
-
return `./${command.segments.filter((segment) => !(0, _shell_shock_core_plugin_utils.isDynamicPathSegment)(segment))[command.segments.filter((segment) => !(0, _shell_shock_core_plugin_utils.isDynamicPathSegment)(segment)).length - 1]}`;
|
|
28
|
-
},
|
|
29
|
-
exportName: "handler"
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}),
|
|
33
|
-
(0, _alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
34
|
-
(0, _alloy_js_core_jsx_runtime.memo)(() => _alloy_js_core.code`return handle${(0, _stryke_string_format_pascal_case.pascalCase)(command.name)}(args);`)
|
|
35
|
-
];
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* The command router component.
|
|
39
|
-
*/
|
|
40
|
-
function CommandRouter(props) {
|
|
41
|
-
const { segments, commands, route } = props;
|
|
42
|
-
const index = (0, _alloy_js_core.computed)(() => 2 + (segments.length ?? 0));
|
|
43
|
-
return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
|
|
44
|
-
get when() {
|
|
45
|
-
return commands && Object.keys(commands).length > 0;
|
|
46
|
-
},
|
|
47
|
-
get children() {
|
|
48
|
-
return [
|
|
49
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
|
|
50
|
-
"let": true,
|
|
51
|
-
name: "command",
|
|
52
|
-
type: "string",
|
|
53
|
-
initializer: _alloy_js_core.code`"";`
|
|
54
|
-
}),
|
|
55
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
56
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
|
|
57
|
-
get when() {
|
|
58
|
-
return commands && Object.keys(commands).length > 0;
|
|
59
|
-
},
|
|
60
|
-
get children() {
|
|
61
|
-
return [(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.IfStatement, {
|
|
62
|
-
get condition() {
|
|
63
|
-
return _alloy_js_core.code`args.length > ${index.value} && args[${index.value}]`;
|
|
64
|
-
},
|
|
65
|
-
get children() {
|
|
66
|
-
return _alloy_js_core.code`command = args[${index.value}];`;
|
|
67
|
-
}
|
|
68
|
-
}), (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {})];
|
|
69
|
-
}
|
|
70
|
-
}),
|
|
71
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(CommandRouterBody, {
|
|
72
|
-
segments,
|
|
73
|
-
commands,
|
|
74
|
-
route
|
|
75
|
-
})
|
|
76
|
-
];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* The internal command router body logic component.
|
|
82
|
-
*/
|
|
83
|
-
function CommandRouterBody(props) {
|
|
84
|
-
const { commands, route } = props;
|
|
85
|
-
const context = (0, _powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
|
|
86
|
-
return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
|
|
87
|
-
get when() {
|
|
88
|
-
return commands && Object.keys(commands).length > 0;
|
|
89
|
-
},
|
|
90
|
-
get children() {
|
|
91
|
-
return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.IfStatement, {
|
|
92
|
-
condition: _alloy_js_core.code`!command.startsWith("-")`,
|
|
93
|
-
get children() {
|
|
94
|
-
return [(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.For, {
|
|
95
|
-
get each() {
|
|
96
|
-
return Object.values(commands ?? {});
|
|
97
|
-
},
|
|
98
|
-
children: (subcommand, idx) => (0, _alloy_js_core_jsx_runtime.createComponent)(_shell_shock_core_contexts_command.CommandContext.Provider, {
|
|
99
|
-
value: subcommand,
|
|
100
|
-
get children() {
|
|
101
|
-
return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
|
|
102
|
-
get when() {
|
|
103
|
-
return Boolean(idx);
|
|
104
|
-
},
|
|
105
|
-
get fallback() {
|
|
106
|
-
return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.IfStatement, {
|
|
107
|
-
get condition() {
|
|
108
|
-
return _alloy_js_core.code`${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${context.config.isCaseSensitive ? subcommand.name : subcommand.name.toLowerCase().replaceAll("-", "").replaceAll("_", "")}"${subcommand.alias && subcommand.alias.length > 0 ? ` || ${subcommand.alias.map((alias) => `${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${context.config.isCaseSensitive ? alias : alias.toLowerCase().replaceAll("-", "").replaceAll("_", "")}"`).join(" || ")}` : ""}`;
|
|
109
|
-
},
|
|
110
|
-
get children() {
|
|
111
|
-
return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
|
|
112
|
-
get when() {
|
|
113
|
-
return Boolean(route);
|
|
114
|
-
},
|
|
115
|
-
get fallback() {
|
|
116
|
-
return (0, _alloy_js_core_jsx_runtime.createComponent)(CommandRouterRoute, {});
|
|
117
|
-
},
|
|
118
|
-
children: route
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
},
|
|
123
|
-
get children() {
|
|
124
|
-
return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.ElseIfClause, {
|
|
125
|
-
get condition() {
|
|
126
|
-
return _alloy_js_core.code`${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${context.config.isCaseSensitive ? subcommand.name : subcommand.name.toLowerCase().replaceAll("-", "").replaceAll("_", "")}"${subcommand.alias && subcommand.alias.length > 0 ? ` || ${subcommand.alias.map((alias) => `${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${context.config.isCaseSensitive ? alias : alias.toLowerCase().replaceAll("-", "").replaceAll("_", "")}"`).join(" || ")}` : ""}`;
|
|
127
|
-
},
|
|
128
|
-
get children() {
|
|
129
|
-
return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
|
|
130
|
-
get when() {
|
|
131
|
-
return Boolean(route);
|
|
132
|
-
},
|
|
133
|
-
get fallback() {
|
|
134
|
-
return (0, _alloy_js_core_jsx_runtime.createComponent)(CommandRouterRoute, {});
|
|
135
|
-
},
|
|
136
|
-
children: route
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
})
|
|
144
|
-
}), (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.ElseIfClause, {
|
|
145
|
-
condition: _alloy_js_core.code`Boolean(command) && !command.startsWith("-")`,
|
|
146
|
-
get children() {
|
|
147
|
-
return _alloy_js_core.code`const suggestions = findSuggestions(command, [${Object.values(commands ?? {}).map((cmd) => `"${cmd.name}"${(cmd.alias ?? []).map((alias) => `, "${alias}"`).join("")}`).join(", ")}]).slice(0, 3);
|
|
148
|
-
error(\`Unknown command: "\${command}"\${suggestions && suggestions.length > 0 ? \`, did you mean: \${suggestions.length === 1 ? \`"\${suggestions[0]}"\` : suggestions.map((suggestion, i) => i < suggestions.length - 1 ? \`"\${suggestion}", \` : \`or "\${suggestion}"\`)}?\` : ""} \`);`;
|
|
149
|
-
}
|
|
150
|
-
})];
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
//#endregion
|
|
158
|
-
exports.CommandRouter = CommandRouter;
|
|
159
|
-
exports.CommandRouterBody = CommandRouterBody;
|
|
160
|
-
exports.CommandRouterRoute = CommandRouterRoute;
|
|
161
|
-
//# sourceMappingURL=command-router.cjs.map
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`@alloy-js/core/jsx-runtime`),t=require(`@alloy-js/core`),n=require(`@alloy-js/typescript`),r=require(`@powerlines/plugin-alloy/core/components/spacing`),i=require(`@powerlines/plugin-alloy/core/contexts/context`),a=require(`@shell-shock/core/plugin-utils`),o=require(`@stryke/string-format/pascal-case`),s=require(`@powerlines/plugin-alloy/typescript/components/dynamic-import-statement`),c=require(`@shell-shock/core/contexts/command`);function l(){let n=(0,c.useCommand)();return[(0,e.createComponent)(t.Show,{get when(){return!n.isVirtual},get children(){return(0,e.createComponent)(s.DynamicImportStatement,{get name(){return`handle${(0,o.pascalCase)(n.name)}`},get importPath(){return`./${n.segments.filter(e=>!(0,a.isDynamicPathSegment)(e))[n.segments.filter(e=>!(0,a.isDynamicPathSegment)(e)).length-1]}`},exportName:`handler`})}}),(0,e.createIntrinsic)(`hbr`,{}),(0,e.memo)(()=>t.code`return handle${(0,o.pascalCase)(n.name)}(args);`)]}function u(i){let{segments:a,commands:o,route:s}=i,c=(0,t.computed)(()=>2+(a.length??0));return(0,e.createComponent)(t.Show,{get when(){return o&&Object.keys(o).length>0},get children(){return[(0,e.createComponent)(n.VarDeclaration,{let:!0,name:`command`,type:`string`,initializer:t.code`"";`}),(0,e.createComponent)(r.Spacing,{}),(0,e.createComponent)(t.Show,{get when(){return o&&Object.keys(o).length>0},get children(){return[(0,e.createComponent)(n.IfStatement,{get condition(){return t.code`args.length > ${c.value} && args[${c.value}]`},get children(){return t.code`command = args[${c.value}];`}}),(0,e.createComponent)(r.Spacing,{})]}}),(0,e.createComponent)(d,{segments:a,commands:o,route:s})]}})}function d(r){let{commands:a,route:o}=r,s=(0,i.usePowerlines)();return(0,e.createComponent)(t.Show,{get when(){return a&&Object.keys(a).length>0},get children(){return(0,e.createComponent)(n.IfStatement,{condition:t.code`!command.startsWith("-")`,get children(){return[(0,e.createComponent)(t.For,{get each(){return Object.values(a??{})},children:(r,i)=>(0,e.createComponent)(c.CommandContext.Provider,{value:r,get children(){return(0,e.createComponent)(t.Show,{get when(){return!!i},get fallback(){return(0,e.createComponent)(n.IfStatement,{get condition(){return t.code`${s.config.isCaseSensitive?`command`:`command.toLowerCase().replaceAll("-", "").replaceAll("_", "")`} === "${s.config.isCaseSensitive?r.name:r.name.toLowerCase().replaceAll(`-`,``).replaceAll(`_`,``)}"${r.alias&&r.alias.length>0?` || ${r.alias.map(e=>`${s.config.isCaseSensitive?`command`:`command.toLowerCase().replaceAll("-", "").replaceAll("_", "")`} === "${s.config.isCaseSensitive?e:e.toLowerCase().replaceAll(`-`,``).replaceAll(`_`,``)}"`).join(` || `)}`:``}`},get children(){return(0,e.createComponent)(t.Show,{get when(){return!!o},get fallback(){return(0,e.createComponent)(l,{})},children:o})}})},get children(){return(0,e.createComponent)(n.ElseIfClause,{get condition(){return t.code`${s.config.isCaseSensitive?`command`:`command.toLowerCase().replaceAll("-", "").replaceAll("_", "")`} === "${s.config.isCaseSensitive?r.name:r.name.toLowerCase().replaceAll(`-`,``).replaceAll(`_`,``)}"${r.alias&&r.alias.length>0?` || ${r.alias.map(e=>`${s.config.isCaseSensitive?`command`:`command.toLowerCase().replaceAll("-", "").replaceAll("_", "")`} === "${s.config.isCaseSensitive?e:e.toLowerCase().replaceAll(`-`,``).replaceAll(`_`,``)}"`).join(` || `)}`:``}`},get children(){return(0,e.createComponent)(t.Show,{get when(){return!!o},get fallback(){return(0,e.createComponent)(l,{})},children:o})}})}})}})}),(0,e.createComponent)(n.ElseIfClause,{condition:t.code`Boolean(command) && !command.startsWith("-")`,get children(){return t.code`const suggestions = findSuggestions(command, [${Object.values(a??{}).map(e=>`"${e.name}"${(e.alias??[]).map(e=>`, "${e}"`).join(``)}`).join(`, `)}]).slice(0, 3);
|
|
2
|
+
error(\`Unknown command: "\${command}"\${suggestions && suggestions.length > 0 ? \`, did you mean: \${suggestions.length === 1 ? \`"\${suggestions[0]}"\` : suggestions.map((suggestion, i) => i < suggestions.length - 1 ? \`"\${suggestion}", \` : \`or "\${suggestion}"\`)}?\` : ""} \`);`}})]}})}})}exports.CommandRouter=u,exports.CommandRouterBody=d,exports.CommandRouterRoute=l;
|
|
@@ -1,157 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import { ElseIfClause, IfStatement, VarDeclaration } from "@alloy-js/typescript";
|
|
4
|
-
import { Spacing } from "@powerlines/plugin-alloy/core/components/spacing";
|
|
5
|
-
import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
|
|
6
|
-
import { isDynamicPathSegment } from "@shell-shock/core/plugin-utils";
|
|
7
|
-
import { pascalCase } from "@stryke/string-format/pascal-case";
|
|
8
|
-
import { DynamicImportStatement } from "@powerlines/plugin-alloy/typescript/components/dynamic-import-statement";
|
|
9
|
-
import { CommandContext, useCommand } from "@shell-shock/core/contexts/command";
|
|
10
|
-
|
|
11
|
-
//#region src/components/command-router.tsx
|
|
12
|
-
function CommandRouterRoute() {
|
|
13
|
-
const command = useCommand();
|
|
14
|
-
return [
|
|
15
|
-
createComponent(Show, {
|
|
16
|
-
get when() {
|
|
17
|
-
return !command.isVirtual;
|
|
18
|
-
},
|
|
19
|
-
get children() {
|
|
20
|
-
return createComponent(DynamicImportStatement, {
|
|
21
|
-
get name() {
|
|
22
|
-
return `handle${pascalCase(command.name)}`;
|
|
23
|
-
},
|
|
24
|
-
get importPath() {
|
|
25
|
-
return `./${command.segments.filter((segment) => !isDynamicPathSegment(segment))[command.segments.filter((segment) => !isDynamicPathSegment(segment)).length - 1]}`;
|
|
26
|
-
},
|
|
27
|
-
exportName: "handler"
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}),
|
|
31
|
-
createIntrinsic("hbr", {}),
|
|
32
|
-
memo(() => code`return handle${pascalCase(command.name)}(args);`)
|
|
33
|
-
];
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* The command router component.
|
|
37
|
-
*/
|
|
38
|
-
function CommandRouter(props) {
|
|
39
|
-
const { segments, commands, route } = props;
|
|
40
|
-
const index = computed(() => 2 + (segments.length ?? 0));
|
|
41
|
-
return createComponent(Show, {
|
|
42
|
-
get when() {
|
|
43
|
-
return commands && Object.keys(commands).length > 0;
|
|
44
|
-
},
|
|
45
|
-
get children() {
|
|
46
|
-
return [
|
|
47
|
-
createComponent(VarDeclaration, {
|
|
48
|
-
"let": true,
|
|
49
|
-
name: "command",
|
|
50
|
-
type: "string",
|
|
51
|
-
initializer: code`"";`
|
|
52
|
-
}),
|
|
53
|
-
createComponent(Spacing, {}),
|
|
54
|
-
createComponent(Show, {
|
|
55
|
-
get when() {
|
|
56
|
-
return commands && Object.keys(commands).length > 0;
|
|
57
|
-
},
|
|
58
|
-
get children() {
|
|
59
|
-
return [createComponent(IfStatement, {
|
|
60
|
-
get condition() {
|
|
61
|
-
return code`args.length > ${index.value} && args[${index.value}]`;
|
|
62
|
-
},
|
|
63
|
-
get children() {
|
|
64
|
-
return code`command = args[${index.value}];`;
|
|
65
|
-
}
|
|
66
|
-
}), createComponent(Spacing, {})];
|
|
67
|
-
}
|
|
68
|
-
}),
|
|
69
|
-
createComponent(CommandRouterBody, {
|
|
70
|
-
segments,
|
|
71
|
-
commands,
|
|
72
|
-
route
|
|
73
|
-
})
|
|
74
|
-
];
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* The internal command router body logic component.
|
|
80
|
-
*/
|
|
81
|
-
function CommandRouterBody(props) {
|
|
82
|
-
const { commands, route } = props;
|
|
83
|
-
const context = usePowerlines();
|
|
84
|
-
return createComponent(Show, {
|
|
85
|
-
get when() {
|
|
86
|
-
return commands && Object.keys(commands).length > 0;
|
|
87
|
-
},
|
|
88
|
-
get children() {
|
|
89
|
-
return createComponent(IfStatement, {
|
|
90
|
-
condition: code`!command.startsWith("-")`,
|
|
91
|
-
get children() {
|
|
92
|
-
return [createComponent(For, {
|
|
93
|
-
get each() {
|
|
94
|
-
return Object.values(commands ?? {});
|
|
95
|
-
},
|
|
96
|
-
children: (subcommand, idx) => createComponent(CommandContext.Provider, {
|
|
97
|
-
value: subcommand,
|
|
98
|
-
get children() {
|
|
99
|
-
return createComponent(Show, {
|
|
100
|
-
get when() {
|
|
101
|
-
return Boolean(idx);
|
|
102
|
-
},
|
|
103
|
-
get fallback() {
|
|
104
|
-
return createComponent(IfStatement, {
|
|
105
|
-
get condition() {
|
|
106
|
-
return code`${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${context.config.isCaseSensitive ? subcommand.name : subcommand.name.toLowerCase().replaceAll("-", "").replaceAll("_", "")}"${subcommand.alias && subcommand.alias.length > 0 ? ` || ${subcommand.alias.map((alias) => `${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${context.config.isCaseSensitive ? alias : alias.toLowerCase().replaceAll("-", "").replaceAll("_", "")}"`).join(" || ")}` : ""}`;
|
|
107
|
-
},
|
|
108
|
-
get children() {
|
|
109
|
-
return createComponent(Show, {
|
|
110
|
-
get when() {
|
|
111
|
-
return Boolean(route);
|
|
112
|
-
},
|
|
113
|
-
get fallback() {
|
|
114
|
-
return createComponent(CommandRouterRoute, {});
|
|
115
|
-
},
|
|
116
|
-
children: route
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
},
|
|
121
|
-
get children() {
|
|
122
|
-
return createComponent(ElseIfClause, {
|
|
123
|
-
get condition() {
|
|
124
|
-
return code`${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${context.config.isCaseSensitive ? subcommand.name : subcommand.name.toLowerCase().replaceAll("-", "").replaceAll("_", "")}"${subcommand.alias && subcommand.alias.length > 0 ? ` || ${subcommand.alias.map((alias) => `${context.config.isCaseSensitive ? "command" : "command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${context.config.isCaseSensitive ? alias : alias.toLowerCase().replaceAll("-", "").replaceAll("_", "")}"`).join(" || ")}` : ""}`;
|
|
125
|
-
},
|
|
126
|
-
get children() {
|
|
127
|
-
return createComponent(Show, {
|
|
128
|
-
get when() {
|
|
129
|
-
return Boolean(route);
|
|
130
|
-
},
|
|
131
|
-
get fallback() {
|
|
132
|
-
return createComponent(CommandRouterRoute, {});
|
|
133
|
-
},
|
|
134
|
-
children: route
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
})
|
|
142
|
-
}), createComponent(ElseIfClause, {
|
|
143
|
-
condition: code`Boolean(command) && !command.startsWith("-")`,
|
|
144
|
-
get children() {
|
|
145
|
-
return code`const suggestions = findSuggestions(command, [${Object.values(commands ?? {}).map((cmd) => `"${cmd.name}"${(cmd.alias ?? []).map((alias) => `, "${alias}"`).join("")}`).join(", ")}]).slice(0, 3);
|
|
146
|
-
error(\`Unknown command: "\${command}"\${suggestions && suggestions.length > 0 ? \`, did you mean: \${suggestions.length === 1 ? \`"\${suggestions[0]}"\` : suggestions.map((suggestion, i) => i < suggestions.length - 1 ? \`"\${suggestion}", \` : \`or "\${suggestion}"\`)}?\` : ""} \`);`;
|
|
147
|
-
}
|
|
148
|
-
})];
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
//#endregion
|
|
156
|
-
export { CommandRouter, CommandRouterBody, CommandRouterRoute };
|
|
1
|
+
import{createComponent as e,createIntrinsic as t,memo as n}from"@alloy-js/core/jsx-runtime";import{For as r,Show as i,code as a,computed as o}from"@alloy-js/core";import{ElseIfClause as s,IfStatement as c,VarDeclaration as l}from"@alloy-js/typescript";import{Spacing as u}from"@powerlines/plugin-alloy/core/components/spacing";import{usePowerlines as d}from"@powerlines/plugin-alloy/core/contexts/context";import{isDynamicPathSegment as f}from"@shell-shock/core/plugin-utils";import{pascalCase as p}from"@stryke/string-format/pascal-case";import{DynamicImportStatement as m}from"@powerlines/plugin-alloy/typescript/components/dynamic-import-statement";import{CommandContext as h,useCommand as g}from"@shell-shock/core/contexts/command";function _(){let r=g();return[e(i,{get when(){return!r.isVirtual},get children(){return e(m,{get name(){return`handle${p(r.name)}`},get importPath(){return`./${r.segments.filter(e=>!f(e))[r.segments.filter(e=>!f(e)).length-1]}`},exportName:`handler`})}}),t(`hbr`,{}),n(()=>a`return handle${p(r.name)}(args);`)]}function v(t){let{segments:n,commands:r,route:s}=t,d=o(()=>2+(n.length??0));return e(i,{get when(){return r&&Object.keys(r).length>0},get children(){return[e(l,{let:!0,name:`command`,type:`string`,initializer:a`"";`}),e(u,{}),e(i,{get when(){return r&&Object.keys(r).length>0},get children(){return[e(c,{get condition(){return a`args.length > ${d.value} && args[${d.value}]`},get children(){return a`command = args[${d.value}];`}}),e(u,{})]}}),e(y,{segments:n,commands:r,route:s})]}})}function y(t){let{commands:n,route:o}=t,l=d();return e(i,{get when(){return n&&Object.keys(n).length>0},get children(){return e(c,{condition:a`!command.startsWith("-")`,get children(){return[e(r,{get each(){return Object.values(n??{})},children:(t,n)=>e(h.Provider,{value:t,get children(){return e(i,{get when(){return!!n},get fallback(){return e(c,{get condition(){return a`${l.config.isCaseSensitive?`command`:`command.toLowerCase().replaceAll("-", "").replaceAll("_", "")`} === "${l.config.isCaseSensitive?t.name:t.name.toLowerCase().replaceAll(`-`,``).replaceAll(`_`,``)}"${t.alias&&t.alias.length>0?` || ${t.alias.map(e=>`${l.config.isCaseSensitive?`command`:`command.toLowerCase().replaceAll("-", "").replaceAll("_", "")`} === "${l.config.isCaseSensitive?e:e.toLowerCase().replaceAll(`-`,``).replaceAll(`_`,``)}"`).join(` || `)}`:``}`},get children(){return e(i,{get when(){return!!o},get fallback(){return e(_,{})},children:o})}})},get children(){return e(s,{get condition(){return a`${l.config.isCaseSensitive?`command`:`command.toLowerCase().replaceAll("-", "").replaceAll("_", "")`} === "${l.config.isCaseSensitive?t.name:t.name.toLowerCase().replaceAll(`-`,``).replaceAll(`_`,``)}"${t.alias&&t.alias.length>0?` || ${t.alias.map(e=>`${l.config.isCaseSensitive?`command`:`command.toLowerCase().replaceAll("-", "").replaceAll("_", "")`} === "${l.config.isCaseSensitive?e:e.toLowerCase().replaceAll(`-`,``).replaceAll(`_`,``)}"`).join(` || `)}`:``}`},get children(){return e(i,{get when(){return!!o},get fallback(){return e(_,{})},children:o})}})}})}})}),e(s,{condition:a`Boolean(command) && !command.startsWith("-")`,get children(){return a`const suggestions = findSuggestions(command, [${Object.values(n??{}).map(e=>`"${e.name}"${(e.alias??[]).map(e=>`, "${e}"`).join(``)}`).join(`, `)}]).slice(0, 3);
|
|
2
|
+
error(\`Unknown command: "\${command}"\${suggestions && suggestions.length > 0 ? \`, did you mean: \${suggestions.length === 1 ? \`"\${suggestions[0]}"\` : suggestions.map((suggestion, i) => i < suggestions.length - 1 ? \`"\${suggestion}", \` : \`or "\${suggestion}"\`)}?\` : ""} \`);`}})]}})}})}export{v as CommandRouter,y as CommandRouterBody,_ as CommandRouterRoute};
|
|
157
3
|
//# sourceMappingURL=command-router.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-router.mjs","names":[],"sources":["../../src/components/command-router.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { Children } from \"@alloy-js/core\";\nimport { code, computed, For, Show } from \"@alloy-js/core\";\nimport {\n ElseIfClause,\n IfStatement,\n VarDeclaration\n} from \"@alloy-js/typescript\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core/components/spacing\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport { DynamicImportStatement } from \"@powerlines/plugin-alloy/typescript/components/dynamic-import-statement\";\nimport { CommandContext, useCommand } from \"@shell-shock/core/contexts/command\";\nimport { isDynamicPathSegment } from \"@shell-shock/core/plugin-utils\";\nimport type { CommandTree } from \"@shell-shock/core/types/command\";\nimport { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport type { ScriptPresetContext } from \"../types/plugin\";\n\nexport function CommandRouterRoute() {\n const command = useCommand();\n\n return (\n <>\n <Show when={!command.isVirtual}>\n <DynamicImportStatement\n name={`handle${pascalCase(command.name)}`}\n importPath={`./${\n command.segments.filter(segment => !isDynamicPathSegment(segment))[\n command.segments.filter(segment => !isDynamicPathSegment(segment))\n .length - 1\n ]\n }`}\n exportName=\"handler\"\n />\n </Show>\n <hbr />\n {code`return handle${pascalCase(command.name)}(args);`}\n </>\n );\n}\n\nexport interface CommandRouterProps {\n segments: string[];\n commands?: Record<string, CommandTree>;\n route?: Children;\n}\n\n/**\n * The command router component.\n */\nexport function CommandRouter(props: CommandRouterProps) {\n const { segments, commands, route } = props;\n\n const index = computed(() => 2 + (segments.length ?? 0));\n\n return (\n <Show when={commands && Object.keys(commands).length > 0}>\n <VarDeclaration\n let\n name=\"command\"\n type=\"string\"\n initializer={code`\"\";`}\n />\n <Spacing />\n <Show when={commands && Object.keys(commands).length > 0}>\n <IfStatement\n condition={code`args.length > ${\n index.value\n } && args[${index.value}]`}>{code`command = args[${\n index.value\n }];`}</IfStatement>\n <Spacing />\n </Show>\n <CommandRouterBody\n segments={segments}\n commands={commands}\n route={route}\n />\n </Show>\n );\n}\n\n/**\n * The internal command router body logic component.\n */\nexport function CommandRouterBody(props: CommandRouterProps) {\n const { commands, route } = props;\n\n const context = usePowerlines<ScriptPresetContext>();\n\n return (\n <Show when={commands && Object.keys(commands).length > 0}>\n <IfStatement condition={code`!command.startsWith(\"-\")`}>\n <For each={Object.values(commands ?? {})}>\n {(subcommand, idx) => (\n <CommandContext.Provider value={subcommand}>\n <Show\n when={Boolean(idx)}\n fallback={\n <IfStatement\n condition={code`${\n context.config.isCaseSensitive\n ? \"command\"\n : 'command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")'\n } === \"${\n context.config.isCaseSensitive\n ? subcommand.name\n : subcommand.name\n .toLowerCase()\n .replaceAll(\"-\", \"\")\n .replaceAll(\"_\", \"\")\n }\"${\n subcommand.alias && subcommand.alias.length > 0\n ? ` || ${subcommand.alias\n .map(\n alias =>\n `${context.config.isCaseSensitive ? \"command\" : 'command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")'} === \"${\n context.config.isCaseSensitive\n ? alias\n : alias\n .toLowerCase()\n .replaceAll(\"-\", \"\")\n .replaceAll(\"_\", \"\")\n }\"`\n )\n .join(\" || \")}`\n : \"\"\n }`}>\n <Show\n when={Boolean(route)}\n fallback={<CommandRouterRoute />}>\n {route}\n </Show>\n </IfStatement>\n }>\n <ElseIfClause\n condition={code`${\n context.config.isCaseSensitive\n ? \"command\"\n : 'command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")'\n } === \"${\n context.config.isCaseSensitive\n ? subcommand.name\n : subcommand.name\n .toLowerCase()\n .replaceAll(\"-\", \"\")\n .replaceAll(\"_\", \"\")\n }\"${\n subcommand.alias && subcommand.alias.length > 0\n ? ` || ${subcommand.alias\n .map(\n alias =>\n `${context.config.isCaseSensitive ? \"command\" : 'command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")'} === \"${\n context.config.isCaseSensitive\n ? alias\n : alias\n .toLowerCase()\n .replaceAll(\"-\", \"\")\n .replaceAll(\"_\", \"\")\n }\"`\n )\n .join(\" || \")}`\n : \"\"\n }`}>\n <Show when={Boolean(route)} fallback={<CommandRouterRoute />}>\n {route}\n </Show>\n </ElseIfClause>\n </Show>\n </CommandContext.Provider>\n )}\n </For>\n <ElseIfClause\n condition={code`Boolean(command) && !command.startsWith(\"-\")`}>{code`const suggestions = findSuggestions(command, [${Object.values(\n commands ?? {}\n )\n .map(\n cmd =>\n `\"${cmd.name}\"${(cmd.alias ?? []).map(alias => `, \"${alias}\"`).join(\"\")}`\n )\n .join(\", \")}]).slice(0, 3);\n error(\\`Unknown command: \"\\${command}\"\\${suggestions && suggestions.length > 0 ? \\`, did you mean: \\${suggestions.length === 1 ? \\`\"\\${suggestions[0]}\"\\` : suggestions.map((suggestion, i) => i < suggestions.length - 1 ? \\`\"\\${suggestion}\", \\` : \\`or \"\\${suggestion}\"\\`)}?\\` : \"\"} \\`);`}</ElseIfClause>\n </IfStatement>\n </Show>\n );\n}\n"],"mappings":";;;;;;;;;;;AA8BA,SAAc,qBAAqB;CACnC,MAAQ,UAAC,YAAoB;AAC7B,QAAO;EAAA,gBAAO,MAAoB;;AAE5B,WAAC,CAAA,QAAS;;;AAGd,WAAO,gBAAA,wBAAA;KACJ,IAAA,OAAA;AACE,aAAU,SAAS,WAAW,QAAA,KAAA;;KAE7B,IAAE,aAAe;AACf,aAAA,KAAY,QAAI,SAAA,QAAA,YAAA,CAAA,qBAAA,QAAA,CAAA,CAAA,QAAA,SAAA,QAAA,YAAA,CAAA,qBAAA,QAAA,CAAA,CAAA,SAAA;;KAElB,YAAM;KACP,CAAC;;GAEL,CAAC;EAAE,gBAAM,OAAA,EAAA,CAAA;EAAA,WAAA,IAAA,gBAAA,WAAA,QAAA,KAAA,CAAA,SAAA;EAAA;;;;;AAWZ,SAAY,cAAQ,OAAA;CAClB,MAAA,EACA,UACF,oBAEE;CACA,MAAK,QAAQ,eAAgB,KAAA,SAAA,UAAA,GAAA;AAC7B,QAAA,gBAAA,MAAA;EACF,IAAO,OAAQ;AACb,UAAQ,YAAU,OAAU,KAAO,SAAQ,CAAA,SAAA;;EAE3C,IAAM,WAAQ;;;KAER,OAAC;KACJ,MAAS;KACP,MAAA;KACC,aAAA,IAAA;KACD,CAAC;IAAA,gBAAa,SAAA,EAAA,CAAA;IAAA,gBAAA,MAAA;KACb,IAAI,OAAE;AACN,aAAA,YAAqB,OAAC,KAAA,SAAA,CAAA,SAAA;;KAEvB,IAAA,W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":[],"sources":["../../src/components/command-router.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { Children } from \"@alloy-js/core\";\nimport { code, computed, For, Show } from \"@alloy-js/core\";\nimport {\n ElseIfClause,\n IfStatement,\n VarDeclaration\n} from \"@alloy-js/typescript\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core/components/spacing\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport { DynamicImportStatement } from \"@powerlines/plugin-alloy/typescript/components/dynamic-import-statement\";\nimport { CommandContext, useCommand } from \"@shell-shock/core/contexts/command\";\nimport { isDynamicPathSegment } from \"@shell-shock/core/plugin-utils\";\nimport type { CommandTree } from \"@shell-shock/core/types/command\";\nimport { pascalCase } from \"@stryke/string-format/pascal-case\";\nimport type { ScriptPresetContext } from \"../types/plugin\";\n\nexport function CommandRouterRoute() {\n const command = useCommand();\n\n return (\n <>\n <Show when={!command.isVirtual}>\n <DynamicImportStatement\n name={`handle${pascalCase(command.name)}`}\n importPath={`./${\n command.segments.filter(segment => !isDynamicPathSegment(segment))[\n command.segments.filter(segment => !isDynamicPathSegment(segment))\n .length - 1\n ]\n }`}\n exportName=\"handler\"\n />\n </Show>\n <hbr />\n {code`return handle${pascalCase(command.name)}(args);`}\n </>\n );\n}\n\nexport interface CommandRouterProps {\n segments: string[];\n commands?: Record<string, CommandTree>;\n route?: Children;\n}\n\n/**\n * The command router component.\n */\nexport function CommandRouter(props: CommandRouterProps) {\n const { segments, commands, route } = props;\n\n const index = computed(() => 2 + (segments.length ?? 0));\n\n return (\n <Show when={commands && Object.keys(commands).length > 0}>\n <VarDeclaration\n let\n name=\"command\"\n type=\"string\"\n initializer={code`\"\";`}\n />\n <Spacing />\n <Show when={commands && Object.keys(commands).length > 0}>\n <IfStatement\n condition={code`args.length > ${\n index.value\n } && args[${index.value}]`}>{code`command = args[${\n index.value\n }];`}</IfStatement>\n <Spacing />\n </Show>\n <CommandRouterBody\n segments={segments}\n commands={commands}\n route={route}\n />\n </Show>\n );\n}\n\n/**\n * The internal command router body logic component.\n */\nexport function CommandRouterBody(props: CommandRouterProps) {\n const { commands, route } = props;\n\n const context = usePowerlines<ScriptPresetContext>();\n\n return (\n <Show when={commands && Object.keys(commands).length > 0}>\n <IfStatement condition={code`!command.startsWith(\"-\")`}>\n <For each={Object.values(commands ?? {})}>\n {(subcommand, idx) => (\n <CommandContext.Provider value={subcommand}>\n <Show\n when={Boolean(idx)}\n fallback={\n <IfStatement\n condition={code`${\n context.config.isCaseSensitive\n ? \"command\"\n : 'command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")'\n } === \"${\n context.config.isCaseSensitive\n ? subcommand.name\n : subcommand.name\n .toLowerCase()\n .replaceAll(\"-\", \"\")\n .replaceAll(\"_\", \"\")\n }\"${\n subcommand.alias && subcommand.alias.length > 0\n ? ` || ${subcommand.alias\n .map(\n alias =>\n `${context.config.isCaseSensitive ? \"command\" : 'command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")'} === \"${\n context.config.isCaseSensitive\n ? alias\n : alias\n .toLowerCase()\n .replaceAll(\"-\", \"\")\n .replaceAll(\"_\", \"\")\n }\"`\n )\n .join(\" || \")}`\n : \"\"\n }`}>\n <Show\n when={Boolean(route)}\n fallback={<CommandRouterRoute />}>\n {route}\n </Show>\n </IfStatement>\n }>\n <ElseIfClause\n condition={code`${\n context.config.isCaseSensitive\n ? \"command\"\n : 'command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")'\n } === \"${\n context.config.isCaseSensitive\n ? subcommand.name\n : subcommand.name\n .toLowerCase()\n .replaceAll(\"-\", \"\")\n .replaceAll(\"_\", \"\")\n }\"${\n subcommand.alias && subcommand.alias.length > 0\n ? ` || ${subcommand.alias\n .map(\n alias =>\n `${context.config.isCaseSensitive ? \"command\" : 'command.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")'} === \"${\n context.config.isCaseSensitive\n ? alias\n : alias\n .toLowerCase()\n .replaceAll(\"-\", \"\")\n .replaceAll(\"_\", \"\")\n }\"`\n )\n .join(\" || \")}`\n : \"\"\n }`}>\n <Show when={Boolean(route)} fallback={<CommandRouterRoute />}>\n {route}\n </Show>\n </ElseIfClause>\n </Show>\n </CommandContext.Provider>\n )}\n </For>\n <ElseIfClause\n condition={code`Boolean(command) && !command.startsWith(\"-\")`}>{code`const suggestions = findSuggestions(command, [${Object.values(\n commands ?? {}\n )\n .map(\n cmd =>\n `\"${cmd.name}\"${(cmd.alias ?? []).map(alias => `, \"${alias}\"`).join(\"\")}`\n )\n .join(\", \")}]).slice(0, 3);\n error(\\`Unknown command: \"\\${command}\"\\${suggestions && suggestions.length > 0 ? \\`, did you mean: \\${suggestions.length === 1 ? \\`\"\\${suggestions[0]}\"\\` : suggestions.map((suggestion, i) => i < suggestions.length - 1 ? \\`\"\\${suggestion}\", \\` : \\`or \"\\${suggestion}\"\\`)}?\\` : \"\"} \\`);`}</ElseIfClause>\n </IfStatement>\n </Show>\n );\n}\n"],"mappings":"guBA2BA,SAAS,GAAyB,CAClC,IAAQ,EAAC,GAAgB,CACzB,MAAS,CAAA,EAAA,EAAuB,CAChC,IAAO,MAAO,CACR,MAAG,CAAA,EAAa,0BAGhB,OAAC,EAAS,EAAqB,CAC7B,IAAA,MAAU,6BAGb,IAAA,YAAA,CACE,MAAU,KAAE,EAAQ,SAAU,OAAA,GAAA,CAAA,EAAA,EAAA,CAAA,CAAA,EAAA,SAAA,OAAA,GAAA,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H,CAAC,CAAE,EAAY,EAAA,CACd,UAAQ,CAAO,+CACf,IAAI,UAAQ,CACV,MAAO,EAAG,iDAAW,OAAA,OAAA,GAAA,EAAA,CAAA,CAAA,IAAA,GAAA,IAAA,EAAA,KAAA,IAAA,EAAA,OAAA,EAAA,EAAA,IAAA,GAAA,MAAA,EAAA,GAAA,CAAA,KAAA,GAAA,GAAA,CAAA,KAAA,KAAA,CAAA;uSAGxB,CAAC,CAAC,EAEN,CAAC,EAEL,CAAC"}
|
|
@@ -1,95 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
4
|
-
let _alloy_js_core = require("@alloy-js/core");
|
|
5
|
-
let _alloy_js_typescript = require("@alloy-js/typescript");
|
|
6
|
-
let _powerlines_plugin_alloy_core_components_spacing = require("@powerlines/plugin-alloy/core/components/spacing");
|
|
7
|
-
let _powerlines_plugin_alloy_core_contexts_context = require("@powerlines/plugin-alloy/core/contexts/context");
|
|
8
|
-
let _shell_shock_core_plugin_utils = require("@shell-shock/core/plugin-utils");
|
|
9
|
-
let _shell_shock_core_components_helpers = require("@shell-shock/core/components/helpers");
|
|
10
|
-
|
|
11
|
-
//#region src/components/exit-function-declaration.tsx
|
|
12
|
-
/**
|
|
13
|
-
* The `exit` handler function declaration code for the Shell Shock project.
|
|
14
|
-
*/
|
|
15
|
-
function ExitFunctionDeclaration() {
|
|
16
|
-
const context = (0, _powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
|
|
17
|
-
return [
|
|
18
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceDeclaration, {
|
|
19
|
-
"export": true,
|
|
20
|
-
name: "ExitOptions",
|
|
21
|
-
doc: "Options for the exit handler function.",
|
|
22
|
-
get children() {
|
|
23
|
-
return [
|
|
24
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
25
|
-
name: "exception",
|
|
26
|
-
optional: true,
|
|
27
|
-
type: "string | Error",
|
|
28
|
-
doc: "An optional exception that caused the exit. This can be a string message or an Error object."
|
|
29
|
-
}),
|
|
30
|
-
(0, _alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
31
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
32
|
-
name: "skipProcessExit",
|
|
33
|
-
optional: true,
|
|
34
|
-
type: "boolean",
|
|
35
|
-
doc: "Indicates whether the exit function should manually exit the process or not. If set to true, the exit function will not call process.exit() and will allow the application to continue running. If set to false or not specified, the exit function will call process.exit() to terminate the application."
|
|
36
|
-
}),
|
|
37
|
-
(0, _alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
38
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
39
|
-
name: "isSynchronous",
|
|
40
|
-
optional: true,
|
|
41
|
-
type: "boolean",
|
|
42
|
-
doc: "Indicates whether the exit function should perform synchronous operations only. If set to true, the exit function will avoid any asynchronous operations during exit. If set to false or not specified, the exit function may perform asynchronous operations as needed."
|
|
43
|
-
}),
|
|
44
|
-
(0, _alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
45
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
46
|
-
name: "signal",
|
|
47
|
-
optional: true,
|
|
48
|
-
type: "number",
|
|
49
|
-
doc: "The signal number that triggered the exit. This is typically used when the shutdown is initiated by a system signal (e.g., SIGINT, SIGTERM)."
|
|
50
|
-
}),
|
|
51
|
-
(0, _alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
52
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
53
|
-
name: "startDate",
|
|
54
|
-
optional: true,
|
|
55
|
-
type: "Date",
|
|
56
|
-
doc: "A Date object representing the timestamp when the process started. This can be used to measure the duration of the shutdown process."
|
|
57
|
-
})
|
|
58
|
-
];
|
|
59
|
-
}
|
|
60
|
-
}),
|
|
61
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
62
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
|
|
63
|
-
"let": true,
|
|
64
|
-
name: "isExiting",
|
|
65
|
-
type: "boolean",
|
|
66
|
-
initializer: _alloy_js_core.code`false;`
|
|
67
|
-
}),
|
|
68
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
|
|
69
|
-
"const": true,
|
|
70
|
-
name: "callbackAsyncQueue",
|
|
71
|
-
type: "Array<[(code: number | string) => Promise<void> | void, number]>",
|
|
72
|
-
initializer: _alloy_js_core.code`[];`
|
|
73
|
-
}),
|
|
74
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
|
|
75
|
-
"const": true,
|
|
76
|
-
name: "callbackSyncQueue",
|
|
77
|
-
type: "Array<(code: number | string) => void>",
|
|
78
|
-
initializer: _alloy_js_core.code`[];`
|
|
79
|
-
}),
|
|
80
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
81
|
-
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
82
|
-
"export": true,
|
|
83
|
-
async: true,
|
|
84
|
-
name: "exit",
|
|
85
|
-
parameters: [{
|
|
86
|
-
name: "options",
|
|
87
|
-
type: "ExitOptions",
|
|
88
|
-
default: "{}"
|
|
89
|
-
}],
|
|
90
|
-
get children() {
|
|
91
|
-
return [
|
|
92
|
-
(0, _alloy_js_core_jsx_runtime.memo)(() => _alloy_js_core.code`
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`@alloy-js/core/jsx-runtime`),t=require(`@alloy-js/core`),n=require(`@alloy-js/typescript`),r=require(`@powerlines/plugin-alloy/core/components/spacing`),i=require(`@powerlines/plugin-alloy/core/contexts/context`),a=require(`@shell-shock/core/plugin-utils`),o=require(`@shell-shock/core/components/helpers`);function s(){let s=(0,i.usePowerlines)();return[(0,e.createComponent)(n.InterfaceDeclaration,{export:!0,name:`ExitOptions`,doc:`Options for the exit handler function.`,get children(){return[(0,e.createComponent)(n.InterfaceMember,{name:`exception`,optional:!0,type:`string | Error`,doc:`An optional exception that caused the exit. This can be a string message or an Error object.`}),(0,e.createIntrinsic)(`hbr`,{}),(0,e.createComponent)(n.InterfaceMember,{name:`skipProcessExit`,optional:!0,type:`boolean`,doc:`Indicates whether the exit function should manually exit the process or not. If set to true, the exit function will not call process.exit() and will allow the application to continue running. If set to false or not specified, the exit function will call process.exit() to terminate the application.`}),(0,e.createIntrinsic)(`hbr`,{}),(0,e.createComponent)(n.InterfaceMember,{name:`isSynchronous`,optional:!0,type:`boolean`,doc:`Indicates whether the exit function should perform synchronous operations only. If set to true, the exit function will avoid any asynchronous operations during exit. If set to false or not specified, the exit function may perform asynchronous operations as needed.`}),(0,e.createIntrinsic)(`hbr`,{}),(0,e.createComponent)(n.InterfaceMember,{name:`signal`,optional:!0,type:`number`,doc:`The signal number that triggered the exit. This is typically used when the shutdown is initiated by a system signal (e.g., SIGINT, SIGTERM).`}),(0,e.createIntrinsic)(`hbr`,{}),(0,e.createComponent)(n.InterfaceMember,{name:`startDate`,optional:!0,type:`Date`,doc:`A Date object representing the timestamp when the process started. This can be used to measure the duration of the shutdown process.`})]}}),(0,e.createComponent)(r.Spacing,{}),(0,e.createComponent)(n.VarDeclaration,{let:!0,name:`isExiting`,type:`boolean`,initializer:t.code`false;`}),(0,e.createComponent)(n.VarDeclaration,{const:!0,name:`callbackAsyncQueue`,type:`Array<[(code: number | string) => Promise<void> | void, number]>`,initializer:t.code`[];`}),(0,e.createComponent)(n.VarDeclaration,{const:!0,name:`callbackSyncQueue`,type:`Array<(code: number | string) => void>`,initializer:t.code`[];`}),(0,e.createComponent)(r.Spacing,{}),(0,e.createComponent)(n.FunctionDeclaration,{export:!0,async:!0,name:`exit`,parameters:[{name:`options`,type:`ExitOptions`,default:`{}`}],get children(){return[(0,e.memo)(()=>t.code`
|
|
93
2
|
try {
|
|
94
3
|
if (isExiting) {
|
|
95
4
|
return;
|
|
@@ -105,21 +14,13 @@ function ExitFunctionDeclaration() {
|
|
|
105
14
|
}
|
|
106
15
|
|
|
107
16
|
if (options.exception) {
|
|
108
|
-
error({ message: \`A fatal error occured while running the application - please contact the ${(0,
|
|
17
|
+
error({ message: \`A fatal error occured while running the application - please contact the ${(0,a.getAppTitle)(s)} support team\${options.exception && typeof options.exception !== "symbol" ? \`: \\n\\n\${typeof options.exception === "string" ? options.exception : options.exception.message}\` : "."}\`,
|
|
109
18
|
...(options.exception && typeof options.exception === "object" ? { stack: (options.exception as { message: string; stack?: string }).stack } : {})
|
|
110
19
|
});
|
|
111
20
|
}
|
|
112
21
|
|
|
113
|
-
const terminate = (force = false) => { `),
|
|
114
|
-
|
|
115
|
-
get condition() {
|
|
116
|
-
return (0, _alloy_js_core_jsx_runtime.createComponent)(_shell_shock_core_components_helpers.IsVerbose, {});
|
|
117
|
-
},
|
|
118
|
-
children: _alloy_js_core.code`writeLine("");`
|
|
119
|
-
}),
|
|
120
|
-
(0, _alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
121
|
-
(0, _alloy_js_core_jsx_runtime.memo)(() => _alloy_js_core.code`
|
|
122
|
-
verbose(\`The ${(0, _shell_shock_core_plugin_utils.getAppTitle)(context, true)} application exited \${options.exception ? \`early due to an exception\` : "successfully"}\${options.startDate ? \`. Total processing time is \${Date.now() - options.startDate.getTime() > 5000 ? Math.floor((Date.now() - options.startDate.getTime()) / 1000) : Date.now() - options.startDate.getTime()} \${Date.now() - options.startDate.getTime() > 5000 ? "seconds" : "milliseconds"}\` : ""}...\`);
|
|
22
|
+
const terminate = (force = false) => { `),(0,e.createComponent)(n.IfStatement,{get condition(){return(0,e.createComponent)(o.IsVerbose,{})},children:t.code`writeLine("");`}),(0,e.createIntrinsic)(`hbr`,{}),(0,e.memo)(()=>t.code`
|
|
23
|
+
verbose(\`The ${(0,a.getAppTitle)(s,!0)} application exited \${options.exception ? \`early due to an exception\` : "successfully"}\${options.startDate ? \`. Total processing time is \${Date.now() - options.startDate.getTime() > 5000 ? Math.floor((Date.now() - options.startDate.getTime()) / 1000) : Date.now() - options.startDate.getTime()} \${Date.now() - options.startDate.getTime() > 5000 ? "seconds" : "milliseconds"}\` : ""}...\`);
|
|
123
24
|
if (!options.skipProcessExit) {
|
|
124
25
|
process.nextTick(() => process.exit(exitCode));
|
|
125
26
|
}
|
|
@@ -146,19 +47,10 @@ function ExitFunctionDeclaration() {
|
|
|
146
47
|
|
|
147
48
|
terminate();
|
|
148
49
|
} catch (err) {
|
|
149
|
-
error(\`The exit process failed to complete\${(err as Error)?.message ? \` - \${(err as Error).message}\` : ""}. Please contact the ${(0,
|
|
50
|
+
error(\`The exit process failed to complete\${(err as Error)?.message ? \` - \${(err as Error).message}\` : ""}. Please contact the ${(0,a.getAppTitle)(s,!0)} support team.\`);
|
|
150
51
|
|
|
151
52
|
if (!options.skipProcessExit) {
|
|
152
53
|
process.nextTick(() => process.exit(1));
|
|
153
54
|
}
|
|
154
55
|
}
|
|
155
|
-
`)
|
|
156
|
-
];
|
|
157
|
-
}
|
|
158
|
-
})
|
|
159
|
-
];
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
//#endregion
|
|
163
|
-
exports.ExitFunctionDeclaration = ExitFunctionDeclaration;
|
|
164
|
-
//# sourceMappingURL=exit-function-declaration.cjs.map
|
|
56
|
+
`)]}})]}exports.ExitFunctionDeclaration=s;
|