hexbus 0.1.0 → 0.1.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 +133 -10
- package/dist/index.d.mts +1216 -36
- package/dist/index.mjs +959 -277
- package/package.json +45 -46
package/dist/index.d.mts
CHANGED
|
@@ -1,312 +1,1492 @@
|
|
|
1
|
-
import color from "picocolors";
|
|
2
|
-
|
|
3
1
|
//#region src/types.d.ts
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Supported logger verbosity levels.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Levels are ordered from least verbose (`error`) to most verbose (`debug`).
|
|
7
|
+
* `createCliLogger` uses this ordering to decide whether a message should be
|
|
8
|
+
* emitted.
|
|
9
|
+
*/
|
|
10
|
+
type LogLevel = "error" | "warn" | "info" | "debug";
|
|
11
|
+
/**
|
|
12
|
+
* Describes how a command-line flag should be parsed.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* `special` flags behave like booleans during parsing but usually trigger
|
|
16
|
+
* control flow outside command execution, such as showing help or version
|
|
17
|
+
* output.
|
|
18
|
+
*/
|
|
19
|
+
type FlagType = "boolean" | "string" | "special";
|
|
20
|
+
/**
|
|
21
|
+
* Defines a global command-line flag accepted by a Hexbus CLI.
|
|
22
|
+
*/
|
|
6
23
|
interface CliFlag {
|
|
24
|
+
/**
|
|
25
|
+
* Flag aliases accepted on the command line.
|
|
26
|
+
*
|
|
27
|
+
* @example ['--help', '-h']
|
|
28
|
+
*/
|
|
7
29
|
names: string[];
|
|
30
|
+
/**
|
|
31
|
+
* Human-readable explanation shown in generated help output.
|
|
32
|
+
*/
|
|
8
33
|
description: string;
|
|
34
|
+
/**
|
|
35
|
+
* Parser behavior for this flag.
|
|
36
|
+
*/
|
|
9
37
|
type: FlagType;
|
|
38
|
+
/**
|
|
39
|
+
* Whether the flag consumes the following argument as its value.
|
|
40
|
+
*/
|
|
10
41
|
expectsValue: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Initial value assigned before raw arguments are parsed.
|
|
44
|
+
*/
|
|
11
45
|
defaultValue?: string | boolean;
|
|
12
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Normalized representation of raw CLI arguments.
|
|
49
|
+
*/
|
|
13
50
|
interface ParsedArgs {
|
|
51
|
+
/**
|
|
52
|
+
* Name of the matched top-level command, if the first positional argument
|
|
53
|
+
* matched a registered command.
|
|
54
|
+
*/
|
|
14
55
|
commandName: string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Positional arguments remaining after the top-level command name is
|
|
58
|
+
* removed.
|
|
59
|
+
*/
|
|
15
60
|
commandArgs: string[];
|
|
61
|
+
/**
|
|
62
|
+
* Parsed global flags keyed by their primary long name without leading
|
|
63
|
+
* dashes.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* The `--no-telemetry` flag is stored as `no-telemetry`.
|
|
67
|
+
*/
|
|
16
68
|
parsedFlags: Record<string, string | boolean | undefined>;
|
|
17
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Defines a command that can be rendered in help output and executed with a
|
|
72
|
+
* fully resolved CLI context.
|
|
73
|
+
*
|
|
74
|
+
* @remarks
|
|
75
|
+
* Commands are intentionally data-first so product CLIs can build menus,
|
|
76
|
+
* telemetry labels, and nested command trees from the same object. The action
|
|
77
|
+
* receives the resolved context after flags, package manager detection,
|
|
78
|
+
* framework detection, logging, and telemetry have been initialized.
|
|
79
|
+
*
|
|
80
|
+
* @typeParam TContext - CLI context shape required by this command. Extend the
|
|
81
|
+
* base context when a product CLI injects additional services or configuration.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* const command: CliCommand = {
|
|
86
|
+
* name: 'init',
|
|
87
|
+
* label: 'Initialize project',
|
|
88
|
+
* hint: 'Scaffold config files',
|
|
89
|
+
* description: 'Creates project configuration files.',
|
|
90
|
+
* async action(context) {
|
|
91
|
+
* context.logger.info(`Running in ${context.projectRoot}`);
|
|
92
|
+
* },
|
|
93
|
+
* };
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
18
96
|
interface CliCommand<TContext extends CliContext = CliContext> {
|
|
97
|
+
/**
|
|
98
|
+
* Stable command name accepted on the command line.
|
|
99
|
+
*/
|
|
19
100
|
name: string;
|
|
101
|
+
/**
|
|
102
|
+
* Short display label for menus or selection prompts.
|
|
103
|
+
*/
|
|
20
104
|
label: string;
|
|
105
|
+
/**
|
|
106
|
+
* Compact hint for interactive command menus.
|
|
107
|
+
*/
|
|
21
108
|
hint: string;
|
|
109
|
+
/**
|
|
110
|
+
* Longer explanation used in help output.
|
|
111
|
+
*/
|
|
22
112
|
description: string;
|
|
113
|
+
/**
|
|
114
|
+
* Command implementation.
|
|
115
|
+
*
|
|
116
|
+
* @remarks
|
|
117
|
+
* Throw `CliError` when possible so shared error handling can render
|
|
118
|
+
* catalog hints and documentation links.
|
|
119
|
+
*/
|
|
23
120
|
action: (context: TContext) => Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Optional nested command list consumed by `parseSubcommand` and custom
|
|
123
|
+
* command routers.
|
|
124
|
+
*/
|
|
24
125
|
subcommands?: CliCommand<TContext>[];
|
|
126
|
+
/**
|
|
127
|
+
* Hides the command from generated help and menu UIs without preventing
|
|
128
|
+
* direct execution by a custom router.
|
|
129
|
+
*/
|
|
25
130
|
hidden?: boolean;
|
|
26
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Minimal package metadata loaded from a project's `package.json`.
|
|
134
|
+
*/
|
|
27
135
|
interface PackageInfo {
|
|
136
|
+
/**
|
|
137
|
+
* Package name, or `unknown` when no readable package name exists.
|
|
138
|
+
*/
|
|
28
139
|
name: string;
|
|
140
|
+
/**
|
|
141
|
+
* Package version, or `unknown` when no readable package version exists.
|
|
142
|
+
*/
|
|
29
143
|
version: string;
|
|
144
|
+
/**
|
|
145
|
+
* Additional package.json fields preserved for callers that need them.
|
|
146
|
+
*/
|
|
30
147
|
[key: string]: unknown;
|
|
31
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Result of inspecting project dependencies for a known frontend framework.
|
|
151
|
+
*
|
|
152
|
+
* @typeParam TPackage - Product-specific package identifier selected from a
|
|
153
|
+
* `FrameworkPackageMap`.
|
|
154
|
+
*/
|
|
32
155
|
interface FrameworkDetectionResult<TPackage extends string = string> {
|
|
156
|
+
/**
|
|
157
|
+
* Detected framework display name, or `null` when no supported framework was
|
|
158
|
+
* found.
|
|
159
|
+
*/
|
|
33
160
|
framework: string | null;
|
|
161
|
+
/**
|
|
162
|
+
* Version range read from `package.json` for the detected framework.
|
|
163
|
+
*/
|
|
34
164
|
frameworkVersion: string | null;
|
|
165
|
+
/**
|
|
166
|
+
* Product package identifier associated with the detected framework.
|
|
167
|
+
*/
|
|
35
168
|
pkg: TPackage | null;
|
|
169
|
+
/**
|
|
170
|
+
* Whether any React dependency was found.
|
|
171
|
+
*/
|
|
36
172
|
hasReact: boolean;
|
|
173
|
+
/**
|
|
174
|
+
* React version range read from `package.json`, if present.
|
|
175
|
+
*/
|
|
37
176
|
reactVersion: string | null;
|
|
177
|
+
/**
|
|
178
|
+
* Tailwind CSS version range read from `package.json`, if present.
|
|
179
|
+
*/
|
|
38
180
|
tailwindVersion: string | null;
|
|
39
181
|
}
|
|
40
|
-
|
|
182
|
+
/**
|
|
183
|
+
* Package managers Hexbus can detect and render commands for.
|
|
184
|
+
*/
|
|
185
|
+
type PackageManager = "npm" | "yarn" | "pnpm" | "bun";
|
|
186
|
+
/**
|
|
187
|
+
* Package manager command templates resolved for the current project.
|
|
188
|
+
*/
|
|
41
189
|
interface PackageManagerResult {
|
|
190
|
+
/**
|
|
191
|
+
* Detected package manager name.
|
|
192
|
+
*/
|
|
42
193
|
name: PackageManager;
|
|
194
|
+
/**
|
|
195
|
+
* Command used to install existing dependencies.
|
|
196
|
+
*/
|
|
43
197
|
installCommand: string;
|
|
198
|
+
/**
|
|
199
|
+
* Command prefix used to add new dependencies.
|
|
200
|
+
*/
|
|
44
201
|
addCommand: string;
|
|
202
|
+
/**
|
|
203
|
+
* Command prefix used to run package scripts.
|
|
204
|
+
*/
|
|
45
205
|
runCommand: string;
|
|
206
|
+
/**
|
|
207
|
+
* Command prefix used to execute package binaries without installing them
|
|
208
|
+
* globally.
|
|
209
|
+
*/
|
|
46
210
|
execCommand: string;
|
|
211
|
+
/**
|
|
212
|
+
* Optional detected package manager version.
|
|
213
|
+
*/
|
|
47
214
|
version?: string | null;
|
|
48
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* User-facing logger abstraction used by Hexbus commands.
|
|
218
|
+
*
|
|
219
|
+
* @remarks
|
|
220
|
+
* The interface mirrors the small subset of logging and prompt output that
|
|
221
|
+
* command authors need. It keeps command code independent from the concrete
|
|
222
|
+
* prompt renderer used by `createCliLogger`.
|
|
223
|
+
*/
|
|
49
224
|
interface CliLogger {
|
|
225
|
+
/**
|
|
226
|
+
* Emits a debug message when the active log level allows debug output.
|
|
227
|
+
*/
|
|
50
228
|
debug(message: string, ...args: unknown[]): void;
|
|
229
|
+
/**
|
|
230
|
+
* Emits an informational message.
|
|
231
|
+
*/
|
|
51
232
|
info(message: string, ...args: unknown[]): void;
|
|
233
|
+
/**
|
|
234
|
+
* Emits a warning message.
|
|
235
|
+
*/
|
|
52
236
|
warn(message: string, ...args: unknown[]): void;
|
|
237
|
+
/**
|
|
238
|
+
* Emits an error message.
|
|
239
|
+
*/
|
|
53
240
|
error(message: string, ...args: unknown[]): void;
|
|
241
|
+
/**
|
|
242
|
+
* Emits an unadorned message without log-level filtering.
|
|
243
|
+
*/
|
|
54
244
|
message(message: string): void;
|
|
245
|
+
/**
|
|
246
|
+
* Renders a note block with optional title.
|
|
247
|
+
*/
|
|
55
248
|
note(content: string, title?: string): void;
|
|
249
|
+
/**
|
|
250
|
+
* Renders a closing message for a completed interaction.
|
|
251
|
+
*/
|
|
56
252
|
outro(message: string): void;
|
|
253
|
+
/**
|
|
254
|
+
* Renders a successful completion message.
|
|
255
|
+
*/
|
|
57
256
|
success(message: string): void;
|
|
257
|
+
/**
|
|
258
|
+
* Renders a failure message and terminates the process.
|
|
259
|
+
*
|
|
260
|
+
* @throws Never returns because it exits the current process.
|
|
261
|
+
*/
|
|
58
262
|
failed(message: string, exitCode?: number): never;
|
|
263
|
+
/**
|
|
264
|
+
* Renders a numbered progress step.
|
|
265
|
+
*/
|
|
59
266
|
step(current: number, total: number, label: string): void;
|
|
60
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* Shared process-ending error and cancellation handlers.
|
|
270
|
+
*/
|
|
61
271
|
interface ErrorHandlers {
|
|
272
|
+
/**
|
|
273
|
+
* Normalizes, displays, tracks, and exits for an unknown thrown value.
|
|
274
|
+
*/
|
|
62
275
|
handleError(error: unknown, command: string): never;
|
|
276
|
+
/**
|
|
277
|
+
* Displays a cancellation message and exits successfully.
|
|
278
|
+
*/
|
|
63
279
|
handleCancel(message?: string, context?: {
|
|
64
280
|
command?: string;
|
|
65
281
|
stage?: string;
|
|
66
282
|
}): never;
|
|
67
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Configuration loading helpers attached to a CLI context.
|
|
286
|
+
*/
|
|
68
287
|
interface ConfigManagement {
|
|
288
|
+
/**
|
|
289
|
+
* Loads optional configuration for the current project.
|
|
290
|
+
*
|
|
291
|
+
* @typeParam TConfig - Expected user configuration shape.
|
|
292
|
+
* @returns The parsed config object, or `null` when no config is found.
|
|
293
|
+
*/
|
|
69
294
|
loadConfig<TConfig = unknown>(): Promise<TConfig | null>;
|
|
295
|
+
/**
|
|
296
|
+
* Loads required configuration for the current project.
|
|
297
|
+
*
|
|
298
|
+
* @typeParam TConfig - Expected user configuration shape.
|
|
299
|
+
* @throws `CliError` with `CONFIG_NOT_FOUND` when no config is found.
|
|
300
|
+
*/
|
|
70
301
|
requireConfig<TConfig = unknown>(): Promise<TConfig>;
|
|
302
|
+
/**
|
|
303
|
+
* Reads TypeScript-style path aliases from configuration when supported.
|
|
304
|
+
*
|
|
305
|
+
* @remarks
|
|
306
|
+
* The default Hexbus context currently returns `null`; product CLIs can
|
|
307
|
+
* override this method when they provide config-aware file resolution.
|
|
308
|
+
*/
|
|
71
309
|
getPathAliases(configPath?: string): Record<string, string> | null;
|
|
72
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* File-system helpers rooted in the detected project.
|
|
313
|
+
*/
|
|
73
314
|
interface FileSystemUtils {
|
|
315
|
+
/**
|
|
316
|
+
* Reads project package metadata.
|
|
317
|
+
*/
|
|
74
318
|
getPackageInfo(): PackageInfo;
|
|
319
|
+
/**
|
|
320
|
+
* Tests whether a file-system path exists.
|
|
321
|
+
*/
|
|
75
322
|
exists(path: string): Promise<boolean>;
|
|
323
|
+
/**
|
|
324
|
+
* Reads a UTF-8 text file.
|
|
325
|
+
*/
|
|
76
326
|
read(path: string): Promise<string>;
|
|
327
|
+
/**
|
|
328
|
+
* Writes a UTF-8 text file.
|
|
329
|
+
*/
|
|
77
330
|
write(path: string, content: string): Promise<void>;
|
|
331
|
+
/**
|
|
332
|
+
* Creates a directory and any missing parents.
|
|
333
|
+
*/
|
|
78
334
|
mkdir(path: string): Promise<void>;
|
|
79
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* Telemetry client used by CLI lifecycle and command code.
|
|
338
|
+
*
|
|
339
|
+
* @remarks
|
|
340
|
+
* The built-in implementation queues events in memory and flushes them only
|
|
341
|
+
* when an endpoint is configured. Commands should treat telemetry as best
|
|
342
|
+
* effort and never depend on it for core behavior.
|
|
343
|
+
*/
|
|
80
344
|
interface Telemetry {
|
|
345
|
+
/**
|
|
346
|
+
* Queues a named telemetry event.
|
|
347
|
+
*/
|
|
81
348
|
trackEvent(eventName: string, properties?: Record<string, unknown>): void;
|
|
349
|
+
/**
|
|
350
|
+
* Queues a standardized command invocation event.
|
|
351
|
+
*/
|
|
82
352
|
trackCommand(command: string, args?: string[], flags?: Record<string, string | number | boolean | undefined>): void;
|
|
353
|
+
/**
|
|
354
|
+
* Queues a standardized error event.
|
|
355
|
+
*/
|
|
83
356
|
trackError(error: Error, command?: string): void;
|
|
357
|
+
/**
|
|
358
|
+
* Sends queued events when possible and clears the local queue.
|
|
359
|
+
*/
|
|
84
360
|
flush(): Promise<void>;
|
|
361
|
+
/**
|
|
362
|
+
* Performs final telemetry cleanup before process exit.
|
|
363
|
+
*/
|
|
85
364
|
shutdown(): Promise<void>;
|
|
365
|
+
/**
|
|
366
|
+
* Indicates whether this telemetry instance is disabled.
|
|
367
|
+
*/
|
|
86
368
|
isDisabled(): boolean;
|
|
87
369
|
}
|
|
370
|
+
/**
|
|
371
|
+
* Fully resolved execution context passed to command actions.
|
|
372
|
+
*
|
|
373
|
+
* @remarks
|
|
374
|
+
* `createCliContext` builds this object once per invocation after parsing raw
|
|
375
|
+
* arguments, detecting the project root, selecting framework/package-manager
|
|
376
|
+
* metadata, and initializing logger, config, file-system, and telemetry
|
|
377
|
+
* services.
|
|
378
|
+
*
|
|
379
|
+
* @typeParam TPackage - Product-specific package identifier selected during
|
|
380
|
+
* framework detection.
|
|
381
|
+
*/
|
|
88
382
|
interface CliContext<TPackage extends string = string> {
|
|
383
|
+
/**
|
|
384
|
+
* Logger for command output.
|
|
385
|
+
*/
|
|
89
386
|
logger: CliLogger;
|
|
90
|
-
|
|
387
|
+
/**
|
|
388
|
+
* Parsed global flags keyed by primary flag name.
|
|
389
|
+
*/
|
|
390
|
+
flags: ParsedArgs["parsedFlags"];
|
|
391
|
+
/**
|
|
392
|
+
* Matched top-level command name, if one was provided.
|
|
393
|
+
*/
|
|
91
394
|
commandName: string | undefined;
|
|
395
|
+
/**
|
|
396
|
+
* Positional arguments remaining after command parsing.
|
|
397
|
+
*/
|
|
92
398
|
commandArgs: string[];
|
|
399
|
+
/**
|
|
400
|
+
* Original working directory where context creation began.
|
|
401
|
+
*/
|
|
93
402
|
cwd: string;
|
|
403
|
+
/**
|
|
404
|
+
* Shared process-ending error handlers.
|
|
405
|
+
*/
|
|
94
406
|
error: ErrorHandlers;
|
|
407
|
+
/**
|
|
408
|
+
* Configuration loading helpers.
|
|
409
|
+
*/
|
|
95
410
|
config: ConfigManagement;
|
|
411
|
+
/**
|
|
412
|
+
* File-system helpers rooted at `projectRoot`.
|
|
413
|
+
*/
|
|
96
414
|
fs: FileSystemUtils;
|
|
415
|
+
/**
|
|
416
|
+
* Telemetry client for lifecycle and command events.
|
|
417
|
+
*/
|
|
97
418
|
telemetry: Telemetry;
|
|
419
|
+
/**
|
|
420
|
+
* Prompts the user to confirm an action.
|
|
421
|
+
*
|
|
422
|
+
* @remarks
|
|
423
|
+
* Returns `true` without prompting when `-y` or `--yes` was provided.
|
|
424
|
+
*/
|
|
98
425
|
confirm(message: string, initialValue?: boolean): Promise<boolean>;
|
|
426
|
+
/**
|
|
427
|
+
* Nearest ancestor directory containing `package.json`, or `cwd` when none
|
|
428
|
+
* was found.
|
|
429
|
+
*/
|
|
99
430
|
projectRoot: string;
|
|
431
|
+
/**
|
|
432
|
+
* Framework and package selection metadata for the detected project.
|
|
433
|
+
*/
|
|
100
434
|
framework: FrameworkDetectionResult<TPackage>;
|
|
435
|
+
/**
|
|
436
|
+
* Package manager commands for the detected project.
|
|
437
|
+
*/
|
|
101
438
|
packageManager: PackageManagerResult;
|
|
102
439
|
}
|
|
103
440
|
//#endregion
|
|
104
441
|
//#region src/context.d.ts
|
|
442
|
+
/**
|
|
443
|
+
* Options used to build a complete CLI execution context.
|
|
444
|
+
*
|
|
445
|
+
* @typeParam TPackage - Product-specific package identifier selected by
|
|
446
|
+
* framework detection.
|
|
447
|
+
*/
|
|
105
448
|
interface CreateContextOptions<TPackage extends string = string> {
|
|
449
|
+
/**
|
|
450
|
+
* Raw process arguments after the executable and script path have been
|
|
451
|
+
* removed.
|
|
452
|
+
*
|
|
453
|
+
* @example process.argv.slice(2)
|
|
454
|
+
*/
|
|
106
455
|
rawArgs: string[];
|
|
456
|
+
/**
|
|
457
|
+
* Directory where invocation started.
|
|
458
|
+
*
|
|
459
|
+
* @default process.cwd()
|
|
460
|
+
*/
|
|
107
461
|
cwd?: string;
|
|
462
|
+
/**
|
|
463
|
+
* Top-level commands used to identify `commandName` during argument parsing.
|
|
464
|
+
*/
|
|
108
465
|
commands: CliCommand[];
|
|
466
|
+
/**
|
|
467
|
+
* Application name used for config lookup, telemetry defaults, and logger
|
|
468
|
+
* metadata.
|
|
469
|
+
*
|
|
470
|
+
* @default "cli"
|
|
471
|
+
*/
|
|
109
472
|
appName?: string;
|
|
473
|
+
/**
|
|
474
|
+
* Config name passed to `c12` when loading project configuration.
|
|
475
|
+
*
|
|
476
|
+
* @default appName
|
|
477
|
+
*/
|
|
110
478
|
configName?: string;
|
|
479
|
+
/**
|
|
480
|
+
* Telemetry configuration for the context.
|
|
481
|
+
*/
|
|
111
482
|
telemetry?: {
|
|
483
|
+
/**
|
|
484
|
+
* Disables telemetry regardless of command-line flags or environment
|
|
485
|
+
* variables.
|
|
486
|
+
*/
|
|
112
487
|
disabled?: boolean;
|
|
488
|
+
/**
|
|
489
|
+
* Emits queued telemetry payloads through the logger debug channel.
|
|
490
|
+
*/
|
|
113
491
|
debug?: boolean;
|
|
492
|
+
/**
|
|
493
|
+
* HTTP endpoint that receives flushed telemetry batches.
|
|
494
|
+
*/
|
|
114
495
|
endpoint?: string;
|
|
496
|
+
/**
|
|
497
|
+
* Environment variable prefix used to read telemetry opt-out flags.
|
|
498
|
+
*
|
|
499
|
+
* @remarks
|
|
500
|
+
* A prefix of `MY_CLI` reads `MY_CLI_TELEMETRY_DISABLED`.
|
|
501
|
+
*/
|
|
115
502
|
envVarPrefix?: string;
|
|
503
|
+
/**
|
|
504
|
+
* Properties merged into every telemetry event created by this context.
|
|
505
|
+
*/
|
|
116
506
|
defaultProperties?: Record<string, unknown>;
|
|
117
507
|
};
|
|
508
|
+
/**
|
|
509
|
+
* Product package identifiers selected for framework-specific installs.
|
|
510
|
+
*/
|
|
118
511
|
packageMap?: {
|
|
512
|
+
/**
|
|
513
|
+
* Package used when no React framework is detected.
|
|
514
|
+
*/
|
|
119
515
|
core?: TPackage;
|
|
516
|
+
/**
|
|
517
|
+
* Package used for generic React-compatible projects.
|
|
518
|
+
*/
|
|
120
519
|
react?: TPackage;
|
|
520
|
+
/**
|
|
521
|
+
* Package used for Next.js projects.
|
|
522
|
+
*/
|
|
121
523
|
next?: TPackage;
|
|
122
524
|
};
|
|
525
|
+
/**
|
|
526
|
+
* Allows package-manager detection to prompt when lockfile and package.json
|
|
527
|
+
* detection fail.
|
|
528
|
+
*
|
|
529
|
+
* @default false
|
|
530
|
+
*/
|
|
123
531
|
interactivePackageManagerDetection?: boolean;
|
|
124
532
|
}
|
|
533
|
+
/**
|
|
534
|
+
* Creates the resolved context passed to command actions.
|
|
535
|
+
*
|
|
536
|
+
* @remarks
|
|
537
|
+
* Context creation performs the standard CLI bootstrap sequence: parse global
|
|
538
|
+
* flags, create the logger, detect the project root, detect framework and
|
|
539
|
+
* package manager metadata, set up telemetry, and attach helpers for config
|
|
540
|
+
* loading, file-system access, confirmation prompts, and process-ending error
|
|
541
|
+
* handling.
|
|
542
|
+
*
|
|
543
|
+
* @typeParam TPackage - Product-specific package identifier returned from
|
|
544
|
+
* framework detection.
|
|
545
|
+
* @param options - Context creation options for the current invocation.
|
|
546
|
+
* @returns A fully initialized `CliContext`.
|
|
547
|
+
*
|
|
548
|
+
* @example
|
|
549
|
+
* ```ts
|
|
550
|
+
* const context = await createCliContext({
|
|
551
|
+
* rawArgs: process.argv.slice(2),
|
|
552
|
+
* appName: 'acme',
|
|
553
|
+
* commands,
|
|
554
|
+
* });
|
|
555
|
+
*
|
|
556
|
+
* await commands.find((command) => command.name === context.commandName)
|
|
557
|
+
* ?.action(context);
|
|
558
|
+
* ```
|
|
559
|
+
*/
|
|
125
560
|
declare function createCliContext<TPackage extends string = string>(options: CreateContextOptions<TPackage>): Promise<CliContext<TPackage>>;
|
|
561
|
+
/**
|
|
562
|
+
* Creates a deterministic context for unit tests.
|
|
563
|
+
*
|
|
564
|
+
* @remarks
|
|
565
|
+
* The test context disables telemetry, uses an error-only logger, avoids real
|
|
566
|
+
* framework or package-manager detection, and provides no-op file-system
|
|
567
|
+
* helpers. Pass overrides to replace only the services a test needs.
|
|
568
|
+
*
|
|
569
|
+
* @param overrides - Partial context fields to merge into the default test
|
|
570
|
+
* context.
|
|
571
|
+
* @returns A `CliContext` suitable for command and helper tests.
|
|
572
|
+
*
|
|
573
|
+
* @example
|
|
574
|
+
* ```ts
|
|
575
|
+
* const context = createTestContext({
|
|
576
|
+
* flags: { force: true },
|
|
577
|
+
* commandName: 'init',
|
|
578
|
+
* });
|
|
579
|
+
* ```
|
|
580
|
+
*/
|
|
126
581
|
declare function createTestContext(overrides?: Partial<CliContext>): CliContext;
|
|
127
582
|
//#endregion
|
|
128
583
|
//#region src/detection.d.ts
|
|
584
|
+
/**
|
|
585
|
+
* Product package identifiers to select after framework detection.
|
|
586
|
+
*
|
|
587
|
+
* @remarks
|
|
588
|
+
* Use this map when a product CLI installs different packages for core,
|
|
589
|
+
* React, or Next.js projects.
|
|
590
|
+
*
|
|
591
|
+
* @typeParam TPackage - Product-specific package identifier.
|
|
592
|
+
*/
|
|
129
593
|
interface FrameworkPackageMap<TPackage extends string = string> {
|
|
594
|
+
/**
|
|
595
|
+
* Package identifier used when no React framework is detected.
|
|
596
|
+
*/
|
|
130
597
|
core?: TPackage;
|
|
598
|
+
/**
|
|
599
|
+
* Package identifier used for React-compatible projects.
|
|
600
|
+
*/
|
|
131
601
|
react?: TPackage;
|
|
602
|
+
/**
|
|
603
|
+
* Package identifier used specifically for Next.js projects.
|
|
604
|
+
*/
|
|
132
605
|
next?: TPackage;
|
|
133
606
|
}
|
|
607
|
+
/**
|
|
608
|
+
* Detects common frontend frameworks from project dependencies.
|
|
609
|
+
*
|
|
610
|
+
* @remarks
|
|
611
|
+
* Detection reads the nearest project's `package.json` and looks at
|
|
612
|
+
* dependencies and devDependencies. It recognizes Next.js, Remix, Vite React,
|
|
613
|
+
* Gatsby, generic React, Tailwind CSS, and a configured core fallback.
|
|
614
|
+
*
|
|
615
|
+
* @typeParam TPackage - Product-specific package identifier returned in
|
|
616
|
+
* `FrameworkDetectionResult.pkg`.
|
|
617
|
+
* @param projectRoot - Directory containing the package.json to inspect.
|
|
618
|
+
* @param logger - Optional logger for debug diagnostics.
|
|
619
|
+
* @param packageMap - Product packages to select for detected frameworks.
|
|
620
|
+
* @returns Framework metadata and the selected product package identifier.
|
|
621
|
+
*/
|
|
134
622
|
declare function detectFramework<TPackage extends string = string>(projectRoot: string, logger?: CliLogger, packageMap?: FrameworkPackageMap<TPackage>): Promise<FrameworkDetectionResult<TPackage>>;
|
|
623
|
+
/**
|
|
624
|
+
* Finds the nearest project root by walking up to a package.json.
|
|
625
|
+
*
|
|
626
|
+
* @remarks
|
|
627
|
+
* The search is capped at ten directory levels to avoid surprising filesystem
|
|
628
|
+
* traversal. When no root is found, the original current working directory is
|
|
629
|
+
* returned and a warning is logged.
|
|
630
|
+
*
|
|
631
|
+
* @param cwd - Directory where invocation started.
|
|
632
|
+
* @param logger - Optional logger for warning output.
|
|
633
|
+
* @returns The detected project root or `cwd` as a fallback.
|
|
634
|
+
*/
|
|
135
635
|
declare function detectProjectRoot(cwd: string, logger?: CliLogger): Promise<string>;
|
|
636
|
+
/**
|
|
637
|
+
* Detects the package manager used by a project.
|
|
638
|
+
*
|
|
639
|
+
* @remarks
|
|
640
|
+
* Detection prefers lockfiles, then the `packageManager` field in
|
|
641
|
+
* `package.json`, then an optional interactive prompt, and finally `npm`.
|
|
642
|
+
*
|
|
643
|
+
* @param projectRoot - Directory to inspect for lockfiles and package.json.
|
|
644
|
+
* @param logger - Optional logger for debug output.
|
|
645
|
+
* @param options - Detection options.
|
|
646
|
+
* @returns Command templates for the detected package manager.
|
|
647
|
+
*
|
|
648
|
+
* @throws When interactive prompting is enabled and the user cancels package
|
|
649
|
+
* manager selection.
|
|
650
|
+
*/
|
|
136
651
|
declare function detectPackageManager(projectRoot: string, logger?: CliLogger, options?: {
|
|
137
652
|
interactive?: boolean;
|
|
138
653
|
}): Promise<PackageManagerResult>;
|
|
654
|
+
/**
|
|
655
|
+
* Builds a dependency installation command for the detected package manager.
|
|
656
|
+
*
|
|
657
|
+
* @param pm - Package manager command templates.
|
|
658
|
+
* @param packages - Package names to install.
|
|
659
|
+
* @param options - Install command options.
|
|
660
|
+
* @returns A shell command string suitable for display or execution.
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
* ```ts
|
|
664
|
+
* getInstallCommand(pm, ['typescript'], { dev: true });
|
|
665
|
+
* ```
|
|
666
|
+
*/
|
|
139
667
|
declare function getInstallCommand(pm: PackageManagerResult, packages: string[], options?: {
|
|
140
668
|
dev?: boolean;
|
|
141
669
|
}): string;
|
|
670
|
+
/**
|
|
671
|
+
* Builds a package-script command for the detected package manager.
|
|
672
|
+
*
|
|
673
|
+
* @param pm - Package manager command templates.
|
|
674
|
+
* @param script - Package script name to run.
|
|
675
|
+
* @returns A shell command string.
|
|
676
|
+
*/
|
|
142
677
|
declare function getRunCommand(pm: PackageManagerResult, script: string): string;
|
|
678
|
+
/**
|
|
679
|
+
* Builds a one-off binary execution command for the detected package manager.
|
|
680
|
+
*
|
|
681
|
+
* @param pm - Package manager command templates.
|
|
682
|
+
* @param binary - Binary name to execute.
|
|
683
|
+
* @param args - Optional arguments appended after the binary name.
|
|
684
|
+
* @returns A shell command string.
|
|
685
|
+
*/
|
|
143
686
|
declare function getExecCommand(pm: PackageManagerResult, binary: string, args?: string[]): string;
|
|
144
687
|
//#endregion
|
|
145
688
|
//#region src/errors.d.ts
|
|
689
|
+
/**
|
|
690
|
+
* Metadata used to render a known CLI error.
|
|
691
|
+
*/
|
|
146
692
|
interface ErrorCatalogEntry {
|
|
693
|
+
/**
|
|
694
|
+
* Stable machine-readable error code.
|
|
695
|
+
*/
|
|
147
696
|
code: string;
|
|
697
|
+
/**
|
|
698
|
+
* User-facing error message.
|
|
699
|
+
*/
|
|
148
700
|
message: string;
|
|
701
|
+
/**
|
|
702
|
+
* Optional recovery guidance displayed after the message.
|
|
703
|
+
*/
|
|
149
704
|
hint?: string;
|
|
705
|
+
/**
|
|
706
|
+
* Optional documentation URL displayed after the hint.
|
|
707
|
+
*/
|
|
150
708
|
docs?: string;
|
|
151
709
|
}
|
|
710
|
+
/**
|
|
711
|
+
* Error catalog keyed by stable error code.
|
|
712
|
+
*/
|
|
152
713
|
type ErrorCatalog = Record<string, ErrorCatalogEntry>;
|
|
714
|
+
/**
|
|
715
|
+
* Built-in errors used by the Hexbus runtime.
|
|
716
|
+
*/
|
|
153
717
|
declare const DEFAULT_ERROR_CATALOG: {
|
|
718
|
+
readonly CANCELLED: {
|
|
719
|
+
readonly code: "CANCELLED";
|
|
720
|
+
readonly message: "Operation cancelled";
|
|
721
|
+
};
|
|
722
|
+
readonly COMMAND_NOT_FOUND: {
|
|
723
|
+
readonly code: "COMMAND_NOT_FOUND";
|
|
724
|
+
readonly hint: "Run --help to see available commands";
|
|
725
|
+
readonly message: "Unknown command";
|
|
726
|
+
};
|
|
154
727
|
readonly CONFIG_NOT_FOUND: {
|
|
155
728
|
readonly code: "CONFIG_NOT_FOUND";
|
|
156
|
-
readonly message: "Configuration not found";
|
|
157
729
|
readonly hint: "Run the setup command to create a configuration";
|
|
730
|
+
readonly message: "Configuration not found";
|
|
158
731
|
};
|
|
159
732
|
readonly FLAG_VALUE_REQUIRED: {
|
|
160
733
|
readonly code: "FLAG_VALUE_REQUIRED";
|
|
161
734
|
readonly message: "Flag requires a value";
|
|
162
735
|
};
|
|
163
|
-
readonly COMMAND_NOT_FOUND: {
|
|
164
|
-
readonly code: "COMMAND_NOT_FOUND";
|
|
165
|
-
readonly message: "Unknown command";
|
|
166
|
-
readonly hint: "Run --help to see available commands";
|
|
167
|
-
};
|
|
168
|
-
readonly CANCELLED: {
|
|
169
|
-
readonly code: "CANCELLED";
|
|
170
|
-
readonly message: "Operation cancelled";
|
|
171
|
-
};
|
|
172
736
|
readonly UNKNOWN_ERROR: {
|
|
173
737
|
readonly code: "UNKNOWN_ERROR";
|
|
174
738
|
readonly message: "An unexpected error occurred";
|
|
175
739
|
};
|
|
176
740
|
};
|
|
741
|
+
/**
|
|
742
|
+
* Adds or replaces entries in the active error catalog.
|
|
743
|
+
*
|
|
744
|
+
* @remarks
|
|
745
|
+
* This mutates process-local catalog state. Product CLIs should call it once
|
|
746
|
+
* during startup before command actions create `CliError` instances.
|
|
747
|
+
*
|
|
748
|
+
* @param entries - Error entries keyed by their stable code.
|
|
749
|
+
*
|
|
750
|
+
* @example
|
|
751
|
+
* ```ts
|
|
752
|
+
* extendErrorCatalog({
|
|
753
|
+
* PROJECT_NOT_READY: {
|
|
754
|
+
* code: 'PROJECT_NOT_READY',
|
|
755
|
+
* message: 'Project is not ready',
|
|
756
|
+
* hint: 'Run init before running this command.',
|
|
757
|
+
* },
|
|
758
|
+
* });
|
|
759
|
+
* ```
|
|
760
|
+
*/
|
|
177
761
|
declare function extendErrorCatalog(entries: ErrorCatalog): void;
|
|
762
|
+
/**
|
|
763
|
+
* Built-in or product-defined CLI error code.
|
|
764
|
+
*/
|
|
178
765
|
type ErrorCode = keyof typeof DEFAULT_ERROR_CATALOG | string;
|
|
766
|
+
/**
|
|
767
|
+
* Error type that carries a catalog entry and optional structured context.
|
|
768
|
+
*
|
|
769
|
+
* @remarks
|
|
770
|
+
* `CliError` keeps command code focused on stable error codes while shared
|
|
771
|
+
* handlers render the configured message, hint, and documentation link.
|
|
772
|
+
*/
|
|
179
773
|
declare class CliError extends Error {
|
|
774
|
+
/**
|
|
775
|
+
* Error code requested by the caller.
|
|
776
|
+
*/
|
|
180
777
|
readonly code: ErrorCode;
|
|
778
|
+
/**
|
|
779
|
+
* Structured diagnostic details attached by the caller.
|
|
780
|
+
*/
|
|
181
781
|
readonly context?: Record<string, unknown>;
|
|
782
|
+
/**
|
|
783
|
+
* Catalog entry used to render this error.
|
|
784
|
+
*/
|
|
182
785
|
readonly entry: ErrorCatalogEntry;
|
|
786
|
+
/**
|
|
787
|
+
* Creates a catalog-backed CLI error.
|
|
788
|
+
*
|
|
789
|
+
* @param code - Built-in or product-defined error code.
|
|
790
|
+
* @param context - Optional diagnostic details for rendering or telemetry.
|
|
791
|
+
*/
|
|
183
792
|
constructor(code: ErrorCode, context?: Record<string, unknown>);
|
|
793
|
+
/**
|
|
794
|
+
* Renders the error message, hint, and docs link through a logger.
|
|
795
|
+
*
|
|
796
|
+
* @param logger - Logger used for user-facing output.
|
|
797
|
+
*/
|
|
184
798
|
display(logger: CliLogger): void;
|
|
799
|
+
/**
|
|
800
|
+
* Normalizes an unknown thrown value into a `CliError`.
|
|
801
|
+
*
|
|
802
|
+
* @param error - Value caught from a `try`/`catch` block.
|
|
803
|
+
* @param fallbackCode - Catalog code to use when `error` is not already a
|
|
804
|
+
* `CliError`.
|
|
805
|
+
* @returns `error` unchanged when it is already a `CliError`, otherwise a
|
|
806
|
+
* wrapped `CliError`.
|
|
807
|
+
*/
|
|
185
808
|
static from(error: unknown, fallbackCode?: ErrorCode): CliError;
|
|
186
809
|
}
|
|
810
|
+
/**
|
|
811
|
+
* Narrows an unknown value to a `CliError`.
|
|
812
|
+
*
|
|
813
|
+
* @param error - Value to inspect.
|
|
814
|
+
* @param code - Optional code that must match the error.
|
|
815
|
+
* @returns `true` when the value is a `CliError` and, if provided, matches the
|
|
816
|
+
* requested code.
|
|
817
|
+
*/
|
|
187
818
|
declare function isCliError(error: unknown, code?: ErrorCode): error is CliError;
|
|
819
|
+
/**
|
|
820
|
+
* Creates shared process-ending error and cancellation handlers.
|
|
821
|
+
*
|
|
822
|
+
* @param logger - Logger used to render messages.
|
|
823
|
+
* @param telemetry - Optional telemetry sink for failed command errors.
|
|
824
|
+
* @returns Error handlers suitable for `CliContext.error`.
|
|
825
|
+
*/
|
|
188
826
|
declare function createErrorHandlers(logger: CliLogger, telemetry?: {
|
|
189
827
|
trackError(error: Error, command?: string): void;
|
|
190
828
|
}): {
|
|
191
|
-
handleError(error: unknown, command: string): never;
|
|
192
829
|
handleCancel(message?: string, context?: {
|
|
193
830
|
command?: string;
|
|
194
831
|
stage?: string;
|
|
195
832
|
}): never;
|
|
833
|
+
handleError(error: unknown, command: string): never;
|
|
196
834
|
};
|
|
835
|
+
/**
|
|
836
|
+
* Wraps an async function with CLI-style error rendering and process exit.
|
|
837
|
+
*
|
|
838
|
+
* @remarks
|
|
839
|
+
* This helper is useful near process entrypoints. Library-style code should
|
|
840
|
+
* usually throw `CliError` and let the caller decide when to exit.
|
|
841
|
+
*
|
|
842
|
+
* @typeParam T - Async function type to preserve.
|
|
843
|
+
* @param fn - Async function to run.
|
|
844
|
+
* @param logger - Logger used to render caught errors.
|
|
845
|
+
* @param context - Optional command metadata shown after an error.
|
|
846
|
+
* @returns A function with the same call signature as `fn`.
|
|
847
|
+
*/
|
|
197
848
|
declare function withErrorHandling<T extends (...args: unknown[]) => Promise<unknown>>(fn: T, logger: CliLogger, context?: {
|
|
198
849
|
command?: string;
|
|
199
850
|
}): T;
|
|
200
851
|
//#endregion
|
|
201
852
|
//#region src/help.d.ts
|
|
853
|
+
/**
|
|
854
|
+
* Metadata shown in the generated CLI help menu.
|
|
855
|
+
*/
|
|
202
856
|
interface ShowHelpMenuOptions {
|
|
857
|
+
/**
|
|
858
|
+
* CLI application name shown in usage and title text.
|
|
859
|
+
*/
|
|
203
860
|
appName: string;
|
|
861
|
+
/**
|
|
862
|
+
* CLI version shown near the top of the help menu.
|
|
863
|
+
*/
|
|
204
864
|
version: string;
|
|
865
|
+
/**
|
|
866
|
+
* Optional documentation URL shown after commands and global flags.
|
|
867
|
+
*/
|
|
205
868
|
docsUrl?: string;
|
|
206
869
|
}
|
|
207
|
-
|
|
870
|
+
/**
|
|
871
|
+
* Renders a help menu for commands and global flags.
|
|
872
|
+
*
|
|
873
|
+
* @param context - Context subset providing the logger used for output.
|
|
874
|
+
* @param options - Application metadata for the help menu.
|
|
875
|
+
* @param commands - Commands to list; commands with `hidden: true` are
|
|
876
|
+
* omitted.
|
|
877
|
+
* @param flags - Global flags to list.
|
|
878
|
+
*/
|
|
879
|
+
declare function showHelpMenu(context: Pick<CliContext, "logger">, options: ShowHelpMenuOptions, commands: CliCommand[], flags: CliFlag[]): void;
|
|
208
880
|
//#endregion
|
|
209
881
|
//#region src/intro.d.ts
|
|
882
|
+
/**
|
|
883
|
+
* Options for rendering a CLI intro banner.
|
|
884
|
+
*/
|
|
210
885
|
interface DisplayIntroOptions {
|
|
886
|
+
/**
|
|
887
|
+
* Application name used as the note title and default banner text.
|
|
888
|
+
*/
|
|
211
889
|
appName: string;
|
|
890
|
+
/**
|
|
891
|
+
* Optional application version shown in the fallback tagline.
|
|
892
|
+
*/
|
|
212
893
|
version?: string;
|
|
894
|
+
/**
|
|
895
|
+
* Optional tagline shown below the banner.
|
|
896
|
+
*/
|
|
213
897
|
tagline?: string;
|
|
898
|
+
/**
|
|
899
|
+
* Optional text passed to figlet instead of `appName`.
|
|
900
|
+
*/
|
|
214
901
|
figletText?: string;
|
|
215
902
|
}
|
|
216
|
-
|
|
903
|
+
/**
|
|
904
|
+
* Renders a figlet banner and short intro note.
|
|
905
|
+
*
|
|
906
|
+
* @remarks
|
|
907
|
+
* If figlet rendering fails, the plain banner text is displayed instead.
|
|
908
|
+
*
|
|
909
|
+
* @param context - Context subset providing the logger used for output.
|
|
910
|
+
* @param options - Intro banner metadata.
|
|
911
|
+
*/
|
|
912
|
+
declare function displayIntro(context: Pick<CliContext, "logger">, options: DisplayIntroOptions): Promise<void>;
|
|
913
|
+
//#endregion
|
|
914
|
+
//#region src/color.d.ts
|
|
915
|
+
/**
|
|
916
|
+
* Formats an arbitrary value as a string, optionally wrapping it in ANSI
|
|
917
|
+
* escape codes.
|
|
918
|
+
*/
|
|
919
|
+
type ColorFormatter = (input: unknown) => string;
|
|
920
|
+
/**
|
|
921
|
+
* Collection of ANSI style and color formatters.
|
|
922
|
+
*
|
|
923
|
+
* @remarks
|
|
924
|
+
* When color is disabled, every formatter returns the input converted with
|
|
925
|
+
* `String(input)` and does not add escape codes.
|
|
926
|
+
*/
|
|
927
|
+
interface Colors {
|
|
928
|
+
/**
|
|
929
|
+
* Whether this formatter set emits ANSI escape codes.
|
|
930
|
+
*/
|
|
931
|
+
isColorSupported: boolean;
|
|
932
|
+
/** Resets all ANSI styles. */
|
|
933
|
+
reset: ColorFormatter;
|
|
934
|
+
/** Applies bold text styling. */
|
|
935
|
+
bold: ColorFormatter;
|
|
936
|
+
/** Applies dim text styling. */
|
|
937
|
+
dim: ColorFormatter;
|
|
938
|
+
/** Applies italic text styling. */
|
|
939
|
+
italic: ColorFormatter;
|
|
940
|
+
/** Applies underline text styling. */
|
|
941
|
+
underline: ColorFormatter;
|
|
942
|
+
/** Applies inverse foreground/background styling. */
|
|
943
|
+
inverse: ColorFormatter;
|
|
944
|
+
/** Applies hidden text styling. */
|
|
945
|
+
hidden: ColorFormatter;
|
|
946
|
+
/** Applies strikethrough text styling. */
|
|
947
|
+
strikethrough: ColorFormatter;
|
|
948
|
+
/** Applies black foreground color. */
|
|
949
|
+
black: ColorFormatter;
|
|
950
|
+
/** Applies red foreground color. */
|
|
951
|
+
red: ColorFormatter;
|
|
952
|
+
/** Applies green foreground color. */
|
|
953
|
+
green: ColorFormatter;
|
|
954
|
+
/** Applies yellow foreground color. */
|
|
955
|
+
yellow: ColorFormatter;
|
|
956
|
+
/** Applies blue foreground color. */
|
|
957
|
+
blue: ColorFormatter;
|
|
958
|
+
/** Applies magenta foreground color. */
|
|
959
|
+
magenta: ColorFormatter;
|
|
960
|
+
/** Applies cyan foreground color. */
|
|
961
|
+
cyan: ColorFormatter;
|
|
962
|
+
/** Applies white foreground color. */
|
|
963
|
+
white: ColorFormatter;
|
|
964
|
+
/** Applies gray foreground color. */
|
|
965
|
+
gray: ColorFormatter;
|
|
966
|
+
/** Applies black background color. */
|
|
967
|
+
bgBlack: ColorFormatter;
|
|
968
|
+
/** Applies red background color. */
|
|
969
|
+
bgRed: ColorFormatter;
|
|
970
|
+
/** Applies green background color. */
|
|
971
|
+
bgGreen: ColorFormatter;
|
|
972
|
+
/** Applies yellow background color. */
|
|
973
|
+
bgYellow: ColorFormatter;
|
|
974
|
+
/** Applies blue background color. */
|
|
975
|
+
bgBlue: ColorFormatter;
|
|
976
|
+
/** Applies magenta background color. */
|
|
977
|
+
bgMagenta: ColorFormatter;
|
|
978
|
+
/** Applies cyan background color. */
|
|
979
|
+
bgCyan: ColorFormatter;
|
|
980
|
+
/** Applies white background color. */
|
|
981
|
+
bgWhite: ColorFormatter;
|
|
982
|
+
/** Applies bright black foreground color. */
|
|
983
|
+
blackBright: ColorFormatter;
|
|
984
|
+
/** Applies bright red foreground color. */
|
|
985
|
+
redBright: ColorFormatter;
|
|
986
|
+
/** Applies bright green foreground color. */
|
|
987
|
+
greenBright: ColorFormatter;
|
|
988
|
+
/** Applies bright yellow foreground color. */
|
|
989
|
+
yellowBright: ColorFormatter;
|
|
990
|
+
/** Applies bright blue foreground color. */
|
|
991
|
+
blueBright: ColorFormatter;
|
|
992
|
+
/** Applies bright magenta foreground color. */
|
|
993
|
+
magentaBright: ColorFormatter;
|
|
994
|
+
/** Applies bright cyan foreground color. */
|
|
995
|
+
cyanBright: ColorFormatter;
|
|
996
|
+
/** Applies bright white foreground color. */
|
|
997
|
+
whiteBright: ColorFormatter;
|
|
998
|
+
/** Applies bright black background color. */
|
|
999
|
+
bgBlackBright: ColorFormatter;
|
|
1000
|
+
/** Applies bright red background color. */
|
|
1001
|
+
bgRedBright: ColorFormatter;
|
|
1002
|
+
/** Applies bright green background color. */
|
|
1003
|
+
bgGreenBright: ColorFormatter;
|
|
1004
|
+
/** Applies bright yellow background color. */
|
|
1005
|
+
bgYellowBright: ColorFormatter;
|
|
1006
|
+
/** Applies bright blue background color. */
|
|
1007
|
+
bgBlueBright: ColorFormatter;
|
|
1008
|
+
/** Applies bright magenta background color. */
|
|
1009
|
+
bgMagentaBright: ColorFormatter;
|
|
1010
|
+
/** Applies bright cyan background color. */
|
|
1011
|
+
bgCyanBright: ColorFormatter;
|
|
1012
|
+
/** Applies bright white background color. */
|
|
1013
|
+
bgWhiteBright: ColorFormatter;
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Default color formatter object plus a factory for creating formatter sets
|
|
1017
|
+
* with explicit color support.
|
|
1018
|
+
*/
|
|
1019
|
+
type Color = Colors & {
|
|
1020
|
+
createColors: typeof createColors;
|
|
1021
|
+
};
|
|
1022
|
+
/**
|
|
1023
|
+
* Creates a complete set of color and style formatters.
|
|
1024
|
+
*
|
|
1025
|
+
* @param enabled - Whether returned formatters should emit ANSI escape codes.
|
|
1026
|
+
* @returns A `Colors` object with either active ANSI formatters or plain string
|
|
1027
|
+
* pass-through formatters.
|
|
1028
|
+
*/
|
|
1029
|
+
declare function createColors(enabled?: boolean): Colors;
|
|
1030
|
+
/**
|
|
1031
|
+
* Default color formatter set for the current process.
|
|
1032
|
+
*
|
|
1033
|
+
* @remarks
|
|
1034
|
+
* Use `color.createColors(false)` when tests need deterministic plain-text
|
|
1035
|
+
* output.
|
|
1036
|
+
*/
|
|
1037
|
+
declare const color: Color;
|
|
217
1038
|
//#endregion
|
|
218
1039
|
//#region src/logger.d.ts
|
|
1040
|
+
/**
|
|
1041
|
+
* Supported log levels in ascending verbosity.
|
|
1042
|
+
*/
|
|
219
1043
|
declare const LOG_LEVELS: LogLevel[];
|
|
1044
|
+
/**
|
|
1045
|
+
* Alias for `LOG_LEVELS` kept for callers that prefer validation-oriented
|
|
1046
|
+
* naming.
|
|
1047
|
+
*/
|
|
220
1048
|
declare const validLogLevels: LogLevel[];
|
|
221
|
-
|
|
222
|
-
|
|
1049
|
+
/**
|
|
1050
|
+
* Formats a log message with a level badge and optional structured arguments.
|
|
1051
|
+
*
|
|
1052
|
+
* @param logLevel - Log level or custom badge label.
|
|
1053
|
+
* @param message - Primary message to render.
|
|
1054
|
+
* @param args - Additional values rendered as indented JSON-like bullets.
|
|
1055
|
+
* @returns A formatted message string.
|
|
1056
|
+
*/
|
|
1057
|
+
declare function formatLogMessage(logLevel: LogLevel | "success" | "failed" | string, message: unknown, args?: unknown[]): string;
|
|
1058
|
+
/**
|
|
1059
|
+
* Emits a formatted message through the prompt logger.
|
|
1060
|
+
*
|
|
1061
|
+
* @param logLevel - Log level or custom badge label.
|
|
1062
|
+
* @param message - Primary message to render.
|
|
1063
|
+
* @param args - Additional values rendered below the message.
|
|
1064
|
+
*/
|
|
1065
|
+
declare function logMessage(logLevel: LogLevel | "success" | "failed" | string, message: unknown, ...args: unknown[]): void;
|
|
1066
|
+
/**
|
|
1067
|
+
* Formats a bounded progress step indicator.
|
|
1068
|
+
*
|
|
1069
|
+
* @remarks
|
|
1070
|
+
* `current` is clamped between `0` and `total`, and `total` is clamped to at
|
|
1071
|
+
* least `0` so malformed progress values still render predictably.
|
|
1072
|
+
*
|
|
1073
|
+
* @param current - Current step number.
|
|
1074
|
+
* @param total - Total number of steps.
|
|
1075
|
+
* @param label - Step label shown after the progress bar.
|
|
1076
|
+
* @returns A formatted progress row.
|
|
1077
|
+
*/
|
|
223
1078
|
declare function formatStep(current: number, total: number, label: string): string;
|
|
1079
|
+
/**
|
|
1080
|
+
* Creates a `CliLogger` backed by Clack prompt output.
|
|
1081
|
+
*
|
|
1082
|
+
* @remarks
|
|
1083
|
+
* Messages below the configured verbosity are ignored for `debug`, `info`,
|
|
1084
|
+
* `warn`, and `error`. Other output helpers such as `message`, `note`,
|
|
1085
|
+
* `success`, `failed`, and `outro` always render because they represent
|
|
1086
|
+
* explicit user interaction states rather than diagnostic verbosity.
|
|
1087
|
+
*
|
|
1088
|
+
* @param level - Minimum log level to emit.
|
|
1089
|
+
* @returns A logger suitable for `CliContext.logger`.
|
|
1090
|
+
*/
|
|
224
1091
|
declare function createCliLogger(level?: LogLevel): CliLogger;
|
|
225
1092
|
//#endregion
|
|
226
1093
|
//#region src/parser.d.ts
|
|
1094
|
+
/**
|
|
1095
|
+
* Built-in flags parsed for every Hexbus CLI invocation.
|
|
1096
|
+
*
|
|
1097
|
+
* @remarks
|
|
1098
|
+
* Primary flag names are derived from the first long flag in each entry. For
|
|
1099
|
+
* example, `--no-telemetry` is exposed as `parsedFlags['no-telemetry']`.
|
|
1100
|
+
*/
|
|
227
1101
|
declare const globalFlags: CliFlag[];
|
|
1102
|
+
/**
|
|
1103
|
+
* Parses raw command-line arguments into command name, command args, and
|
|
1104
|
+
* global flags.
|
|
1105
|
+
*
|
|
1106
|
+
* @remarks
|
|
1107
|
+
* Only flags declared in `globalFlags` are parsed. Unknown flags and
|
|
1108
|
+
* positional arguments are preserved as command arguments unless the first
|
|
1109
|
+
* positional argument matches a registered top-level command.
|
|
1110
|
+
*
|
|
1111
|
+
* @param rawArgs - Arguments after the executable and script path.
|
|
1112
|
+
* @param commands - Top-level commands used to identify the command name.
|
|
1113
|
+
* @returns Normalized parsed arguments for context creation or custom routing.
|
|
1114
|
+
*
|
|
1115
|
+
* @example
|
|
1116
|
+
* ```ts
|
|
1117
|
+
* const parsed = parseCliArgs(['init', '--logger', 'debug'], commands);
|
|
1118
|
+
* // parsed.commandName === 'init'
|
|
1119
|
+
* // parsed.parsedFlags.logger === 'debug'
|
|
1120
|
+
* ```
|
|
1121
|
+
*/
|
|
228
1122
|
declare function parseCliArgs(rawArgs: string[], commands: CliCommand[]): ParsedArgs;
|
|
1123
|
+
/**
|
|
1124
|
+
* Formats a single flag for display in help output.
|
|
1125
|
+
*
|
|
1126
|
+
* @param flag - Flag definition to render.
|
|
1127
|
+
* @returns A help row containing names, value hint, and description.
|
|
1128
|
+
*/
|
|
229
1129
|
declare function formatFlagHelp(flag: CliFlag): string;
|
|
1130
|
+
/**
|
|
1131
|
+
* Formats all built-in global flags for help output.
|
|
1132
|
+
*
|
|
1133
|
+
* @returns Newline-delimited help rows for `globalFlags`.
|
|
1134
|
+
*/
|
|
230
1135
|
declare function generateFlagsHelp(): string;
|
|
231
|
-
|
|
232
|
-
|
|
1136
|
+
/**
|
|
1137
|
+
* Checks whether a parsed boolean flag is enabled.
|
|
1138
|
+
*
|
|
1139
|
+
* @param flags - Parsed flag map from `parseCliArgs` or `CliContext`.
|
|
1140
|
+
* @param name - Primary flag name without leading dashes.
|
|
1141
|
+
* @returns `true` only when the flag value is exactly `true`.
|
|
1142
|
+
*
|
|
1143
|
+
* @example
|
|
1144
|
+
* ```ts
|
|
1145
|
+
* if (hasFlag(context.flags, 'force')) {
|
|
1146
|
+
* // overwrite existing files
|
|
1147
|
+
* }
|
|
1148
|
+
* ```
|
|
1149
|
+
*/
|
|
1150
|
+
declare function hasFlag(flags: ParsedArgs["parsedFlags"], name: string): boolean;
|
|
1151
|
+
/**
|
|
1152
|
+
* Reads a string-valued flag from a parsed flag map.
|
|
1153
|
+
*
|
|
1154
|
+
* @param flags - Parsed flag map from `parseCliArgs` or `CliContext`.
|
|
1155
|
+
* @param name - Primary flag name without leading dashes.
|
|
1156
|
+
* @returns The flag value when it is a string, otherwise `undefined`.
|
|
1157
|
+
*/
|
|
1158
|
+
declare function getFlagValue(flags: ParsedArgs["parsedFlags"], name: string): string | undefined;
|
|
1159
|
+
/**
|
|
1160
|
+
* Splits command arguments into an optional nested subcommand and remaining
|
|
1161
|
+
* args.
|
|
1162
|
+
*
|
|
1163
|
+
* @param args - Positional command arguments to inspect.
|
|
1164
|
+
* @param subcommands - Available subcommands for the current command.
|
|
1165
|
+
* @returns The matched subcommand, if any, plus arguments after the subcommand
|
|
1166
|
+
* name.
|
|
1167
|
+
*
|
|
1168
|
+
* @example
|
|
1169
|
+
* ```ts
|
|
1170
|
+
* const { subcommand, remainingArgs } = parseSubcommand(
|
|
1171
|
+
* context.commandArgs,
|
|
1172
|
+
* command.subcommands ?? []
|
|
1173
|
+
* );
|
|
1174
|
+
* ```
|
|
1175
|
+
*/
|
|
233
1176
|
declare function parseSubcommand(args: string[], subcommands: CliCommand[]): {
|
|
234
1177
|
subcommand: CliCommand | undefined;
|
|
235
1178
|
remainingArgs: string[];
|
|
236
1179
|
};
|
|
237
1180
|
//#endregion
|
|
238
1181
|
//#region src/spinner.d.ts
|
|
1182
|
+
/**
|
|
1183
|
+
* Minimal spinner controller used for long-running CLI tasks.
|
|
1184
|
+
*/
|
|
239
1185
|
interface Spinner {
|
|
1186
|
+
/**
|
|
1187
|
+
* Starts the spinner with an optional message override.
|
|
1188
|
+
*/
|
|
240
1189
|
start(message?: string): void;
|
|
1190
|
+
/**
|
|
1191
|
+
* Stops the spinner with an optional completion message.
|
|
1192
|
+
*/
|
|
241
1193
|
stop(message?: string): void;
|
|
1194
|
+
/**
|
|
1195
|
+
* Updates the spinner message while it is running.
|
|
1196
|
+
*/
|
|
242
1197
|
message(message: string): void;
|
|
243
1198
|
}
|
|
1199
|
+
/**
|
|
1200
|
+
* Creates a Clack-backed spinner.
|
|
1201
|
+
*
|
|
1202
|
+
* @param initialMessage - Message used when `start()` is called without an
|
|
1203
|
+
* explicit message.
|
|
1204
|
+
* @returns A spinner controller.
|
|
1205
|
+
*/
|
|
244
1206
|
declare function createSpinner(initialMessage?: string): Spinner;
|
|
1207
|
+
/**
|
|
1208
|
+
* Runs an async task while displaying a spinner.
|
|
1209
|
+
*
|
|
1210
|
+
* @typeParam T - Value returned by the task.
|
|
1211
|
+
* @param message - Message shown when the spinner starts.
|
|
1212
|
+
* @param task - Async work to run.
|
|
1213
|
+
* @param options - Optional success and error messages shown when the task
|
|
1214
|
+
* settles.
|
|
1215
|
+
* @returns The value returned by `task`.
|
|
1216
|
+
*
|
|
1217
|
+
* @throws Re-throws any error from `task` after stopping the spinner.
|
|
1218
|
+
*/
|
|
245
1219
|
declare function withSpinner<T>(message: string, task: () => Promise<T>, options?: {
|
|
246
1220
|
successMessage?: string;
|
|
247
1221
|
errorMessage?: string;
|
|
248
1222
|
}): Promise<T>;
|
|
249
1223
|
//#endregion
|
|
250
1224
|
//#region src/telemetry.d.ts
|
|
1225
|
+
/**
|
|
1226
|
+
* Options for the built-in in-memory telemetry client.
|
|
1227
|
+
*/
|
|
251
1228
|
interface TelemetryOptions {
|
|
1229
|
+
/**
|
|
1230
|
+
* Disables telemetry completely.
|
|
1231
|
+
*/
|
|
252
1232
|
disabled?: boolean;
|
|
1233
|
+
/**
|
|
1234
|
+
* Logs queued telemetry payloads through the optional debug logger.
|
|
1235
|
+
*/
|
|
253
1236
|
debug?: boolean;
|
|
1237
|
+
/**
|
|
1238
|
+
* HTTP endpoint that receives telemetry batches on flush.
|
|
1239
|
+
*/
|
|
254
1240
|
endpoint?: string;
|
|
1241
|
+
/**
|
|
1242
|
+
* Application name included in every telemetry event.
|
|
1243
|
+
*
|
|
1244
|
+
* @default "cli"
|
|
1245
|
+
*/
|
|
255
1246
|
appName?: string;
|
|
1247
|
+
/**
|
|
1248
|
+
* Environment variable prefix used for opt-out detection.
|
|
1249
|
+
*
|
|
1250
|
+
* @remarks
|
|
1251
|
+
* A prefix of `MY_CLI` reads `MY_CLI_TELEMETRY_DISABLED`.
|
|
1252
|
+
*
|
|
1253
|
+
* @default "APP"
|
|
1254
|
+
*/
|
|
256
1255
|
envVarPrefix?: string;
|
|
1256
|
+
/**
|
|
1257
|
+
* Properties merged into every telemetry event before event-specific
|
|
1258
|
+
* properties.
|
|
1259
|
+
*/
|
|
257
1260
|
defaultProperties?: Record<string, unknown>;
|
|
258
|
-
|
|
1261
|
+
/**
|
|
1262
|
+
* Logger used for debug payload output and flush warnings.
|
|
1263
|
+
*/
|
|
1264
|
+
logger?: Pick<CliLogger, "debug" | "warn">;
|
|
259
1265
|
}
|
|
1266
|
+
/**
|
|
1267
|
+
* Standard telemetry event names emitted by Hexbus runtime helpers.
|
|
1268
|
+
*/
|
|
260
1269
|
declare const TelemetryEventName: {
|
|
261
|
-
readonly CLI_INVOKED: "cli_invoked";
|
|
262
|
-
readonly CLI_ENVIRONMENT_DETECTED: "cli_environment_detected";
|
|
263
1270
|
readonly CLI_COMPLETED: "cli_completed";
|
|
1271
|
+
readonly CLI_ENVIRONMENT_DETECTED: "cli_environment_detected";
|
|
1272
|
+
readonly CLI_INVOKED: "cli_invoked";
|
|
1273
|
+
readonly COMMAND_FAILED: "command_failed";
|
|
264
1274
|
readonly COMMAND_INVOKED: "command_invoked";
|
|
265
1275
|
readonly COMMAND_SUCCEEDED: "command_succeeded";
|
|
266
|
-
readonly COMMAND_FAILED: "command_failed";
|
|
267
1276
|
readonly COMMAND_UNKNOWN: "command_unknown";
|
|
268
1277
|
readonly ERROR_OCCURRED: "error_occurred";
|
|
269
1278
|
readonly HELP_DISPLAYED: "help_displayed";
|
|
270
|
-
readonly VERSION_DISPLAYED: "version_displayed";
|
|
271
|
-
readonly INTERACTIVE_MENU_OPENED: "interactive_menu_opened";
|
|
272
1279
|
readonly INTERACTIVE_MENU_EXITED: "interactive_menu_exited";
|
|
1280
|
+
readonly INTERACTIVE_MENU_OPENED: "interactive_menu_opened";
|
|
1281
|
+
readonly VERSION_DISPLAYED: "version_displayed";
|
|
273
1282
|
};
|
|
1283
|
+
/**
|
|
1284
|
+
* Union of standard telemetry event name string values.
|
|
1285
|
+
*/
|
|
274
1286
|
type TelemetryEventNameType = (typeof TelemetryEventName)[keyof typeof TelemetryEventName];
|
|
1287
|
+
/**
|
|
1288
|
+
* Creates a no-op telemetry client.
|
|
1289
|
+
*
|
|
1290
|
+
* @returns A telemetry implementation whose methods do nothing and whose
|
|
1291
|
+
* `isDisabled()` method returns `true`.
|
|
1292
|
+
*/
|
|
275
1293
|
declare function createDisabledTelemetry(): Telemetry;
|
|
1294
|
+
/**
|
|
1295
|
+
* Creates the built-in telemetry client.
|
|
1296
|
+
*
|
|
1297
|
+
* @remarks
|
|
1298
|
+
* Events are queued in memory. `flush()` posts the queue to `endpoint` when one
|
|
1299
|
+
* is configured, then clears the queue. Failed flushes are reported through
|
|
1300
|
+
* the optional logger and do not throw, keeping telemetry best effort.
|
|
1301
|
+
*
|
|
1302
|
+
* @param options - Telemetry behavior and event defaults.
|
|
1303
|
+
* @returns An enabled or disabled telemetry client depending on options and
|
|
1304
|
+
* environment opt-out variables.
|
|
1305
|
+
*/
|
|
276
1306
|
declare function createTelemetry(options?: TelemetryOptions): Telemetry;
|
|
277
1307
|
//#endregion
|
|
278
|
-
//#region src/version-check.d.ts
|
|
279
|
-
|
|
1308
|
+
//#region src/version-check/types.d.ts
|
|
1309
|
+
/**
|
|
1310
|
+
* Installation source inferred from the running binary path and package manager
|
|
1311
|
+
* environment.
|
|
1312
|
+
*/
|
|
1313
|
+
type InstallSource = "npm-global" | "brew" | "npx" | "bunx" | "pnpm-dlx" | "yarn-dlx" | "local" | "unknown";
|
|
1314
|
+
/**
|
|
1315
|
+
* Result returned by an update check.
|
|
1316
|
+
*/
|
|
280
1317
|
interface UpdateCheckResult {
|
|
1318
|
+
/**
|
|
1319
|
+
* Version currently running.
|
|
1320
|
+
*/
|
|
281
1321
|
currentVersion: string;
|
|
1322
|
+
/**
|
|
1323
|
+
* Latest version fetched from the registry or cache, or `null` when lookup
|
|
1324
|
+
* failed.
|
|
1325
|
+
*/
|
|
282
1326
|
latestVersion: string | null;
|
|
1327
|
+
/**
|
|
1328
|
+
* Whether `latestVersion` is newer than `currentVersion`.
|
|
1329
|
+
*
|
|
1330
|
+
* @remarks
|
|
1331
|
+
* This is `false` when `latestVersion` is `null` due to lookup failure.
|
|
1332
|
+
* Callers can check `latestVersion === null` to distinguish lookup failure
|
|
1333
|
+
* from an up-to-date package.
|
|
1334
|
+
*/
|
|
283
1335
|
isOutdated: boolean;
|
|
1336
|
+
/**
|
|
1337
|
+
* Detected installation source for the current binary.
|
|
1338
|
+
*/
|
|
284
1339
|
source: InstallSource;
|
|
1340
|
+
/**
|
|
1341
|
+
* Update command appropriate for the detected source, when Hexbus can infer
|
|
1342
|
+
* one.
|
|
1343
|
+
*/
|
|
285
1344
|
updateCommand: string | null;
|
|
1345
|
+
/**
|
|
1346
|
+
* User-facing update hint, or `null` when no actionable update is available.
|
|
1347
|
+
*/
|
|
286
1348
|
hint: string | null;
|
|
287
1349
|
}
|
|
1350
|
+
/**
|
|
1351
|
+
* Options for checking package registry state and update hints.
|
|
1352
|
+
*/
|
|
288
1353
|
interface UpdateCheckOptions {
|
|
1354
|
+
/**
|
|
1355
|
+
* Published package name to query.
|
|
1356
|
+
*/
|
|
289
1357
|
packageName: string;
|
|
1358
|
+
/**
|
|
1359
|
+
* Version currently running.
|
|
1360
|
+
*/
|
|
290
1361
|
currentVersion: string;
|
|
1362
|
+
/**
|
|
1363
|
+
* Homebrew formula name used for Homebrew update hints.
|
|
1364
|
+
*
|
|
1365
|
+
* @default packageName
|
|
1366
|
+
*/
|
|
291
1367
|
brewFormula?: string;
|
|
1368
|
+
/**
|
|
1369
|
+
* Registry base URL used to fetch latest package metadata.
|
|
1370
|
+
*
|
|
1371
|
+
* @default "https://registry.npmjs.org"
|
|
1372
|
+
*/
|
|
292
1373
|
registryUrl?: string;
|
|
1374
|
+
/**
|
|
1375
|
+
* Maximum registry request duration in milliseconds.
|
|
1376
|
+
*
|
|
1377
|
+
* @default 1500
|
|
1378
|
+
*/
|
|
293
1379
|
timeoutMs?: number;
|
|
1380
|
+
/**
|
|
1381
|
+
* Directory where latest-version cache files are stored.
|
|
1382
|
+
*
|
|
1383
|
+
* @default path.join(os.tmpdir(), "hexbus-version-cache")
|
|
1384
|
+
*/
|
|
294
1385
|
cacheDir?: string;
|
|
1386
|
+
/**
|
|
1387
|
+
* How long cached latest-version data stays fresh.
|
|
1388
|
+
*
|
|
1389
|
+
* @default 86400000
|
|
1390
|
+
*/
|
|
295
1391
|
cacheTtlMs?: number;
|
|
1392
|
+
/**
|
|
1393
|
+
* Binary path used for installation-source detection.
|
|
1394
|
+
*
|
|
1395
|
+
* @default process.argv[1]
|
|
1396
|
+
*/
|
|
296
1397
|
binPath?: string;
|
|
1398
|
+
/**
|
|
1399
|
+
* Optional logger used for debug output when update checks fail.
|
|
1400
|
+
*/
|
|
1401
|
+
logger?: VersionInfoLogger;
|
|
1402
|
+
/**
|
|
1403
|
+
* Clock override used by tests and deterministic callers.
|
|
1404
|
+
*
|
|
1405
|
+
* @default Date.now
|
|
1406
|
+
*/
|
|
297
1407
|
now?: () => number;
|
|
298
1408
|
}
|
|
299
|
-
type VersionInfoLogger = Pick<CliLogger,
|
|
1409
|
+
type VersionInfoLogger = Pick<CliLogger, "message" | "note"> & Partial<Pick<CliLogger, "debug">>;
|
|
1410
|
+
/**
|
|
1411
|
+
* Options for printing or background-checking CLI version information.
|
|
1412
|
+
*/
|
|
300
1413
|
interface VersionInfoOptions extends UpdateCheckOptions {
|
|
1414
|
+
/**
|
|
1415
|
+
* Application name shown in version output.
|
|
1416
|
+
*/
|
|
301
1417
|
appName: string;
|
|
302
|
-
logger?: VersionInfoLogger;
|
|
303
1418
|
}
|
|
1419
|
+
//#endregion
|
|
1420
|
+
//#region src/version-check/check.d.ts
|
|
1421
|
+
/**
|
|
1422
|
+
* Checks whether raw arguments request version output.
|
|
1423
|
+
*
|
|
1424
|
+
* @param rawArgs - Arguments after executable and script path.
|
|
1425
|
+
* @returns `true` when `-v` or `--version` is present.
|
|
1426
|
+
*/
|
|
304
1427
|
declare function isVersionRequest(rawArgs: string[]): boolean;
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
1428
|
+
/**
|
|
1429
|
+
* Formats a user-facing update hint from an update-check result.
|
|
1430
|
+
*
|
|
1431
|
+
* @param result - Update-check result to render.
|
|
1432
|
+
* @returns A formatted hint when the result is outdated and has an update
|
|
1433
|
+
* command, otherwise `null`.
|
|
1434
|
+
*/
|
|
308
1435
|
declare function formatUpdateHint(result: UpdateCheckResult): string | null;
|
|
1436
|
+
/**
|
|
1437
|
+
* Checks whether a newer package version is available.
|
|
1438
|
+
*
|
|
1439
|
+
* @remarks
|
|
1440
|
+
* The function first reads the local cache. On a cache miss it refreshes the
|
|
1441
|
+
* cache from the configured registry. Refresh failures produce a result with
|
|
1442
|
+
* `latestVersion: null` rather than throwing.
|
|
1443
|
+
*
|
|
1444
|
+
* @param options - Update-check configuration.
|
|
1445
|
+
* @returns Update metadata and a formatted hint when an update is available.
|
|
1446
|
+
*/
|
|
1447
|
+
declare function checkForUpdate(options: UpdateCheckOptions): Promise<UpdateCheckResult>;
|
|
1448
|
+
//#endregion
|
|
1449
|
+
//#region src/version-check/display.d.ts
|
|
1450
|
+
/**
|
|
1451
|
+
* Prints CLI version information and any available update hint.
|
|
1452
|
+
*
|
|
1453
|
+
* @param options - Version display and update-check options.
|
|
1454
|
+
*/
|
|
309
1455
|
declare function printVersionInfo(options: VersionInfoOptions): Promise<void>;
|
|
1456
|
+
/**
|
|
1457
|
+
* Starts a non-blocking update check.
|
|
1458
|
+
*
|
|
1459
|
+
* @remarks
|
|
1460
|
+
* Cached hints are displayed synchronously when available. If the cache is
|
|
1461
|
+
* stale or missing, a refresh is started in the background and failures are
|
|
1462
|
+
* only logged at debug level.
|
|
1463
|
+
*
|
|
1464
|
+
* @param options - Version display and update-check options.
|
|
1465
|
+
*/
|
|
310
1466
|
declare function startBackgroundUpdateCheck(options: VersionInfoOptions): void;
|
|
311
1467
|
//#endregion
|
|
1468
|
+
//#region src/version-check/install-source.d.ts
|
|
1469
|
+
/**
|
|
1470
|
+
* Infers how the current CLI binary was installed.
|
|
1471
|
+
*
|
|
1472
|
+
* @remarks
|
|
1473
|
+
* Detection is heuristic and based on binary path, realpath, and package
|
|
1474
|
+
* manager environment variables. Unknown or transient install modes return
|
|
1475
|
+
* `unknown` instead of throwing.
|
|
1476
|
+
*
|
|
1477
|
+
* @param binPath - Binary path to inspect.
|
|
1478
|
+
* @returns The inferred installation source.
|
|
1479
|
+
*/
|
|
1480
|
+
declare function detectInstallSource(binPath?: string): InstallSource;
|
|
1481
|
+
/**
|
|
1482
|
+
* Builds an update command for an installation source.
|
|
1483
|
+
*
|
|
1484
|
+
* @param source - Installation source returned by `detectInstallSource`.
|
|
1485
|
+
* @param packageName - Package name to update.
|
|
1486
|
+
* @param brewFormula - Homebrew formula name when `source` is `brew`.
|
|
1487
|
+
* @returns A command string when the source has an actionable update path,
|
|
1488
|
+
* otherwise `null`.
|
|
1489
|
+
*/
|
|
1490
|
+
declare function getUpdateCommand(source: InstallSource, packageName: string, brewFormula?: string): string | null;
|
|
1491
|
+
//#endregion
|
|
312
1492
|
export { type CliCommand, type CliContext, CliError, type CliFlag, type CliLogger, type ConfigManagement, type CreateContextOptions, DEFAULT_ERROR_CATALOG, type DisplayIntroOptions, type ErrorCatalog, type ErrorCatalogEntry, type ErrorCode, type ErrorHandlers, type FileSystemUtils, type FlagType, type FrameworkDetectionResult, type FrameworkPackageMap, type InstallSource, LOG_LEVELS, type LogLevel, type PackageInfo, type PackageManager, type PackageManagerResult, type ParsedArgs, type ShowHelpMenuOptions, type Spinner, type Telemetry, TelemetryEventName, type TelemetryEventNameType, type TelemetryOptions, type UpdateCheckOptions, type UpdateCheckResult, type VersionInfoOptions, checkForUpdate, color, createCliContext, createCliLogger, createDisabledTelemetry, createErrorHandlers, createSpinner, createTelemetry, createTestContext, detectFramework, detectInstallSource, detectPackageManager, detectProjectRoot, displayIntro, extendErrorCatalog, formatFlagHelp, formatLogMessage, formatStep, formatUpdateHint, generateFlagsHelp, getExecCommand, getFlagValue, getInstallCommand, getRunCommand, getUpdateCommand, globalFlags, hasFlag, isCliError, isVersionRequest, logMessage, parseCliArgs, parseSubcommand, printVersionInfo, showHelpMenu, startBackgroundUpdateCheck, validLogLevels, withErrorHandling, withSpinner };
|