@shell-shock/core 0.17.8 → 0.17.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.cjs +29 -1
- package/dist/api.cjs +148 -1
- package/dist/api.d.cts +6 -6
- package/dist/api.d.cts.map +1 -1
- package/dist/api.d.mts +6 -6
- package/dist/api.d.mts.map +1 -1
- package/dist/api.mjs +145 -1
- package/dist/api.mjs.map +1 -1
- package/dist/components/command-validation-logic.cjs +292 -1
- package/dist/components/command-validation-logic.mjs +289 -1
- package/dist/components/command-validation-logic.mjs.map +1 -1
- package/dist/components/docs.cjs +265 -1
- package/dist/components/docs.mjs +256 -1
- package/dist/components/docs.mjs.map +1 -1
- package/dist/components/exec-builtin.cjs +429 -13
- package/dist/components/exec-builtin.mjs +425 -13
- package/dist/components/exec-builtin.mjs.map +1 -1
- package/dist/components/helpers.cjs +120 -1
- package/dist/components/helpers.mjs +112 -1
- package/dist/components/helpers.mjs.map +1 -1
- package/dist/components/index.cjs +58 -1
- package/dist/components/index.mjs +10 -1
- package/dist/components/options-parser-logic.cjs +960 -5
- package/dist/components/options-parser-logic.d.cts +1 -1
- package/dist/components/options-parser-logic.mjs +945 -5
- package/dist/components/options-parser-logic.mjs.map +1 -1
- package/dist/components/state-builtin.cjs +629 -8
- package/dist/components/state-builtin.mjs +622 -8
- package/dist/components/state-builtin.mjs.map +1 -1
- package/dist/components/usage.cjs +117 -1
- package/dist/components/usage.mjs +114 -1
- package/dist/components/usage.mjs.map +1 -1
- package/dist/components/utils-builtin.cjs +838 -33
- package/dist/components/utils-builtin.mjs +828 -33
- package/dist/components/utils-builtin.mjs.map +1 -1
- package/dist/config.cjs +31 -1
- package/dist/config.mjs +29 -1
- package/dist/config.mjs.map +1 -1
- package/dist/contexts/command.cjs +26 -1
- package/dist/contexts/command.mjs +23 -1
- package/dist/contexts/command.mjs.map +1 -1
- package/dist/contexts/index.cjs +9 -1
- package/dist/contexts/index.mjs +4 -1
- package/dist/contexts/options.cjs +63 -1
- package/dist/contexts/options.mjs +58 -1
- package/dist/contexts/options.mjs.map +1 -1
- package/dist/helpers/automd.cjs +71 -1
- package/dist/helpers/automd.mjs +70 -1
- package/dist/helpers/automd.mjs.map +1 -1
- package/dist/helpers/docs-helpers.cjs +23 -1
- package/dist/helpers/docs-helpers.mjs +22 -1
- package/dist/helpers/docs-helpers.mjs.map +1 -1
- package/dist/helpers/paths.cjs +137 -1
- package/dist/helpers/paths.mjs +133 -1
- package/dist/helpers/paths.mjs.map +1 -1
- package/dist/helpers/persistence.cjs +115 -1
- package/dist/helpers/persistence.mjs +112 -1
- package/dist/helpers/persistence.mjs.map +1 -1
- package/dist/helpers/update-package-json.cjs +65 -1
- package/dist/helpers/update-package-json.mjs +63 -1
- package/dist/helpers/update-package-json.mjs.map +1 -1
- package/dist/helpers/utilities.cjs +95 -1
- package/dist/helpers/utilities.mjs +93 -1
- package/dist/helpers/utilities.mjs.map +1 -1
- package/dist/helpers/validations.cjs +71 -1
- package/dist/helpers/validations.mjs +71 -1
- package/dist/helpers/validations.mjs.map +1 -1
- package/dist/index.cjs +53 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +7 -1
- package/dist/plugin-utils/compute-bin.cjs +50 -1
- package/dist/plugin-utils/compute-bin.mjs +49 -1
- package/dist/plugin-utils/compute-bin.mjs.map +1 -1
- package/dist/plugin-utils/context-helpers.cjs +231 -1
- package/dist/plugin-utils/context-helpers.mjs +221 -1
- package/dist/plugin-utils/context-helpers.mjs.map +1 -1
- package/dist/plugin-utils/deepkit.cjs +71 -1
- package/dist/plugin-utils/deepkit.mjs +69 -1
- package/dist/plugin-utils/deepkit.mjs.map +1 -1
- package/dist/plugin-utils/description-helpers.cjs +111 -2
- package/dist/plugin-utils/description-helpers.mjs +107 -2
- package/dist/plugin-utils/description-helpers.mjs.map +1 -1
- package/dist/plugin-utils/get-command-tree.cjs +117 -1
- package/dist/plugin-utils/get-command-tree.mjs +114 -1
- package/dist/plugin-utils/get-command-tree.mjs.map +1 -1
- package/dist/plugin-utils/index.cjs +39 -1
- package/dist/plugin-utils/index.mjs +10 -1
- package/dist/plugin-utils/reflect.cjs +52 -1
- package/dist/plugin-utils/reflect.mjs +52 -1
- package/dist/plugin-utils/reflect.mjs.map +1 -1
- package/dist/plugin-utils/traverse-command-tree.cjs +64 -1
- package/dist/plugin-utils/traverse-command-tree.mjs +62 -1
- package/dist/plugin-utils/traverse-command-tree.mjs.map +1 -1
- package/dist/plugin-utils/type-checks.cjs +93 -1
- package/dist/plugin-utils/type-checks.mjs +88 -1
- package/dist/plugin-utils/type-checks.mjs.map +1 -1
- package/dist/plugin.cjs +471 -4
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +465 -4
- package/dist/plugin.mjs.map +1 -1
- package/dist/resolver/deepkit.cjs +135 -1
- package/dist/resolver/deepkit.mjs +134 -1
- package/dist/resolver/deepkit.mjs.map +1 -1
- package/dist/resolver/helpers.cjs +173 -1
- package/dist/resolver/helpers.mjs +168 -1
- package/dist/resolver/helpers.mjs.map +1 -1
- package/dist/resolver/module.cjs +145 -1
- package/dist/resolver/module.mjs +144 -1
- package/dist/resolver/module.mjs.map +1 -1
- package/dist/resolver/resolve.cjs +222 -1
- package/dist/resolver/resolve.mjs +221 -1
- package/dist/resolver/resolve.mjs.map +1 -1
- package/dist/types/command.cjs +441 -1
- package/dist/types/command.d.cts +1 -1
- package/dist/types/command.d.mts +2 -2
- package/dist/types/command.mjs +405 -1
- package/dist/types/command.mjs.map +1 -1
- package/dist/types/config.cjs +134 -1
- package/dist/types/config.d.cts +10 -8
- package/dist/types/config.d.cts.map +1 -1
- package/dist/types/config.d.mts +10 -8
- package/dist/types/config.d.mts.map +1 -1
- package/dist/types/config.mjs +127 -1
- package/dist/types/config.mjs.map +1 -1
- package/dist/types/context.cjs +37 -1
- package/dist/types/context.mjs +34 -1
- package/dist/types/context.mjs.map +1 -1
- package/dist/types/env.cjs +52 -1
- package/dist/types/env.d.cts +1 -1
- package/dist/types/env.d.mts +1 -1
- package/dist/types/env.mjs +50 -1
- package/dist/types/env.mjs.map +1 -1
- package/dist/types/index.cjs +50 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.mts +2 -2
- package/dist/types/index.mjs +6 -1
- package/dist/types/options.cjs +12 -1
- package/dist/types/options.mjs +10 -1
- package/package.json +22 -21
|
@@ -1,2 +1,50 @@
|
|
|
1
|
-
import{getAppDescription
|
|
1
|
+
import { getAppDescription, getAppName, getAppTitle } from "./context-helpers.mjs";
|
|
2
|
+
import { joinPaths } from "@stryke/path/join-paths";
|
|
3
|
+
import { computed } from "@alloy-js/core";
|
|
4
|
+
|
|
5
|
+
//#region src/plugin-utils/compute-bin.ts
|
|
6
|
+
function __assignType(fn, args) {
|
|
7
|
+
fn.__type = args;
|
|
8
|
+
return fn;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Compute the command tree for the CLI application, starting from the root bin command. This will be used to determine which commands are available in the CLI application and their respective details.
|
|
12
|
+
*
|
|
13
|
+
* @param context - The plugin context containing the necessary information to compute the command tree.
|
|
14
|
+
* @returns The computed command tree for the CLI application, starting from the root bin command. This will include all commands discovered in the project and their respective details, organized in a hierarchical structure based on their segments and paths.
|
|
15
|
+
*/
|
|
16
|
+
function computeBin(context) {
|
|
17
|
+
return computed(() => ({
|
|
18
|
+
id: "",
|
|
19
|
+
name: getAppName(context),
|
|
20
|
+
title: getAppTitle(context),
|
|
21
|
+
description: getAppDescription(context),
|
|
22
|
+
isVirtual: true,
|
|
23
|
+
path: null,
|
|
24
|
+
segments: [],
|
|
25
|
+
alias: [],
|
|
26
|
+
tags: [],
|
|
27
|
+
source: "file",
|
|
28
|
+
options: Object.fromEntries(context.globalOptions.map(__assignType((option) => [option.name, option], [
|
|
29
|
+
"option",
|
|
30
|
+
"",
|
|
31
|
+
"P\"2!\"/\""
|
|
32
|
+
]))),
|
|
33
|
+
args: [],
|
|
34
|
+
entry: { file: joinPaths(context.entryPath, "bin.ts") },
|
|
35
|
+
parent: null,
|
|
36
|
+
children: context.commands
|
|
37
|
+
})).value;
|
|
38
|
+
}
|
|
39
|
+
computeBin.__type = [
|
|
40
|
+
"Context",
|
|
41
|
+
"context",
|
|
42
|
+
"CommandTree",
|
|
43
|
+
"computeBin",
|
|
44
|
+
"Compute the command tree for the CLI application, starting from the root bin command. This will be used to determine which commands are available in the CLI application and their respective details.",
|
|
45
|
+
"P\"w!2\"\"w#/$?%"
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { computeBin };
|
|
2
50
|
//# sourceMappingURL=compute-bin.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compute-bin.mjs","names":[],"sources":["../../src/plugin-utils/compute-bin.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 { computed } from \"@alloy-js/core\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport type { CommandTree, Context } from \"../types\";\nimport { getAppDescription, getAppName, getAppTitle } from \"./context-helpers\";\n\n/**\n * Compute the command tree for the CLI application, starting from the root bin command. This will be used to determine which commands are available in the CLI application and their respective details.\n *\n * @param context - The plugin context containing the necessary information to compute the command tree.\n * @returns The computed command tree for the CLI application, starting from the root bin command. This will include all commands discovered in the project and their respective details, organized in a hierarchical structure based on their segments and paths.\n */\nexport function computeBin(context: Context): CommandTree {\n const bin = computed(() => ({\n id: \"\",\n name: getAppName(context),\n title: getAppTitle(context),\n description: getAppDescription(context),\n isVirtual: true,\n path: null,\n segments: [],\n alias: [],\n tags: [],\n source: \"file\",\n options: Object.fromEntries(\n context.globalOptions.map(option => [option.name, option])\n ),\n args: [],\n entry: {\n file: joinPaths(context.entryPath, \"bin.ts\")\n },\n parent: null,\n children: context.commands\n }));\n\n return bin.value;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"compute-bin.mjs","names":[],"sources":["../../src/plugin-utils/compute-bin.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 { computed } from \"@alloy-js/core\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport type { CommandTree, Context } from \"../types\";\nimport { getAppDescription, getAppName, getAppTitle } from \"./context-helpers\";\n\n/**\n * Compute the command tree for the CLI application, starting from the root bin command. This will be used to determine which commands are available in the CLI application and their respective details.\n *\n * @param context - The plugin context containing the necessary information to compute the command tree.\n * @returns The computed command tree for the CLI application, starting from the root bin command. This will include all commands discovered in the project and their respective details, organized in a hierarchical structure based on their segments and paths.\n */\nexport function computeBin(context: Context): CommandTree {\n const bin = computed(() => ({\n id: \"\",\n name: getAppName(context),\n title: getAppTitle(context),\n description: getAppDescription(context),\n isVirtual: true,\n path: null,\n segments: [],\n alias: [],\n tags: [],\n source: \"file\",\n options: Object.fromEntries(\n context.globalOptions.map(option => [option.name, option])\n ),\n args: [],\n entry: {\n file: joinPaths(context.entryPath, \"bin.ts\")\n },\n parent: null,\n children: context.commands\n }));\n\n return bin.value;\n}\n"],"mappings":";;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE9B,QAAO;;;;;;;;AA4BT,SAAc,WAAa,SAAG;AAoB5B,QAnBQ,gBAAA;EACN,IAAI;EACJ,MAAM,WAAC,QAAY;EACnB,OAAA,YAAa,QAAA;EACb,aAAW,kBAAI,QAAA;EACf,WAAU;EACV,MAAA;EACA,UAAS,EAAA;EACT,OAAO,EAAC;EACR,MAAM,EAAE;EACR,QAAQ;EACR,SAAS,OAAC,YAAkB,QAAQ,cAAc,IAAE,cAAO,WAAA,CAAA,OAAA,MAAA,OAAA,EAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA,CAAA;EAC3D,MAAC,EAAA;EACD,OAAO,EACP,MAAO,UAAA,QAAA,WAAA,SAAA,EACN;EACD,QAAC;EACD,UAAQ,QAAI;EACb,EACE,CAAA;;AAEL,WAAS,SAAS;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA"}
|
|
@@ -1 +1,231 @@
|
|
|
1
|
-
require(
|
|
1
|
+
const require_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_string = require("@stryke/type-checks/is-set-string");
|
|
4
|
+
let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
5
|
+
let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
6
|
+
|
|
7
|
+
//#region src/plugin-utils/context-helpers.ts
|
|
8
|
+
function __assignType(fn, args) {
|
|
9
|
+
fn.__type = args;
|
|
10
|
+
return fn;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Sorts command argument aliases, placing single-character aliases first, followed by multi-character aliases, and then sorting them alphabetically.
|
|
14
|
+
*
|
|
15
|
+
* @param aliases - An array of argument aliases to sort.
|
|
16
|
+
* @returns A new array of sorted aliases.
|
|
17
|
+
*/
|
|
18
|
+
function sortArgAliases(aliases) {
|
|
19
|
+
if (aliases.length === 0) return [];
|
|
20
|
+
const result = aliases.filter(__assignType((alias) => alias.length === 1, [
|
|
21
|
+
"alias",
|
|
22
|
+
"",
|
|
23
|
+
"P\"2!\"/\""
|
|
24
|
+
]));
|
|
25
|
+
result.push(...aliases.filter(__assignType((alias) => alias.length > 1, [
|
|
26
|
+
"alias",
|
|
27
|
+
"",
|
|
28
|
+
"P\"2!\"/\""
|
|
29
|
+
])));
|
|
30
|
+
return result.sort(__assignType((a, b) => a.localeCompare(b), [
|
|
31
|
+
"a",
|
|
32
|
+
"b",
|
|
33
|
+
"",
|
|
34
|
+
"P\"2!\"2\"\"/#"
|
|
35
|
+
]));
|
|
36
|
+
}
|
|
37
|
+
sortArgAliases.__type = [
|
|
38
|
+
"aliases",
|
|
39
|
+
"sortArgAliases",
|
|
40
|
+
"Sorts command argument aliases, placing single-character aliases first, followed by multi-character aliases, and then sorting them alphabetically.",
|
|
41
|
+
"P&F2!&F/\"?#"
|
|
42
|
+
];
|
|
43
|
+
/**
|
|
44
|
+
* Retrieves the application name from the context and configuration.
|
|
45
|
+
*
|
|
46
|
+
* @param context - The build context containing workspace and package information.
|
|
47
|
+
* @returns The application name in kebab-case format.
|
|
48
|
+
* @throws An error if no valid application name is found.
|
|
49
|
+
*/
|
|
50
|
+
function getAppName(context) {
|
|
51
|
+
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);
|
|
52
|
+
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.");
|
|
53
|
+
return (0, _stryke_string_format_kebab_case.kebabCase)(result);
|
|
54
|
+
}
|
|
55
|
+
getAppName.__type = [
|
|
56
|
+
"UnresolvedContext",
|
|
57
|
+
"Context",
|
|
58
|
+
"context",
|
|
59
|
+
"getAppName",
|
|
60
|
+
"Retrieves the application name from the context and configuration.",
|
|
61
|
+
"PP\"w!\"w\"J2#&/$?%"
|
|
62
|
+
];
|
|
63
|
+
/**
|
|
64
|
+
* Retrieves the application title from the context and configuration.
|
|
65
|
+
*
|
|
66
|
+
* @param context - The build context containing workspace and package information.
|
|
67
|
+
* @param replaceCLI - Whether to replace CLI-related terms in the title with the application name.
|
|
68
|
+
* @returns The application title in title-case format.
|
|
69
|
+
*/
|
|
70
|
+
function getAppTitle(context, replaceCLI = false) {
|
|
71
|
+
const title = context.config.title || (0, _stryke_string_format_title_case.titleCase)(context.config.name || getAppName(context));
|
|
72
|
+
return (replaceCLI ? title.replace(/(?:cli|command-line|command line)\s*(?:interface\s*)?(?:application|app)?$/gi, "") : title).trim();
|
|
73
|
+
}
|
|
74
|
+
getAppTitle.__type = [
|
|
75
|
+
"UnresolvedContext",
|
|
76
|
+
"Context",
|
|
77
|
+
"context",
|
|
78
|
+
"replaceCLI",
|
|
79
|
+
"getAppTitle",
|
|
80
|
+
"Retrieves the application title from the context and configuration.",
|
|
81
|
+
"PP\"w!\"w\"J2#\"2$&/%?&"
|
|
82
|
+
];
|
|
83
|
+
/**
|
|
84
|
+
* Retrieves the application description from the context and configuration.
|
|
85
|
+
*
|
|
86
|
+
* @param context - The build context containing workspace and package information.
|
|
87
|
+
* @returns The application description.
|
|
88
|
+
*/
|
|
89
|
+
function getAppDescription(context) {
|
|
90
|
+
return context.config.description || context.packageJson?.description || `The ${getAppTitle(context, true)} command-line interface application.`;
|
|
91
|
+
}
|
|
92
|
+
getAppDescription.__type = [
|
|
93
|
+
"UnresolvedContext",
|
|
94
|
+
"Context",
|
|
95
|
+
"context",
|
|
96
|
+
"getAppDescription",
|
|
97
|
+
"Retrieves the application description from the context and configuration.",
|
|
98
|
+
"PP\"w!\"w\"J2#&/$?%"
|
|
99
|
+
];
|
|
100
|
+
/**
|
|
101
|
+
* Retrieves the primary binary name for the application.
|
|
102
|
+
*
|
|
103
|
+
* @param context - The build context containing workspace and package information.
|
|
104
|
+
* @returns The primary binary name as a string.
|
|
105
|
+
*/
|
|
106
|
+
function getAppBin(context) {
|
|
107
|
+
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));
|
|
108
|
+
}
|
|
109
|
+
getAppBin.__type = [
|
|
110
|
+
"Context",
|
|
111
|
+
"context",
|
|
112
|
+
"getAppBin",
|
|
113
|
+
"Retrieves the primary binary name for the application.",
|
|
114
|
+
"P\"w!2\"&/#?$"
|
|
115
|
+
];
|
|
116
|
+
/**
|
|
117
|
+
* Determines if a given command path segment is variable (enclosed in square brackets).
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* isDynamicPathSegment("[user]"); // true
|
|
122
|
+
* isDynamicPathSegment("user"); // false
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @param path - The command path segment to check.
|
|
126
|
+
* @returns True if the path is variable, false otherwise.
|
|
127
|
+
*/
|
|
128
|
+
function isDynamicPathSegment(path) {
|
|
129
|
+
return path.startsWith("[") && path.endsWith("]");
|
|
130
|
+
}
|
|
131
|
+
isDynamicPathSegment.__type = [
|
|
132
|
+
"path",
|
|
133
|
+
"isDynamicPathSegment",
|
|
134
|
+
"Determines if a given command path segment is variable (enclosed in square brackets).",
|
|
135
|
+
"P&2!)/\"?#"
|
|
136
|
+
];
|
|
137
|
+
/**
|
|
138
|
+
* Extracts the variable name from a command path segment by removing enclosing square brackets.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* getDynamicPathSegmentName("[user]"); // "user"
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
145
|
+
* @param path - The command path segment.
|
|
146
|
+
* @returns The variable name without square brackets.
|
|
147
|
+
*/
|
|
148
|
+
function getDynamicPathSegmentName(path) {
|
|
149
|
+
return path.replaceAll(/^\[+/g, "").replaceAll(/\]+$/g, "");
|
|
150
|
+
}
|
|
151
|
+
getDynamicPathSegmentName.__type = [
|
|
152
|
+
"path",
|
|
153
|
+
"getDynamicPathSegmentName",
|
|
154
|
+
"Extracts the variable name from a command path segment by removing enclosing square brackets.",
|
|
155
|
+
"P&2!&/\"?#"
|
|
156
|
+
];
|
|
157
|
+
/**
|
|
158
|
+
* Determines if a given command path segment is a path segment group (enclosed in parentheses).
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* isPathSegmentGroup("(user)"); // true
|
|
163
|
+
* isPathSegmentGroup("[user]"); // false
|
|
164
|
+
* isPathSegmentGroup("user"); // false
|
|
165
|
+
* ```
|
|
166
|
+
*
|
|
167
|
+
* @param path - The command path segment to check.
|
|
168
|
+
* @returns True if the path is a path segment group, false otherwise.
|
|
169
|
+
*/
|
|
170
|
+
function isPathSegmentGroup(path) {
|
|
171
|
+
return path.startsWith("(") && path.endsWith(")") || path.startsWith("_");
|
|
172
|
+
}
|
|
173
|
+
isPathSegmentGroup.__type = [
|
|
174
|
+
"path",
|
|
175
|
+
"isPathSegmentGroup",
|
|
176
|
+
"Determines if a given command path segment is a path segment group (enclosed in parentheses).",
|
|
177
|
+
"P&2!)/\"?#"
|
|
178
|
+
];
|
|
179
|
+
/**
|
|
180
|
+
* Extracts the group name from a command path segment by removing enclosing parentheses.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* getPathSegmentGroupName("(admin)"); // "admin"
|
|
185
|
+
* getPathSegmentGroupName("((group))"); // "group"
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* @param path - The command path segment.
|
|
189
|
+
* @returns The group name without parentheses.
|
|
190
|
+
*/
|
|
191
|
+
function getPathSegmentGroupName(path) {
|
|
192
|
+
return path.replaceAll(/^\(+/g, "").replaceAll(/\)+$/g, "").replaceAll(/^_+/g, "");
|
|
193
|
+
}
|
|
194
|
+
getPathSegmentGroupName.__type = [
|
|
195
|
+
"path",
|
|
196
|
+
"getPathSegmentGroupName",
|
|
197
|
+
"Extracts the group name from a command path segment by removing enclosing parentheses.",
|
|
198
|
+
"P&2!&/\"?#"
|
|
199
|
+
];
|
|
200
|
+
/**
|
|
201
|
+
* Extracts the variable name from a command path segment by removing enclosing square brackets.
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* getDynamicPathSegmentName("[user]"); // "user"
|
|
206
|
+
* ```
|
|
207
|
+
*
|
|
208
|
+
* @param path - The command path segment.
|
|
209
|
+
* @returns The variable name without square brackets.
|
|
210
|
+
*/
|
|
211
|
+
function getPathSegmentName(path) {
|
|
212
|
+
return getPathSegmentGroupName(getDynamicPathSegmentName(path));
|
|
213
|
+
}
|
|
214
|
+
getPathSegmentName.__type = [
|
|
215
|
+
"path",
|
|
216
|
+
"getPathSegmentName",
|
|
217
|
+
"Extracts the variable name from a command path segment by removing enclosing square brackets.",
|
|
218
|
+
"P&2!&/\"?#"
|
|
219
|
+
];
|
|
220
|
+
|
|
221
|
+
//#endregion
|
|
222
|
+
exports.getAppBin = getAppBin;
|
|
223
|
+
exports.getAppDescription = getAppDescription;
|
|
224
|
+
exports.getAppName = getAppName;
|
|
225
|
+
exports.getAppTitle = getAppTitle;
|
|
226
|
+
exports.getDynamicPathSegmentName = getDynamicPathSegmentName;
|
|
227
|
+
exports.getPathSegmentGroupName = getPathSegmentGroupName;
|
|
228
|
+
exports.getPathSegmentName = getPathSegmentName;
|
|
229
|
+
exports.isDynamicPathSegment = isDynamicPathSegment;
|
|
230
|
+
exports.isPathSegmentGroup = isPathSegmentGroup;
|
|
231
|
+
exports.sortArgAliases = sortArgAliases;
|
|
@@ -1,2 +1,222 @@
|
|
|
1
|
-
import{kebabCase
|
|
1
|
+
import { kebabCase } from "@stryke/string-format/kebab-case";
|
|
2
|
+
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
3
|
+
import { titleCase } from "@stryke/string-format/title-case";
|
|
4
|
+
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
5
|
+
|
|
6
|
+
//#region src/plugin-utils/context-helpers.ts
|
|
7
|
+
function __assignType(fn, args) {
|
|
8
|
+
fn.__type = args;
|
|
9
|
+
return fn;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Sorts command argument aliases, placing single-character aliases first, followed by multi-character aliases, and then sorting them alphabetically.
|
|
13
|
+
*
|
|
14
|
+
* @param aliases - An array of argument aliases to sort.
|
|
15
|
+
* @returns A new array of sorted aliases.
|
|
16
|
+
*/
|
|
17
|
+
function sortArgAliases(aliases) {
|
|
18
|
+
if (aliases.length === 0) return [];
|
|
19
|
+
const result = aliases.filter(__assignType((alias) => alias.length === 1, [
|
|
20
|
+
"alias",
|
|
21
|
+
"",
|
|
22
|
+
"P\"2!\"/\""
|
|
23
|
+
]));
|
|
24
|
+
result.push(...aliases.filter(__assignType((alias) => alias.length > 1, [
|
|
25
|
+
"alias",
|
|
26
|
+
"",
|
|
27
|
+
"P\"2!\"/\""
|
|
28
|
+
])));
|
|
29
|
+
return result.sort(__assignType((a, b) => a.localeCompare(b), [
|
|
30
|
+
"a",
|
|
31
|
+
"b",
|
|
32
|
+
"",
|
|
33
|
+
"P\"2!\"2\"\"/#"
|
|
34
|
+
]));
|
|
35
|
+
}
|
|
36
|
+
sortArgAliases.__type = [
|
|
37
|
+
"aliases",
|
|
38
|
+
"sortArgAliases",
|
|
39
|
+
"Sorts command argument aliases, placing single-character aliases first, followed by multi-character aliases, and then sorting them alphabetically.",
|
|
40
|
+
"P&F2!&F/\"?#"
|
|
41
|
+
];
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves the application name from the context and configuration.
|
|
44
|
+
*
|
|
45
|
+
* @param context - The build context containing workspace and package information.
|
|
46
|
+
* @returns The application name in kebab-case format.
|
|
47
|
+
* @throws An error if no valid application name is found.
|
|
48
|
+
*/
|
|
49
|
+
function getAppName(context) {
|
|
50
|
+
const result = context.config.name || (isSetString(context.config.bin) || Array.isArray(context.config.bin) && context.config.bin.length > 0 && isSetString(context.config.bin[0]) ? isSetString(context.config.bin) ? context.config.bin : context.config.bin[0] : context.packageJson?.name);
|
|
51
|
+
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.");
|
|
52
|
+
return kebabCase(result);
|
|
53
|
+
}
|
|
54
|
+
getAppName.__type = [
|
|
55
|
+
"UnresolvedContext",
|
|
56
|
+
"Context",
|
|
57
|
+
"context",
|
|
58
|
+
"getAppName",
|
|
59
|
+
"Retrieves the application name from the context and configuration.",
|
|
60
|
+
"PP\"w!\"w\"J2#&/$?%"
|
|
61
|
+
];
|
|
62
|
+
/**
|
|
63
|
+
* Retrieves the application title from the context and configuration.
|
|
64
|
+
*
|
|
65
|
+
* @param context - The build context containing workspace and package information.
|
|
66
|
+
* @param replaceCLI - Whether to replace CLI-related terms in the title with the application name.
|
|
67
|
+
* @returns The application title in title-case format.
|
|
68
|
+
*/
|
|
69
|
+
function getAppTitle(context, replaceCLI = false) {
|
|
70
|
+
const title = context.config.title || titleCase(context.config.name || getAppName(context));
|
|
71
|
+
return (replaceCLI ? title.replace(/(?:cli|command-line|command line)\s*(?:interface\s*)?(?:application|app)?$/gi, "") : title).trim();
|
|
72
|
+
}
|
|
73
|
+
getAppTitle.__type = [
|
|
74
|
+
"UnresolvedContext",
|
|
75
|
+
"Context",
|
|
76
|
+
"context",
|
|
77
|
+
"replaceCLI",
|
|
78
|
+
"getAppTitle",
|
|
79
|
+
"Retrieves the application title from the context and configuration.",
|
|
80
|
+
"PP\"w!\"w\"J2#\"2$&/%?&"
|
|
81
|
+
];
|
|
82
|
+
/**
|
|
83
|
+
* Retrieves the application description from the context and configuration.
|
|
84
|
+
*
|
|
85
|
+
* @param context - The build context containing workspace and package information.
|
|
86
|
+
* @returns The application description.
|
|
87
|
+
*/
|
|
88
|
+
function getAppDescription(context) {
|
|
89
|
+
return context.config.description || context.packageJson?.description || `The ${getAppTitle(context, true)} command-line interface application.`;
|
|
90
|
+
}
|
|
91
|
+
getAppDescription.__type = [
|
|
92
|
+
"UnresolvedContext",
|
|
93
|
+
"Context",
|
|
94
|
+
"context",
|
|
95
|
+
"getAppDescription",
|
|
96
|
+
"Retrieves the application description from the context and configuration.",
|
|
97
|
+
"PP\"w!\"w\"J2#&/$?%"
|
|
98
|
+
];
|
|
99
|
+
/**
|
|
100
|
+
* Retrieves the primary binary name for the application.
|
|
101
|
+
*
|
|
102
|
+
* @param context - The build context containing workspace and package information.
|
|
103
|
+
* @returns The primary binary name as a string.
|
|
104
|
+
*/
|
|
105
|
+
function getAppBin(context) {
|
|
106
|
+
return isSetObject(context.config.bin) ? Object.keys(context.config.bin)[0] : kebabCase(getAppName(context));
|
|
107
|
+
}
|
|
108
|
+
getAppBin.__type = [
|
|
109
|
+
"Context",
|
|
110
|
+
"context",
|
|
111
|
+
"getAppBin",
|
|
112
|
+
"Retrieves the primary binary name for the application.",
|
|
113
|
+
"P\"w!2\"&/#?$"
|
|
114
|
+
];
|
|
115
|
+
/**
|
|
116
|
+
* Determines if a given command path segment is variable (enclosed in square brackets).
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* isDynamicPathSegment("[user]"); // true
|
|
121
|
+
* isDynamicPathSegment("user"); // false
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @param path - The command path segment to check.
|
|
125
|
+
* @returns True if the path is variable, false otherwise.
|
|
126
|
+
*/
|
|
127
|
+
function isDynamicPathSegment(path) {
|
|
128
|
+
return path.startsWith("[") && path.endsWith("]");
|
|
129
|
+
}
|
|
130
|
+
isDynamicPathSegment.__type = [
|
|
131
|
+
"path",
|
|
132
|
+
"isDynamicPathSegment",
|
|
133
|
+
"Determines if a given command path segment is variable (enclosed in square brackets).",
|
|
134
|
+
"P&2!)/\"?#"
|
|
135
|
+
];
|
|
136
|
+
/**
|
|
137
|
+
* Extracts the variable name from a command path segment by removing enclosing square brackets.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* getDynamicPathSegmentName("[user]"); // "user"
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* @param path - The command path segment.
|
|
145
|
+
* @returns The variable name without square brackets.
|
|
146
|
+
*/
|
|
147
|
+
function getDynamicPathSegmentName(path) {
|
|
148
|
+
return path.replaceAll(/^\[+/g, "").replaceAll(/\]+$/g, "");
|
|
149
|
+
}
|
|
150
|
+
getDynamicPathSegmentName.__type = [
|
|
151
|
+
"path",
|
|
152
|
+
"getDynamicPathSegmentName",
|
|
153
|
+
"Extracts the variable name from a command path segment by removing enclosing square brackets.",
|
|
154
|
+
"P&2!&/\"?#"
|
|
155
|
+
];
|
|
156
|
+
/**
|
|
157
|
+
* Determines if a given command path segment is a path segment group (enclosed in parentheses).
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* isPathSegmentGroup("(user)"); // true
|
|
162
|
+
* isPathSegmentGroup("[user]"); // false
|
|
163
|
+
* isPathSegmentGroup("user"); // false
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @param path - The command path segment to check.
|
|
167
|
+
* @returns True if the path is a path segment group, false otherwise.
|
|
168
|
+
*/
|
|
169
|
+
function isPathSegmentGroup(path) {
|
|
170
|
+
return path.startsWith("(") && path.endsWith(")") || path.startsWith("_");
|
|
171
|
+
}
|
|
172
|
+
isPathSegmentGroup.__type = [
|
|
173
|
+
"path",
|
|
174
|
+
"isPathSegmentGroup",
|
|
175
|
+
"Determines if a given command path segment is a path segment group (enclosed in parentheses).",
|
|
176
|
+
"P&2!)/\"?#"
|
|
177
|
+
];
|
|
178
|
+
/**
|
|
179
|
+
* Extracts the group name from a command path segment by removing enclosing parentheses.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* getPathSegmentGroupName("(admin)"); // "admin"
|
|
184
|
+
* getPathSegmentGroupName("((group))"); // "group"
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* @param path - The command path segment.
|
|
188
|
+
* @returns The group name without parentheses.
|
|
189
|
+
*/
|
|
190
|
+
function getPathSegmentGroupName(path) {
|
|
191
|
+
return path.replaceAll(/^\(+/g, "").replaceAll(/\)+$/g, "").replaceAll(/^_+/g, "");
|
|
192
|
+
}
|
|
193
|
+
getPathSegmentGroupName.__type = [
|
|
194
|
+
"path",
|
|
195
|
+
"getPathSegmentGroupName",
|
|
196
|
+
"Extracts the group name from a command path segment by removing enclosing parentheses.",
|
|
197
|
+
"P&2!&/\"?#"
|
|
198
|
+
];
|
|
199
|
+
/**
|
|
200
|
+
* Extracts the variable name from a command path segment by removing enclosing square brackets.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* getDynamicPathSegmentName("[user]"); // "user"
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* @param path - The command path segment.
|
|
208
|
+
* @returns The variable name without square brackets.
|
|
209
|
+
*/
|
|
210
|
+
function getPathSegmentName(path) {
|
|
211
|
+
return getPathSegmentGroupName(getDynamicPathSegmentName(path));
|
|
212
|
+
}
|
|
213
|
+
getPathSegmentName.__type = [
|
|
214
|
+
"path",
|
|
215
|
+
"getPathSegmentName",
|
|
216
|
+
"Extracts the variable name from a command path segment by removing enclosing square brackets.",
|
|
217
|
+
"P&2!&/\"?#"
|
|
218
|
+
];
|
|
219
|
+
|
|
220
|
+
//#endregion
|
|
221
|
+
export { getAppBin, getAppDescription, getAppName, getAppTitle, getDynamicPathSegmentName, getPathSegmentGroupName, getPathSegmentName, isDynamicPathSegment, isPathSegmentGroup, sortArgAliases };
|
|
2
222
|
//# sourceMappingURL=context-helpers.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-helpers.mjs","names":[],"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 * @param replaceCLI - Whether to replace CLI-related terms in the title with the application name.\n * @returns The application title in title-case format.\n */\nexport function getAppTitle(\n context: UnresolvedContext | Context,\n replaceCLI = false\n): string {\n const title =\n context.config.title ||\n titleCase(context.config.name || getAppName(context));\n\n return (\n replaceCLI\n ? title.replace(\n /(?:cli|command-line|command line)\\s*(?:interface\\s*)?(?:application|app)?$/gi,\n \"\"\n )\n : title\n ).trim();\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, true)} 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 * @example\n * ```typescript\n * isDynamicPathSegment(\"[user]\"); // true\n * isDynamicPathSegment(\"user\"); // false\n * ```\n *\n * @param path - The command path segment to check.\n * @returns True if the path is variable, false otherwise.\n */\nexport function isDynamicPathSegment(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 * @example\n * ```typescript\n * getDynamicPathSegmentName(\"[user]\"); // \"user\"\n * ```\n *\n * @param path - The command path segment.\n * @returns The variable name without square brackets.\n */\nexport function getDynamicPathSegmentName(path: string): string {\n return path.replaceAll(/^\\[+/g, \"\").replaceAll(/\\]+$/g, \"\");\n}\n\n/**\n * Determines if a given command path segment is a path segment group (enclosed in parentheses).\n *\n * @example\n * ```typescript\n * isPathSegmentGroup(\"(user)\"); // true\n * isPathSegmentGroup(\"[user]\"); // false\n * isPathSegmentGroup(\"user\"); // false\n * ```\n *\n * @param path - The command path segment to check.\n * @returns True if the path is a path segment group, false otherwise.\n */\nexport function isPathSegmentGroup(path: string): boolean {\n return (path.startsWith(\"(\") && path.endsWith(\")\")) || path.startsWith(\"_\");\n}\n\n/**\n * Extracts the group name from a command path segment by removing enclosing parentheses.\n *\n * @example\n * ```typescript\n * getPathSegmentGroupName(\"(admin)\"); // \"admin\"\n * getPathSegmentGroupName(\"((group))\"); // \"group\"\n * ```\n *\n * @param path - The command path segment.\n * @returns The group name without parentheses.\n */\nexport function getPathSegmentGroupName(path: string): string {\n return path\n .replaceAll(/^\\(+/g, \"\")\n .replaceAll(/\\)+$/g, \"\")\n .replaceAll(/^_+/g, \"\");\n}\n\n/**\n * Extracts the variable name from a command path segment by removing enclosing square brackets.\n *\n * @example\n * ```typescript\n * getDynamicPathSegmentName(\"[user]\"); // \"user\"\n * ```\n *\n * @param path - The command path segment.\n * @returns The variable name without square brackets.\n */\nexport function getPathSegmentName(path: string): string {\n return getPathSegmentGroupName(getDynamicPathSegmentName(path));\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"context-helpers.mjs","names":[],"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 * @param replaceCLI - Whether to replace CLI-related terms in the title with the application name.\n * @returns The application title in title-case format.\n */\nexport function getAppTitle(\n context: UnresolvedContext | Context,\n replaceCLI = false\n): string {\n const title =\n context.config.title ||\n titleCase(context.config.name || getAppName(context));\n\n return (\n replaceCLI\n ? title.replace(\n /(?:cli|command-line|command line)\\s*(?:interface\\s*)?(?:application|app)?$/gi,\n \"\"\n )\n : title\n ).trim();\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, true)} 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 * @example\n * ```typescript\n * isDynamicPathSegment(\"[user]\"); // true\n * isDynamicPathSegment(\"user\"); // false\n * ```\n *\n * @param path - The command path segment to check.\n * @returns True if the path is variable, false otherwise.\n */\nexport function isDynamicPathSegment(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 * @example\n * ```typescript\n * getDynamicPathSegmentName(\"[user]\"); // \"user\"\n * ```\n *\n * @param path - The command path segment.\n * @returns The variable name without square brackets.\n */\nexport function getDynamicPathSegmentName(path: string): string {\n return path.replaceAll(/^\\[+/g, \"\").replaceAll(/\\]+$/g, \"\");\n}\n\n/**\n * Determines if a given command path segment is a path segment group (enclosed in parentheses).\n *\n * @example\n * ```typescript\n * isPathSegmentGroup(\"(user)\"); // true\n * isPathSegmentGroup(\"[user]\"); // false\n * isPathSegmentGroup(\"user\"); // false\n * ```\n *\n * @param path - The command path segment to check.\n * @returns True if the path is a path segment group, false otherwise.\n */\nexport function isPathSegmentGroup(path: string): boolean {\n return (path.startsWith(\"(\") && path.endsWith(\")\")) || path.startsWith(\"_\");\n}\n\n/**\n * Extracts the group name from a command path segment by removing enclosing parentheses.\n *\n * @example\n * ```typescript\n * getPathSegmentGroupName(\"(admin)\"); // \"admin\"\n * getPathSegmentGroupName(\"((group))\"); // \"group\"\n * ```\n *\n * @param path - The command path segment.\n * @returns The group name without parentheses.\n */\nexport function getPathSegmentGroupName(path: string): string {\n return path\n .replaceAll(/^\\(+/g, \"\")\n .replaceAll(/\\)+$/g, \"\")\n .replaceAll(/^_+/g, \"\");\n}\n\n/**\n * Extracts the variable name from a command path segment by removing enclosing square brackets.\n *\n * @example\n * ```typescript\n * getDynamicPathSegmentName(\"[user]\"); // \"user\"\n * ```\n *\n * @param path - The command path segment.\n * @returns The variable name without square brackets.\n */\nexport function getPathSegmentName(path: string): string {\n return getPathSegmentGroupName(getDynamicPathSegmentName(path));\n}\n"],"mappings":";;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE9B,QAAO;;;;;;;;AA6BT,SAAc,eAAc,SAAA;AAC1B,KAAE,QAAS,WAAA,EACX,QAAA,EAAA;CAEA,MAAM,SAAS,QAAQ,OAAO,cAAS,UAAa,MAAM,WAAA,GAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA;AAC1D,QAAO,KAAK,GAAG,QAAQ,OAAO,cAAS,UAAa,MAAK,SAAA,GAAA;EAAA;EAAA;EAAA;EAAA,CAAA,CAAA,CAAA;;;;;;;;AAG3D,eAAA,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;AAQA,SAAE,WAAA,SAAA;CACF,MAAO,SAAS,QAAA,OAAW,SAAS,YAAiB,QAAG,OAAU,IAAM,IAAC,MAAA,QAAA,QAAA,OAAA,IAAA,IAAA,QAAA,OAAA,IAAA,SAAA,KAAA,YAAA,QAAA,OAAA,IAAA,GAAA,GAAA,YAAA,QAAA,OAAA,IAAA,GAAA,QAAA,OAAA,MAAA,QAAA,OAAA,IAAA,KAAA,QAAA,aAAA;AACvE,KAAA,CAAK,YAAQ,OAAA,CACX,OAAA,IAAQ,MAAO,qIAAM;AAEvB,QAAG,UAAc,OAAO;;AAE1B,WAAM,SAAY;CAAA;CAAsB;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;AAQxC,SAAK,YAAA,SAAA,aAAA,OAAA;CACH,MAAA,QAAA,QAAA,OAAA,SAAA,UAAA,QAAA,OAAA,QAAA,WAAA,QAAA,CAAA;;;AAGF,YAAA,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;AAOA,SAAgB,kBAAkB,SAAS;AACzC,QAAA,QAAA,OAAA,eAAA,QAAA,aAAA,eAAA,OAAA,YAAA,SAAA,KAAA,CAAA;;AAEF,kBAAW,SAAA;CAAiB;CAAU;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;AAOtC,SAAS,UAAA,SAAA;AACP,QAAE,YAAA,QAAA,OAAA,IAAA,GAAA,OAAA,KAAA,QAAA,OAAA,IAAA,CAAA,KAAA,UAAA,WAAA,QAAA,CAAA;;AAEJ,UAAU,SAAQ;CAAA;CAAa;CAAQ;CAAW;CAAsC;CAAA;;;;;;;;;;;;;AAaxF,SAAgB,qBAAiB,MAAA;AAC/B,QAAO,KAAE,WAAA,IAAkB,IAAE,KAAA,SAAA,IAAA;;AAE/B,qBAAS,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;;;;;AAYT,SAAE,0BAAA,MAAA;AACF,QAAO,KAAA,WAAkB,SAAS,GAAC,CAAA,WAAU,SAAO,GAAA;;AAEpD,0BAA0B,SAAO;CAAG;CAAI;CAAA;CAAA;CAAA;;;;;;;;;;;;;;AAcxC,SAAgB,mBAAgB,MAAS;AACvC,QAAA,KAAA,WAAA,IAAA,IAAA,KAAA,SAAA,IAAA,IAAA,KAAA,WAAA,IAAA;;AAEF,mBAAc,SAAc;CAAC;CAAQ;CAAc;CAAA;CAAA;;;;;;;;;;;;;AAanD,SAAE,wBAAA,MAAA;AACF,QAAO,KAAA,WAAS,SAAA,GAAA,CAAA,WAAgC,SAAS,GAAA,CAAA,WAAO,QAAA,GAAA;;AAEhE,wBAAA,SAAA;CAAA;CAAA;CAAA;CAAA;CAAA;;;;;;;;;;;;AAYA,SAAgB,mBAAkB,MAAO;AACvC,QAAE,wBAA6B,0BAA0B,KAAC,CAAA;;AAE5D,mBAAgB,SAAA;CAAA;CAAmB;CAAuB;CAAA;CAAA"}
|