@shell-shock/core 0.2.0 → 0.2.1
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 +45 -1
- package/dist/api.mjs +44 -1
- package/dist/components/index.cjs +7 -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/components/utils-builtin.cjs +453 -0
- package/dist/components/utils-builtin.d.cts +27 -0
- package/dist/components/utils-builtin.d.mts +27 -0
- package/dist/components/utils-builtin.mjs +447 -0
- package/dist/config.cjs +17 -1
- package/dist/config.mjs +16 -1
- package/dist/helpers/persistence.cjs +49 -1
- package/dist/helpers/persistence.mjs +46 -1
- package/dist/helpers/resolve-command.cjs +92 -1
- package/dist/helpers/resolve-command.mjs +88 -1
- package/dist/helpers/update-package-json.cjs +28 -1
- package/dist/helpers/update-package-json.mjs +27 -1
- package/dist/helpers/utilities.cjs +41 -1
- package/dist/helpers/utilities.mjs +38 -1
- package/dist/index.cjs +24 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +1 -2
- package/dist/index.mjs +19 -1
- package/dist/plugin-utils/get-command-tree.cjs +22 -0
- package/dist/plugin-utils/get-command-tree.d.cts +15 -0
- package/dist/plugin-utils/get-command-tree.d.mts +15 -0
- package/dist/plugin-utils/get-command-tree.mjs +21 -0
- package/dist/plugin-utils/index.cjs +3 -0
- package/dist/plugin-utils/index.d.cts +2 -0
- package/dist/plugin-utils/index.d.mts +2 -0
- package/dist/plugin-utils/index.mjs +3 -0
- package/dist/powerlines.cjs +172 -3
- package/dist/powerlines.mjs +168 -3
- package/dist/types/command.mjs +1 -1
- package/dist/types/config.d.cts +4 -19
- package/dist/types/config.d.mts +4 -19
- package/dist/types/config.mjs +1 -1
- package/dist/types/context.d.cts +2 -1
- package/dist/types/context.d.mts +2 -1
- package/dist/types/context.mjs +1 -1
- package/dist/types/index.mjs +1 -1
- package/dist/types/options.mjs +1 -1
- package/package.json +75 -15
- 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
|
@@ -1 +1,92 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let __stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
|
|
3
|
+
let __stryke_path_append = require("@stryke/path/append");
|
|
4
|
+
let __stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
|
|
5
|
+
let __stryke_path_replace = require("@stryke/path/replace");
|
|
6
|
+
let __stryke_path_resolve_parent_path = require("@stryke/path/resolve-parent-path");
|
|
7
|
+
let __stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
8
|
+
let __stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
9
|
+
let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
10
|
+
let __powerlines_deepkit_reflect_type = require("@powerlines/deepkit/reflect-type");
|
|
11
|
+
let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
12
|
+
let __stryke_path_common = require("@stryke/path/common");
|
|
13
|
+
let __stryke_path_normalize = require("@stryke/path/normalize");
|
|
14
|
+
let __stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
15
|
+
|
|
16
|
+
//#region src/helpers/resolve-command.ts
|
|
17
|
+
function resolveCommandPath(context, file) {
|
|
18
|
+
return (0, __stryke_path_replace.replacePath)((0, __stryke_path_file_path_fns.findFilePath)(file), context.commandsPath).replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "");
|
|
19
|
+
}
|
|
20
|
+
function findCommandsRoot(context) {
|
|
21
|
+
if ((0, __stryke_type_checks_is_set_string.isSetString)(context.config.entry)) return (0, __stryke_path_append.appendPath)((0, __stryke_path_append.appendPath)((0, __stryke_path_normalize.stripStars)(context.config.entry), context.config.projectRoot), context.workspaceConfig.workspaceRoot);
|
|
22
|
+
else if ((0, __stryke_type_checks_is_set_object.isSetObject)(context.config.entry) && "file" in context.config.entry) return (0, __stryke_path_append.appendPath)((0, __stryke_path_append.appendPath)((0, __stryke_path_normalize.stripStars)(context.config.entry.file), context.config.projectRoot), context.workspaceConfig.workspaceRoot);
|
|
23
|
+
else if (Array.isArray(context.config.entry) && context.config.entry.length > 0) return (0, __stryke_path_common.commonPath)(context.config.entry.map((entry) => (0, __stryke_path_append.appendPath)((0, __stryke_path_append.appendPath)((0, __stryke_path_normalize.stripStars)((0, __stryke_type_checks_is_set_string.isSetString)(entry) ? entry : entry.file), context.config.projectRoot), context.workspaceConfig.workspaceRoot)));
|
|
24
|
+
return (0, __stryke_path_append.appendPath)(context.config.sourceRoot || context.config.projectRoot, context.workspaceConfig.workspaceRoot);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Finds the command name from the given file path.
|
|
28
|
+
*
|
|
29
|
+
* @param file - The file path to extract the command name from.
|
|
30
|
+
* @returns The command name.
|
|
31
|
+
*/
|
|
32
|
+
function findCommandName(file) {
|
|
33
|
+
let name = (0, __stryke_path_file_path_fns.findFolderName)(file);
|
|
34
|
+
let count = 1;
|
|
35
|
+
while (name.startsWith("[") && name.endsWith("]")) name = (0, __stryke_path_file_path_fns.findFolderName)((0, __stryke_path_resolve_parent_path.resolveParentPath)(file, count++));
|
|
36
|
+
return name;
|
|
37
|
+
}
|
|
38
|
+
async function reflectCommandTree(context, command, parent) {
|
|
39
|
+
const title = command.title || `${parent?.title ? `${parent.title} - ` : ""}${(0, __stryke_string_format_title_case.titleCase)(command.name)}`;
|
|
40
|
+
const commandTree = {
|
|
41
|
+
...command,
|
|
42
|
+
title,
|
|
43
|
+
description: command.description || `The ${title} ${parent ? "sub-" : ""}command.`,
|
|
44
|
+
options: {},
|
|
45
|
+
params: [],
|
|
46
|
+
parent: parent ?? null,
|
|
47
|
+
children: {}
|
|
48
|
+
};
|
|
49
|
+
if (context.config.defaultOptions === false) commandTree.options = {};
|
|
50
|
+
else if (Array.isArray(context.config.defaultOptions)) commandTree.options = Object.fromEntries((0, __stryke_helpers_get_unique.getUniqueBy)(context.config.defaultOptions, (item) => item.name).map((option) => [option.name, option]));
|
|
51
|
+
else if ((0, __stryke_type_checks_is_function.isFunction)(context.config.defaultOptions)) commandTree.options = Object.fromEntries((0, __stryke_helpers_get_unique.getUniqueBy)(context.config.defaultOptions(context, command), (item) => item.name).map((option) => [option.name, option]));
|
|
52
|
+
if (command.isVirtual) context.trace(`Adding reflection for virtual command: ${command.id}`);
|
|
53
|
+
else {
|
|
54
|
+
if (!command.entry.input?.file || !context.fs.existsSync(command.entry.input.file)) throw new Error(`${!command.entry.input?.file ? "Missing" : "Non-existent"} command entry file for "${command.name}"`);
|
|
55
|
+
context.trace(`Adding reflection for user-defined command: ${command.id} (file: ${command.entry.input.file})`);
|
|
56
|
+
const type = await (0, __powerlines_deepkit_reflect_type.reflectType)(context, command.entry.input);
|
|
57
|
+
if (type.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.function) throw new Error(`The command entry file "${command.entry.input.file}" does not export a valid function.`);
|
|
58
|
+
if (type.parameters.length > 0 && type.parameters[0]) {
|
|
59
|
+
const firstParam = type.parameters[0];
|
|
60
|
+
if (firstParam.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral || firstParam.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.class) {
|
|
61
|
+
const optionsReflection = __powerlines_deepkit_vendor_type.ReflectionClass.from(firstParam.type);
|
|
62
|
+
for (const propertyReflection of optionsReflection.getProperties()) {
|
|
63
|
+
const propertyType = propertyReflection.getType();
|
|
64
|
+
commandTree.options[propertyReflection.getNameAsString()] = {
|
|
65
|
+
name: propertyReflection.getNameAsString(),
|
|
66
|
+
alias: propertyReflection.getTags().alias ?? [],
|
|
67
|
+
title: propertyReflection.getTags().title || (0, __stryke_string_format_title_case.titleCase)(propertyReflection.getNameAsString()),
|
|
68
|
+
description: propertyReflection.getDescription(),
|
|
69
|
+
kind: propertyType.kind,
|
|
70
|
+
optional: propertyReflection.isOptional(),
|
|
71
|
+
default: propertyReflection.getDefaultValue(),
|
|
72
|
+
variadic: false
|
|
73
|
+
};
|
|
74
|
+
commandTree.options[propertyReflection.getNameAsString()].description ??= `The ${commandTree.options[propertyReflection.getNameAsString()].title} option.`;
|
|
75
|
+
if (propertyType.kind === __powerlines_deepkit_vendor_type.ReflectionKind.array) if (propertyType.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.string || propertyType.type.kind === __powerlines_deepkit_vendor_type.ReflectionKind.number) {
|
|
76
|
+
commandTree.options[propertyReflection.getNameAsString()].variadic = true;
|
|
77
|
+
commandTree.options[propertyReflection.getNameAsString()].kind = propertyType.type.kind;
|
|
78
|
+
} else throw new Error(`Unsupported array type for option "${propertyReflection.getNameAsString()}" in command "${command.name}". Only string[] and number[] are supported.`);
|
|
79
|
+
else if (propertyType.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.boolean && propertyType.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.string && propertyType.kind !== __powerlines_deepkit_vendor_type.ReflectionKind.number) throw new Error(`Unsupported type for option "${propertyReflection.getNameAsString()}" in command "${command.name}". Only string, number, boolean, string[] and number[] are supported, received ${(0, __powerlines_deepkit_vendor_type.stringifyType)(propertyType).trim().replaceAll(" | ", ", or ")}.`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
for (const input of context.inputs.filter((input$1) => input$1.path.length === command.path.length + 1 && input$1.path.slice(0, command.path.length).every((value, index) => value === command.path[index]))) commandTree.children[input.name] = await reflectCommandTree(context, input, commandTree);
|
|
85
|
+
return commandTree;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
exports.findCommandName = findCommandName;
|
|
90
|
+
exports.findCommandsRoot = findCommandsRoot;
|
|
91
|
+
exports.reflectCommandTree = reflectCommandTree;
|
|
92
|
+
exports.resolveCommandPath = resolveCommandPath;
|
|
@@ -1 +1,88 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getUniqueBy } from "@stryke/helpers/get-unique";
|
|
2
|
+
import { appendPath } from "@stryke/path/append";
|
|
3
|
+
import { findFilePath, findFolderName } from "@stryke/path/file-path-fns";
|
|
4
|
+
import { replacePath } from "@stryke/path/replace";
|
|
5
|
+
import { resolveParentPath } from "@stryke/path/resolve-parent-path";
|
|
6
|
+
import { titleCase } from "@stryke/string-format/title-case";
|
|
7
|
+
import { isFunction } from "@stryke/type-checks/is-function";
|
|
8
|
+
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
9
|
+
import { reflectType } from "@powerlines/deepkit/reflect-type";
|
|
10
|
+
import { ReflectionClass, ReflectionKind, stringifyType } from "@powerlines/deepkit/vendor/type";
|
|
11
|
+
import { commonPath } from "@stryke/path/common";
|
|
12
|
+
import { stripStars } from "@stryke/path/normalize";
|
|
13
|
+
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
14
|
+
|
|
15
|
+
//#region src/helpers/resolve-command.ts
|
|
16
|
+
function resolveCommandPath(context, file) {
|
|
17
|
+
return replacePath(findFilePath(file), context.commandsPath).replaceAll(/^\/+/g, "").replaceAll(/\/+$/g, "");
|
|
18
|
+
}
|
|
19
|
+
function findCommandsRoot(context) {
|
|
20
|
+
if (isSetString(context.config.entry)) return appendPath(appendPath(stripStars(context.config.entry), context.config.projectRoot), context.workspaceConfig.workspaceRoot);
|
|
21
|
+
else if (isSetObject(context.config.entry) && "file" in context.config.entry) return appendPath(appendPath(stripStars(context.config.entry.file), context.config.projectRoot), context.workspaceConfig.workspaceRoot);
|
|
22
|
+
else if (Array.isArray(context.config.entry) && context.config.entry.length > 0) return commonPath(context.config.entry.map((entry) => appendPath(appendPath(stripStars(isSetString(entry) ? entry : entry.file), context.config.projectRoot), context.workspaceConfig.workspaceRoot)));
|
|
23
|
+
return appendPath(context.config.sourceRoot || context.config.projectRoot, context.workspaceConfig.workspaceRoot);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Finds the command name from the given file path.
|
|
27
|
+
*
|
|
28
|
+
* @param file - The file path to extract the command name from.
|
|
29
|
+
* @returns The command name.
|
|
30
|
+
*/
|
|
31
|
+
function findCommandName(file) {
|
|
32
|
+
let name = findFolderName(file);
|
|
33
|
+
let count = 1;
|
|
34
|
+
while (name.startsWith("[") && name.endsWith("]")) name = findFolderName(resolveParentPath(file, count++));
|
|
35
|
+
return name;
|
|
36
|
+
}
|
|
37
|
+
async function reflectCommandTree(context, command, parent) {
|
|
38
|
+
const title = command.title || `${parent?.title ? `${parent.title} - ` : ""}${titleCase(command.name)}`;
|
|
39
|
+
const commandTree = {
|
|
40
|
+
...command,
|
|
41
|
+
title,
|
|
42
|
+
description: command.description || `The ${title} ${parent ? "sub-" : ""}command.`,
|
|
43
|
+
options: {},
|
|
44
|
+
params: [],
|
|
45
|
+
parent: parent ?? null,
|
|
46
|
+
children: {}
|
|
47
|
+
};
|
|
48
|
+
if (context.config.defaultOptions === false) commandTree.options = {};
|
|
49
|
+
else if (Array.isArray(context.config.defaultOptions)) commandTree.options = Object.fromEntries(getUniqueBy(context.config.defaultOptions, (item) => item.name).map((option) => [option.name, option]));
|
|
50
|
+
else if (isFunction(context.config.defaultOptions)) commandTree.options = Object.fromEntries(getUniqueBy(context.config.defaultOptions(context, command), (item) => item.name).map((option) => [option.name, option]));
|
|
51
|
+
if (command.isVirtual) context.trace(`Adding reflection for virtual command: ${command.id}`);
|
|
52
|
+
else {
|
|
53
|
+
if (!command.entry.input?.file || !context.fs.existsSync(command.entry.input.file)) throw new Error(`${!command.entry.input?.file ? "Missing" : "Non-existent"} command entry file for "${command.name}"`);
|
|
54
|
+
context.trace(`Adding reflection for user-defined command: ${command.id} (file: ${command.entry.input.file})`);
|
|
55
|
+
const type = await reflectType(context, command.entry.input);
|
|
56
|
+
if (type.kind !== ReflectionKind.function) throw new Error(`The command entry file "${command.entry.input.file}" does not export a valid function.`);
|
|
57
|
+
if (type.parameters.length > 0 && type.parameters[0]) {
|
|
58
|
+
const firstParam = type.parameters[0];
|
|
59
|
+
if (firstParam.type.kind === ReflectionKind.objectLiteral || firstParam.type.kind === ReflectionKind.class) {
|
|
60
|
+
const optionsReflection = ReflectionClass.from(firstParam.type);
|
|
61
|
+
for (const propertyReflection of optionsReflection.getProperties()) {
|
|
62
|
+
const propertyType = propertyReflection.getType();
|
|
63
|
+
commandTree.options[propertyReflection.getNameAsString()] = {
|
|
64
|
+
name: propertyReflection.getNameAsString(),
|
|
65
|
+
alias: propertyReflection.getTags().alias ?? [],
|
|
66
|
+
title: propertyReflection.getTags().title || titleCase(propertyReflection.getNameAsString()),
|
|
67
|
+
description: propertyReflection.getDescription(),
|
|
68
|
+
kind: propertyType.kind,
|
|
69
|
+
optional: propertyReflection.isOptional(),
|
|
70
|
+
default: propertyReflection.getDefaultValue(),
|
|
71
|
+
variadic: false
|
|
72
|
+
};
|
|
73
|
+
commandTree.options[propertyReflection.getNameAsString()].description ??= `The ${commandTree.options[propertyReflection.getNameAsString()].title} option.`;
|
|
74
|
+
if (propertyType.kind === ReflectionKind.array) if (propertyType.type.kind === ReflectionKind.string || propertyType.type.kind === ReflectionKind.number) {
|
|
75
|
+
commandTree.options[propertyReflection.getNameAsString()].variadic = true;
|
|
76
|
+
commandTree.options[propertyReflection.getNameAsString()].kind = propertyType.type.kind;
|
|
77
|
+
} else throw new Error(`Unsupported array type for option "${propertyReflection.getNameAsString()}" in command "${command.name}". Only string[] and number[] are supported.`);
|
|
78
|
+
else if (propertyType.kind !== ReflectionKind.boolean && propertyType.kind !== ReflectionKind.string && propertyType.kind !== ReflectionKind.number) throw new Error(`Unsupported type for option "${propertyReflection.getNameAsString()}" in command "${command.name}". Only string, number, boolean, string[] and number[] are supported, received ${stringifyType(propertyType).trim().replaceAll(" | ", ", or ")}.`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
for (const input of context.inputs.filter((input$1) => input$1.path.length === command.path.length + 1 && input$1.path.slice(0, command.path.length).every((value, index) => value === command.path[index]))) commandTree.children[input.name] = await reflectCommandTree(context, input, commandTree);
|
|
84
|
+
return commandTree;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
export { findCommandName, findCommandsRoot, reflectCommandTree, resolveCommandPath };
|
|
@@ -1 +1,28 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let __stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
|
|
3
|
+
let __stryke_path_join_paths = require("@stryke/path/join-paths");
|
|
4
|
+
let __stryke_path_replace = require("@stryke/path/replace");
|
|
5
|
+
let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
6
|
+
let __stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
7
|
+
let __stryke_json_storm_json = require("@stryke/json/storm-json");
|
|
8
|
+
let __stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
|
|
9
|
+
|
|
10
|
+
//#region src/helpers/update-package-json.ts
|
|
11
|
+
function formatBinaryPath(name, format) {
|
|
12
|
+
return `./bin/${(0, __stryke_string_format_kebab_case.kebabCase)((0, __stryke_path_replace.replaceExtension)(name))}.${format === "cjs" || Array.isArray(format) && format.includes("cjs") ? "cjs" : "mjs"}`;
|
|
13
|
+
}
|
|
14
|
+
async function updatePackageJsonBinary(context) {
|
|
15
|
+
const packageJsonPath = (0, __stryke_path_join_paths.joinPaths)(context.workspaceConfig.workspaceRoot, context.config.projectRoot, "package.json");
|
|
16
|
+
if (context.config.bin && Array.isArray(context.config.bin) && context.config.bin.length > 0) {
|
|
17
|
+
context.packageJson.bin = Object.fromEntries((0, __stryke_helpers_get_unique.getUnique)((0, __stryke_convert_to_array.toArray)(context.config.bin)).map((bin) => [bin, formatBinaryPath(bin, context.config.output.format)]));
|
|
18
|
+
await context.fs.write(packageJsonPath, __stryke_json_storm_json.StormJSON.stringify(context.packageJson));
|
|
19
|
+
} else if (!(0, __stryke_type_checks_is_set_object.isSetObject)(context.packageJson.bin) && (context.config.name || context.packageJson.name)) {
|
|
20
|
+
context.packageJson.bin = { [context.config.name || context.packageJson.name]: formatBinaryPath(context.config.name || context.packageJson.name, context.config.output.format) };
|
|
21
|
+
await context.fs.write(packageJsonPath, __stryke_json_storm_json.StormJSON.stringify(context.packageJson));
|
|
22
|
+
}
|
|
23
|
+
if (!(0, __stryke_type_checks_is_set_object.isSetObject)(context.packageJson.bin)) throw new Error("Unable to determine the CLI binary name. Please specify the `bin` option in your Shell Shock configuration or ensure that the `name` field is set in your package.json.");
|
|
24
|
+
context.config.bin = Object.keys(context.packageJson.bin);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.updatePackageJsonBinary = updatePackageJsonBinary;
|
|
@@ -1 +1,27 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getUnique } from "@stryke/helpers/get-unique";
|
|
2
|
+
import { joinPaths } from "@stryke/path/join-paths";
|
|
3
|
+
import { replaceExtension } from "@stryke/path/replace";
|
|
4
|
+
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
5
|
+
import { toArray } from "@stryke/convert/to-array";
|
|
6
|
+
import { StormJSON } from "@stryke/json/storm-json";
|
|
7
|
+
import { kebabCase } from "@stryke/string-format/kebab-case";
|
|
8
|
+
|
|
9
|
+
//#region src/helpers/update-package-json.ts
|
|
10
|
+
function formatBinaryPath(name, format) {
|
|
11
|
+
return `./bin/${kebabCase(replaceExtension(name))}.${format === "cjs" || Array.isArray(format) && format.includes("cjs") ? "cjs" : "mjs"}`;
|
|
12
|
+
}
|
|
13
|
+
async function updatePackageJsonBinary(context) {
|
|
14
|
+
const packageJsonPath = joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot, "package.json");
|
|
15
|
+
if (context.config.bin && Array.isArray(context.config.bin) && context.config.bin.length > 0) {
|
|
16
|
+
context.packageJson.bin = Object.fromEntries(getUnique(toArray(context.config.bin)).map((bin) => [bin, formatBinaryPath(bin, context.config.output.format)]));
|
|
17
|
+
await context.fs.write(packageJsonPath, StormJSON.stringify(context.packageJson));
|
|
18
|
+
} else if (!isSetObject(context.packageJson.bin) && (context.config.name || context.packageJson.name)) {
|
|
19
|
+
context.packageJson.bin = { [context.config.name || context.packageJson.name]: formatBinaryPath(context.config.name || context.packageJson.name, context.config.output.format) };
|
|
20
|
+
await context.fs.write(packageJsonPath, StormJSON.stringify(context.packageJson));
|
|
21
|
+
}
|
|
22
|
+
if (!isSetObject(context.packageJson.bin)) throw new Error("Unable to determine the CLI binary name. Please specify the `bin` option in your Shell Shock configuration or ensure that the `name` field is set in your package.json.");
|
|
23
|
+
context.config.bin = Object.keys(context.packageJson.bin);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { updatePackageJsonBinary };
|
|
@@ -1 +1,41 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let __stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
3
|
+
let __stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
4
|
+
let __stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
|
|
5
|
+
|
|
6
|
+
//#region src/helpers/utilities.ts
|
|
7
|
+
/**
|
|
8
|
+
* Retrieves the application name from the context and configuration.
|
|
9
|
+
*
|
|
10
|
+
* @param context - The build context containing workspace and package information.
|
|
11
|
+
* @returns The application name in kebab-case format.
|
|
12
|
+
* @throws An error if no valid application name is found.
|
|
13
|
+
*/
|
|
14
|
+
function getAppName(context) {
|
|
15
|
+
const result = context.config.bin && ((0, __stryke_type_checks_is_set_string.isSetString)(context.config.bin) || Array.isArray(context.config.bin) && context.config.bin.length > 0 && context.config.bin[0]) ? (0, __stryke_type_checks_is_set_string.isSetString)(context.config.bin) ? context.config.bin : context.config.bin[0] : context.config.name || context.packageJson?.name;
|
|
16
|
+
if (!(0, __stryke_type_checks_is_set_string.isSetString)(result)) throw new Error("No application name found. Please provide a 'bin' option in the configuration or ensure the package.json has a valid 'name' field.");
|
|
17
|
+
return (0, __stryke_string_format_kebab_case.kebabCase)(result);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves the application title from the context and configuration.
|
|
21
|
+
*
|
|
22
|
+
* @param context - The build context containing workspace and package information.
|
|
23
|
+
* @returns The application title in title-case format.
|
|
24
|
+
*/
|
|
25
|
+
function getAppTitle(context) {
|
|
26
|
+
return (0, __stryke_string_format_title_case.titleCase)(context.config.name || getAppName(context));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves the application description from the context and configuration.
|
|
30
|
+
*
|
|
31
|
+
* @param context - The build context containing workspace and package information.
|
|
32
|
+
* @returns The application description.
|
|
33
|
+
*/
|
|
34
|
+
function getAppDescription(context) {
|
|
35
|
+
return context.config.description || context.packageJson?.description || `The ${getAppTitle(context)} command-line interface application.`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
exports.getAppDescription = getAppDescription;
|
|
40
|
+
exports.getAppName = getAppName;
|
|
41
|
+
exports.getAppTitle = getAppTitle;
|
|
@@ -1 +1,38 @@
|
|
|
1
|
-
import{titleCase
|
|
1
|
+
import { titleCase } from "@stryke/string-format/title-case";
|
|
2
|
+
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
3
|
+
import { kebabCase } from "@stryke/string-format/kebab-case";
|
|
4
|
+
|
|
5
|
+
//#region src/helpers/utilities.ts
|
|
6
|
+
/**
|
|
7
|
+
* Retrieves the application name from the context and configuration.
|
|
8
|
+
*
|
|
9
|
+
* @param context - The build context containing workspace and package information.
|
|
10
|
+
* @returns The application name in kebab-case format.
|
|
11
|
+
* @throws An error if no valid application name is found.
|
|
12
|
+
*/
|
|
13
|
+
function getAppName(context) {
|
|
14
|
+
const result = context.config.bin && (isSetString(context.config.bin) || Array.isArray(context.config.bin) && context.config.bin.length > 0 && context.config.bin[0]) ? isSetString(context.config.bin) ? context.config.bin : context.config.bin[0] : context.config.name || context.packageJson?.name;
|
|
15
|
+
if (!isSetString(result)) throw new Error("No application name found. Please provide a 'bin' option in the configuration or ensure the package.json has a valid 'name' field.");
|
|
16
|
+
return kebabCase(result);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves the application title from the context and configuration.
|
|
20
|
+
*
|
|
21
|
+
* @param context - The build context containing workspace and package information.
|
|
22
|
+
* @returns The application title in title-case format.
|
|
23
|
+
*/
|
|
24
|
+
function getAppTitle(context) {
|
|
25
|
+
return titleCase(context.config.name || getAppName(context));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves the application description from the context and configuration.
|
|
29
|
+
*
|
|
30
|
+
* @param context - The build context containing workspace and package information.
|
|
31
|
+
* @returns The application description.
|
|
32
|
+
*/
|
|
33
|
+
function getAppDescription(context) {
|
|
34
|
+
return context.config.description || context.packageJson?.description || `The ${getAppTitle(context)} command-line interface application.`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { getAppDescription, getAppName, getAppTitle };
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1,24 @@
|
|
|
1
|
-
Object.defineProperty(exports
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_powerlines = require('./powerlines.cjs');
|
|
3
|
+
const require_api = require('./api.cjs');
|
|
4
|
+
const require_config = require('./config.cjs');
|
|
5
|
+
|
|
6
|
+
//#region src/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new {@link ShellShockAPI} instance.
|
|
9
|
+
*
|
|
10
|
+
* @param options - The user configuration options.
|
|
11
|
+
* @returns A promise that resolves to a {@link ShellShockAPI} instance.
|
|
12
|
+
*/
|
|
13
|
+
async function createShellShock(options = {}) {
|
|
14
|
+
options.root ??= process.cwd();
|
|
15
|
+
return require_api.ShellShockAPI.from(options);
|
|
16
|
+
}
|
|
17
|
+
var src_default = require_api.ShellShockAPI;
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.ShellShockAPI = require_api.ShellShockAPI;
|
|
21
|
+
exports.createShellShock = createShellShock;
|
|
22
|
+
exports.default = src_default;
|
|
23
|
+
exports.defineConfig = require_config.defineConfig;
|
|
24
|
+
exports.shellShock = require_powerlines.shellShock;
|
package/dist/index.d.cts
CHANGED
|
@@ -3,9 +3,9 @@ import { Context } from "./types/context.cjs";
|
|
|
3
3
|
import { Options, ResolvedConfig, UserConfig } from "./types/config.cjs";
|
|
4
4
|
import { ShellShockAPI } from "./api.cjs";
|
|
5
5
|
import { defineConfig } from "./config.cjs";
|
|
6
|
-
import { getDefaultOptions } from "./helpers/get-default-options.cjs";
|
|
7
6
|
import shellShock from "./powerlines.cjs";
|
|
8
7
|
import { BaseCommandOptions } from "./types/options.cjs";
|
|
8
|
+
import "./types/index.cjs";
|
|
9
9
|
|
|
10
10
|
//#region src/index.d.ts
|
|
11
11
|
|
|
@@ -17,4 +17,4 @@ import { BaseCommandOptions } from "./types/options.cjs";
|
|
|
17
17
|
*/
|
|
18
18
|
declare function createShellShock(options?: Partial<UserConfig>): Promise<ShellShockAPI>;
|
|
19
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,
|
|
20
|
+
export { BaseCommandOption, BaseCommandOptions, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandTree, Context, NumberCommandOption, Options, ResolvedConfig, SerializedCommandTree, ShellShockAPI, ShellShockAPI as default, StringCommandOption, UserConfig, createShellShock, defineConfig, shellShock };
|
package/dist/index.d.mts
CHANGED
|
@@ -3,7 +3,6 @@ import { Context } from "./types/context.mjs";
|
|
|
3
3
|
import { Options, ResolvedConfig, UserConfig } from "./types/config.mjs";
|
|
4
4
|
import { ShellShockAPI } from "./api.mjs";
|
|
5
5
|
import { defineConfig } from "./config.mjs";
|
|
6
|
-
import { getDefaultOptions } from "./helpers/get-default-options.mjs";
|
|
7
6
|
import shellShock from "./powerlines.mjs";
|
|
8
7
|
import { BaseCommandOptions } from "./types/options.mjs";
|
|
9
8
|
import "./types/index.mjs";
|
|
@@ -18,4 +17,4 @@ import "./types/index.mjs";
|
|
|
18
17
|
*/
|
|
19
18
|
declare function createShellShock(options?: Partial<UserConfig>): Promise<ShellShockAPI>;
|
|
20
19
|
//#endregion
|
|
21
|
-
export { BaseCommandOption, BaseCommandOptions, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandTree, Context, NumberCommandOption, Options, ResolvedConfig, SerializedCommandTree, ShellShockAPI, ShellShockAPI as default, StringCommandOption, UserConfig, createShellShock, defineConfig,
|
|
20
|
+
export { BaseCommandOption, BaseCommandOptions, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandTree, Context, NumberCommandOption, Options, ResolvedConfig, SerializedCommandTree, ShellShockAPI, ShellShockAPI as default, StringCommandOption, UserConfig, createShellShock, defineConfig, shellShock };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,19 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { shellShock } from "./powerlines.mjs";
|
|
2
|
+
import { ShellShockAPI } from "./api.mjs";
|
|
3
|
+
import { defineConfig } from "./config.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/index.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new {@link ShellShockAPI} instance.
|
|
8
|
+
*
|
|
9
|
+
* @param options - The user configuration options.
|
|
10
|
+
* @returns A promise that resolves to a {@link ShellShockAPI} instance.
|
|
11
|
+
*/
|
|
12
|
+
async function createShellShock(options = {}) {
|
|
13
|
+
options.root ??= process.cwd();
|
|
14
|
+
return ShellShockAPI.from(options);
|
|
15
|
+
}
|
|
16
|
+
var src_default = ShellShockAPI;
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { ShellShockAPI, createShellShock, src_default as default, defineConfig, shellShock };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/plugin-utils/get-command-tree.ts
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves a specific command tree based on the provided path.
|
|
5
|
+
*
|
|
6
|
+
* @param context - The build context containing the command definitions.
|
|
7
|
+
* @param path - An array of strings representing the command path.
|
|
8
|
+
* @returns The command tree at the specified path, or null if not found.
|
|
9
|
+
*/
|
|
10
|
+
function getCommandTree(context, path = []) {
|
|
11
|
+
if (path.length === 0) return null;
|
|
12
|
+
let currentTree = context.commands[path[0]] ?? null;
|
|
13
|
+
if (path.length > 1) {
|
|
14
|
+
const segments = path.slice(1);
|
|
15
|
+
for (const segment of segments) if (currentTree?.children && Object.prototype.hasOwnProperty.call(currentTree.children, segment)) currentTree = currentTree.children[segment] ?? null;
|
|
16
|
+
else return null;
|
|
17
|
+
}
|
|
18
|
+
return currentTree;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.getCommandTree = getCommandTree;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CommandTree } from "../types/command.cjs";
|
|
2
|
+
import { Context } from "../types/context.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/plugin-utils/get-command-tree.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Retrieves a specific command tree based on the provided path.
|
|
8
|
+
*
|
|
9
|
+
* @param context - The build context containing the command definitions.
|
|
10
|
+
* @param path - An array of strings representing the command path.
|
|
11
|
+
* @returns The command tree at the specified path, or null if not found.
|
|
12
|
+
*/
|
|
13
|
+
declare function getCommandTree(context: Context, path?: string[]): CommandTree | null;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { getCommandTree };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CommandTree } from "../types/command.mjs";
|
|
2
|
+
import { Context } from "../types/context.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/plugin-utils/get-command-tree.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Retrieves a specific command tree based on the provided path.
|
|
8
|
+
*
|
|
9
|
+
* @param context - The build context containing the command definitions.
|
|
10
|
+
* @param path - An array of strings representing the command path.
|
|
11
|
+
* @returns The command tree at the specified path, or null if not found.
|
|
12
|
+
*/
|
|
13
|
+
declare function getCommandTree(context: Context, path?: string[]): CommandTree | null;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { getCommandTree };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/plugin-utils/get-command-tree.ts
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves a specific command tree based on the provided path.
|
|
4
|
+
*
|
|
5
|
+
* @param context - The build context containing the command definitions.
|
|
6
|
+
* @param path - An array of strings representing the command path.
|
|
7
|
+
* @returns The command tree at the specified path, or null if not found.
|
|
8
|
+
*/
|
|
9
|
+
function getCommandTree(context, path = []) {
|
|
10
|
+
if (path.length === 0) return null;
|
|
11
|
+
let currentTree = context.commands[path[0]] ?? null;
|
|
12
|
+
if (path.length > 1) {
|
|
13
|
+
const segments = path.slice(1);
|
|
14
|
+
for (const segment of segments) if (currentTree?.children && Object.prototype.hasOwnProperty.call(currentTree.children, segment)) currentTree = currentTree.children[segment] ?? null;
|
|
15
|
+
else return null;
|
|
16
|
+
}
|
|
17
|
+
return currentTree;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { getCommandTree };
|