@shell-shock/core 0.1.1 → 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.d.cts +7 -0
- package/dist/api.d.mts +7 -0
- 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 -0
- package/dist/helpers/persistence.mjs +46 -0
- 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 -0
- package/dist/helpers/utilities.mjs +38 -0
- package/dist/index.cjs +24 -1
- package/dist/index.d.cts +16 -2
- package/dist/index.d.mts +15 -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 -2
- package/dist/powerlines.d.cts +2 -2
- package/dist/powerlines.d.mts +2 -2
- package/dist/powerlines.mjs +168 -2
- package/dist/types/command.d.cts +63 -0
- package/dist/types/command.d.mts +63 -0
- package/dist/types/command.mjs +1 -0
- package/dist/types/config.d.cts +9 -26
- package/dist/types/config.d.mts +9 -26
- package/dist/types/config.mjs +1 -1
- package/dist/types/context.cjs +0 -0
- package/dist/types/context.d.cts +26 -0
- package/dist/types/context.d.mts +26 -0
- package/dist/types/context.mjs +1 -0
- package/dist/types/index.d.cts +4 -2
- package/dist/types/index.d.mts +4 -2
- package/dist/types/index.mjs +1 -1
- package/dist/types/options.cjs +0 -0
- package/dist/types/options.d.cts +7 -0
- package/dist/types/options.d.mts +7 -0
- package/dist/types/options.mjs +1 -0
- package/package.json +76 -13
- package/dist/types/build.d.cts +0 -66
- package/dist/types/build.d.mts +0 -66
- package/dist/types/build.mjs +0 -1
- /package/dist/types/{build.cjs → command.cjs} +0 -0
|
@@ -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 };
|
|
@@ -0,0 +1,41 @@
|
|
|
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;
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
-
|
|
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
|
@@ -1,6 +1,20 @@
|
|
|
1
|
+
import { BaseCommandOption, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandTree, NumberCommandOption, SerializedCommandTree, StringCommandOption } from "./types/command.cjs";
|
|
2
|
+
import { Context } from "./types/context.cjs";
|
|
1
3
|
import { Options, ResolvedConfig, UserConfig } from "./types/config.cjs";
|
|
2
4
|
import { ShellShockAPI } from "./api.cjs";
|
|
3
5
|
import { defineConfig } from "./config.cjs";
|
|
4
|
-
import { BuildContext, CommandArg, CommandEntry, CommandRelations, CommandTree } from "./types/build.cjs";
|
|
5
6
|
import shellShock from "./powerlines.cjs";
|
|
6
|
-
|
|
7
|
+
import { BaseCommandOptions } from "./types/options.cjs";
|
|
8
|
+
import "./types/index.cjs";
|
|
9
|
+
|
|
10
|
+
//#region src/index.d.ts
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new {@link ShellShockAPI} instance.
|
|
14
|
+
*
|
|
15
|
+
* @param options - The user configuration options.
|
|
16
|
+
* @returns A promise that resolves to a {@link ShellShockAPI} instance.
|
|
17
|
+
*/
|
|
18
|
+
declare function createShellShock(options?: Partial<UserConfig>): Promise<ShellShockAPI>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { BaseCommandOption, BaseCommandOptions, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandTree, Context, NumberCommandOption, Options, ResolvedConfig, SerializedCommandTree, ShellShockAPI, ShellShockAPI as default, StringCommandOption, UserConfig, createShellShock, defineConfig, shellShock };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
|
+
import { BaseCommandOption, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandTree, NumberCommandOption, SerializedCommandTree, StringCommandOption } from "./types/command.mjs";
|
|
2
|
+
import { Context } from "./types/context.mjs";
|
|
1
3
|
import { Options, ResolvedConfig, UserConfig } from "./types/config.mjs";
|
|
2
4
|
import { ShellShockAPI } from "./api.mjs";
|
|
3
5
|
import { defineConfig } from "./config.mjs";
|
|
4
|
-
import { BuildContext, CommandArg, CommandEntry, CommandRelations, CommandTree } from "./types/build.mjs";
|
|
5
6
|
import shellShock from "./powerlines.mjs";
|
|
7
|
+
import { BaseCommandOptions } from "./types/options.mjs";
|
|
6
8
|
import "./types/index.mjs";
|
|
7
|
-
|
|
9
|
+
|
|
10
|
+
//#region src/index.d.ts
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new {@link ShellShockAPI} instance.
|
|
14
|
+
*
|
|
15
|
+
* @param options - The user configuration options.
|
|
16
|
+
* @returns A promise that resolves to a {@link ShellShockAPI} instance.
|
|
17
|
+
*/
|
|
18
|
+
declare function createShellShock(options?: Partial<UserConfig>): Promise<ShellShockAPI>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { BaseCommandOption, BaseCommandOptions, BooleanCommandOption, CommandBase, CommandInput, CommandOption, CommandParam, CommandTree, Context, NumberCommandOption, Options, ResolvedConfig, SerializedCommandTree, ShellShockAPI, ShellShockAPI as default, StringCommandOption, UserConfig, createShellShock, defineConfig, shellShock };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,19 @@
|
|
|
1
|
-
import{shellShock
|
|
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 };
|
package/dist/powerlines.cjs
CHANGED
|
@@ -1,2 +1,172 @@
|
|
|
1
|
-
Object.defineProperty(exports
|
|
2
|
-
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_persistence = require('./helpers/persistence.cjs');
|
|
4
|
+
const require_resolve_command = require('./helpers/resolve-command.cjs');
|
|
5
|
+
const require_update_package_json = require('./helpers/update-package-json.cjs');
|
|
6
|
+
const require_utilities = require('./helpers/utilities.cjs');
|
|
7
|
+
let __powerlines_plugin_tsdown = require("@powerlines/plugin-tsdown");
|
|
8
|
+
__powerlines_plugin_tsdown = require_rolldown_runtime.__toESM(__powerlines_plugin_tsdown);
|
|
9
|
+
let __stryke_fs_chmod_x = require("@stryke/fs/chmod-x");
|
|
10
|
+
let __stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
|
|
11
|
+
let __stryke_path_append = require("@stryke/path/append");
|
|
12
|
+
let __stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
|
|
13
|
+
let __stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
|
|
14
|
+
let __stryke_path_join_paths = require("@stryke/path/join-paths");
|
|
15
|
+
let __stryke_path_replace = require("@stryke/path/replace");
|
|
16
|
+
let __stryke_path_resolve_parent_path = require("@stryke/path/resolve-parent-path");
|
|
17
|
+
let __stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
18
|
+
let __stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
19
|
+
let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
20
|
+
let defu = require("defu");
|
|
21
|
+
|
|
22
|
+
//#region src/powerlines.ts
|
|
23
|
+
const MAX_DEPTH = 50;
|
|
24
|
+
/**
|
|
25
|
+
* The core Powerlines plugin to build Shell Shock projects.
|
|
26
|
+
*/
|
|
27
|
+
const shellShock = (options = {}) => {
|
|
28
|
+
return [
|
|
29
|
+
(0, __powerlines_plugin_tsdown.default)(),
|
|
30
|
+
{
|
|
31
|
+
name: "shell-shock:config",
|
|
32
|
+
async config() {
|
|
33
|
+
this.trace("Resolving the Shell Shock configuration.");
|
|
34
|
+
return (0, defu.defu)(options, {
|
|
35
|
+
entry: !this.config.entry || Array.isArray(this.config.entry) && this.config.entry.length === 0 ? [(0, __stryke_path_join_paths.joinPaths)(this.config.sourceRoot, "**/*")] : void 0,
|
|
36
|
+
build: {
|
|
37
|
+
target: "node22",
|
|
38
|
+
platform: "node"
|
|
39
|
+
},
|
|
40
|
+
type: "application",
|
|
41
|
+
framework: "shell-shock"
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
configResolved: {
|
|
45
|
+
order: "pre",
|
|
46
|
+
async handler() {
|
|
47
|
+
this.trace("Shell Shock configuration has been resolved.");
|
|
48
|
+
await require_update_package_json.updatePackageJsonBinary(this);
|
|
49
|
+
this.config.name = require_utilities.getAppName(this);
|
|
50
|
+
this.config.title = require_utilities.getAppTitle(this);
|
|
51
|
+
this.config.description = require_utilities.getAppDescription(this);
|
|
52
|
+
if (this.config.defaultOptions === false) this.options = [];
|
|
53
|
+
else if (Array.isArray(this.config.defaultOptions)) this.options = (0, __stryke_helpers_get_unique.getUniqueBy)(this.config.defaultOptions, (item) => item.name);
|
|
54
|
+
else if ((0, __stryke_type_checks_is_function.isFunction)(this.config.defaultOptions)) this.options = (0, __stryke_helpers_get_unique.getUniqueBy)(this.config.defaultOptions(this, {
|
|
55
|
+
id: null,
|
|
56
|
+
name: this.config.name,
|
|
57
|
+
title: this.config.title,
|
|
58
|
+
description: this.config.description,
|
|
59
|
+
path: [],
|
|
60
|
+
isVirtual: false
|
|
61
|
+
}), (item) => item.name);
|
|
62
|
+
this.inputs ??= [];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: "shell-shock:inputs",
|
|
68
|
+
async configResolved() {
|
|
69
|
+
this.trace("Finding command entry points.");
|
|
70
|
+
this.commandsPath = require_resolve_command.findCommandsRoot(this);
|
|
71
|
+
this.inputs = this.entry.filter((entry) => (0, __stryke_path_file_path_fns.findFileName)(entry.file, { withExtension: false }) === "command").reduce((ret, entry) => {
|
|
72
|
+
const file = (0, __stryke_path_append.appendPath)((0, __stryke_path_append.appendPath)(entry.file, this.config.projectRoot), this.workspaceConfig.workspaceRoot);
|
|
73
|
+
if (!(0, __stryke_path_is_parent_path.isParentPath)(file, this.commandsPath)) throw new Error(`Command entry point "${file}" is not located within the commands root "${this.commandsPath}". Please ensure that all command entry points are located within the current project.`);
|
|
74
|
+
const path = require_resolve_command.resolveCommandPath(this, file);
|
|
75
|
+
const id = path.replaceAll("/", "-");
|
|
76
|
+
if (!ret.some((existing) => existing.id === id)) {
|
|
77
|
+
const name = require_resolve_command.findCommandName(file);
|
|
78
|
+
ret.push({
|
|
79
|
+
id,
|
|
80
|
+
path: path.split("/").filter(Boolean),
|
|
81
|
+
name,
|
|
82
|
+
title: (0, __stryke_string_format_title_case.titleCase)(name),
|
|
83
|
+
isVirtual: false,
|
|
84
|
+
entry: {
|
|
85
|
+
...entry,
|
|
86
|
+
file,
|
|
87
|
+
input: {
|
|
88
|
+
file: entry.file,
|
|
89
|
+
name: entry.name
|
|
90
|
+
},
|
|
91
|
+
output: name
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return ret;
|
|
96
|
+
}, this.inputs);
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: "shell-shock:virtual-inputs",
|
|
101
|
+
configResolved: {
|
|
102
|
+
order: "post",
|
|
103
|
+
async handler() {
|
|
104
|
+
if (this.inputs.length === 0) this.warn("No commands were found in the project. Please ensure at least one command exists.");
|
|
105
|
+
else {
|
|
106
|
+
this.info(`Shell Shock will create an application with the following commands: \n${this.inputs.filter((cmd) => !cmd.isVirtual).map((command) => ` - ${command.id}: ${(0, __stryke_path_replace.replacePath)(command.entry.file, this.commandsPath)}${command.isVirtual ? " (virtual)" : ""}`).join("\n")}`);
|
|
107
|
+
this.trace("Finding and adding virtual command inputs for each command previously found.");
|
|
108
|
+
this.inputs = this.inputs.reduce((ret, command) => {
|
|
109
|
+
let depth = 0;
|
|
110
|
+
let parentPath = (0, __stryke_path_resolve_parent_path.resolveParentPath)((0, __stryke_path_file_path_fns.findFilePath)(command.entry.file));
|
|
111
|
+
while (parentPath !== this.commandsPath) {
|
|
112
|
+
if (depth++ > MAX_DEPTH) throw new Error(`Maximum command virtual parent depth of ${MAX_DEPTH} exceeded while processing command: ${command.name}`);
|
|
113
|
+
if (!ret.some((existing) => (0, __stryke_path_file_path_fns.findFilePath)(existing.entry.file) === parentPath)) {
|
|
114
|
+
const file = (0, __stryke_path_join_paths.joinPaths)(parentPath, "command.ts");
|
|
115
|
+
const path = require_resolve_command.resolveCommandPath(this, file);
|
|
116
|
+
const id = path.replaceAll("/", "-");
|
|
117
|
+
if (!ret.some((existing) => existing.id === id)) {
|
|
118
|
+
const name = require_resolve_command.findCommandName(file);
|
|
119
|
+
ret.push({
|
|
120
|
+
id,
|
|
121
|
+
path: path.split("/").filter(Boolean),
|
|
122
|
+
name,
|
|
123
|
+
title: (0, __stryke_string_format_title_case.titleCase)(name),
|
|
124
|
+
isVirtual: true,
|
|
125
|
+
entry: {
|
|
126
|
+
file,
|
|
127
|
+
input: { file }
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
parentPath = (0, __stryke_path_resolve_parent_path.resolveParentPath)(parentPath);
|
|
133
|
+
}
|
|
134
|
+
return ret;
|
|
135
|
+
}, this.inputs).sort((a, b) => a.path.length - b.path.length);
|
|
136
|
+
this.trace(`Final command input list: \n${this.inputs.map((command) => ` - ${command.id}: ${(0, __stryke_path_replace.replacePath)(command.entry.file, this.commandsPath)}${command.isVirtual ? " (virtual)" : ""}`).join("\n")}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: "shell-shock:reflect-commands",
|
|
143
|
+
async prepare() {
|
|
144
|
+
this.entry = [];
|
|
145
|
+
this.commands = {};
|
|
146
|
+
if (this.config.command !== "prepare" && this.config.skipCache !== true && this.persistedMeta?.checksum === this.meta.checksum && this.fs.existsSync(require_persistence.getCommandsPersistencePath(this))) {
|
|
147
|
+
this.debug(`Skipping reflection initialization as the meta checksum has not changed.`);
|
|
148
|
+
await require_persistence.readCommandsPersistence(this);
|
|
149
|
+
} else {
|
|
150
|
+
for (const input of this.inputs.filter((input$1) => input$1.path.length === 1)) this.commands[input.name] = await require_resolve_command.reflectCommandTree(this, input);
|
|
151
|
+
await require_persistence.writeCommandsPersistence(this);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: "shell-shock:chmod+x",
|
|
157
|
+
async buildEnd() {
|
|
158
|
+
if (!(0, __stryke_type_checks_is_set_object.isSetObject)(this.packageJson.bin)) {
|
|
159
|
+
this.warn("No binaries were found in package.json. Please ensure the binaries are correctly configured.");
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
this.debug("Adding executable permissions to binaries.");
|
|
163
|
+
for (const executablePath of Object.values(this.packageJson.bin)) if (this.fs.existsSync((0, __stryke_path_append.appendPath)(executablePath, this.config.output.buildPath))) await (0, __stryke_fs_chmod_x.chmodX)((0, __stryke_path_append.appendPath)(executablePath, this.config.output.buildPath));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
];
|
|
167
|
+
};
|
|
168
|
+
var powerlines_default = shellShock;
|
|
169
|
+
|
|
170
|
+
//#endregion
|
|
171
|
+
exports.default = powerlines_default;
|
|
172
|
+
exports.shellShock = shellShock;
|
package/dist/powerlines.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { Context } from "./types/context.cjs";
|
|
1
2
|
import { Options } from "./types/config.cjs";
|
|
2
|
-
import { BuildContext } from "./types/build.cjs";
|
|
3
3
|
import { Plugin } from "powerlines";
|
|
4
4
|
|
|
5
5
|
//#region src/powerlines.d.ts
|
|
@@ -7,6 +7,6 @@ import { Plugin } from "powerlines";
|
|
|
7
7
|
/**
|
|
8
8
|
* The core Powerlines plugin to build Shell Shock projects.
|
|
9
9
|
*/
|
|
10
|
-
declare const shellShock: <TContext extends
|
|
10
|
+
declare const shellShock: <TContext extends Context = Context>(options?: Options) => Plugin<TContext>[];
|
|
11
11
|
//#endregion
|
|
12
12
|
export { shellShock as default, shellShock };
|