@visulima/cerebro 3.0.0-alpha.14 → 3.0.0-alpha.15

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.
Files changed (31) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/LICENSE.md +6 -0
  3. package/dist/commands/completion-command.js +5 -204
  4. package/dist/commands/help-command.js +1 -262
  5. package/dist/commands/readme-command.js +32 -317
  6. package/dist/commands/version-command.js +1 -18
  7. package/dist/index.js +1 -8
  8. package/dist/logger/create-pail-logger.js +1 -34
  9. package/dist/packem_chunks/has-new-version.js +1 -264
  10. package/dist/packem_shared/Cerebro-Cnr7AGMP.js +4 -0
  11. package/dist/packem_shared/VERBOSITY_QUIET-XPultrIA.js +1 -0
  12. package/dist/packem_shared/VisulimaError-Bh91XNXu.js +76 -0
  13. package/dist/packem_shared/cerebro-error-BnJTixb2.js +1 -0
  14. package/dist/packem_shared/index-B0BiusY7.js +6 -0
  15. package/dist/packem_shared/isVisulimaError-jVZgumOU-C4fgdbWg.js +1 -0
  16. package/dist/packem_shared/lazyNamed-DOmefeJM.js +1 -0
  17. package/dist/packem_shared/renderError-B_XyYPKJ-B65kP-Ou.js +24 -0
  18. package/dist/packem_shared/runtime-process-DKHFvYkv.js +1 -0
  19. package/dist/plugins/error-handler-plugin.js +1 -648
  20. package/dist/plugins/runtime-version-check-plugin.js +1 -77
  21. package/dist/plugins/update-notifier/update-notifier-plugin.js +1 -517
  22. package/dist/util/general/compile-cache.js +1 -16
  23. package/dist/util/general/heap-tuning.js +1 -91
  24. package/package.json +23 -23
  25. package/dist/packem_shared/Cerebro-C1h3DXwy.js +0 -3509
  26. package/dist/packem_shared/VERBOSITY_QUIET-Dp46zlLW.js +0 -10
  27. package/dist/packem_shared/VisulimaError-DA7QsCxH.js +0 -34
  28. package/dist/packem_shared/cerebro-error-GmJ3jN7Q.js +0 -16
  29. package/dist/packem_shared/index--1UArng3.js +0 -267
  30. package/dist/packem_shared/lazyNamed-B278Tf9_.js +0 -6
  31. package/dist/packem_shared/runtime-process-B6ZplyWn.js +0 -187
