@visulima/cerebro 3.0.0-alpha.11 → 3.0.0-alpha.13
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/CHANGELOG.md +36 -0
- package/LICENSE.md +471 -4345
- package/README.md +26 -0
- package/dist/commands/completion-command.d.ts +6 -5
- package/dist/commands/help-command.d.ts +9 -9
- package/dist/commands/help-command.js +63 -1
- package/dist/commands/readme-command.d.ts +6 -5
- package/dist/commands/readme-command.js +1 -1
- package/dist/commands/version-command.d.ts +4 -3
- package/dist/index.d.ts +422 -95
- package/dist/index.js +2 -1
- package/dist/logger/create-pail-logger.d.ts +779 -8
- package/dist/packem_shared/{Cerebro-CXEIHSN2.js → Cerebro-C1h3DXwy.js} +66 -8
- package/dist/packem_shared/{index-DNXLgme3.js → index--1UArng3.js} +1 -2
- package/dist/packem_shared/index.d-Br8HpP0A.d.ts +93 -0
- package/dist/packem_shared/lazyNamed-B278Tf9_.js +6 -0
- package/dist/packem_shared/plugin-manager.d-Du-YXFui.d.ts +541 -0
- package/dist/plugins/error-handler-plugin.d.ts +21 -19
- package/dist/plugins/runtime-version-check-plugin.d.ts +22 -20
- package/dist/plugins/update-notifier/update-notifier-plugin.d.ts +21 -8
- package/dist/plugins/update-notifier/update-notifier-plugin.js +1 -2
- package/dist/util/general/compile-cache.d.ts +38 -38
- package/dist/util/general/heap-tuning.d.ts +14 -77
- package/package.json +18 -18
- package/dist/cli.d.ts +0 -225
- package/dist/constants.d.ts +0 -29
- package/dist/default-env.d.ts +0 -7
- package/dist/default-options.d.ts +0 -3
- package/dist/empty-toolbox.d.ts +0 -16
- package/dist/errors/cerebro-error.d.ts +0 -10
- package/dist/errors/command-not-found-error.d.ts +0 -9
- package/dist/errors/command-validation-error.d.ts +0 -10
- package/dist/errors/completion-error.d.ts +0 -9
- package/dist/errors/conflicting-options-error.d.ts +0 -10
- package/dist/errors/plugin-error.d.ts +0 -9
- package/dist/errors/update-notifier-error.d.ts +0 -7
- package/dist/plugin-manager.d.ts +0 -53
- package/dist/plugins/update-notifier/cache.d.ts +0 -11
- package/dist/plugins/update-notifier/get-distribution-version.d.ts +0 -2
- package/dist/plugins/update-notifier/has-new-version.d.ts +0 -14
- package/dist/types/cli.d.ts +0 -113
- package/dist/types/command-line-usage.d.ts +0 -37
- package/dist/types/command.d.ts +0 -136
- package/dist/types/option-types.d.ts +0 -83
- package/dist/types/options.d.ts +0 -4
- package/dist/types/plugin.d.ts +0 -53
- package/dist/types/toolbox.d.ts +0 -120
- package/dist/util/arg-processing/get-boolean-values.d.ts +0 -7
- package/dist/util/arg-processing/get-parameter-option.d.ts +0 -7
- package/dist/util/arg-processing/map-option-type-label.d.ts +0 -3
- package/dist/util/arg-processing/option-is-boolean.d.ts +0 -9
- package/dist/util/arg-processing/remove-boolean-values.d.ts +0 -9
- package/dist/util/command-line-commands.d.ts +0 -10
- package/dist/util/command-line-usage/get-terminal-width.d.ts +0 -7
- package/dist/util/command-line-usage/index.d.ts +0 -3
- package/dist/util/command-line-usage/section/base-section.d.ts +0 -8
- package/dist/util/command-line-usage/section/content-section.d.ts +0 -65
- package/dist/util/command-line-usage/section/option-list-section.d.ts +0 -44
- package/dist/util/command-processing/command-processor.d.ts +0 -37
- package/dist/util/command-processing/command-validation.d.ts +0 -17
- package/dist/util/command-processing/nested-command-parser.d.ts +0 -25
- package/dist/util/command-processing/option-processor.d.ts +0 -44
- package/dist/util/data-processing/list-missing-arguments.d.ts +0 -15
- package/dist/util/data-processing/merge-arguments.d.ts +0 -7
- package/dist/util/general/find-alternatives.d.ts +0 -8
- package/dist/util/general/hide-bin.d.ts +0 -2
- package/dist/util/general/parse-raw-command.d.ts +0 -7
- package/dist/util/general/register-exception-handler.d.ts +0 -9
- package/dist/util/general/runtime-process.d.ts +0 -65
- package/dist/util/general/semver-gt.d.ts +0 -2
- package/dist/util/general/validate-input.d.ts +0 -24
- package/dist/util/process-env-variables.d.ts +0 -9
- package/dist/util/security.d.ts +0 -58
- package/dist/util/text-processing/template-format.d.ts +0 -5
package/README.md
CHANGED
|
@@ -158,6 +158,32 @@ You should see help output and command execution based on the options provided:
|
|
|
158
158
|
|
|
159
159
|

