@shell-shock/core 0.2.1 → 0.4.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/README.md +1 -1
- package/dist/api.cjs +15 -3
- package/dist/api.cjs.map +1 -0
- package/dist/api.d.cts +9 -1
- package/dist/api.d.cts.map +1 -0
- package/dist/api.d.mts +9 -1
- package/dist/api.d.mts.map +1 -0
- package/dist/api.mjs +14 -3
- package/dist/api.mjs.map +1 -0
- package/dist/components/docs.cjs +175 -0
- package/dist/components/docs.cjs.map +1 -0
- package/dist/components/docs.d.cts +81 -0
- package/dist/components/docs.d.cts.map +1 -0
- package/dist/components/docs.d.mts +81 -0
- package/dist/components/docs.d.mts.map +1 -0
- package/dist/components/docs.mjs +171 -0
- package/dist/components/docs.mjs.map +1 -0
- package/dist/components/index.cjs +5 -6
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.mts +2 -2
- package/dist/components/index.mjs +2 -2
- package/dist/config.cjs +2 -1
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +2 -1
- package/dist/config.d.cts.map +1 -0
- package/dist/config.d.mts +2 -1
- package/dist/config.d.mts.map +1 -0
- package/dist/config.mjs +2 -1
- package/dist/config.mjs.map +1 -0
- package/dist/contexts/command.cjs +21 -0
- package/dist/contexts/command.cjs.map +1 -0
- package/dist/contexts/command.d.cts +18 -0
- package/dist/contexts/command.d.cts.map +1 -0
- package/dist/contexts/command.d.mts +18 -0
- package/dist/contexts/command.d.mts.map +1 -0
- package/dist/contexts/command.mjs +19 -0
- package/dist/contexts/command.mjs.map +1 -0
- package/dist/contexts/index.cjs +4 -0
- package/dist/contexts/index.d.cts +2 -0
- package/dist/contexts/index.d.mts +2 -0
- package/dist/contexts/index.mjs +3 -0
- package/dist/helpers/automd.cjs +59 -0
- package/dist/helpers/automd.cjs.map +1 -0
- package/dist/helpers/automd.mjs +58 -0
- package/dist/helpers/automd.mjs.map +1 -0
- package/dist/helpers/docs-helpers.cjs +17 -0
- package/dist/helpers/docs-helpers.cjs.map +1 -0
- package/dist/helpers/docs-helpers.mjs +16 -0
- package/dist/helpers/docs-helpers.mjs.map +1 -0
- package/dist/helpers/persistence.cjs +2 -1
- package/dist/helpers/persistence.cjs.map +1 -0
- package/dist/helpers/persistence.mjs +2 -1
- package/dist/helpers/persistence.mjs.map +1 -0
- package/dist/helpers/resolve-command.cjs +118 -33
- package/dist/helpers/resolve-command.cjs.map +1 -0
- package/dist/helpers/resolve-command.mjs +116 -32
- package/dist/helpers/resolve-command.mjs.map +1 -0
- package/dist/helpers/update-package-json.cjs +18 -10
- package/dist/helpers/update-package-json.cjs.map +1 -0
- package/dist/helpers/update-package-json.mjs +17 -10
- package/dist/helpers/update-package-json.mjs.map +1 -0
- package/dist/helpers/utilities.cjs +30 -30
- package/dist/helpers/utilities.cjs.map +1 -0
- package/dist/helpers/utilities.mjs +29 -28
- package/dist/helpers/utilities.mjs.map +1 -0
- package/dist/helpers/validations.cjs +97 -0
- package/dist/helpers/validations.cjs.map +1 -0
- package/dist/helpers/validations.mjs +97 -0
- package/dist/helpers/validations.mjs.map +1 -0
- package/dist/index.cjs +5 -13
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -17
- package/dist/index.d.mts +6 -17
- package/dist/index.mjs +4 -13
- package/dist/index.mjs.map +1 -0
- package/dist/plugin-utils/context-helpers.cjs +86 -0
- package/dist/plugin-utils/context-helpers.cjs.map +1 -0
- package/dist/plugin-utils/context-helpers.d.cts +58 -0
- package/dist/plugin-utils/context-helpers.d.cts.map +1 -0
- package/dist/plugin-utils/context-helpers.d.mts +58 -0
- package/dist/plugin-utils/context-helpers.d.mts.map +1 -0
- package/dist/plugin-utils/context-helpers.mjs +79 -0
- package/dist/plugin-utils/context-helpers.mjs.map +1 -0
- package/dist/plugin-utils/get-command-tree.cjs +4 -2
- package/dist/plugin-utils/get-command-tree.cjs.map +1 -0
- package/dist/plugin-utils/get-command-tree.d.cts +2 -1
- package/dist/plugin-utils/get-command-tree.d.cts.map +1 -0
- package/dist/plugin-utils/get-command-tree.d.mts +2 -1
- package/dist/plugin-utils/get-command-tree.d.mts.map +1 -0
- package/dist/plugin-utils/get-command-tree.mjs +5 -2
- package/dist/plugin-utils/get-command-tree.mjs.map +1 -0
- package/dist/plugin-utils/index.cjs +14 -1
- package/dist/plugin-utils/index.d.cts +4 -1
- package/dist/plugin-utils/index.d.mts +4 -1
- package/dist/plugin-utils/index.mjs +4 -1
- package/dist/plugin-utils/reflect.cjs +25 -0
- package/dist/plugin-utils/reflect.cjs.map +1 -0
- package/dist/plugin-utils/reflect.d.cts +14 -0
- package/dist/plugin-utils/reflect.d.cts.map +1 -0
- package/dist/plugin-utils/reflect.d.mts +14 -0
- package/dist/plugin-utils/reflect.d.mts.map +1 -0
- package/dist/plugin-utils/reflect.mjs +24 -0
- package/dist/plugin-utils/reflect.mjs.map +1 -0
- package/dist/plugin-utils/traverse-command-tree.cjs +33 -0
- package/dist/plugin-utils/traverse-command-tree.cjs.map +1 -0
- package/dist/plugin-utils/traverse-command-tree.d.cts +23 -0
- package/dist/plugin-utils/traverse-command-tree.d.cts.map +1 -0
- package/dist/plugin-utils/traverse-command-tree.d.mts +23 -0
- package/dist/plugin-utils/traverse-command-tree.d.mts.map +1 -0
- package/dist/plugin-utils/traverse-command-tree.mjs +31 -0
- package/dist/plugin-utils/traverse-command-tree.mjs.map +1 -0
- package/dist/plugin.cjs +284 -0
- package/dist/plugin.cjs.map +1 -0
- package/dist/plugin.d.cts +13 -0
- package/dist/plugin.d.cts.map +1 -0
- package/dist/plugin.d.mts +13 -0
- package/dist/plugin.d.mts.map +1 -0
- package/dist/plugin.mjs +276 -0
- package/dist/plugin.mjs.map +1 -0
- package/dist/types/command.d.cts +14 -4
- package/dist/types/command.d.cts.map +1 -0
- package/dist/types/command.d.mts +14 -4
- package/dist/types/command.d.mts.map +1 -0
- package/dist/types/config.d.cts +74 -10
- package/dist/types/config.d.cts.map +1 -0
- package/dist/types/config.d.mts +74 -10
- package/dist/types/config.d.mts.map +1 -0
- package/dist/types/context.d.cts +7 -4
- package/dist/types/context.d.cts.map +1 -0
- package/dist/types/context.d.mts +7 -4
- package/dist/types/context.d.mts.map +1 -0
- package/dist/types/index.d.cts +4 -4
- package/dist/types/index.d.mts +4 -4
- package/dist/types/internal.cjs +0 -0
- package/dist/types/internal.d.cts +24 -0
- package/dist/types/internal.d.cts.map +1 -0
- package/dist/types/internal.d.mts +24 -0
- package/dist/types/internal.d.mts.map +1 -0
- package/dist/types/internal.mjs +1 -0
- package/dist/types/options.d.cts +2 -1
- package/dist/types/options.d.cts.map +1 -0
- package/dist/types/options.d.mts +2 -1
- package/dist/types/options.d.mts.map +1 -0
- package/dist/types/runtime.cjs +0 -0
- package/dist/types/runtime.d.cts +24 -0
- package/dist/types/runtime.d.cts.map +1 -0
- package/dist/types/runtime.d.mts +24 -0
- package/dist/types/runtime.d.mts.map +1 -0
- package/dist/types/runtime.mjs +1 -0
- package/package.json +223 -91
- package/dist/components/utils-builtin.cjs +0 -453
- package/dist/components/utils-builtin.d.cts +0 -27
- package/dist/components/utils-builtin.d.mts +0 -27
- package/dist/components/utils-builtin.mjs +0 -447
- package/dist/powerlines.cjs +0 -172
- package/dist/powerlines.d.cts +0 -12
- package/dist/powerlines.d.mts +0 -12
- package/dist/powerlines.mjs +0 -168
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getAppName } from "../plugin-utils/context-helpers.mjs";
|
|
2
|
+
import { toArray } from "@stryke/convert/to-array";
|
|
2
3
|
import { joinPaths } from "@stryke/path/join-paths";
|
|
3
|
-
import {
|
|
4
|
+
import { kebabCase } from "@stryke/string-format/kebab-case";
|
|
4
5
|
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
5
|
-
import {
|
|
6
|
+
import { getUnique } from "@stryke/helpers/get-unique";
|
|
6
7
|
import { StormJSON } from "@stryke/json/storm-json";
|
|
7
|
-
import { kebabCase } from "@stryke/string-format/kebab-case";
|
|
8
8
|
|
|
9
9
|
//#region src/helpers/update-package-json.ts
|
|
10
|
-
function formatBinaryPath(
|
|
11
|
-
return `./bin
|
|
10
|
+
function formatBinaryPath(format) {
|
|
11
|
+
return `./dist/bin.${format === "cjs" || Array.isArray(format) && format.includes("cjs") ? "cjs" : "mjs"}`;
|
|
12
12
|
}
|
|
13
13
|
async function updatePackageJsonBinary(context) {
|
|
14
14
|
const packageJsonPath = joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot, "package.json");
|
|
15
15
|
if (context.config.bin && Array.isArray(context.config.bin) && context.config.bin.length > 0) {
|
|
16
|
-
context.packageJson.bin = Object.fromEntries(getUnique(toArray(context.config.bin)).map((bin) => [bin, formatBinaryPath(
|
|
16
|
+
context.packageJson.bin = Object.fromEntries(getUnique(toArray(context.config.bin)).map((bin) => [bin, formatBinaryPath(context.config.output.format)]));
|
|
17
17
|
await context.fs.write(packageJsonPath, StormJSON.stringify(context.packageJson));
|
|
18
|
-
} else
|
|
19
|
-
|
|
18
|
+
} else {
|
|
19
|
+
if (Array.isArray(context.config.output.format) && context.config.output.format.length > 1) {
|
|
20
|
+
context.packageJson.bin = { [kebabCase(getAppName(context))]: formatBinaryPath(toArray(context.config.output.format)[0]) };
|
|
21
|
+
context.packageJson.bin = toArray(context.config.output.format).reduce((ret, format) => {
|
|
22
|
+
ret[`${kebabCase(getAppName(context))}-${format}`] = formatBinaryPath(format);
|
|
23
|
+
return ret;
|
|
24
|
+
}, context.packageJson.bin);
|
|
25
|
+
} else context.packageJson.bin = { [kebabCase(getAppName(context))]: formatBinaryPath(context.config.output.format) };
|
|
20
26
|
await context.fs.write(packageJsonPath, StormJSON.stringify(context.packageJson));
|
|
21
27
|
}
|
|
22
28
|
if (!isSetObject(context.packageJson.bin)) throw new Error("Unable to determine the CLI binary name. Please specify the `bin` option in your Shell Shock configuration or ensure that the `name` field is set in your package.json.");
|
|
@@ -24,4 +30,5 @@ async function updatePackageJsonBinary(context) {
|
|
|
24
30
|
}
|
|
25
31
|
|
|
26
32
|
//#endregion
|
|
27
|
-
export { updatePackageJsonBinary };
|
|
33
|
+
export { formatBinaryPath, updatePackageJsonBinary };
|
|
34
|
+
//# sourceMappingURL=update-package-json.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-package-json.mjs","names":["toArray","getUnique","StormJSON","joinPaths","kebabCase","isSetObject","getAppName","formatBinaryPath","format","Array","isArray","includes","updatePackageJsonBinary","context","packageJsonPath","workspaceConfig","workspaceRoot","config","projectRoot","bin","length","packageJson","Object","fromEntries","map","output","fs","write","stringify","reduce","ret","Error","keys"],"sources":["../../src/helpers/update-package-json.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 { toArray } from \"@stryke/convert/to-array\";\nimport { getUnique } from \"@stryke/helpers/get-unique\";\nimport { StormJSON } from \"@stryke/json/storm-json\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { getAppName } from \"../plugin-utils/context-helpers\";\nimport type { UnresolvedContext } from \"../types/context\";\n\nexport function formatBinaryPath(\n format: string | string[] | undefined\n): string {\n return `./dist/bin.${\n format === \"cjs\" || (Array.isArray(format) && format.includes(\"cjs\"))\n ? \"cjs\"\n : \"mjs\"\n }`;\n}\n\nexport async function updatePackageJsonBinary(\n context: UnresolvedContext\n): Promise<void> {\n const packageJsonPath = joinPaths(\n context.workspaceConfig.workspaceRoot,\n context.config.projectRoot,\n \"package.json\"\n );\n if (\n context.config.bin &&\n Array.isArray(context.config.bin) &&\n context.config.bin.length > 0\n ) {\n context.packageJson.bin = Object.fromEntries(\n getUnique(toArray(context.config.bin)).map(bin => [\n bin,\n formatBinaryPath(context.config.output.format)\n ])\n );\n\n await context.fs.write(\n packageJsonPath,\n StormJSON.stringify(context.packageJson)\n );\n } else {\n if (\n Array.isArray(context.config.output.format) &&\n context.config.output.format.length > 1\n ) {\n context.packageJson.bin = {\n [kebabCase(getAppName(context))]: formatBinaryPath(\n toArray(context.config.output.format)[0]\n )\n };\n context.packageJson.bin = toArray(context.config.output.format).reduce(\n (ret, format) => {\n ret[`${kebabCase(getAppName(context))}-${format}`] =\n formatBinaryPath(format);\n\n return ret;\n },\n context.packageJson.bin\n );\n } else {\n context.packageJson.bin = {\n [kebabCase(getAppName(context))]: formatBinaryPath(\n context.config.output.format\n )\n };\n }\n\n await context.fs.write(\n packageJsonPath,\n StormJSON.stringify(context.packageJson)\n );\n }\n\n if (!isSetObject(context.packageJson.bin)) {\n throw new Error(\n \"Unable to determine the CLI binary name. Please specify the `bin` option in your Shell Shock configuration or ensure that the `name` field is set in your package.json.\"\n );\n }\n\n context.config.bin = Object.keys(context.packageJson.bin);\n}\n"],"mappings":";;;;;;;;;AA2BA,SAAgBO,iBACdC,QACQ;AACR,QAAO,cACLA,WAAW,SAAUC,MAAMC,QAAQF,OAAO,IAAIA,OAAOG,SAAS,MAAO,GACjE,QACA;;AAIR,eAAsBC,wBACpBC,SACe;CACf,MAAMC,kBAAkBX,UACtBU,QAAQE,gBAAgBC,eACxBH,QAAQI,OAAOC,aACf,eACD;AACD,KACEL,QAAQI,OAAOE,OACfV,MAAMC,QAAQG,QAAQI,OAAOE,IAAI,IACjCN,QAAQI,OAAOE,IAAIC,SAAS,GAC5B;AACAP,UAAQQ,YAAYF,MAAMG,OAAOC,YAC/BtB,UAAUD,QAAQa,QAAQI,OAAOE,IAAI,CAAC,CAACK,KAAIL,QAAO,CAChDA,KACAZ,iBAAiBM,QAAQI,OAAOQ,OAAOjB,OAAO,CAC/C,CACH,CAAC;AAED,QAAMK,QAAQa,GAAGC,MACfb,iBACAZ,UAAU0B,UAAUf,QAAQQ,YAC9B,CAAC;QACI;AACL,MACEZ,MAAMC,QAAQG,QAAQI,OAAOQ,OAAOjB,OAAO,IAC3CK,QAAQI,OAAOQ,OAAOjB,OAAOY,SAAS,GACtC;AACAP,WAAQQ,YAAYF,MAAM,GACvBf,UAAUE,WAAWO,QAAQ,CAAC,GAAGN,iBAChCP,QAAQa,QAAQI,OAAOQ,OAAOjB,OAAO,CAAC,GACxC,EACD;AACDK,WAAQQ,YAAYF,MAAMnB,QAAQa,QAAQI,OAAOQ,OAAOjB,OAAO,CAACqB,QAC7DC,KAAKtB,WAAW;AACfsB,QAAI,GAAG1B,UAAUE,WAAWO,QAAQ,CAAC,CAAA,GAAIL,YACvCD,iBAAiBC,OAAO;AAE1B,WAAOsB;MAETjB,QAAQQ,YAAYF,IACrB;QAEDN,SAAQQ,YAAYF,MAAM,GACvBf,UAAUE,WAAWO,QAAQ,CAAC,GAAGN,iBAChCM,QAAQI,OAAOQ,OAAOjB,OACxB,EACD;AAGH,QAAMK,QAAQa,GAAGC,MACfb,iBACAZ,UAAU0B,UAAUf,QAAQQ,YAC9B,CAAC;;AAGH,KAAI,CAAChB,YAAYQ,QAAQQ,YAAYF,IAAI,CACvC,OAAM,IAAIY,MACR,0KACD;AAGHlB,SAAQI,OAAOE,MAAMG,OAAOU,KAAKnB,QAAQQ,YAAYF,IAAI"}
|
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
3
|
-
let
|
|
4
|
-
let
|
|
2
|
+
let __stryke_string_format_constant_case = require("@stryke/string-format/constant-case");
|
|
3
|
+
let __stryke_cli_utils_tree = require("@stryke/cli/utils/tree");
|
|
4
|
+
let __stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
|
|
5
|
+
let __stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
5
6
|
|
|
6
7
|
//#region src/helpers/utilities.ts
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* @throws An error if no valid application name is found.
|
|
13
|
-
*/
|
|
14
|
-
function getAppName(context) {
|
|
15
|
-
const result = context.config.bin && ((0, __stryke_type_checks_is_set_string.isSetString)(context.config.bin) || Array.isArray(context.config.bin) && context.config.bin.length > 0 && context.config.bin[0]) ? (0, __stryke_type_checks_is_set_string.isSetString)(context.config.bin) ? context.config.bin : context.config.bin[0] : context.config.name || context.packageJson?.name;
|
|
16
|
-
if (!(0, __stryke_type_checks_is_set_string.isSetString)(result)) throw new Error("No application name found. Please provide a 'bin' option in the configuration or ensure the package.json has a valid 'name' field.");
|
|
17
|
-
return (0, __stryke_string_format_kebab_case.kebabCase)(result);
|
|
8
|
+
function innerFormatCommandTree(command) {
|
|
9
|
+
return {
|
|
10
|
+
name: `${command.name}${command.isVirtual ? " (virtual)" : ""}`,
|
|
11
|
+
children: Object.values(command.children ?? {}).map(innerFormatCommandTree)
|
|
12
|
+
};
|
|
18
13
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*/
|
|
25
|
-
function getAppTitle(context) {
|
|
26
|
-
return (0, __stryke_string_format_title_case.titleCase)(context.config.name || getAppName(context));
|
|
14
|
+
function formatCommandTree(context) {
|
|
15
|
+
return (0, __stryke_cli_utils_tree.formatTree)({
|
|
16
|
+
name: context.config.name,
|
|
17
|
+
children: Object.values(context.commands ?? {}).map(innerFormatCommandTree)
|
|
18
|
+
});
|
|
27
19
|
}
|
|
28
20
|
/**
|
|
29
|
-
* Retrieves the
|
|
21
|
+
* Retrieves the default command options based on the context configuration.
|
|
30
22
|
*
|
|
31
|
-
* @param context - The build context
|
|
32
|
-
* @
|
|
23
|
+
* @param context - The build context.
|
|
24
|
+
* @param command - The command for which to retrieve default options.
|
|
25
|
+
* @returns A record of default command options.
|
|
33
26
|
*/
|
|
34
|
-
function
|
|
35
|
-
|
|
27
|
+
function getDefaultOptions(context, command) {
|
|
28
|
+
let options;
|
|
29
|
+
if (Array.isArray(context.config.defaultOptions)) options = Object.fromEntries((0, __stryke_helpers_get_unique.getUniqueBy)(context.config.defaultOptions, (item) => item.name).map((option) => [option.name, option]));
|
|
30
|
+
else if ((0, __stryke_type_checks_is_function.isFunction)(context.config.defaultOptions)) options = Object.fromEntries((0, __stryke_helpers_get_unique.getUniqueBy)(context.config.defaultOptions(context, command), (item) => item.name).map((option) => [option.name, option]));
|
|
31
|
+
else options = {};
|
|
32
|
+
return Object.fromEntries(Object.entries(options).map(([key, value]) => [key, {
|
|
33
|
+
...value,
|
|
34
|
+
env: value.env ?? (0, __stryke_string_format_constant_case.constantCase)(key)
|
|
35
|
+
}]));
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
//#endregion
|
|
39
|
-
exports.
|
|
40
|
-
exports.
|
|
41
|
-
|
|
39
|
+
exports.formatCommandTree = formatCommandTree;
|
|
40
|
+
exports.getDefaultOptions = getDefaultOptions;
|
|
41
|
+
//# sourceMappingURL=utilities.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.cjs","names":["formatTree","getUniqueBy","constantCase","isFunction","innerFormatCommandTree","command","name","isVirtual","children","Object","values","map","formatCommandTree","context","config","commands","getDefaultOptions","options","Array","isArray","defaultOptions","fromEntries","item","option","entries","key","value","env"],"sources":["../../src/helpers/utilities.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 { TreeItem } from \"@stryke/cli/utils/tree\";\nimport { formatTree } from \"@stryke/cli/utils/tree\";\nimport { getUniqueBy } from \"@stryke/helpers/get-unique\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport type { CommandBase, CommandOption, CommandTree } from \"../types/command\";\nimport type { Context } from \"../types/context\";\n\nfunction innerFormatCommandTree(command: CommandTree): TreeItem {\n return {\n name: `${command.name}${command.isVirtual ? \" (virtual)\" : \"\"}`,\n children: Object.values(command.children ?? {}).map(innerFormatCommandTree)\n };\n}\n\nexport function formatCommandTree(context: Context): string {\n return formatTree({\n name: context.config.name,\n children: Object.values(context.commands ?? {}).map(innerFormatCommandTree)\n });\n}\n\n/**\n * Retrieves the default command options based on the context configuration.\n *\n * @param context - The build context.\n * @param command - The command for which to retrieve default options.\n * @returns A record of default command options.\n */\nexport function getDefaultOptions(\n context: Context,\n command: CommandBase\n): Record<string, CommandOption> {\n let options!: Record<string, CommandOption>;\n if (Array.isArray(context.config.defaultOptions)) {\n options = Object.fromEntries(\n getUniqueBy(\n context.config.defaultOptions,\n (item: CommandOption) => item.name\n ).map(option => [option.name, option])\n );\n } else if (isFunction(context.config.defaultOptions)) {\n options = Object.fromEntries(\n getUniqueBy(\n context.config.defaultOptions(context, command),\n (item: CommandOption) => item.name\n ).map(option => [option.name, option])\n );\n } else {\n options = {};\n }\n\n return Object.fromEntries(\n Object.entries(options).map(([key, value]) => [\n key,\n { ...value, env: value.env ?? constantCase(key) }\n ])\n );\n}\n"],"mappings":";;;;;;;AA0BA,SAASI,uBAAuBC,SAAgC;AAC9D,QAAO;EACLC,MAAM,GAAGD,QAAQC,OAAOD,QAAQE,YAAY,eAAe;EAC3DC,UAAUC,OAAOC,OAAOL,QAAQG,YAAY,EAAE,CAAC,CAACG,IAAIP,uBAAsB;EAC3E;;AAGH,SAAgBQ,kBAAkBC,SAA0B;AAC1D,gDAAkB;EAChBP,MAAMO,QAAQC,OAAOR;EACrBE,UAAUC,OAAOC,OAAOG,QAAQE,YAAY,EAAE,CAAC,CAACJ,IAAIP,uBAAsB;EAC3E,CAAC;;;;;;;;;AAUJ,SAAgBY,kBACdH,SACAR,SAC+B;CAC/B,IAAIY;AACJ,KAAIC,MAAMC,QAAQN,QAAQC,OAAOM,eAAe,CAC9CH,WAAUR,OAAOY,yDAEbR,QAAQC,OAAOM,iBACdE,SAAwBA,KAAKhB,KAC/B,CAACK,KAAIY,WAAU,CAACA,OAAOjB,MAAMiB,OAAO,CACvC,CAAC;2DACmBV,QAAQC,OAAOM,eAAe,CAClDH,WAAUR,OAAOY,yDAEbR,QAAQC,OAAOM,eAAeP,SAASR,QAAQ,GAC9CiB,SAAwBA,KAAKhB,KAC/B,CAACK,KAAIY,WAAU,CAACA,OAAOjB,MAAMiB,OAAO,CACvC,CAAC;KAEDN,WAAU,EAAE;AAGd,QAAOR,OAAOY,YACZZ,OAAOe,QAAQP,QAAQ,CAACN,KAAK,CAACc,KAAKC,WAAW,CAC5CD,KACA;EAAE,GAAGC;EAAOC,KAAKD,MAAMC,8DAAoBF,IAAG;EAAG,CAClD,CACH,CAAC"}
|
|
@@ -1,38 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { constantCase } from "@stryke/string-format/constant-case";
|
|
2
|
+
import { formatTree } from "@stryke/cli/utils/tree";
|
|
3
|
+
import { getUniqueBy } from "@stryke/helpers/get-unique";
|
|
4
|
+
import { isFunction } from "@stryke/type-checks/is-function";
|
|
4
5
|
|
|
5
6
|
//#region src/helpers/utilities.ts
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @throws An error if no valid application name is found.
|
|
12
|
-
*/
|
|
13
|
-
function getAppName(context) {
|
|
14
|
-
const result = context.config.bin && (isSetString(context.config.bin) || Array.isArray(context.config.bin) && context.config.bin.length > 0 && context.config.bin[0]) ? isSetString(context.config.bin) ? context.config.bin : context.config.bin[0] : context.config.name || context.packageJson?.name;
|
|
15
|
-
if (!isSetString(result)) throw new Error("No application name found. Please provide a 'bin' option in the configuration or ensure the package.json has a valid 'name' field.");
|
|
16
|
-
return kebabCase(result);
|
|
7
|
+
function innerFormatCommandTree(command) {
|
|
8
|
+
return {
|
|
9
|
+
name: `${command.name}${command.isVirtual ? " (virtual)" : ""}`,
|
|
10
|
+
children: Object.values(command.children ?? {}).map(innerFormatCommandTree)
|
|
11
|
+
};
|
|
17
12
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*/
|
|
24
|
-
function getAppTitle(context) {
|
|
25
|
-
return titleCase(context.config.name || getAppName(context));
|
|
13
|
+
function formatCommandTree(context) {
|
|
14
|
+
return formatTree({
|
|
15
|
+
name: context.config.name,
|
|
16
|
+
children: Object.values(context.commands ?? {}).map(innerFormatCommandTree)
|
|
17
|
+
});
|
|
26
18
|
}
|
|
27
19
|
/**
|
|
28
|
-
* Retrieves the
|
|
20
|
+
* Retrieves the default command options based on the context configuration.
|
|
29
21
|
*
|
|
30
|
-
* @param context - The build context
|
|
31
|
-
* @
|
|
22
|
+
* @param context - The build context.
|
|
23
|
+
* @param command - The command for which to retrieve default options.
|
|
24
|
+
* @returns A record of default command options.
|
|
32
25
|
*/
|
|
33
|
-
function
|
|
34
|
-
|
|
26
|
+
function getDefaultOptions(context, command) {
|
|
27
|
+
let options;
|
|
28
|
+
if (Array.isArray(context.config.defaultOptions)) options = Object.fromEntries(getUniqueBy(context.config.defaultOptions, (item) => item.name).map((option) => [option.name, option]));
|
|
29
|
+
else if (isFunction(context.config.defaultOptions)) options = Object.fromEntries(getUniqueBy(context.config.defaultOptions(context, command), (item) => item.name).map((option) => [option.name, option]));
|
|
30
|
+
else options = {};
|
|
31
|
+
return Object.fromEntries(Object.entries(options).map(([key, value]) => [key, {
|
|
32
|
+
...value,
|
|
33
|
+
env: value.env ?? constantCase(key)
|
|
34
|
+
}]));
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
//#endregion
|
|
38
|
-
export {
|
|
38
|
+
export { formatCommandTree, getDefaultOptions };
|
|
39
|
+
//# sourceMappingURL=utilities.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.mjs","names":["formatTree","getUniqueBy","constantCase","isFunction","innerFormatCommandTree","command","name","isVirtual","children","Object","values","map","formatCommandTree","context","config","commands","getDefaultOptions","options","Array","isArray","defaultOptions","fromEntries","item","option","entries","key","value","env"],"sources":["../../src/helpers/utilities.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 { TreeItem } from \"@stryke/cli/utils/tree\";\nimport { formatTree } from \"@stryke/cli/utils/tree\";\nimport { getUniqueBy } from \"@stryke/helpers/get-unique\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport type { CommandBase, CommandOption, CommandTree } from \"../types/command\";\nimport type { Context } from \"../types/context\";\n\nfunction innerFormatCommandTree(command: CommandTree): TreeItem {\n return {\n name: `${command.name}${command.isVirtual ? \" (virtual)\" : \"\"}`,\n children: Object.values(command.children ?? {}).map(innerFormatCommandTree)\n };\n}\n\nexport function formatCommandTree(context: Context): string {\n return formatTree({\n name: context.config.name,\n children: Object.values(context.commands ?? {}).map(innerFormatCommandTree)\n });\n}\n\n/**\n * Retrieves the default command options based on the context configuration.\n *\n * @param context - The build context.\n * @param command - The command for which to retrieve default options.\n * @returns A record of default command options.\n */\nexport function getDefaultOptions(\n context: Context,\n command: CommandBase\n): Record<string, CommandOption> {\n let options!: Record<string, CommandOption>;\n if (Array.isArray(context.config.defaultOptions)) {\n options = Object.fromEntries(\n getUniqueBy(\n context.config.defaultOptions,\n (item: CommandOption) => item.name\n ).map(option => [option.name, option])\n );\n } else if (isFunction(context.config.defaultOptions)) {\n options = Object.fromEntries(\n getUniqueBy(\n context.config.defaultOptions(context, command),\n (item: CommandOption) => item.name\n ).map(option => [option.name, option])\n );\n } else {\n options = {};\n }\n\n return Object.fromEntries(\n Object.entries(options).map(([key, value]) => [\n key,\n { ...value, env: value.env ?? constantCase(key) }\n ])\n );\n}\n"],"mappings":";;;;;;AA0BA,SAASI,uBAAuBC,SAAgC;AAC9D,QAAO;EACLC,MAAM,GAAGD,QAAQC,OAAOD,QAAQE,YAAY,eAAe;EAC3DC,UAAUC,OAAOC,OAAOL,QAAQG,YAAY,EAAE,CAAC,CAACG,IAAIP,uBAAsB;EAC3E;;AAGH,SAAgBQ,kBAAkBC,SAA0B;AAC1D,QAAOb,WAAW;EAChBM,MAAMO,QAAQC,OAAOR;EACrBE,UAAUC,OAAOC,OAAOG,QAAQE,YAAY,EAAE,CAAC,CAACJ,IAAIP,uBAAsB;EAC3E,CAAC;;;;;;;;;AAUJ,SAAgBY,kBACdH,SACAR,SAC+B;CAC/B,IAAIY;AACJ,KAAIC,MAAMC,QAAQN,QAAQC,OAAOM,eAAe,CAC9CH,WAAUR,OAAOY,YACfpB,YACEY,QAAQC,OAAOM,iBACdE,SAAwBA,KAAKhB,KAC/B,CAACK,KAAIY,WAAU,CAACA,OAAOjB,MAAMiB,OAAO,CACvC,CAAC;UACQpB,WAAWU,QAAQC,OAAOM,eAAe,CAClDH,WAAUR,OAAOY,YACfpB,YACEY,QAAQC,OAAOM,eAAeP,SAASR,QAAQ,GAC9CiB,SAAwBA,KAAKhB,KAC/B,CAACK,KAAIY,WAAU,CAACA,OAAOjB,MAAMiB,OAAO,CACvC,CAAC;KAEDN,WAAU,EAAE;AAGd,QAAOR,OAAOY,YACZZ,OAAOe,QAAQP,QAAQ,CAACN,KAAK,CAACc,KAAKC,WAAW,CAC5CD,KACA;EAAE,GAAGC;EAAOC,KAAKD,MAAMC,OAAOzB,aAAauB,IAAG;EAAG,CAClD,CACH,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const require_plugin_utils_context_helpers = require('../plugin-utils/context-helpers.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/helpers/validations.ts
|
|
4
|
+
function validateCommandVariablePaths(command) {
|
|
5
|
+
const failures = [];
|
|
6
|
+
if (!command.isVirtual && command.path.segments.length > 0) {
|
|
7
|
+
const variablePathNames = /* @__PURE__ */ new Set();
|
|
8
|
+
for (const segment of command.path.segments.filter(require_plugin_utils_context_helpers.isVariableCommandPath) ?? []) {
|
|
9
|
+
if (variablePathNames.has(segment)) failures.push({
|
|
10
|
+
code: "DUPLICATE_VARIABLE_PATH_NAME",
|
|
11
|
+
details: `Duplicate variable path name "${require_plugin_utils_context_helpers.getVariableCommandPathName(segment)}" found in command.`
|
|
12
|
+
});
|
|
13
|
+
variablePathNames.add(require_plugin_utils_context_helpers.getVariableCommandPathName(segment));
|
|
14
|
+
}
|
|
15
|
+
if (command.path.segments.filter(require_plugin_utils_context_helpers.isVariableCommandPath).length !== Object.keys(command.path.variables ?? {}).length) failures.push({
|
|
16
|
+
code: "VARIABLE_PATH_MISMATCH",
|
|
17
|
+
details: `Mismatch between variable path segments and defined path variables in command (found ${command.path.segments.filter(require_plugin_utils_context_helpers.isVariableCommandPath).length} variables in the command folder path "${command.path.segments.join("/")}", but ${Object.keys(command.path.variables ?? {}).length} potential variable path(s) could be determined from the command's function signature).`
|
|
18
|
+
});
|
|
19
|
+
const missing = command.path.segments.filter(require_plugin_utils_context_helpers.isVariableCommandPath).filter((segment) => Object.prototype.hasOwnProperty.call(command.path.variables ?? {}, require_plugin_utils_context_helpers.getVariableCommandPathName(segment)) === false);
|
|
20
|
+
if (missing.length > 0) failures.push({
|
|
21
|
+
code: "MISSING_VARIABLE_PATH",
|
|
22
|
+
details: `${missing.length} variable path segment${missing.length > 1 ? "s" : ""} in the command folder path "${command.path.segments.join("/")}" do${missing.length > 1 ? "" : "es"} not have corresponding entr${missing.length > 1 ? "ies" : "y"} in the command's path variables: \n- ${missing.map((segment) => `"${require_plugin_utils_context_helpers.getVariableCommandPathName(segment)}"`).join("\n- ")}`
|
|
23
|
+
});
|
|
24
|
+
else {
|
|
25
|
+
for (const varName of Object.keys(command.path.variables ?? {})) if (!command.path.segments.filter(require_plugin_utils_context_helpers.isVariableCommandPath).find((segment) => require_plugin_utils_context_helpers.getVariableCommandPathName(segment) === varName)) failures.push({
|
|
26
|
+
code: "UNUSED_VARIABLE_PATH",
|
|
27
|
+
details: `The variable path name "${varName}" defined in the command's path variables is not used in the command folder path "${command.path.segments.join("/")}".`
|
|
28
|
+
});
|
|
29
|
+
command.path.segments.forEach((segment, index) => {
|
|
30
|
+
if (require_plugin_utils_context_helpers.isVariableCommandPath(segment) && command.path.variables[require_plugin_utils_context_helpers.getVariableCommandPathName(segment)]?.variadic === true && index + 1 < command.path.segments.length && command.path.segments[index + 1] && command.path.variables[require_plugin_utils_context_helpers.getVariableCommandPathName(command.path.segments[index + 1])]?.variadic === true) failures.push({
|
|
31
|
+
code: "MULTIPLE_VARIADIC_VARIABLE_PATHS",
|
|
32
|
+
details: `The variable path segment "${require_plugin_utils_context_helpers.getVariableCommandPathName(segment)}" in the command at path "${command.path.segments.join("/")}" is marked as variadic, and it is followed by another variadic variable path segment "${require_plugin_utils_context_helpers.getVariableCommandPathName(command.path.segments[index + 1])}". Only one variadic variable path segment is allowed per command, and it must be the final path segment.`
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return failures;
|
|
38
|
+
}
|
|
39
|
+
function validateCommandOptions(command) {
|
|
40
|
+
const failures = [];
|
|
41
|
+
const optionNames = /* @__PURE__ */ new Set();
|
|
42
|
+
for (const option of Object.values(command.options ?? {})) {
|
|
43
|
+
if (optionNames.has(option.name)) failures.push({
|
|
44
|
+
code: "DUPLICATE_OPTION_NAME",
|
|
45
|
+
details: `Duplicate option name "${option.name}" found in command.`
|
|
46
|
+
});
|
|
47
|
+
optionNames.add(option.name);
|
|
48
|
+
for (const alias of option.alias) {
|
|
49
|
+
if (optionNames.has(alias)) failures.push({
|
|
50
|
+
code: "DUPLICATE_OPTION_ALIAS",
|
|
51
|
+
details: `Duplicate option name "${alias}" (an alias of "${option.name}") found in command.`
|
|
52
|
+
});
|
|
53
|
+
optionNames.add(alias);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return failures;
|
|
57
|
+
}
|
|
58
|
+
function validateCommandParams(command) {
|
|
59
|
+
const failures = [];
|
|
60
|
+
if (!command.isVirtual && command.params.length > 0) {
|
|
61
|
+
const paramNames = /* @__PURE__ */ new Set();
|
|
62
|
+
command.params.forEach((param, index) => {
|
|
63
|
+
if (paramNames.has(param.name)) failures.push({
|
|
64
|
+
code: "DUPLICATE_PARAM_NAME",
|
|
65
|
+
details: `Duplicate parameter name "${param.name}" found in command.`
|
|
66
|
+
});
|
|
67
|
+
paramNames.add(param.name);
|
|
68
|
+
if (param.optional) command.params.slice(index + 1).forEach((nextParam) => {
|
|
69
|
+
if (nextParam.optional && !nextParam.default) failures.push({
|
|
70
|
+
code: "OPTIONAL_PARAM_NOT_LAST",
|
|
71
|
+
details: `The parameter "${nextParam.name}" in the command at path "${command.path.segments.join("/")}" is required, but it follows an optional parameter "${param.name}". All required parameters must come before any optional parameters.`
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
if (param.variadic && index + 1 < command.params.length) {
|
|
75
|
+
if (command.params[index + 1]?.variadic) failures.push({
|
|
76
|
+
code: "MULTIPLE_VARIADIC_PARAMS",
|
|
77
|
+
details: `The parameter "${param.name}" in the command at path "${command.path.segments.join("/")}" is variadic, and it is followed by another variadic parameter "${command.params[index + 1]?.name}". Only one variadic parameter is allowed per command, and it must be the final parameter.`
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return failures;
|
|
83
|
+
}
|
|
84
|
+
function validateCommand(command) {
|
|
85
|
+
const results = [];
|
|
86
|
+
let failures = validateCommandVariablePaths(command);
|
|
87
|
+
if (failures.length > 0) results.push(...failures);
|
|
88
|
+
failures = validateCommandParams(command);
|
|
89
|
+
if (failures.length > 0) results.push(...failures);
|
|
90
|
+
failures = validateCommandOptions(command);
|
|
91
|
+
if (failures.length > 0) results.push(...failures);
|
|
92
|
+
return results;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
exports.validateCommand = validateCommand;
|
|
97
|
+
//# sourceMappingURL=validations.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validations.cjs","names":["getVariableCommandPathName","isVariableCommandPath","validateCommandVariablePaths","command","failures","isVirtual","path","segments","length","variablePathNames","Set","segment","filter","has","push","code","details","add","Object","keys","variables","join","missing","prototype","hasOwnProperty","call","map","varName","find","forEach","index","variadic","validateCommandOptions","optionNames","option","values","options","name","alias","validateCommandParams","params","paramNames","param","optional","slice","nextParam","default","validateCommand","results"],"sources":["../../src/helpers/validations.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 {\n getVariableCommandPathName,\n isVariableCommandPath\n} from \"../plugin-utils/context-helpers\";\nimport type { CommandTree } from \"../types\";\n\nexport interface ValidationFailure {\n code: string;\n details: string;\n}\n\nexport function validateCommandVariablePaths(\n command: CommandTree\n): ValidationFailure[] {\n const failures: ValidationFailure[] = [];\n if (!command.isVirtual && command.path.segments.length > 0) {\n const variablePathNames = new Set<string>();\n for (const segment of command.path.segments.filter(isVariableCommandPath) ??\n []) {\n if (variablePathNames.has(segment)) {\n failures.push({\n code: \"DUPLICATE_VARIABLE_PATH_NAME\",\n details: `Duplicate variable path name \"${getVariableCommandPathName(segment)}\" found in command.`\n });\n }\n variablePathNames.add(getVariableCommandPathName(segment));\n }\n\n if (\n command.path.segments.filter(isVariableCommandPath).length !==\n Object.keys(command.path.variables ?? {}).length\n ) {\n failures.push({\n code: \"VARIABLE_PATH_MISMATCH\",\n details: `Mismatch between variable path segments and defined path variables in command (found ${\n command.path.segments.filter(isVariableCommandPath).length\n } variables in the command folder path \"${command.path.segments.join(\"/\")}\", but ${\n Object.keys(command.path.variables ?? {}).length\n } potential variable path(s) could be determined from the command's function signature).`\n });\n }\n\n const missing = command.path.segments\n .filter(isVariableCommandPath)\n .filter(\n segment =>\n Object.prototype.hasOwnProperty.call(\n command.path.variables ?? {},\n getVariableCommandPathName(segment)\n ) === false\n );\n if (missing.length > 0) {\n failures.push({\n code: \"MISSING_VARIABLE_PATH\",\n details: `${missing.length} variable path segment${missing.length > 1 ? \"s\" : \"\"} in the command folder path \"${command.path.segments.join(\n \"/\"\n )}\" do${missing.length > 1 ? \"\" : \"es\"} not have corresponding entr${\n missing.length > 1 ? \"ies\" : \"y\"\n } in the command's path variables: \\n- ${missing\n .map(segment => `\"${getVariableCommandPathName(segment)}\"`)\n .join(\"\\n- \")}`\n });\n } else {\n for (const varName of Object.keys(command.path.variables ?? {})) {\n if (\n !command.path.segments\n .filter(isVariableCommandPath)\n .find(segment => getVariableCommandPathName(segment) === varName)\n ) {\n failures.push({\n code: \"UNUSED_VARIABLE_PATH\",\n details: `The variable path name \"${varName}\" defined in the command's path variables is not used in the command folder path \"${command.path.segments.join(\n \"/\"\n )}\".`\n });\n }\n }\n\n command.path.segments.forEach((segment, index) => {\n if (\n isVariableCommandPath(segment) &&\n command.path.variables[getVariableCommandPathName(segment)]\n ?.variadic === true &&\n index + 1 < command.path.segments.length &&\n command.path.segments[index + 1] &&\n command.path.variables[\n getVariableCommandPathName(command.path.segments[index + 1]!)\n ]?.variadic === true\n ) {\n failures.push({\n code: \"MULTIPLE_VARIADIC_VARIABLE_PATHS\",\n details: `The variable path segment \"${getVariableCommandPathName(\n segment\n )}\" in the command at path \"${command.path.segments.join(\n \"/\"\n )}\" is marked as variadic, and it is followed by another variadic variable path segment \"${getVariableCommandPathName(\n command.path.segments[index + 1]!\n )}\". Only one variadic variable path segment is allowed per command, and it must be the final path segment.`\n });\n }\n });\n }\n }\n\n return failures;\n}\n\nexport function validateCommandOptions(\n command: CommandTree\n): ValidationFailure[] {\n const failures: ValidationFailure[] = [];\n\n const optionNames = new Set<string>();\n for (const option of Object.values(command.options ?? {})) {\n if (optionNames.has(option.name)) {\n failures.push({\n code: \"DUPLICATE_OPTION_NAME\",\n details: `Duplicate option name \"${option.name}\" found in command.`\n });\n }\n optionNames.add(option.name);\n\n for (const alias of option.alias) {\n if (optionNames.has(alias)) {\n failures.push({\n code: \"DUPLICATE_OPTION_ALIAS\",\n details: `Duplicate option name \"${alias}\" (an alias of \"${\n option.name\n }\") found in command.`\n });\n }\n optionNames.add(alias);\n }\n }\n\n return failures;\n}\n\nexport function validateCommandParams(\n command: CommandTree\n): ValidationFailure[] {\n const failures: ValidationFailure[] = [];\n if (!command.isVirtual && command.params.length > 0) {\n const paramNames = new Set<string>();\n command.params.forEach((param, index) => {\n if (paramNames.has(param.name)) {\n failures.push({\n code: \"DUPLICATE_PARAM_NAME\",\n details: `Duplicate parameter name \"${param.name}\" found in command.`\n });\n }\n paramNames.add(param.name);\n\n if (param.optional) {\n command.params.slice(index + 1).forEach(nextParam => {\n if (nextParam.optional && !nextParam.default) {\n failures.push({\n code: \"OPTIONAL_PARAM_NOT_LAST\",\n details: `The parameter \"${nextParam.name}\" in the command at path \"${command.path.segments.join(\n \"/\"\n )}\" is required, but it follows an optional parameter \"${\n param.name\n }\". All required parameters must come before any optional parameters.`\n });\n }\n });\n }\n\n if (param.variadic && index + 1 < command.params.length) {\n if (command.params[index + 1]?.variadic) {\n failures.push({\n code: \"MULTIPLE_VARIADIC_PARAMS\",\n details: `The parameter \"${param.name}\" in the command at path \"${command.path.segments.join(\n \"/\"\n )}\" is variadic, and it is followed by another variadic parameter \"${\n command.params[index + 1]?.name\n }\". Only one variadic parameter is allowed per command, and it must be the final parameter.`\n });\n }\n }\n });\n }\n\n return failures;\n}\n\nexport function validateCommand(command: CommandTree): ValidationFailure[] {\n const results: ValidationFailure[] = [];\n\n let failures = validateCommandVariablePaths(command);\n if (failures.length > 0) {\n results.push(...failures);\n }\n\n failures = validateCommandParams(command);\n if (failures.length > 0) {\n results.push(...failures);\n }\n\n failures = validateCommandOptions(command);\n if (failures.length > 0) {\n results.push(...failures);\n }\n\n return results;\n}\n"],"mappings":";;;AA6BA,SAAgBE,6BACdC,SACqB;CACrB,MAAMC,WAAgC,EAAE;AACxC,KAAI,CAACD,QAAQE,aAAaF,QAAQG,KAAKC,SAASC,SAAS,GAAG;EAC1D,MAAMC,oCAAoB,IAAIC,KAAa;AAC3C,OAAK,MAAMC,WAAWR,QAAQG,KAAKC,SAASK,OAAOX,2DAAsB,IACvE,EAAE,EAAE;AACJ,OAAIQ,kBAAkBI,IAAIF,QAAQ,CAChCP,UAASU,KAAK;IACZC,MAAM;IACNC,SAAS,iCAAiChB,gEAA2BW,QAAQ,CAAA;IAC9E,CAAC;AAEJF,qBAAkBQ,IAAIjB,gEAA2BW,QAAQ,CAAC;;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
|
2
|
+
|
|
3
|
+
//#region src/helpers/validations.ts
|
|
4
|
+
function validateCommandVariablePaths(command) {
|
|
5
|
+
const failures = [];
|
|
6
|
+
if (!command.isVirtual && command.path.segments.length > 0) {
|
|
7
|
+
const variablePathNames = /* @__PURE__ */ new Set();
|
|
8
|
+
for (const segment of command.path.segments.filter(isVariableCommandPath) ?? []) {
|
|
9
|
+
if (variablePathNames.has(segment)) failures.push({
|
|
10
|
+
code: "DUPLICATE_VARIABLE_PATH_NAME",
|
|
11
|
+
details: `Duplicate variable path name "${getVariableCommandPathName(segment)}" found in command.`
|
|
12
|
+
});
|
|
13
|
+
variablePathNames.add(getVariableCommandPathName(segment));
|
|
14
|
+
}
|
|
15
|
+
if (command.path.segments.filter(isVariableCommandPath).length !== Object.keys(command.path.variables ?? {}).length) failures.push({
|
|
16
|
+
code: "VARIABLE_PATH_MISMATCH",
|
|
17
|
+
details: `Mismatch between variable path segments and defined path variables in command (found ${command.path.segments.filter(isVariableCommandPath).length} variables in the command folder path "${command.path.segments.join("/")}", but ${Object.keys(command.path.variables ?? {}).length} potential variable path(s) could be determined from the command's function signature).`
|
|
18
|
+
});
|
|
19
|
+
const missing = command.path.segments.filter(isVariableCommandPath).filter((segment) => Object.prototype.hasOwnProperty.call(command.path.variables ?? {}, getVariableCommandPathName(segment)) === false);
|
|
20
|
+
if (missing.length > 0) failures.push({
|
|
21
|
+
code: "MISSING_VARIABLE_PATH",
|
|
22
|
+
details: `${missing.length} variable path segment${missing.length > 1 ? "s" : ""} in the command folder path "${command.path.segments.join("/")}" do${missing.length > 1 ? "" : "es"} not have corresponding entr${missing.length > 1 ? "ies" : "y"} in the command's path variables: \n- ${missing.map((segment) => `"${getVariableCommandPathName(segment)}"`).join("\n- ")}`
|
|
23
|
+
});
|
|
24
|
+
else {
|
|
25
|
+
for (const varName of Object.keys(command.path.variables ?? {})) if (!command.path.segments.filter(isVariableCommandPath).find((segment) => getVariableCommandPathName(segment) === varName)) failures.push({
|
|
26
|
+
code: "UNUSED_VARIABLE_PATH",
|
|
27
|
+
details: `The variable path name "${varName}" defined in the command's path variables is not used in the command folder path "${command.path.segments.join("/")}".`
|
|
28
|
+
});
|
|
29
|
+
command.path.segments.forEach((segment, index) => {
|
|
30
|
+
if (isVariableCommandPath(segment) && command.path.variables[getVariableCommandPathName(segment)]?.variadic === true && index + 1 < command.path.segments.length && command.path.segments[index + 1] && command.path.variables[getVariableCommandPathName(command.path.segments[index + 1])]?.variadic === true) failures.push({
|
|
31
|
+
code: "MULTIPLE_VARIADIC_VARIABLE_PATHS",
|
|
32
|
+
details: `The variable path segment "${getVariableCommandPathName(segment)}" in the command at path "${command.path.segments.join("/")}" is marked as variadic, and it is followed by another variadic variable path segment "${getVariableCommandPathName(command.path.segments[index + 1])}". Only one variadic variable path segment is allowed per command, and it must be the final path segment.`
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return failures;
|
|
38
|
+
}
|
|
39
|
+
function validateCommandOptions(command) {
|
|
40
|
+
const failures = [];
|
|
41
|
+
const optionNames = /* @__PURE__ */ new Set();
|
|
42
|
+
for (const option of Object.values(command.options ?? {})) {
|
|
43
|
+
if (optionNames.has(option.name)) failures.push({
|
|
44
|
+
code: "DUPLICATE_OPTION_NAME",
|
|
45
|
+
details: `Duplicate option name "${option.name}" found in command.`
|
|
46
|
+
});
|
|
47
|
+
optionNames.add(option.name);
|
|
48
|
+
for (const alias of option.alias) {
|
|
49
|
+
if (optionNames.has(alias)) failures.push({
|
|
50
|
+
code: "DUPLICATE_OPTION_ALIAS",
|
|
51
|
+
details: `Duplicate option name "${alias}" (an alias of "${option.name}") found in command.`
|
|
52
|
+
});
|
|
53
|
+
optionNames.add(alias);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return failures;
|
|
57
|
+
}
|
|
58
|
+
function validateCommandParams(command) {
|
|
59
|
+
const failures = [];
|
|
60
|
+
if (!command.isVirtual && command.params.length > 0) {
|
|
61
|
+
const paramNames = /* @__PURE__ */ new Set();
|
|
62
|
+
command.params.forEach((param, index) => {
|
|
63
|
+
if (paramNames.has(param.name)) failures.push({
|
|
64
|
+
code: "DUPLICATE_PARAM_NAME",
|
|
65
|
+
details: `Duplicate parameter name "${param.name}" found in command.`
|
|
66
|
+
});
|
|
67
|
+
paramNames.add(param.name);
|
|
68
|
+
if (param.optional) command.params.slice(index + 1).forEach((nextParam) => {
|
|
69
|
+
if (nextParam.optional && !nextParam.default) failures.push({
|
|
70
|
+
code: "OPTIONAL_PARAM_NOT_LAST",
|
|
71
|
+
details: `The parameter "${nextParam.name}" in the command at path "${command.path.segments.join("/")}" is required, but it follows an optional parameter "${param.name}". All required parameters must come before any optional parameters.`
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
if (param.variadic && index + 1 < command.params.length) {
|
|
75
|
+
if (command.params[index + 1]?.variadic) failures.push({
|
|
76
|
+
code: "MULTIPLE_VARIADIC_PARAMS",
|
|
77
|
+
details: `The parameter "${param.name}" in the command at path "${command.path.segments.join("/")}" is variadic, and it is followed by another variadic parameter "${command.params[index + 1]?.name}". Only one variadic parameter is allowed per command, and it must be the final parameter.`
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return failures;
|
|
83
|
+
}
|
|
84
|
+
function validateCommand(command) {
|
|
85
|
+
const results = [];
|
|
86
|
+
let failures = validateCommandVariablePaths(command);
|
|
87
|
+
if (failures.length > 0) results.push(...failures);
|
|
88
|
+
failures = validateCommandParams(command);
|
|
89
|
+
if (failures.length > 0) results.push(...failures);
|
|
90
|
+
failures = validateCommandOptions(command);
|
|
91
|
+
if (failures.length > 0) results.push(...failures);
|
|
92
|
+
return results;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
export { validateCommand };
|
|
97
|
+
//# sourceMappingURL=validations.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validations.mjs","names":["getVariableCommandPathName","isVariableCommandPath","validateCommandVariablePaths","command","failures","isVirtual","path","segments","length","variablePathNames","Set","segment","filter","has","push","code","details","add","Object","keys","variables","join","missing","prototype","hasOwnProperty","call","map","varName","find","forEach","index","variadic","validateCommandOptions","optionNames","option","values","options","name","alias","validateCommandParams","params","paramNames","param","optional","slice","nextParam","default","validateCommand","results"],"sources":["../../src/helpers/validations.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 {\n getVariableCommandPathName,\n isVariableCommandPath\n} from \"../plugin-utils/context-helpers\";\nimport type { CommandTree } from \"../types\";\n\nexport interface ValidationFailure {\n code: string;\n details: string;\n}\n\nexport function validateCommandVariablePaths(\n command: CommandTree\n): ValidationFailure[] {\n const failures: ValidationFailure[] = [];\n if (!command.isVirtual && command.path.segments.length > 0) {\n const variablePathNames = new Set<string>();\n for (const segment of command.path.segments.filter(isVariableCommandPath) ??\n []) {\n if (variablePathNames.has(segment)) {\n failures.push({\n code: \"DUPLICATE_VARIABLE_PATH_NAME\",\n details: `Duplicate variable path name \"${getVariableCommandPathName(segment)}\" found in command.`\n });\n }\n variablePathNames.add(getVariableCommandPathName(segment));\n }\n\n if (\n command.path.segments.filter(isVariableCommandPath).length !==\n Object.keys(command.path.variables ?? {}).length\n ) {\n failures.push({\n code: \"VARIABLE_PATH_MISMATCH\",\n details: `Mismatch between variable path segments and defined path variables in command (found ${\n command.path.segments.filter(isVariableCommandPath).length\n } variables in the command folder path \"${command.path.segments.join(\"/\")}\", but ${\n Object.keys(command.path.variables ?? {}).length\n } potential variable path(s) could be determined from the command's function signature).`\n });\n }\n\n const missing = command.path.segments\n .filter(isVariableCommandPath)\n .filter(\n segment =>\n Object.prototype.hasOwnProperty.call(\n command.path.variables ?? {},\n getVariableCommandPathName(segment)\n ) === false\n );\n if (missing.length > 0) {\n failures.push({\n code: \"MISSING_VARIABLE_PATH\",\n details: `${missing.length} variable path segment${missing.length > 1 ? \"s\" : \"\"} in the command folder path \"${command.path.segments.join(\n \"/\"\n )}\" do${missing.length > 1 ? \"\" : \"es\"} not have corresponding entr${\n missing.length > 1 ? \"ies\" : \"y\"\n } in the command's path variables: \\n- ${missing\n .map(segment => `\"${getVariableCommandPathName(segment)}\"`)\n .join(\"\\n- \")}`\n });\n } else {\n for (const varName of Object.keys(command.path.variables ?? {})) {\n if (\n !command.path.segments\n .filter(isVariableCommandPath)\n .find(segment => getVariableCommandPathName(segment) === varName)\n ) {\n failures.push({\n code: \"UNUSED_VARIABLE_PATH\",\n details: `The variable path name \"${varName}\" defined in the command's path variables is not used in the command folder path \"${command.path.segments.join(\n \"/\"\n )}\".`\n });\n }\n }\n\n command.path.segments.forEach((segment, index) => {\n if (\n isVariableCommandPath(segment) &&\n command.path.variables[getVariableCommandPathName(segment)]\n ?.variadic === true &&\n index + 1 < command.path.segments.length &&\n command.path.segments[index + 1] &&\n command.path.variables[\n getVariableCommandPathName(command.path.segments[index + 1]!)\n ]?.variadic === true\n ) {\n failures.push({\n code: \"MULTIPLE_VARIADIC_VARIABLE_PATHS\",\n details: `The variable path segment \"${getVariableCommandPathName(\n segment\n )}\" in the command at path \"${command.path.segments.join(\n \"/\"\n )}\" is marked as variadic, and it is followed by another variadic variable path segment \"${getVariableCommandPathName(\n command.path.segments[index + 1]!\n )}\". Only one variadic variable path segment is allowed per command, and it must be the final path segment.`\n });\n }\n });\n }\n }\n\n return failures;\n}\n\nexport function validateCommandOptions(\n command: CommandTree\n): ValidationFailure[] {\n const failures: ValidationFailure[] = [];\n\n const optionNames = new Set<string>();\n for (const option of Object.values(command.options ?? {})) {\n if (optionNames.has(option.name)) {\n failures.push({\n code: \"DUPLICATE_OPTION_NAME\",\n details: `Duplicate option name \"${option.name}\" found in command.`\n });\n }\n optionNames.add(option.name);\n\n for (const alias of option.alias) {\n if (optionNames.has(alias)) {\n failures.push({\n code: \"DUPLICATE_OPTION_ALIAS\",\n details: `Duplicate option name \"${alias}\" (an alias of \"${\n option.name\n }\") found in command.`\n });\n }\n optionNames.add(alias);\n }\n }\n\n return failures;\n}\n\nexport function validateCommandParams(\n command: CommandTree\n): ValidationFailure[] {\n const failures: ValidationFailure[] = [];\n if (!command.isVirtual && command.params.length > 0) {\n const paramNames = new Set<string>();\n command.params.forEach((param, index) => {\n if (paramNames.has(param.name)) {\n failures.push({\n code: \"DUPLICATE_PARAM_NAME\",\n details: `Duplicate parameter name \"${param.name}\" found in command.`\n });\n }\n paramNames.add(param.name);\n\n if (param.optional) {\n command.params.slice(index + 1).forEach(nextParam => {\n if (nextParam.optional && !nextParam.default) {\n failures.push({\n code: \"OPTIONAL_PARAM_NOT_LAST\",\n details: `The parameter \"${nextParam.name}\" in the command at path \"${command.path.segments.join(\n \"/\"\n )}\" is required, but it follows an optional parameter \"${\n param.name\n }\". All required parameters must come before any optional parameters.`\n });\n }\n });\n }\n\n if (param.variadic && index + 1 < command.params.length) {\n if (command.params[index + 1]?.variadic) {\n failures.push({\n code: \"MULTIPLE_VARIADIC_PARAMS\",\n details: `The parameter \"${param.name}\" in the command at path \"${command.path.segments.join(\n \"/\"\n )}\" is variadic, and it is followed by another variadic parameter \"${\n command.params[index + 1]?.name\n }\". Only one variadic parameter is allowed per command, and it must be the final parameter.`\n });\n }\n }\n });\n }\n\n return failures;\n}\n\nexport function validateCommand(command: CommandTree): ValidationFailure[] {\n const results: ValidationFailure[] = [];\n\n let failures = validateCommandVariablePaths(command);\n if (failures.length > 0) {\n results.push(...failures);\n }\n\n failures = validateCommandParams(command);\n if (failures.length > 0) {\n results.push(...failures);\n }\n\n failures = validateCommandOptions(command);\n if (failures.length > 0) {\n results.push(...failures);\n }\n\n return results;\n}\n"],"mappings":";;;AA6BA,SAAgBE,6BACdC,SACqB;CACrB,MAAMC,WAAgC,EAAE;AACxC,KAAI,CAACD,QAAQE,aAAaF,QAAQG,KAAKC,SAASC,SAAS,GAAG;EAC1D,MAAMC,oCAAoB,IAAIC,KAAa;AAC3C,OAAK,MAAMC,WAAWR,QAAQG,KAAKC,SAASK,OAAOX,sBAAsB,IACvE,EAAE,EAAE;AACJ,OAAIQ,kBAAkBI,IAAIF,QAAQ,CAChCP,UAASU,KAAK;IACZC,MAAM;IACNC,SAAS,iCAAiChB,2BAA2BW,QAAQ,CAAA;IAC9E,CAAC;AAEJF,qBAAkBQ,IAAIjB,2BAA2BW,QAAQ,CAAC;;AAG5D,MACER,QAAQG,KAAKC,SAASK,OAAOX,sBAAsB,CAACO,WACpDU,OAAOC,KAAKhB,QAAQG,KAAKc,aAAa,EAAE,CAAC,CAACZ,OAE1CJ,UAASU,KAAK;GACZC,MAAM;GACNC,SAAS,wFACPb,QAAQG,KAAKC,SAASK,OAAOX,sBAAsB,CAACO,OAAM,yCAClBL,QAAQG,KAAKC,SAASc,KAAK,IAAI,CAAA,SACvEH,OAAOC,KAAKhB,QAAQG,KAAKc,aAAa,EAAE,CAAC,CAACZ,OAAM;GAEnD,CAAC;EAGJ,MAAMc,UAAUnB,QAAQG,KAAKC,SAC1BK,OAAOX,sBAAsB,CAC7BW,QACCD,YACEO,OAAOK,UAAUC,eAAeC,KAC9BtB,QAAQG,KAAKc,aAAa,EAAE,EAC5BpB,2BAA2BW,QAC7B,CAAC,KAAK,MACT;AACH,MAAIW,QAAQd,SAAS,EACnBJ,UAASU,KAAK;GACZC,MAAM;GACNC,SAAS,GAAGM,QAAQd,OAAM,wBAAyBc,QAAQd,SAAS,IAAI,MAAM,GAAE,+BAAgCL,QAAQG,KAAKC,SAASc,KACpI,IACD,CAAA,MAAOC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,IAAIO,KAAI;KAElC,CAAC;;IAGN;;AAGJ,QAAOjC;;AAGT,SAAgB2C,gBAAgB5C,SAA2C;CACzE,MAAM6C,UAA+B,EAAE;CAEvC,IAAI5C,WAAWF,6BAA6BC,QAAQ;AACpD,KAAIC,SAASI,SAAS,EACpBwC,SAAQlC,KAAK,GAAGV,SAAS;AAG3BA,YAAWmC,sBAAsBpC,QAAQ;AACzC,KAAIC,SAASI,SAAS,EACpBwC,SAAQlC,KAAK,GAAGV,SAAS;AAG3BA,YAAW4B,uBAAuB7B,QAAQ;AAC1C,KAAIC,SAASI,SAAS,EACpBwC,SAAQlC,KAAK,GAAGV,SAAS;AAG3B,QAAO4C"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
-
const
|
|
2
|
+
const require_plugin = require('./plugin.cjs');
|
|
3
3
|
const require_api = require('./api.cjs');
|
|
4
4
|
const require_config = require('./config.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/index.ts
|
|
7
|
-
/**
|
|
8
|
-
* Creates a new {@link ShellShockAPI} instance.
|
|
9
|
-
*
|
|
10
|
-
* @param options - The user configuration options.
|
|
11
|
-
* @returns A promise that resolves to a {@link ShellShockAPI} instance.
|
|
12
|
-
*/
|
|
13
|
-
async function createShellShock(options = {}) {
|
|
14
|
-
options.root ??= process.cwd();
|
|
15
|
-
return require_api.ShellShockAPI.from(options);
|
|
16
|
-
}
|
|
17
7
|
var src_default = require_api.ShellShockAPI;
|
|
18
8
|
|
|
19
9
|
//#endregion
|
|
20
10
|
exports.ShellShockAPI = require_api.ShellShockAPI;
|
|
21
|
-
exports.createShellShock = createShellShock;
|
|
11
|
+
exports.createShellShock = require_api.createShellShock;
|
|
22
12
|
exports.default = src_default;
|
|
23
13
|
exports.defineConfig = require_config.defineConfig;
|
|
24
|
-
exports.
|
|
14
|
+
exports.plugin = require_plugin.plugin;
|
|
15
|
+
exports.shellShock = require_plugin.plugin;
|
|
16
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["ShellShockAPI","createShellShock","plugin","shellShock"],"sources":["../src/index.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 { ShellShockAPI, createShellShock } from \"./api\";\n\nexport * from \"./config\";\n\nexport { plugin, shellShock } from \"./plugin\";\nexport * from \"./types\";\n\n// eslint-disable-next-line perfectionist/sort-named-exports\nexport { ShellShockAPI, createShellShock };\nexport default ShellShockAPI;\n"],"mappings":";;;;;;AA2BA,kBAAeA"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
import { BaseCommandOption, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandTree, NumberCommandOption, SerializedCommandTree, StringCommandOption } from "./types/command.cjs";
|
|
2
|
-
import { Context } from "./types/context.cjs";
|
|
3
|
-
import { Options, ResolvedConfig, UserConfig } from "./types/config.cjs";
|
|
4
|
-
import { ShellShockAPI } from "./api.cjs";
|
|
1
|
+
import { BaseCommandOption, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandPath, CommandTree, CommandTreePath, NumberCommandOption, SerializedCommandTree, StringCommandOption } from "./types/command.cjs";
|
|
2
|
+
import { Context, UnresolvedContext } from "./types/context.cjs";
|
|
3
|
+
import { BaseConfig, Options, OutputConfig, ResolvedConfig, UserConfig } from "./types/config.cjs";
|
|
4
|
+
import { ShellShockAPI, createShellShock } from "./api.cjs";
|
|
5
5
|
import { defineConfig } from "./config.cjs";
|
|
6
|
-
import
|
|
6
|
+
import plugin from "./plugin.cjs";
|
|
7
7
|
import { BaseCommandOptions } from "./types/options.cjs";
|
|
8
8
|
import "./types/index.cjs";
|
|
9
|
-
|
|
10
|
-
//#region src/index.d.ts
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new {@link ShellShockAPI} instance.
|
|
14
|
-
*
|
|
15
|
-
* @param options - The user configuration options.
|
|
16
|
-
* @returns A promise that resolves to a {@link ShellShockAPI} instance.
|
|
17
|
-
*/
|
|
18
|
-
declare function createShellShock(options?: Partial<UserConfig>): Promise<ShellShockAPI>;
|
|
19
|
-
//#endregion
|
|
20
|
-
export { BaseCommandOption, BaseCommandOptions, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandTree, Context, NumberCommandOption, Options, ResolvedConfig, SerializedCommandTree, ShellShockAPI, ShellShockAPI as default, StringCommandOption, UserConfig, createShellShock, defineConfig, shellShock };
|
|
9
|
+
export { BaseCommandOption, BaseCommandOptions, BaseConfig, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandPath, CommandTree, CommandTreePath, Context, NumberCommandOption, Options, OutputConfig, ResolvedConfig, SerializedCommandTree, ShellShockAPI, ShellShockAPI as default, StringCommandOption, UnresolvedContext, UserConfig, createShellShock, defineConfig, plugin, plugin as shellShock };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
import { BaseCommandOption, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandTree, NumberCommandOption, SerializedCommandTree, StringCommandOption } from "./types/command.mjs";
|
|
2
|
-
import { Context } from "./types/context.mjs";
|
|
3
|
-
import { Options, ResolvedConfig, UserConfig } from "./types/config.mjs";
|
|
4
|
-
import { ShellShockAPI } from "./api.mjs";
|
|
1
|
+
import { BaseCommandOption, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandPath, CommandTree, CommandTreePath, NumberCommandOption, SerializedCommandTree, StringCommandOption } from "./types/command.mjs";
|
|
2
|
+
import { Context, UnresolvedContext } from "./types/context.mjs";
|
|
3
|
+
import { BaseConfig, Options, OutputConfig, ResolvedConfig, UserConfig } from "./types/config.mjs";
|
|
4
|
+
import { ShellShockAPI, createShellShock } from "./api.mjs";
|
|
5
5
|
import { defineConfig } from "./config.mjs";
|
|
6
|
-
import
|
|
6
|
+
import plugin from "./plugin.mjs";
|
|
7
7
|
import { BaseCommandOptions } from "./types/options.mjs";
|
|
8
8
|
import "./types/index.mjs";
|
|
9
|
-
|
|
10
|
-
//#region src/index.d.ts
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new {@link ShellShockAPI} instance.
|
|
14
|
-
*
|
|
15
|
-
* @param options - The user configuration options.
|
|
16
|
-
* @returns A promise that resolves to a {@link ShellShockAPI} instance.
|
|
17
|
-
*/
|
|
18
|
-
declare function createShellShock(options?: Partial<UserConfig>): Promise<ShellShockAPI>;
|
|
19
|
-
//#endregion
|
|
20
|
-
export { BaseCommandOption, BaseCommandOptions, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandTree, Context, NumberCommandOption, Options, ResolvedConfig, SerializedCommandTree, ShellShockAPI, ShellShockAPI as default, StringCommandOption, UserConfig, createShellShock, defineConfig, shellShock };
|
|
9
|
+
export { BaseCommandOption, BaseCommandOptions, BaseConfig, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandPath, CommandTree, CommandTreePath, Context, NumberCommandOption, Options, OutputConfig, ResolvedConfig, SerializedCommandTree, ShellShockAPI, ShellShockAPI as default, StringCommandOption, UnresolvedContext, UserConfig, createShellShock, defineConfig, plugin, plugin as shellShock };
|
package/dist/index.mjs
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ShellShockAPI } from "./api.mjs";
|
|
1
|
+
import { plugin } from "./plugin.mjs";
|
|
2
|
+
import { ShellShockAPI, createShellShock } from "./api.mjs";
|
|
3
3
|
import { defineConfig } from "./config.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/index.ts
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new {@link ShellShockAPI} instance.
|
|
8
|
-
*
|
|
9
|
-
* @param options - The user configuration options.
|
|
10
|
-
* @returns A promise that resolves to a {@link ShellShockAPI} instance.
|
|
11
|
-
*/
|
|
12
|
-
async function createShellShock(options = {}) {
|
|
13
|
-
options.root ??= process.cwd();
|
|
14
|
-
return ShellShockAPI.from(options);
|
|
15
|
-
}
|
|
16
6
|
var src_default = ShellShockAPI;
|
|
17
7
|
|
|
18
8
|
//#endregion
|
|
19
|
-
export { ShellShockAPI, createShellShock, src_default as default, defineConfig, shellShock };
|
|
9
|
+
export { ShellShockAPI, createShellShock, src_default as default, defineConfig, plugin, plugin as shellShock };
|
|
10
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["ShellShockAPI","createShellShock","plugin","shellShock"],"sources":["../src/index.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 { ShellShockAPI, createShellShock } from \"./api\";\n\nexport * from \"./config\";\n\nexport { plugin, shellShock } from \"./plugin\";\nexport * from \"./types\";\n\n// eslint-disable-next-line perfectionist/sort-named-exports\nexport { ShellShockAPI, createShellShock };\nexport default ShellShockAPI;\n"],"mappings":";;;;;AA2BA,kBAAeA"}
|