package/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## @visulima/cerebro [3.0.0-alpha.15](https://github.com/visulima/visulima/compare/@visulima/cerebro@3.0.0-alpha.14...@visulima/cerebro@3.0.0-alpha.15) (2026-05-06)
2
+
3
+ ### Miscellaneous Chores
4
+
5
+ * **cerebro:** apply prettier and eslint quote-style auto-fix ([31132ae](https://github.com/visulima/visulima/commit/31132aeab40b3f6fa920a37635813e14d7e8b17e))
6
+ * **cerebro:** fix lint errors ([87649b0](https://github.com/visulima/visulima/commit/87649b0408ce3667bf1be9be795321851e6e8f15))
7
+ * **cerebro:** housekeeping cleanup ([643b7d9](https://github.com/visulima/visulima/commit/643b7d9e268dca11544f0b9476b011a8620c04c8))
8
+
9
+ ### Continuous Integration
10
+
11
+ * integrate codspeed for benchmark tracking ([e758f3d](https://github.com/visulima/visulima/commit/e758f3da491cc00d3f8bbf10d7ba3fdf8deb5325))
12
+
13
+
14
+ ### Dependencies
15
+
16
+ * **@visulima/error:** upgraded to 6.0.0-alpha.16
17
+ * **@visulima/pail:** upgraded to 4.0.0-alpha.13
18
+
1
19
  ## @visulima/cerebro [3.0.0-alpha.14](https://github.com/visulima/visulima/compare/@visulima/cerebro@3.0.0-alpha.13...@visulima/cerebro@3.0.0-alpha.14) (2026-05-04)
2
20
 
3
21
 
package/LICENSE.md CHANGED
@@ -289,11 +289,14 @@ Repository: git+https://github.com/visulima/visulima.git
289
289
  >
290
290
  >
291
291
  > # Licenses of bundled dependencies
292
+ >
292
293
  > The published @visulima/error artifact additionally contains code with the following licenses:
293
294
  > MIT
294
295
  >
295
296
  > # Bundled dependencies:
297
+ >
296
298
  > ## is-plain-obj
299
+ >
297
300
  > License: MIT
298
301
  > By: Sindre Sorhus
299
302
  > Repository: sindresorhus/is-plain-obj
@@ -1398,11 +1401,14 @@ Repository: git+https://github.com/visulima/visulima.git
1398
1401
  > <!-- DEPENDENCIES -->
1399
1402
  >
1400
1403
  > # Licenses of bundled dependencies
1404
+ >
1401
1405
  > The published @visulima/error artifact additionally contains code with the following licenses:
1402
1406
  > MIT
1403
1407
  >
1404
1408
  > # Bundled dependencies:
1409
+ >
1405
1410
  > ## is-plain-obj
1411
+ >
1406
1412
  > License: MIT
1407
1413
  > By: Sindre Sorhus
1408
1414
  > Repository: sindresorhus/is-plain-obj
@@ -1,204 +1,5 @@
1
- import tab from '@bomb.sh/tab';
2
- import { C as CerebroError } from '../packem_shared/cerebro-error-GmJ3jN7Q.js';
3
-
4
- class CompletionError extends CerebroError {
5
- troubleshooting;
6
- constructor(message, code, troubleshooting = []) {
7
- super(message, code, { troubleshooting });
8
- this.name = "CompletionError";
9
- this.troubleshooting = troubleshooting;
10
- if (troubleshooting.length > 0) {
11
- this.hint = troubleshooting.join("\n");
12
- }
13
- }
14
- }
15
-
16
- const validShells = ["bash", "zsh", "fish", "powershell"];
17
- const validRuntimes = ["node", "bun", "deno"];
18
- const hasDeno = (global) => "Deno" in global;
19
- const hasBun = (global) => "Bun" in global;
20
- const detectRuntime = () => {
21
- if (hasDeno(globalThis)) {
22
- return "deno";
23
- }
24
- if (hasBun(globalThis)) {
25
- return "bun";
26
- }
27
- return "node";
28
- };
29
- const detectShell = (toolboxEnv) => {
30
- const starshipShell = toolboxEnv?.starshipShell;
31
- const shell = starshipShell ?? toolboxEnv?.shell;
32
- if (shell) {
33
- const shellPath = shell.toLowerCase();
34
- if (shellPath.includes("zsh")) {
35
- return "zsh";
36
- }
37
- if (shellPath.includes("bash")) {
38
- return "bash";
39
- }
40
- if (shellPath.includes("fish")) {
41
- return "fish";
42
- }
43
- }
44
- const psModulePath = toolboxEnv?.psModulePath;
45
- const prompt = toolboxEnv?.prompt;
46
- if (psModulePath || prompt?.includes("PS")) {
47
- return "powershell";
48
- }
49
- const comSpec = toolboxEnv?.comSpec;
50
- if (comSpec?.toLowerCase().includes("cmd.exe")) {
51
- return "bash";
52
- }
53
- return void 0;
54
- };
55
- const tabInstance = tab;
56
- const registerCommandOptions = (cmd, options) => {
57
- for (const option of options) {
58
- if (option.hidden) {
59
- continue;
60
- }
61
- if (option.name) {
62
- cmd.option(option.name, option.description ?? "");
63
- }
64
- if (option.alias) {
65
- cmd.option(option.alias, option.description ?? "");
66
- }
67
- }
68
- };
69
- const registerCommands = (tabInstance2, commands) => {
70
- for (const [commandName, command] of commands) {
71
- if (command.name !== commandName || command.hidden) {
72
- continue;
73
- }
74
- const cmd = tabInstance2.command(command.name, command.description ?? "");
75
- if (command.options) {
76
- registerCommandOptions(cmd, command.options);
77
- }
78
- }
79
- };
80
- const validateShell = (shell) => {
81
- if (!validShells.includes(shell)) {
82
- throw new CompletionError(`Invalid shell type: ${shell}`, "INVALID_SHELL", [
83
- `Valid shells are: ${validShells.join(", ")}`,
84
- "Shell will be auto-detected if not specified"
85
- ]);
86
- }
87
- };
88
- const validateRuntime = (runtime) => {
89
- if (runtime && !validRuntimes.includes(runtime)) {
90
- throw new CompletionError(`Invalid runtime: ${runtime}`, "INVALID_RUNTIME", [
91
- `Valid runtimes are: ${validRuntimes.join(", ")}`,
92
- "Runtime will be auto-detected if not specified"
93
- ]);
94
- }
95
- };
96
- const printUsageInstructions = (logger, cliName) => {
97
- logger.error("Could not detect current shell");
98
- const usageInfo = [
99
- `Usage: ${cliName} completion --shell=<bash|zsh|fish|powershell> [--runtime=<node|bun|deno>]`,
100
- "",
101
- "Examples:",
102
- ` # Install completions for zsh:`,
103
- ` ${cliName} completion --shell=zsh > ~/.${cliName}-completion.zsh`,
104
- ` echo 'source ~/.${cliName}-completion.zsh' >> ~/.zshrc`,
105
- "",
106
- ` # Install completions for bash with custom runtime:`,
107
- ` ${cliName} completion --shell=bash --runtime=bun > ~/.${cliName}-completion.bash`,
108
- ` echo 'source ~/.${cliName}-completion.bash' >> ~/.bashrc`,
109
- "",
110
- ` # Install completions for fish:`,
111
- ` ${cliName} completion --shell=fish > ~/.config/fish/completions/${cliName}.fish`
112
- ].join("\n");
113
- logger.info(usageInfo);
114
- };
115
- const completionCommand = {
116
- description: "Generate shell completion scripts",
117
- env: [
118
- {
119
- description: "Shell path (Unix-like systems). Used for shell detection.",
120
- name: "SHELL",
121
- type: String
122
- },
123
- {
124
- description: "Starship shell configuration. Takes precedence over SHELL for detection.",
125
- name: "STARSHIP_SHELL",
126
- type: String
127
- },
128
- {
129
- description: "PowerShell module path (Windows). Used for PowerShell detection.",
130
- name: "PSModulePath",
131
- type: String
132
- },
133
- {
134
- description: "Command prompt variable (Windows). Used for PowerShell detection.",
135
- name: "PROMPT",
136
- type: String
137
- },
138
- {
139
- description: "Command processor (Windows). Used for Windows Command Prompt detection.",
140
- name: "ComSpec",
141
- type: String
142
- }
143
- ],
144
- // eslint-disable-next-line @typescript-eslint/require-await
145
- execute: async ({ env: toolboxEnv, logger, options, runtime }) => {
146
- const cliName = runtime.getCliName();
147
- const shell = options.shell ?? detectShell(toolboxEnv);
148
- if (!shell) {
149
- printUsageInstructions(logger, cliName);
150
- return;
151
- }
152
- try {
153
- validateShell(shell);
154
- validateRuntime(options.runtime);
155
- registerCommands(tabInstance, runtime.getCommands());
156
- const jsRuntime = options.runtime ?? detectRuntime();
157
- const scriptPath = `${jsRuntime} ${cliName}`;
158
- tabInstance.setup(cliName, scriptPath, shell);
159
- } catch (error) {
160
- if (error instanceof CompletionError) {
161
- const errorMessages = [`Failed to generate completion script: ${error.message}`, `Error code: ${error.code}`];
162
- if (error.troubleshooting.length > 0) {
163
- errorMessages.push("", "Troubleshooting:", ...error.troubleshooting.map((tip) => ` • ${tip}`));
164
- }
165
- logger.error(errorMessages.join("\n"));
166
- throw error;
167
- } else {
168
- const errorMessage = error instanceof Error ? error.message : String(error);
169
- const errorMessages = [
170
- "Failed to generate completion script",
171
- `Error: ${errorMessage}`,
172
- "",
173
- "Troubleshooting:",
174
- " • Ensure @bomb.sh/tab is installed: pnpm add @bomb.sh/tab",
175
- ` • Verify shell is supported: ${validShells.join(", ")}`,
176
- ` • Verify runtime is supported: ${validRuntimes.join(", ")}`,
177
- " • Check that your CLI name is correct"
178
- ];
179
- logger.error(errorMessages.join("\n"));
180
- }
181
- }
182
- },
183
- name: "completion",
184
- options: [
185
- {
186
- defaultOption: true,
187
- defaultValue: detectShell(),
188
- description: "Shell type (bash, zsh, fish, powershell). Defaults to current shell if detected.",
189
- name: "shell",
190
- type: String,
191
- typeLabel: "{underline shell}"
192
- },
193
- {
194
- defaultOption: true,
195
- defaultValue: detectRuntime(),
196
- description: "JavaScript runtime (node, bun, deno). Defaults to current runtime if detected.",
197
- name: "runtime",
198
- type: String,
199
- typeLabel: "{underline runtime}"
200
- }
201
- ]
202
- };
203
-
204
- export { completionCommand as default };
1
+ var g=Object.defineProperty;var a=(e,t)=>g(e,"name",{value:t,configurable:!0});import S from"@bomb.sh/tab";import{c as $}from"../packem_shared/cerebro-error-BnJTixb2.js";var w=Object.defineProperty,y=a((e,t)=>w(e,"name",{value:t,configurable:!0}),"n");class p extends ${static{a(this,"l")}static{y(this,"CompletionError")}troubleshooting;constructor(t,o,n=[]){super(t,o,{troubleshooting:n}),this.name="CompletionError",this.troubleshooting=n,n.length>0&&(this.hint=n.join(`
2
+ `))}}var C=Object.defineProperty,s=a((e,t)=>C(e,"name",{value:t,configurable:!0}),"s");const h=["bash","zsh","fish","powershell"],d=["node","bun","deno"],v=s(e=>"Deno"in e,"hasDeno"),L=s(e=>"Bun"in e,"hasBun"),u=s(()=>v(globalThis)?"deno":L(globalThis)?"bun":"node","detectRuntime"),m=s(e=>{const t=e?.starshipShell??e?.shell;if(t){const r=t.toLowerCase();if(r.includes("zsh"))return"zsh";if(r.includes("bash"))return"bash";if(r.includes("fish"))return"fish"}const o=e?.psModulePath,n=e?.prompt;if(o||n?.includes("PS"))return"powershell";if(e?.comSpec?.toLowerCase().includes("cmd.exe"))return"bash"},"detectShell"),f=S,I=s((e,t)=>{for(const o of t)o.hidden||(o.name&&e.option(o.name,o.description??""),o.alias&&e.option(o.alias,o.description??""))},"registerCommandOptions"),P=s((e,t)=>{for(const[o,n]of t){if(n.name!==o||n.hidden)continue;const r=e.command(n.name,n.description??"");n.options&&I(r,n.options)}},"registerCommands"),E=s(e=>{if(!h.includes(e))throw new p(`Invalid shell type: ${e}`,"INVALID_SHELL",[`Valid shells are: ${h.join(", ")}`,"Shell will be auto-detected if not specified"])},"validateShell"),j=s(e=>{if(e&&!d.includes(e))throw new p(`Invalid runtime: ${e}`,"INVALID_RUNTIME",[`Valid runtimes are: ${d.join(", ")}`,"Runtime will be auto-detected if not specified"])},"validateRuntime"),z=s((e,t)=>{e.error("Could not detect current shell");const o=[`Usage: ${t} completion --shell=<bash|zsh|fish|powershell> [--runtime=<node|bun|deno>]`,"","Examples:"," # Install completions for zsh:",` ${t} completion --shell=zsh > ~/.${t}-completion.zsh`,` echo 'source ~/.${t}-completion.zsh' >> ~/.zshrc`,""," # Install completions for bash with custom runtime:",` ${t} completion --shell=bash --runtime=bun > ~/.${t}-completion.bash`,` echo 'source ~/.${t}-completion.bash' >> ~/.bashrc`,""," # Install completions for fish:",` ${t} completion --shell=fish > ~/.config/fish/completions/${t}.fish`].join(`
3
+ `);e.info(o)},"printUsageInstructions"),x={description:"Generate shell completion scripts",env:[{description:"Shell path (Unix-like systems). Used for shell detection.",name:"SHELL",type:String},{description:"Starship shell configuration. Takes precedence over SHELL for detection.",name:"STARSHIP_SHELL",type:String},{description:"PowerShell module path (Windows). Used for PowerShell detection.",name:"PSModulePath",type:String},{description:"Command prompt variable (Windows). Used for PowerShell detection.",name:"PROMPT",type:String},{description:"Command processor (Windows). Used for Windows Command Prompt detection.",name:"ComSpec",type:String}],execute:s(async({env:e,logger:t,options:o,runtime:n})=>{const r=n.getCliName(),c=o.shell??m(e);if(!c){z(t,r);return}try{E(c),j(o.runtime),P(f,n.getCommands());const i=`${o.runtime??u()} ${r}`;f.setup(r,i,c)}catch(i){if(i instanceof p){const l=[`Failed to generate completion script: ${i.message}`,`Error code: ${i.code}`];throw i.troubleshooting.length>0&&l.push("","Troubleshooting:",...i.troubleshooting.map(b=>` • ${b}`)),t.error(l.join(`
4
+ `)),i}else{const l=["Failed to generate completion script",`Error: ${i instanceof Error?i.message:String(i)}`,"","Troubleshooting:"," • Ensure @bomb.sh/tab is installed: pnpm add @bomb.sh/tab",` • Verify shell is supported: ${h.join(", ")}`,` • Verify runtime is supported: ${d.join(", ")}`," • Check that your CLI name is correct"];t.error(l.join(`
5
+ `))}}},"execute"),name:"completion",options:[{defaultOption:!0,defaultValue:m(),description:"Shell type (bash, zsh, fish, powershell). Defaults to current shell if detected.",name:"shell",type:String,typeLabel:"{underline shell}"},{defaultOption:!0,defaultValue:u(),description:"JavaScript runtime (node, bun, deno). Defaults to current runtime if detected.",name:"runtime",type:String,typeLabel:"{underline runtime}"}]};export{x as default};
@@ -1,262 +1 @@
1
- import { inverse, cyan, green, yellow } from '@visulima/colorize';
2
- import { t as templateFormat, c as commandLineUsage } from '../packem_shared/index--1UArng3.js';
3
-
4
- const defaultEnv = [
5
- {
6
- defaultValue: "32",
7
- description: "Controls the verbosity level of output. Valid values: '16' (quiet), '32' (normal), '64' (verbose), '128' (debug)",
8
- name: "CEREBRO_OUTPUT_LEVEL",
9
- type: String
10
- },
11
- {
12
- description: "Sets the minimum required Node.js version. Overrides the default minimum version check",
13
- name: "CEREBRO_MIN_NODE_VERSION",
14
- type: Number
15
- },
16
- {
17
- defaultValue: false,
18
- description: "When set, disables the update notifier check",
19
- name: "NO_UPDATE_NOTIFIER",
20
- type: Boolean
21
- },
22
- {
23
- description: "Standard Node.js environment variable. When set to 'test', disables update notifier",
24
- name: "NODE_ENV",
25
- type: String
26
- },
27
- {
28
- defaultValue: false,
29
- description: "When set, enables debug output (same as --debug flag)",
30
- name: "DEBUG",
31
- type: Boolean
32
- },
33
- {
34
- description: "Sets the terminal width for table rendering. Useful for testing and consistent output",
35
- name: "CEREBRO_TERMINAL_WIDTH",
36
- type: Number
37
- }
38
- ];
39
-
40
- const EMPTY_GROUP_KEY = "__Other";
41
- const upperFirstChar = (string_) => string_.charAt(0).toUpperCase() + string_.slice(1);
42
- const printGeneralHelp = (logger, runtime, commands, groupOption) => {
43
- logger.debug("no command given, printing general help...");
44
- let filteredCommands = [...new Set(commands.values())].filter((command) => !command.hidden);
45
- if (groupOption) {
46
- filteredCommands = filteredCommands.filter((command) => command.group === groupOption);
47
- }
48
- const groupedCommands = filteredCommands.reduce((accumulator, command) => {
49
- const group = command.group ?? EMPTY_GROUP_KEY;
50
- accumulator[group] ??= [];
51
- accumulator[group].push(command);
52
- return accumulator;
53
- }, {});
54
- const buildCommandList = (commandList) => commandList.map((command) => {
55
- let aliases = "";
56
- if (typeof command.alias === "string") {
57
- aliases = command.alias;
58
- } else if (Array.isArray(command.alias)) {
59
- aliases = command.alias.join(", ");
60
- }
61
- if (aliases !== "") {
62
- aliases = ` [${aliases}]`;
63
- }
64
- let commandDisplay = command.name;
65
- if (command.commandPath && command.commandPath.length > 0) {
66
- commandDisplay = `${command.commandPath.join(" ")} ${command.name}`;
67
- }
68
- return [`${green(commandDisplay)}${aliases}`, command.description ?? ""];
69
- });
70
- (logger.raw ?? logger.log)(
71
- commandLineUsage(
72
- [
73
- {
74
- content: `${cyan(runtime.getCliName())} ${green("<command>")} [positional arguments] ${yellow("[options]")}`,
75
- header: inverse.cyan(" Usage ")
76
- },
77
- ...Object.keys(groupedCommands).map((key) => {
78
- const groupOptionName = groupOption ? ` ${upperFirstChar(groupOption)}` : "";
79
- return {
80
- content: buildCommandList(groupedCommands[key]),
81
- header: key === EMPTY_GROUP_KEY || groupOption ? inverse.green(` Available${groupOptionName} Commands `) : ` ${inverse.green(` ${upperFirstChar(key)} `)}`
82
- };
83
- }),
84
- commands.has("help") ? {
85
- header: inverse.yellow(" Command Options "),
86
- optionList: commands.get("help").options?.filter((option) => !option.hidden)
87
- } : void 0,
88
- { header: inverse.yellow(" Global Options "), optionList: runtime.getGlobalOptions() },
89
- {
90
- content: defaultEnv.filter((envVariable) => !envVariable.hidden).map((envVariable) => [envVariable.name, envVariable.description ?? ""]),
91
- header: inverse.magenta(" Environment Variables ")
92
- },
93
- {
94
- content: `Run "${cyan(runtime.getCliName())} ${green("help <command>")}" or "${cyan(runtime.getCliName())} ${green("<command>")} ${yellow("--help")}" for help with a specific command.`,
95
- raw: true
96
- }
97
- ].filter(Boolean)
98
- )
99
- );
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
- };
146
- const printCommandHelp = (logger, runtime, commands, name) => {
147
- let command = commands.get(name);
148
- if (!command) {
149
- for (const cmd of commands.values()) {
150
- const fullPath = cmd.commandPath ? [...cmd.commandPath, cmd.name] : [cmd.name];
151
- if (fullPath.at(-1) === name || fullPath.join(" ") === name) {
152
- command = cmd;
153
- break;
154
- }
155
- }
156
- }
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
- }
164
- logger.error(`Command "${name}" not found`);
165
- return;
166
- }
167
- const usageGroups = [];
168
- const fullCommandPath = command.commandPath ? [...command.commandPath, command.name] : [command.name];
169
- const commandDisplay = fullCommandPath.join(" ");
170
- usageGroups.push({
171
- content: `${cyan(runtime.getCliName())} ${green(commandDisplay)}${command.argument ? " [positional arguments]" : ""}${command.options ? " [options]" : ""}`,
172
- header: inverse.cyan(" Usage ")
173
- });
174
- if (command.description) {
175
- usageGroups.push({ content: command.description, header: inverse.green(" Description ") });
176
- }
177
- if (command.argument) {
178
- usageGroups.push({ header: "Command Positional Arguments", isArgument: true, optionList: [command.argument] });
179
- }
180
- if (Array.isArray(command.options) && command.options.length > 0) {
181
- usageGroups.push({
182
- header: inverse.yellow(" Command Options "),
183
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
184
- optionList: command.options.filter((option) => !option.hidden)
185
- });
186
- }
187
- usageGroups.push({ header: inverse.yellow(" Global Options "), optionList: runtime.getGlobalOptions() });
188
- if (Array.isArray(command.env) && command.env.length > 0) {
189
- const visibleEnvVariables = command.env.filter((envVariable) => !envVariable.hidden);
190
- if (visibleEnvVariables.length > 0) {
191
- usageGroups.push({
192
- content: visibleEnvVariables.map((envVariable) => [envVariable.name, envVariable.description ?? ""]),
193
- header: inverse.magenta(" Environment Variables ")
194
- });
195
- }
196
- }
197
- if (command.alias !== void 0 && command.alias.length > 0) {
198
- let alias = command.alias;
199
- if (typeof command.alias === "string") {
200
- alias = [command.alias];
201
- }
202
- usageGroups.splice(1, 0, {
203
- content: alias,
204
- header: "Alias(es)"
205
- });
206
- }
207
- if (Array.isArray(command.examples) && command.examples.length > 0) {
208
- usageGroups.push({
209
- content: command.examples,
210
- header: "Examples"
211
- });
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
- }
224
- (logger.raw ?? logger.log)(commandLineUsage(usageGroups));
225
- };
226
- class HelpCommand {
227
- name = "help";
228
- options = [
229
- {
230
- description: "Display only the specified group",
231
- name: "group",
232
- type: String
233
- }
234
- ];
235
- commands;
236
- constructor(commands) {
237
- this.commands = commands;
238
- }
239
- execute(toolbox) {
240
- const { commandName, logger, options, runtime } = toolbox;
241
- const { footer, header } = runtime.getCommandSection();
242
- if (header) {
243
- (logger.raw ?? logger.log)(templateFormat(header));
244
- }
245
- if (commandName === "help") {
246
- printGeneralHelp(
247
- logger,
248
- runtime,
249
- this.commands,
250
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- options may be undefined at runtime
251
- typeof options?.group === "string" ? options.group : void 0
252
- );
253
- } else {
254
- printCommandHelp(logger, runtime, this.commands, commandName);
255
- }
256
- if (footer) {
257
- (logger.raw ?? logger.log)(templateFormat(footer));
258
- }
259
- }
260
- }
261
-
262
- export { HelpCommand as default };
1
+ var O=Object.defineProperty;var f=(r,a)=>O(r,"name",{value:a,configurable:!0});import{green as c,inverse as p,cyan as u,yellow as g}from"@visulima/colorize";import{f as y,p as b}from"../packem_shared/index-B0BiusY7.js";const E=[{defaultValue:"32",description:"Controls the verbosity level of output. Valid values: '16' (quiet), '32' (normal), '64' (verbose), '128' (debug)",name:"CEREBRO_OUTPUT_LEVEL",type:String},{description:"Sets the minimum required Node.js version. Overrides the default minimum version check",name:"CEREBRO_MIN_NODE_VERSION",type:Number},{defaultValue:!1,description:"When set, disables the update notifier check",name:"NO_UPDATE_NOTIFIER",type:Boolean},{description:"Standard Node.js environment variable. When set to 'test', disables update notifier",name:"NODE_ENV",type:String},{defaultValue:!1,description:"When set, enables debug output (same as --debug flag)",name:"DEBUG",type:Boolean},{description:"Sets the terminal width for table rendering. Useful for testing and consistent output",name:"CEREBRO_TERMINAL_WIDTH",type:Number}];var N=Object.defineProperty,h=f((r,a)=>N(r,"name",{value:a,configurable:!0}),"h");const $="__Other",v=h(r=>r.charAt(0).toUpperCase()+r.slice(1),"upperFirstChar"),w=h((r,a,l,o)=>{r.debug("no command given, printing general help...");let e=[...new Set(l.values())].filter(t=>!t.hidden);o&&(e=e.filter(t=>t.group===o));const i=e.reduce((t,s)=>{const n=s.group??$;return t[n]??=[],t[n].push(s),t},{}),d=h(t=>t.map(s=>{let n="";typeof s.alias=="string"?n=s.alias:Array.isArray(s.alias)&&(n=s.alias.join(", ")),n!==""&&(n=` [${n}]`);let m=s.name;return s.commandPath&&s.commandPath.length>0&&(m=`${s.commandPath.join(" ")} ${s.name}`),[`${c(m)}${n}`,s.description??""]}),"buildCommandList");(r.raw??r.log)(b([{content:`${u(a.getCliName())} ${c("<command>")} [positional arguments] ${g("[options]")}`,header:p.cyan(" Usage ")},...Object.keys(i).map(t=>{const s=o?` ${v(o)}`:"";return{content:d(i[t]),header:t===$||o?p.green(` Available${s} Commands `):` ${p.green(` ${v(t)} `)}`}}),l.has("help")?{header:p.yellow(" Command Options "),optionList:l.get("help").options?.filter(t=>!t.hidden)}:void 0,{header:p.yellow(" Global Options "),optionList:a.getGlobalOptions()},{content:E.filter(t=>!t.hidden).map(t=>[t.name,t.description??""]),header:p.magenta(" Environment Variables ")},{content:`Run "${u(a.getCliName())} ${c("help <command>")}" or "${u(a.getCliName())} ${c("<command>")} ${g("--help")}" for help with a specific command.`,raw:!0}].filter(Boolean)))},"printGeneralHelp"),C=h((r,a)=>{const l=[];for(const o of r.values()){if(o.hidden)continue;const e=o.commandPath??[];if(e.length!==a.length)continue;let i=!0;for(const[d,t]of a.entries())if(e[d]!==t){i=!1;break}i&&l.push(o)}return l},"findChildren"),P=h((r,a,l,o)=>{const e=l.join(" "),i=[{content:`${u(a.getCliName())} ${c(e)} ${c("<subcommand>")} [positional arguments] ${g("[options]")}`,header:p.cyan(" Usage ")},{content:o.map(d=>{const t=[...d.commandPath??[],d.name].join(" ");return[c(t),d.description??""]}),header:p.green(" Subcommands ")},{header:p.yellow(" Global Options "),optionList:a.getGlobalOptions()},{content:`Run "${u(a.getCliName())} ${c(`${e} <subcommand>`)} ${g("--help")}" for help with a specific subcommand.`,raw:!0}];(r.raw??r.log)(b(i))},"printParentHelp"),A=h((r,a,l,o)=>{let e=l.get(o);if(!e)for(const n of l.values()){const m=n.commandPath?[...n.commandPath,n.name]:[n.name];if(m.at(-1)===o||m.join(" ")===o){e=n;break}}if(!e){const n=o.split(" ").filter(Boolean),m=n.length>0?C(l,n):[];if(m.length>0){P(r,a,n,m);return}r.error(`Command "${o}" not found`);return}const i=[],d=(e.commandPath?[...e.commandPath,e.name]:[e.name]).join(" ");if(i.push({content:`${u(a.getCliName())} ${c(d)}${e.argument?" [positional arguments]":""}${e.options?" [options]":""}`,header:p.cyan(" Usage ")}),e.description&&i.push({content:e.description,header:p.green(" Description ")}),e.argument&&i.push({header:"Command Positional Arguments",isArgument:!0,optionList:[e.argument]}),Array.isArray(e.options)&&e.options.length>0&&i.push({header:p.yellow(" Command Options "),optionList:e.options.filter(n=>!n.hidden)}),i.push({header:p.yellow(" Global Options "),optionList:a.getGlobalOptions()}),Array.isArray(e.env)&&e.env.length>0){const n=e.env.filter(m=>!m.hidden);n.length>0&&i.push({content:n.map(m=>[m.name,m.description??""]),header:p.magenta(" Environment Variables ")})}if(e.alias!==void 0&&e.alias.length>0){let n=e.alias;typeof e.alias=="string"&&(n=[e.alias]),i.splice(1,0,{content:n,header:"Alias(es)"})}Array.isArray(e.examples)&&e.examples.length>0&&i.push({content:e.examples,header:"Examples"});const t=[...e.commandPath??[],e.name],s=C(l,t);s.length>0&&i.push({content:s.map(n=>{const m=[...n.commandPath??[],n.name].join(" ");return[c(m),n.description??""]}),header:p.green(" Subcommands ")}),(r.raw??r.log)(b(i))},"printCommandHelp");class S{static{f(this,"x")}static{h(this,"HelpCommand")}name="help";options=[{description:"Display only the specified group",name:"group",type:String}];commands;constructor(a){this.commands=a}execute(a){const{commandName:l,logger:o,options:e,runtime:i}=a,{footer:d,header:t}=i.getCommandSection();t&&(o.raw??o.log)(y(t)),l==="help"?w(o,i,this.commands,typeof e?.group=="string"?e.group:void 0):A(o,i,this.commands,l),d&&(o.raw??o.log)(y(d))}}export{S as default};