|
|
160
160
|
|
|
161
|
+
## Lazy commands
|
|
162
|
+
|
|
163
|
+
For CLIs with many subcommands or heavy per-command dependencies, you can defer importing each handler until the command is actually invoked. Declare the metadata inline and point `loader` at a dynamic `import()`:
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
// commands/build.ts
|
|
167
|
+
export default ({ logger, options }) => {
|
|
168
|
+
logger.info(`Building to ${options.output ?? "dist"}`);
|
|
169
|
+
};
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
// index.ts
|
|
174
|
+
cli.addCommand({
|
|
175
|
+
name: "build",
|
|
176
|
+
description: "Build the project",
|
|
177
|
+
options: [{ name: "output", alias: "o", type: String, description: "Output directory" }],
|
|
178
|
+
argument: { name: "target", type: String },
|
|
179
|
+
loader: () => import("./commands/build"),
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
`loader` is a zero-argument function that returns a promise resolving to a module — typically `() => import("./path")`. The handler module's **default export** is the toolbox-receiving function. Help, completion, and option validation work entirely from the metadata you declared on `addCommand` and never trigger the loader. The first invocation of the command imports the module; subsequent calls reuse the cached handler.
|
|
184
|
+
|
|
185
|
+
A command may declare either `execute` or `loader`, but not both. If a loader rejects or returns a module without a default-exported function, a `CommandLoaderError` is thrown.
|
|
186
|
+
|
|
161
187
|
## Toolbox API
|
|
162
188
|
|
|
163
189
|
When your command's `execute` function is called, it receives a toolbox object with various utilities and context. Here's what you can access:
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { C as Command } from "../packem_shared/plugin-manager.d-Du-YXFui.js";
|
|
2
|
+
import '@visulima/tabular';
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare const completionCommand:
|
|
6
|
-
export default
|
|
4
|
+
* Generates shell completion scripts for the CLI application.
|
|
5
|
+
*/
|
|
6
|
+
declare const completionCommand: Command;
|
|
7
|
+
export { completionCommand as default };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
declare class HelpCommand<TLogger extends Console = Console> implements
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { O as OptionDefinition, C as Command, T as Toolbox } from "../packem_shared/plugin-manager.d-Du-YXFui.js";
|
|
2
|
+
import '@visulima/tabular';
|
|
3
|
+
declare class HelpCommand<TLogger extends Console = Console> implements Command<OptionDefinition<string>, TLogger> {
|
|
4
|
+
name: string;
|
|
5
|
+
options: OptionDefinition<string>[];
|
|
6
|
+
private readonly commands;
|
|
7
|
+
constructor(commands: Map<string, Command<OptionDefinition<unknown>, TLogger>>);
|
|
8
|
+
execute(toolbox: Toolbox<TLogger>): void;
|
|
9
9
|
}
|
|
10
|
-
export default
|
|
10
|
+
export { HelpCommand as default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { inverse, cyan, green, yellow } from '@visulima/colorize';
|
|
2
|
-
import { t as templateFormat, c as commandLineUsage } from '../packem_shared/index
|
|
2
|
+
import { t as templateFormat, c as commandLineUsage } from '../packem_shared/index--1UArng3.js';
|
|
3
3
|
|
|
4
4
|
const defaultEnv = [
|
|
5
5
|
{
|
|
@@ -98,6 +98,51 @@ const printGeneralHelp = (logger, runtime, commands, groupOption) => {
|
|
|
98
98
|
)
|
|
99
99
|
);
|
|
100
100
|
};
|
|
101
|
+
const findChildren = (commands, parentPath) => {
|
|
102
|
+
const matches = [];
|
|
103
|
+
for (const cmd of commands.values()) {
|
|
104
|
+
if (cmd.hidden) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const commandPath = cmd.commandPath ?? [];
|
|
108
|
+
if (commandPath.length !== parentPath.length) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
let isMatch = true;
|
|
112
|
+
for (let index = 0; index < parentPath.length; index += 1) {
|
|
113
|
+
if (commandPath[index] !== parentPath[index]) {
|
|
114
|
+
isMatch = false;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (isMatch) {
|
|
119
|
+
matches.push(cmd);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return matches;
|
|
123
|
+
};
|
|
124
|
+
const printParentHelp = (logger, runtime, parentPath, children) => {
|
|
125
|
+
const parentDisplay = parentPath.join(" ");
|
|
126
|
+
const usageGroups = [
|
|
127
|
+
{
|
|
128
|
+
content: `${cyan(runtime.getCliName())} ${green(parentDisplay)} ${green("<subcommand>")} [positional arguments] ${yellow("[options]")}`,
|
|
129
|
+
header: inverse.cyan(" Usage ")
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
content: children.map((child) => {
|
|
133
|
+
const fullPath = [...child.commandPath ?? [], child.name].join(" ");
|
|
134
|
+
return [green(fullPath), child.description ?? ""];
|
|
135
|
+
}),
|
|
136
|
+
header: inverse.green(" Subcommands ")
|
|
137
|
+
},
|
|
138
|
+
{ header: inverse.yellow(" Global Options "), optionList: runtime.getGlobalOptions() },
|
|
139
|
+
{
|
|
140
|
+
content: `Run "${cyan(runtime.getCliName())} ${green(`${parentDisplay} <subcommand>`)} ${yellow("--help")}" for help with a specific subcommand.`,
|
|
141
|
+
raw: true
|
|
142
|
+
}
|
|
143
|
+
];
|
|
144
|
+
(logger.raw ?? logger.log)(commandLineUsage(usageGroups));
|
|
145
|
+
};
|
|
101
146
|
const printCommandHelp = (logger, runtime, commands, name) => {
|
|
102
147
|
let command = commands.get(name);
|
|
103
148
|
if (!command) {
|
|
@@ -110,6 +155,12 @@ const printCommandHelp = (logger, runtime, commands, name) => {
|
|
|
110
155
|
}
|
|
111
156
|
}
|
|
112
157
|
if (!command) {
|
|
158
|
+
const parentPath = name.split(" ").filter(Boolean);
|
|
159
|
+
const children = parentPath.length > 0 ? findChildren(commands, parentPath) : [];
|
|
160
|
+
if (children.length > 0) {
|
|
161
|
+
printParentHelp(logger, runtime, parentPath, children);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
113
164
|
logger.error(`Command "${name}" not found`);
|
|
114
165
|
return;
|
|
115
166
|
}
|
|
@@ -159,6 +210,17 @@ const printCommandHelp = (logger, runtime, commands, name) => {
|
|
|
159
210
|
header: "Examples"
|
|
160
211
|
});
|
|
161
212
|
}
|
|
213
|
+
const ownPath = [...command.commandPath ?? [], command.name];
|
|
214
|
+
const ownChildren = findChildren(commands, ownPath);
|
|
215
|
+
if (ownChildren.length > 0) {
|
|
216
|
+
usageGroups.push({
|
|
217
|
+
content: ownChildren.map((child) => {
|
|
218
|
+
const fullPath = [...child.commandPath ?? [], child.name].join(" ");
|
|
219
|
+
return [green(fullPath), child.description ?? ""];
|
|
220
|
+
}),
|
|
221
|
+
header: inverse.green(" Subcommands ")
|
|
222
|
+
});
|
|
223
|
+
}
|
|
162
224
|
(logger.raw ?? logger.log)(commandLineUsage(usageGroups));
|
|
163
225
|
};
|
|
164
226
|
class HelpCommand {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { C as Command } from "../packem_shared/plugin-manager.d-Du-YXFui.js";
|
|
2
|
+
import '@visulima/tabular';
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare const readmeCommand:
|
|
6
|
-
export default
|
|
4
|
+
* Generates README documentation for cerebro CLI commands.
|
|
5
|
+
*/
|
|
6
|
+
declare const readmeCommand: Command;
|
|
7
|
+
export { readmeCommand as default };
|
|
@@ -31,7 +31,7 @@ const {
|
|
|
31
31
|
dirname
|
|
32
32
|
} = __cjs_getBuiltinModule("node:path");
|
|
33
33
|
import GithubSlugger from 'github-slugger';
|
|
34
|
-
import { c as commandLineUsage } from '../packem_shared/index
|
|
34
|
+
import { c as commandLineUsage } from '../packem_shared/index--1UArng3.js';
|
|
35
35
|
import { g as getCwd, a as getVersions, b as getPlatform, c as getArch } from '../packem_shared/runtime-process-B6ZplyWn.js';
|
|
36
36
|
|
|
37
37
|
const slugger = new GithubSlugger();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { C as Command } from "../packem_shared/plugin-manager.d-Du-YXFui.js";
|
|
2
|
+
import '@visulima/tabular';
|
|
3
|
+
declare const _default: Command;
|
|
4
|
+
export { _default as default };
|