@shell-shock/core 0.2.0 → 0.3.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 +221 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -1
- package/dist/api.cjs +57 -1
- 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 +55 -1
- package/dist/api.mjs.map +1 -0
- package/dist/components/docs.cjs +105 -0
- package/dist/components/docs.cjs.map +1 -0
- package/dist/components/docs.d.cts +56 -0
- package/dist/components/docs.d.cts.map +1 -0
- package/dist/components/docs.d.mts +56 -0
- package/dist/components/docs.d.mts.map +1 -0
- package/dist/components/docs.mjs +102 -0
- package/dist/components/docs.mjs.map +1 -0
- package/dist/components/index.cjs +5 -0
- package/dist/components/index.d.cts +2 -0
- package/dist/components/index.d.mts +2 -0
- package/dist/components/index.mjs +3 -0
- package/dist/config.cjs +18 -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 +17 -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/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 +50 -1
- package/dist/helpers/persistence.cjs.map +1 -0
- package/dist/helpers/persistence.mjs +47 -1
- package/dist/helpers/persistence.mjs.map +1 -0
- package/dist/helpers/resolve-command.cjs +177 -1
- package/dist/helpers/resolve-command.cjs.map +1 -0
- package/dist/helpers/resolve-command.mjs +172 -1
- package/dist/helpers/resolve-command.mjs.map +1 -0
- package/dist/helpers/update-package-json.cjs +36 -1
- package/dist/helpers/update-package-json.cjs.map +1 -0
- package/dist/helpers/update-package-json.mjs +34 -1
- package/dist/helpers/update-package-json.mjs.map +1 -0
- package/dist/helpers/utilities.cjs +41 -1
- package/dist/helpers/utilities.cjs.map +1 -0
- package/dist/helpers/utilities.mjs +39 -1
- 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 +16 -1
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7 -18
- package/dist/index.d.mts +6 -18
- package/dist/index.mjs +10 -1
- 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 +24 -0
- package/dist/plugin-utils/get-command-tree.cjs.map +1 -0
- package/dist/plugin-utils/get-command-tree.d.cts +16 -0
- package/dist/plugin-utils/get-command-tree.d.cts.map +1 -0
- package/dist/plugin-utils/get-command-tree.d.mts +16 -0
- package/dist/plugin-utils/get-command-tree.d.mts.map +1 -0
- package/dist/plugin-utils/get-command-tree.mjs +24 -0
- package/dist/plugin-utils/get-command-tree.mjs.map +1 -0
- package/dist/plugin-utils/index.cjs +16 -0
- package/dist/plugin-utils/index.d.cts +5 -0
- package/dist/plugin-utils/index.d.mts +5 -0
- package/dist/plugin-utils/index.mjs +6 -0
- 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 +267 -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 +261 -0
- package/dist/plugin.mjs.map +1 -0
- package/dist/types/command.d.cts +13 -4
- package/dist/types/command.d.cts.map +1 -0
- package/dist/types/command.d.mts +13 -4
- package/dist/types/command.d.mts.map +1 -0
- package/dist/types/command.mjs +1 -1
- package/dist/types/config.d.cts +71 -23
- package/dist/types/config.d.cts.map +1 -0
- package/dist/types/config.d.mts +71 -23
- package/dist/types/config.d.mts.map +1 -0
- package/dist/types/config.mjs +1 -1
- package/dist/types/context.d.cts +7 -3
- package/dist/types/context.d.cts.map +1 -0
- package/dist/types/context.d.mts +7 -3
- package/dist/types/context.d.mts.map +1 -0
- package/dist/types/context.mjs +1 -1
- package/dist/types/index.d.cts +4 -4
- package/dist/types/index.d.mts +4 -4
- package/dist/types/index.mjs +1 -1
- 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/options.mjs +1 -1
- package/package.json +230 -55
- package/dist/helpers/get-default-options.cjs +0 -1
- package/dist/helpers/get-default-options.d.cts +0 -15
- package/dist/helpers/get-default-options.d.mts +0 -15
- package/dist/helpers/get-default-options.mjs +0 -1
- package/dist/powerlines.cjs +0 -3
- package/dist/powerlines.d.cts +0 -12
- package/dist/powerlines.d.mts +0 -12
- package/dist/powerlines.mjs +0 -3
|
@@ -1 +1,41 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
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");
|
|
6
|
+
|
|
7
|
+
//#region src/helpers/utilities.ts
|
|
8
|
+
function innerFormatCommandTree(command) {
|
|
9
|
+
return {
|
|
10
|
+
name: `${command.name}${command.isVirtual ? " (virtual)" : ""}`,
|
|
11
|
+
children: Object.values(command.children ?? {}).map(innerFormatCommandTree)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
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
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the default command options based on the context configuration.
|
|
22
|
+
*
|
|
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.
|
|
26
|
+
*/
|
|
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
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
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 +1,39 @@
|
|
|
1
|
-
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";
|
|
5
|
+
|
|
6
|
+
//#region src/helpers/utilities.ts
|
|
7
|
+
function innerFormatCommandTree(command) {
|
|
8
|
+
return {
|
|
9
|
+
name: `${command.name}${command.isVirtual ? " (virtual)" : ""}`,
|
|
10
|
+
children: Object.values(command.children ?? {}).map(innerFormatCommandTree)
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function formatCommandTree(context) {
|
|
14
|
+
return formatTree({
|
|
15
|
+
name: context.config.name,
|
|
16
|
+
children: Object.values(context.commands ?? {}).map(innerFormatCommandTree)
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves the default command options based on the context configuration.
|
|
21
|
+
*
|
|
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.
|
|
25
|
+
*/
|
|
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
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
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;;AAG5D,MACER,QAAQG,KAAKC,SAASK,OAAOX,2DAAsB,CAACO,WACpDU,OAAOC,KAAKhB,QAAQG,KAAKc,aAAa,EAAE,CAAC,CAACZ,OAE1CJ,UAASU,KAAK;GACZC,MAAM;GACNC,SAAS,wFACPb,QAAQG,KAAKC,SAASK,OAAOX,2DAAsB,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,2DAAsB,CAC7BW,QACCD,YACEO,OAAOK,UAAUC,eAAeC,KAC9BtB,QAAQG,KAAKc,aAAa,EAAE,EAC5BpB,gEAA2BW,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,QAAQqC,OAAOhC,QAC/C;QAAIL,QAAQqC,OAAOV,QAAQ,IAAIC,SAC7B3B,UAASU,KAAK;KACZC,MAAM;KACNC,SAAS,kBAAkB0B,MAAML,KAAI,4BAA6BlC,QAAQG,KAAKC,SAASc,KACtF,IACD,CAAA,mEACClB,QAAQqC,OAAOV,QAAQ,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"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { getVariableCommandPathName, isVariableCommandPath } from "../plugin-utils/context-helpers.mjs";
|
|
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,Q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
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_plugin = require('./plugin.cjs');
|
|
3
|
+
const require_api = require('./api.cjs');
|
|
4
|
+
const require_config = require('./config.cjs');
|
|
5
|
+
|
|
6
|
+
//#region src/index.ts
|
|
7
|
+
var src_default = require_api.ShellShockAPI;
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
exports.ShellShockAPI = require_api.ShellShockAPI;
|
|
11
|
+
exports.createShellShock = require_api.createShellShock;
|
|
12
|
+
exports.default = src_default;
|
|
13
|
+
exports.defineConfig = require_config.defineConfig;
|
|
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
|
|
7
|
-
import shellShock from "./powerlines.cjs";
|
|
6
|
+
import plugin from "./plugin.cjs";
|
|
8
7
|
import { BaseCommandOptions } from "./types/options.cjs";
|
|
9
|
-
|
|
10
|
-
|
|
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, getDefaultOptions, shellShock };
|
|
8
|
+
import "./types/index.cjs";
|
|
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,21 +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
|
|
7
|
-
import shellShock from "./powerlines.mjs";
|
|
6
|
+
import plugin from "./plugin.mjs";
|
|
8
7
|
import { BaseCommandOptions } from "./types/options.mjs";
|
|
9
8
|
import "./types/index.mjs";
|
|
10
|
-
|
|
11
|
-
//#region src/index.d.ts
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Creates a new {@link ShellShockAPI} instance.
|
|
15
|
-
*
|
|
16
|
-
* @param options - The user configuration options.
|
|
17
|
-
* @returns A promise that resolves to a {@link ShellShockAPI} instance.
|
|
18
|
-
*/
|
|
19
|
-
declare function createShellShock(options?: Partial<UserConfig>): Promise<ShellShockAPI>;
|
|
20
|
-
//#endregion
|
|
21
|
-
export { BaseCommandOption, BaseCommandOptions, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandTree, Context, NumberCommandOption, Options, ResolvedConfig, SerializedCommandTree, ShellShockAPI, ShellShockAPI as default, StringCommandOption, UserConfig, createShellShock, defineConfig, getDefaultOptions, 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 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { plugin } from "./plugin.mjs";
|
|
2
|
+
import { ShellShockAPI, createShellShock } from "./api.mjs";
|
|
3
|
+
import { defineConfig } from "./config.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/index.ts
|
|
6
|
+
var src_default = ShellShockAPI;
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
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"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let __stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
|
|
3
|
+
let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
4
|
+
let __stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
5
|
+
let __stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
6
|
+
|
|
7
|
+
//#region src/plugin-utils/context-helpers.ts
|
|
8
|
+
/**
|
|
9
|
+
* Sorts command argument aliases, placing single-character aliases first, followed by multi-character aliases, and then sorting them alphabetically.
|
|
10
|
+
*
|
|
11
|
+
* @param aliases - An array of argument aliases to sort.
|
|
12
|
+
* @returns A new array of sorted aliases.
|
|
13
|
+
*/
|
|
14
|
+
function sortArgAliases(aliases) {
|
|
15
|
+
if (aliases.length === 0) return [];
|
|
16
|
+
const result = aliases.filter((alias) => alias.length === 1);
|
|
17
|
+
result.push(...aliases.filter((alias) => alias.length > 1));
|
|
18
|
+
return result.sort((a, b) => a.localeCompare(b));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the application name from the context and configuration.
|
|
22
|
+
*
|
|
23
|
+
* @param context - The build context containing workspace and package information.
|
|
24
|
+
* @returns The application name in kebab-case format.
|
|
25
|
+
* @throws An error if no valid application name is found.
|
|
26
|
+
*/
|
|
27
|
+
function getAppName(context) {
|
|
28
|
+
const result = context.config.name || ((0, __stryke_type_checks_is_set_string.isSetString)(context.config.bin) || Array.isArray(context.config.bin) && context.config.bin.length > 0 && (0, __stryke_type_checks_is_set_string.isSetString)(context.config.bin[0]) ? (0, __stryke_type_checks_is_set_string.isSetString)(context.config.bin) ? context.config.bin : context.config.bin[0] : context.packageJson?.name);
|
|
29
|
+
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.");
|
|
30
|
+
return (0, __stryke_string_format_kebab_case.kebabCase)(result);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Retrieves the application title from the context and configuration.
|
|
34
|
+
*
|
|
35
|
+
* @param context - The build context containing workspace and package information.
|
|
36
|
+
* @returns The application title in title-case format.
|
|
37
|
+
*/
|
|
38
|
+
function getAppTitle(context) {
|
|
39
|
+
return (0, __stryke_string_format_title_case.titleCase)(context.config.name || getAppName(context));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Retrieves the application description from the context and configuration.
|
|
43
|
+
*
|
|
44
|
+
* @param context - The build context containing workspace and package information.
|
|
45
|
+
* @returns The application description.
|
|
46
|
+
*/
|
|
47
|
+
function getAppDescription(context) {
|
|
48
|
+
return context.config.description || context.packageJson?.description || `The ${getAppTitle(context)} command-line interface application.`;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves the primary binary name for the application.
|
|
52
|
+
*
|
|
53
|
+
* @param context - The build context containing workspace and package information.
|
|
54
|
+
* @returns The primary binary name as a string.
|
|
55
|
+
*/
|
|
56
|
+
function getAppBin(context) {
|
|
57
|
+
return (0, __stryke_type_checks_is_set_object.isSetObject)(context.config.bin) ? Object.keys(context.config.bin)[0] : (0, __stryke_string_format_kebab_case.kebabCase)(getAppName(context));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Determines if a given command path segment is variable (enclosed in square brackets).
|
|
61
|
+
*
|
|
62
|
+
* @param path - The command path segment to check.
|
|
63
|
+
* @returns True if the path is variable, false otherwise.
|
|
64
|
+
*/
|
|
65
|
+
function isVariableCommandPath(path) {
|
|
66
|
+
return path.startsWith("[") && path.endsWith("]");
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Extracts the variable name from a command path segment by removing enclosing square brackets.
|
|
70
|
+
*
|
|
71
|
+
* @param path - The command path segment.
|
|
72
|
+
* @returns The variable name without square brackets.
|
|
73
|
+
*/
|
|
74
|
+
function getVariableCommandPathName(path) {
|
|
75
|
+
return path.replaceAll(/^\[+/g, "").replaceAll(/\]+$/g, "");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
exports.getAppBin = getAppBin;
|
|
80
|
+
exports.getAppDescription = getAppDescription;
|
|
81
|
+
exports.getAppName = getAppName;
|
|
82
|
+
exports.getAppTitle = getAppTitle;
|
|
83
|
+
exports.getVariableCommandPathName = getVariableCommandPathName;
|
|
84
|
+
exports.isVariableCommandPath = isVariableCommandPath;
|
|
85
|
+
exports.sortArgAliases = sortArgAliases;
|
|
86
|
+
//# sourceMappingURL=context-helpers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-helpers.cjs","names":["kebabCase","titleCase","isSetObject","isSetString","sortArgAliases","aliases","length","result","filter","alias","push","sort","a","b","localeCompare","getAppName","context","config","name","bin","Array","isArray","packageJson","Error","getAppTitle","getAppDescription","description","getAppBin","Object","keys","isVariableCommandPath","path","startsWith","endsWith","getVariableCommandPathName","replaceAll"],"sources":["../../src/plugin-utils/context-helpers.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 { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport type { Context, UnresolvedContext } from \"../types\";\n\n/**\n * Sorts command argument aliases, placing single-character aliases first, followed by multi-character aliases, and then sorting them alphabetically.\n *\n * @param aliases - An array of argument aliases to sort.\n * @returns A new array of sorted aliases.\n */\nexport function sortArgAliases(aliases: string[]): string[] {\n if (aliases.length === 0) {\n return [];\n }\n\n const result = aliases.filter(alias => alias.length === 1);\n result.push(...aliases.filter(alias => alias.length > 1));\n\n return result.sort((a, b) => a.localeCompare(b));\n}\n\n/**\n * Retrieves the application name from the context and configuration.\n *\n * @param context - The build context containing workspace and package information.\n * @returns The application name in kebab-case format.\n * @throws An error if no valid application name is found.\n */\nexport function getAppName(context: UnresolvedContext | Context): string {\n const result =\n context.config.name ||\n (isSetString(context.config.bin) ||\n (Array.isArray(context.config.bin) &&\n context.config.bin.length > 0 &&\n isSetString(context.config.bin[0]))\n ? isSetString(context.config.bin)\n ? context.config.bin\n : context.config.bin[0]\n : context.packageJson?.name);\n if (!isSetString(result)) {\n throw new Error(\n \"No application name found. Please provide a 'bin' option in the configuration or ensure the package.json has a valid 'name' field.\"\n );\n }\n\n return kebabCase(result);\n}\n\n/**\n * Retrieves the application title from the context and configuration.\n *\n * @param context - The build context containing workspace and package information.\n * @returns The application title in title-case format.\n */\nexport function getAppTitle(context: UnresolvedContext | Context): string {\n return titleCase(context.config.name || getAppName(context));\n}\n\n/**\n * Retrieves the application description from the context and configuration.\n *\n * @param context - The build context containing workspace and package information.\n * @returns The application description.\n */\nexport function getAppDescription(\n context: UnresolvedContext | Context\n): string {\n return (\n context.config.description ||\n context.packageJson?.description ||\n `The ${getAppTitle(context)} command-line interface application.`\n );\n}\n\n/**\n * Retrieves the primary binary name for the application.\n *\n * @param context - The build context containing workspace and package information.\n * @returns The primary binary name as a string.\n */\nexport function getAppBin(context: Context): string {\n return isSetObject(context.config.bin)\n ? Object.keys(context.config.bin)[0]!\n : kebabCase(getAppName(context));\n}\n\n/**\n * Determines if a given command path segment is variable (enclosed in square brackets).\n *\n * @param path - The command path segment to check.\n * @returns True if the path is variable, false otherwise.\n */\nexport function isVariableCommandPath(path: string): boolean {\n return path.startsWith(\"[\") && path.endsWith(\"]\");\n}\n\n/**\n * Extracts the variable name from a command path segment by removing enclosing square brackets.\n *\n * @param path - The command path segment.\n * @returns The variable name without square brackets.\n */\nexport function getVariableCommandPathName(path: string): string {\n return path.replaceAll(/^\\[+/g, \"\").replaceAll(/\\]+$/g, \"\");\n}\n"],"mappings":";;;;;;;;;;;;;AA8BA,SAAgBI,eAAeC,SAA6B;AAC1D,KAAIA,QAAQC,WAAW,EACrB,QAAO,EAAE;CAGX,MAAMC,SAASF,QAAQG,QAAOC,UAASA,MAAMH,WAAW,EAAE;AAC1DC,QAAOG,KAAK,GAAGL,QAAQG,QAAOC,UAASA,MAAMH,SAAS,EAAE,CAAC;AAEzD,QAAOC,OAAOI,MAAMC,GAAGC,MAAMD,EAAEE,cAAcD,EAAE,CAAC;;;;;;;;;AAUlD,SAAgBE,WAAWC,SAA8C;CACvE,MAAMT,SACJS,QAAQC,OAAOC,6DACFF,QAAQC,OAAOE,IAAI,IAC/BC,MAAMC,QAAQL,QAAQC,OAAOE,IAAI,IAChCH,QAAQC,OAAOE,IAAIb,SAAS,yDAChBU,QAAQC,OAAOE,IAAI,GAAI,uDACrBH,QAAQC,OAAOE,IAAI,GAC7BH,QAAQC,OAAOE,MACfH,QAAQC,OAAOE,IAAI,KACrBH,QAAQM,aAAaJ;AAC3B,KAAI,qDAAaX,OAAO,CACtB,OAAM,IAAIgB,MACR,qIACD;AAGH,yDAAiBhB,OAAO;;;;;;;;AAS1B,SAAgBiB,YAAYR,SAA8C;AACxE,yDAAiBA,QAAQC,OAAOC,QAAQH,WAAWC,QAAQ,CAAC;;;;;;;;AAS9D,SAAgBS,kBACdT,SACQ;AACR,QACEA,QAAQC,OAAO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