@stacksjs/cli 0.70.258 → 0.70.260

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 (2) hide show
  1. package/dist/index.js +7 -1065
  2. package/package.json +19 -12
package/dist/index.js CHANGED
@@ -1,1066 +1,8 @@
1
1
  // @bun
2
- // src/actions/install.ts
3
- import process2 from "process";
4
- async function runInstall(name, options = { silent: true }) {
5
- const pm = options.packageManager ?? "bun";
6
- const args = [pm === "npm" ? "install" : "add"];
7
- if (options.dev)
8
- args.push("-D");
9
- if (options.preferOffline && pm !== "bun")
10
- args.push("--prefer-offline");
11
- if (options.additionalArgs)
12
- args.push(...options.additionalArgs);
13
- args.push(name);
14
- const proc = Bun.spawn([pm, ...args], {
15
- cwd: options.cwd ?? process2.cwd(),
16
- stdout: options.silent ? "ignore" : "inherit",
17
- stderr: options.silent ? "ignore" : "inherit",
18
- stdin: "ignore",
19
- env: process2.env
20
- });
21
- const exitCode = await proc.exited;
22
- if (exitCode !== 0)
23
- throw new Error(`Failed to install ${name} (exit code ${exitCode})`);
24
- }
25
- async function installPackage(name, options) {
26
- return runInstall(name, options ?? { silent: true });
27
- }
28
- async function installStack(name, options) {
29
- return runInstall(`@stacksjs/${name}`, options ?? { silent: true });
30
- }
31
- // src/cli.ts
32
- import { CLI, cli as createCli, onUnknownSubcommand } from "@stacksjs/clapp";
33
- function cli(name, options) {
34
- if (typeof name === "object") {
35
- options = name;
36
- name = options.name;
37
- }
38
- return createCli(name || "buddy");
39
- }
40
- // src/exec.ts
41
- import process3 from "process";
42
- import { err, handleError, ok } from "@stacksjs/error-handling";
43
- import { ExitCode } from "@stacksjs/types";
44
- async function exec(command, options) {
45
- const cmd = Array.isArray(command) ? command : command.match(/(?:[^\s"]|"[^"]*")+/g);
46
- if (!cmd)
47
- return err(handleError(`Failed to parse command: ${cmd}`, options));
48
- const cwd = options?.cwd ?? process3.cwd();
49
- const timeoutMs = options?.timeoutMs;
50
- const proc = Bun.spawn(cmd, {
51
- stdin: options?.stdin ?? "inherit",
52
- stdout: options?.silent || options?.quiet ? "ignore" : options?.stdin ? options.stdin : options?.stdout || "inherit",
53
- stderr: options?.silent || options?.quiet ? "ignore" : options?.stderr || "inherit",
54
- cwd,
55
- env: { ...process3.env, ...options?.env },
56
- onExit(subprocess, exitCode, signalCode, error) {
57
- exitHandler("spawn", subprocess, exitCode, signalCode, error);
58
- }
59
- });
60
- if (options?.stdin === "pipe" && options.input) {
61
- if (proc.stdin) {
62
- proc.stdin.write(options.input);
63
- proc.stdin.end();
64
- }
65
- }
66
- let timeoutId;
67
- const exited = await Promise.race([
68
- proc.exited,
69
- new Promise((resolve) => {
70
- if (!timeoutMs)
71
- return;
72
- timeoutId = setTimeout(() => {
73
- try {
74
- proc.kill();
75
- } catch {}
76
- resolve(ExitCode.FatalError);
77
- }, timeoutMs);
78
- })
79
- ]);
80
- if (timeoutId)
81
- clearTimeout(timeoutId);
82
- if (timeoutMs && exited === ExitCode.FatalError && proc.exitCode === null)
83
- return err(handleError(`Command timed out after ${timeoutMs}ms: ${italic(cmd.join(" "))} in ${italic(cwd)}`, options));
84
- if (exited === ExitCode.Success)
85
- return ok(proc);
86
- const sig = proc.signalCode;
87
- if (sig === "SIGTERM" || sig === "SIGINT" || sig === "SIGKILL" || proc.exitCode === null && exited !== ExitCode.Success) {
88
- return err(new Error(`Command terminated by ${sig ?? "signal"}: ${cmd.join(" ")}`));
89
- }
90
- return err(handleError(`Failed to execute command: ${italic(cmd.join(" "))} in ${italic(cwd)}`, options));
91
- }
92
- async function execSync(command, options) {
93
- const cmd = Array.isArray(command) ? command : command.match(/(?:[^\s"]|"[^"]*")+/g);
94
- if (!cmd) {
95
- log.error(`Failed to parse command: ${cmd}`, options);
96
- throw new Error(`Failed to parse command: ${cmd}`);
97
- }
98
- const proc = Bun.spawnSync(cmd, {
99
- ...options,
100
- stdin: options?.stdin ?? "inherit",
101
- stdout: options?.stdout ?? "pipe",
102
- stderr: options?.stderr ?? "inherit",
103
- cwd: options?.cwd ?? process3.cwd(),
104
- env: { ...process3.env, ...options?.env },
105
- onExit(subprocess, exitCode, signalCode, error) {
106
- exitHandler("spawnSync", subprocess, exitCode, signalCode, error);
107
- }
108
- });
109
- const stdout = proc.stdout?.toString() ?? "";
110
- if (options?.throwOnError && proc.exitCode !== 0) {
111
- const stderr = proc.stderr?.toString() ?? "";
112
- const detail = (stderr.trim() || stdout.trim() || "(no output)").split(`
113
- `).slice(0, 5).join(`
114
- `);
115
- throw new Error(`Command failed with exit code ${proc.exitCode}: ${cmd.join(" ")}
116
- ${detail}`);
117
- }
118
- return stdout;
119
- }
120
- function exitHandler(type, _subprocess, exitCode, signalCode, error) {
121
- log.debug(`exitHandler: ${type}, exitCode: ${exitCode}, signalCode: ${signalCode}`);
122
- if (error) {
123
- log.debug("Process error:", error.message);
124
- }
125
- }
126
- // src/helpers.ts
127
- import { handleError as handleError2 } from "@stacksjs/error-handling";
128
- import { log } from "@stacksjs/logging";
129
- import { ExitCode as ExitCode2 } from "@stacksjs/types";
130
-
131
- // src/utils.ts
132
- import { collect } from "@stacksjs/collections";
133
- var ansiSupport = !process.env.NO_COLOR && (process.env.FORCE_COLOR ? process.env.FORCE_COLOR !== "0" : !!process.stdout?.isTTY);
134
- var ansi = {
135
- reset: ansiSupport ? "\x1B[0m" : "",
136
- black: ansiSupport ? "\x1B[30m" : "",
137
- red: ansiSupport ? "\x1B[31m" : "",
138
- green: ansiSupport ? "\x1B[32m" : "",
139
- yellow: ansiSupport ? "\x1B[33m" : "",
140
- blue: ansiSupport ? "\x1B[34m" : "",
141
- magenta: ansiSupport ? "\x1B[35m" : "",
142
- cyan: ansiSupport ? "\x1B[36m" : "",
143
- white: ansiSupport ? "\x1B[37m" : "",
144
- gray: ansiSupport ? "\x1B[90m" : "",
145
- lightRed: ansiSupport ? "\x1B[91m" : "",
146
- lightGreen: ansiSupport ? "\x1B[92m" : "",
147
- lightYellow: ansiSupport ? "\x1B[93m" : "",
148
- lightBlue: ansiSupport ? "\x1B[94m" : "",
149
- lightMagenta: ansiSupport ? "\x1B[95m" : "",
150
- lightCyan: ansiSupport ? "\x1B[96m" : "",
151
- lightGray: ansiSupport ? "\x1B[37m" : "",
152
- bgBlack: ansiSupport ? "\x1B[40m" : "",
153
- bgRed: ansiSupport ? "\x1B[41m" : "",
154
- bgGreen: ansiSupport ? "\x1B[42m" : "",
155
- bgYellow: ansiSupport ? "\x1B[43m" : "",
156
- bgBlue: ansiSupport ? "\x1B[44m" : "",
157
- bgMagenta: ansiSupport ? "\x1B[45m" : "",
158
- bgCyan: ansiSupport ? "\x1B[46m" : "",
159
- bgWhite: ansiSupport ? "\x1B[47m" : "",
160
- bgGray: ansiSupport ? "\x1B[100m" : "",
161
- bgLightRed: ansiSupport ? "\x1B[101m" : "",
162
- bgLightGreen: ansiSupport ? "\x1B[102m" : "",
163
- bgLightYellow: ansiSupport ? "\x1B[103m" : "",
164
- bgLightBlue: ansiSupport ? "\x1B[104m" : "",
165
- bgLightMagenta: ansiSupport ? "\x1B[105m" : "",
166
- bgLightCyan: ansiSupport ? "\x1B[106m" : "",
167
- bgLightGray: ansiSupport ? "\x1B[47m" : "",
168
- bold: ansiSupport ? "\x1B[1m" : "",
169
- dim: ansiSupport ? "\x1B[2m" : "",
170
- italic: ansiSupport ? "\x1B[3m" : "",
171
- underline: ansiSupport ? "\x1B[4m" : "",
172
- inverse: ansiSupport ? "\x1B[7m" : "",
173
- hidden: ansiSupport ? "\x1B[8m" : "",
174
- strikethrough: ansiSupport ? "\x1B[9m" : ""
175
- };
176
- var ansiCsi = "\x1B[";
177
- var hyperlinkOpen = "\x1B]8;;";
178
- var hyperlinkClose = "\x1B]8;;\x07";
179
- var passthrough = (text) => String(text);
180
- function clamp(value, min, max) {
181
- return Math.min(Math.max(Math.floor(value), min), max);
182
- }
183
- function color(openCode, closeCode = ansi.reset) {
184
- return (text) => {
185
- if (!ansiSupport)
186
- return String(text);
187
- return `${openCode}${String(text)}${closeCode}`;
188
- };
189
- }
190
- function stripHyperlinks(text) {
191
- return text.replace(/\x1B\]8;;[^\x07]*(?:\x07|\x1B\\)/g, "").replace(/\x1B\]8;;(?:\x07|\x1B\\)/g, "");
192
- }
193
- function stripAnsi(text) {
194
- return stripHyperlinks(text).replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, "");
195
- }
196
- var stripColors = stripAnsi;
197
- function visibleWidth(text) {
198
- return Array.from(stripAnsi(text)).length;
199
- }
200
- var black = color(ansi.black);
201
- var red = color(ansi.red);
202
- var green = color(ansi.green);
203
- var yellow = color(ansi.yellow);
204
- var blue = color(ansi.blue);
205
- var magenta = color(ansi.magenta);
206
- var cyan = color(ansi.cyan);
207
- var white = color(ansi.white);
208
- var gray = color(ansi.gray);
209
- var lightRed = color(ansi.lightRed);
210
- var lightGreen = color(ansi.lightGreen);
211
- var lightYellow = color(ansi.lightYellow);
212
- var lightBlue = color(ansi.lightBlue);
213
- var lightMagenta = color(ansi.lightMagenta);
214
- var lightCyan = color(ansi.lightCyan);
215
- var lightGray = color(ansi.lightGray);
216
- var bgBlack = color(ansi.bgBlack);
217
- var bgRed = color(ansi.bgRed);
218
- var bgGreen = color(ansi.bgGreen);
219
- var bgYellow = color(ansi.bgYellow);
220
- var bgBlue = color(ansi.bgBlue);
221
- var bgMagenta = color(ansi.bgMagenta);
222
- var bgCyan = color(ansi.bgCyan);
223
- var bgWhite = color(ansi.bgWhite);
224
- var bgGray = color(ansi.bgGray);
225
- var bgLightRed = color(ansi.bgLightRed);
226
- var bgLightGreen = color(ansi.bgLightGreen);
227
- var bgLightYellow = color(ansi.bgLightYellow);
228
- var bgLightBlue = color(ansi.bgLightBlue);
229
- var bgLightMagenta = color(ansi.bgLightMagenta);
230
- var bgLightCyan = color(ansi.bgLightCyan);
231
- var bgLightGray = color(ansi.bgLightGray);
232
- var bold = color(ansi.bold);
233
- var dim = color(ansi.dim);
234
- var italic = color(ansi.italic);
235
- var underline = color(ansi.underline);
236
- var inverse = color(ansi.inverse);
237
- var hidden = color(ansi.hidden);
238
- var strikethrough = color(ansi.strikethrough);
239
- var reset = color(ansi.reset, "");
240
- function ansi256(code) {
241
- return color(`${ansiCsi}38;5;${clamp(code, 0, 255)}m`);
242
- }
243
- function ansi256Bg(code) {
244
- return color(`${ansiCsi}48;5;${clamp(code, 0, 255)}m`);
245
- }
246
- function trueColor(r, g, b) {
247
- return color(`${ansiCsi}38;2;${clamp(r, 0, 255)};${clamp(g, 0, 255)};${clamp(b, 0, 255)}m`);
248
- }
249
- function trueColorBg(r, g, b) {
250
- return color(`${ansiCsi}48;2;${clamp(r, 0, 255)};${clamp(g, 0, 255)};${clamp(b, 0, 255)}m`);
251
- }
252
- function link(textOrUrl, maybeUrl) {
253
- const createLink = (text, url2) => {
254
- const value = String(text);
255
- if (!ansiSupport)
256
- return value;
257
- return `${hyperlinkOpen}${url2}\x07${value}${hyperlinkClose}`;
258
- };
259
- if (typeof maybeUrl === "string")
260
- return createLink(textOrUrl, maybeUrl);
261
- const url = String(textOrUrl);
262
- return (text) => createLink(text, url);
263
- }
264
- var namedColors = {
265
- black,
266
- red,
267
- green,
268
- yellow,
269
- blue,
270
- magenta,
271
- cyan,
272
- white,
273
- gray,
274
- lightRed,
275
- lightGreen,
276
- lightYellow,
277
- lightBlue,
278
- lightMagenta,
279
- lightCyan,
280
- lightGray,
281
- bgBlack,
282
- bgRed,
283
- bgGreen,
284
- bgYellow,
285
- bgBlue,
286
- bgMagenta,
287
- bgCyan,
288
- bgWhite,
289
- bgGray,
290
- bgLightRed,
291
- bgLightGreen,
292
- bgLightYellow,
293
- bgLightBlue,
294
- bgLightMagenta,
295
- bgLightCyan,
296
- bgLightGray,
297
- bold,
298
- dim,
299
- italic,
300
- underline,
301
- inverse,
302
- hidden,
303
- strikethrough,
304
- reset
305
- };
306
- function getColor(colorName) {
307
- return namedColors[colorName] ?? passthrough;
308
- }
309
- function colorize(text, colorOrFn) {
310
- if (typeof colorOrFn === "function")
311
- return colorOrFn(text);
312
- return getColor(colorOrFn)(text);
313
- }
314
- function supportsColor() {
315
- return ansiSupport;
316
- }
317
- var colors = {
318
- black,
319
- red,
320
- green,
321
- yellow,
322
- blue,
323
- magenta,
324
- cyan,
325
- white,
326
- gray,
327
- lightRed,
328
- lightGreen,
329
- lightYellow,
330
- lightBlue,
331
- lightMagenta,
332
- lightCyan,
333
- lightGray,
334
- bgBlack,
335
- bgRed,
336
- bgGreen,
337
- bgYellow,
338
- bgBlue,
339
- bgMagenta,
340
- bgCyan,
341
- bgWhite,
342
- bgGray,
343
- bgLightRed,
344
- bgLightGreen,
345
- bgLightYellow,
346
- bgLightBlue,
347
- bgLightMagenta,
348
- bgLightCyan,
349
- bgLightGray,
350
- bold,
351
- dim,
352
- italic,
353
- underline,
354
- inverse,
355
- hidden,
356
- strikethrough,
357
- reset,
358
- ansi256,
359
- ansi256Bg,
360
- trueColor,
361
- trueColorBg,
362
- link,
363
- stripColors
364
- };
365
- var kolorist = {
366
- black,
367
- red,
368
- green,
369
- yellow,
370
- blue,
371
- magenta,
372
- cyan,
373
- white,
374
- gray,
375
- lightRed,
376
- lightGreen,
377
- lightYellow,
378
- lightBlue,
379
- lightMagenta,
380
- lightCyan,
381
- lightGray,
382
- bgBlack,
383
- bgRed,
384
- bgGreen,
385
- bgYellow,
386
- bgBlue,
387
- bgMagenta,
388
- bgCyan,
389
- bgWhite,
390
- bgGray,
391
- bgLightRed,
392
- bgLightGreen,
393
- bgLightYellow,
394
- bgLightBlue,
395
- bgLightMagenta,
396
- bgLightCyan,
397
- bgLightGray,
398
- bold,
399
- dim,
400
- italic,
401
- underline,
402
- inverse,
403
- hidden,
404
- strikethrough,
405
- reset,
406
- ansi256,
407
- ansi256Bg,
408
- trueColor,
409
- trueColorBg,
410
- link,
411
- stripColors,
412
- grey: gray,
413
- lightGrey: lightGray,
414
- bgLightGrey: bgLightGray,
415
- supportsColor
416
- };
417
- function padLine(text, width, alignMode, padChar) {
418
- const printableWidth = visibleWidth(text);
419
- if (printableWidth >= width)
420
- return text;
421
- const char = padChar[0] || " ";
422
- const diff = width - printableWidth;
423
- if (alignMode === "right")
424
- return `${char.repeat(diff)}${text}`;
425
- if (alignMode === "center") {
426
- const left = Math.floor(diff / 2);
427
- const right = diff - left;
428
- return `${char.repeat(left)}${text}${char.repeat(right)}`;
429
- }
430
- return `${text}${char.repeat(diff)}`;
431
- }
432
- function normalizedWidth(lines) {
433
- return Math.max(0, ...lines.map(visibleWidth));
434
- }
435
- function align(text, widthOrOptions, alignMode = "left") {
436
- const lines = String(text).split(/\r?\n/);
437
- const options = typeof widthOrOptions === "object" ? widthOrOptions : undefined;
438
- const width = typeof widthOrOptions === "number" ? widthOrOptions : options?.width ?? normalizedWidth(lines);
439
- const alignment = options?.align ?? alignMode;
440
- const padChar = options?.padChar ?? " ";
441
- return lines.map((line) => padLine(line, Math.max(0, width), alignment, padChar)).join(`
442
- `);
443
- }
444
- function leftAlign(text, width) {
445
- return align(text, width, "left");
446
- }
447
- function rightAlign(text, width) {
448
- const lines = String(text).split(/\r?\n/);
449
- return align(text, width ?? process.stdout?.columns ?? normalizedWidth(lines), "right");
450
- }
451
- function centerAlign(text, width) {
452
- const lines = String(text).split(/\r?\n/);
453
- return align(text, width ?? process.stdout?.columns ?? normalizedWidth(lines), "center");
454
- }
455
- var boxStyles = {
456
- single: { topLeft: "\u250C", topRight: "\u2510", bottomLeft: "\u2514", bottomRight: "\u2518", horizontal: "\u2500", vertical: "\u2502" },
457
- double: { topLeft: "\u2554", topRight: "\u2557", bottomLeft: "\u255A", bottomRight: "\u255D", horizontal: "\u2550", vertical: "\u2551" },
458
- round: { topLeft: "\u256D", topRight: "\u256E", bottomLeft: "\u2570", bottomRight: "\u256F", horizontal: "\u2500", vertical: "\u2502" }
459
- };
460
- function box(text, options = {}) {
461
- const lines = String(text).split(/\r?\n/);
462
- const style = boxStyles[options.borderStyle ?? "single"];
463
- const padding = Math.max(0, options.padding ?? 1);
464
- const margin = Math.max(0, options.margin ?? 0);
465
- const contentAlign = options.align ?? "left";
466
- const contentWidth = normalizedWidth(lines);
467
- const innerWidth = contentWidth + padding * 2;
468
- const borderColor = typeof options.borderColor === "function" ? options.borderColor : options.borderColor ? getColor(options.borderColor) : passthrough;
469
- const buildTopBorder = () => {
470
- if (!options.title)
471
- return `${style.topLeft}${style.horizontal.repeat(innerWidth)}${style.topRight}`;
472
- const rawTitle = ` ${stripAnsi(String(options.title))} `;
473
- const title = rawTitle.slice(0, innerWidth);
474
- const remainder = style.horizontal.repeat(Math.max(0, innerWidth - title.length));
475
- return `${style.topLeft}${title}${remainder}${style.topRight}`;
476
- };
477
- const top = borderColor(buildTopBorder());
478
- const bottom = borderColor(`${style.bottomLeft}${style.horizontal.repeat(innerWidth)}${style.bottomRight}`);
479
- const body = lines.map((line) => {
480
- const aligned = align(line, { align: contentAlign, width: contentWidth });
481
- const middle = `${" ".repeat(padding)}${aligned}${" ".repeat(padding)}`;
482
- return `${borderColor(style.vertical)}${middle}${borderColor(style.vertical)}`;
483
- });
484
- const indent = " ".repeat(margin);
485
- return [top, ...body, bottom].map((line) => `${indent}${line}`).join(`
486
- `);
487
- }
488
- var quotes = collect([
489
- "The best way to get started is to quit talking and begin doing.",
490
- "The pessimist sees difficulty in every opportunity. The optimist sees opportunity in every difficulty.",
491
- "Don\u2019t let yesterday take up too much of today.",
492
- "You learn more from failure than from success. Don\u2019t let it stop you. Failure builds character.",
493
- "It\u2019s not whether you get knocked down, it\u2019s whether you get up.",
494
- "If you are working on something that you really care about, you don\u2019t have to be pushed. The vision pulls you.",
495
- "People who are crazy enough to think they can change the world, are the ones who do.",
496
- "Failure will never overtake me if my determination to succeed is strong enough.",
497
- "Entrepreneurs are great at dealing with uncertainty and also very good at minimizing risk. That\u2019s the classic entrepreneur.",
498
- "We may encounter many defeats but we must not be defeated.",
499
- "Knowing is not enough; we must apply. Wishing is not enough; we must do.",
500
- "Imagine your life is perfect in every respect; what would it look like?",
501
- "We generate fears while we sit. We overcome them by action.",
502
- "Whether you think you can or think you can\u2019t, you\u2019re right.",
503
- "Security is mostly a superstition. Life is either a daring adventure or nothing."
504
- ]);
505
- // package.json
506
- var version = "0.70.258";
507
- // src/helpers.ts
508
- async function intro(command, options) {
509
- return new Promise((resolve) => {
510
- if (options?.quiet === false) {
511
- console.log();
512
- console.log(cyan(bold("Stacks CLI")) + dim(` v${version}`));
513
- console.log();
514
- }
515
- log.info(`Running ${bgCyan(italic(bold(` ${command} `)))}`);
516
- if (options?.showPerformance === false || options?.quiet)
517
- return resolve(0);
518
- return resolve(performance.now());
519
- });
520
- }
521
- function outro(text, options, error) {
522
- const opts = {
523
- type: "success",
524
- useSeconds: true,
525
- ...options
526
- };
527
- opts.message = options?.message || text;
528
- return new Promise((resolve) => {
529
- if (error) {
530
- handleError2(error);
531
- return resolve(ExitCode2.FatalError);
532
- }
533
- if (opts?.startTime) {
534
- let time = performance.now() - opts.startTime;
535
- if (opts.useSeconds) {
536
- time = time / 1000;
537
- time = Math.round(time * 100) / 100;
538
- }
539
- if (opts.quiet === true)
540
- return resolve(ExitCode2.Success);
541
- if (error) {
542
- log.error(`[${time.toFixed(2)}${opts.useSeconds ? "s" : "ms"}] Failed`);
543
- } else if (opts.type === "info") {
544
- log.info(`${dim(gray(`[${time.toFixed(2)}${opts.useSeconds ? "s" : "ms"}]`))} ${opts.message ?? "Complete"}`);
545
- } else {
546
- log.success(`${dim(gray(bold(`[${time.toFixed(2)}${opts.useSeconds ? "s" : "ms"}]`)))} ${bold(green(opts.message ?? "Complete"))}`);
547
- }
548
- } else {
549
- if (opts?.type === "info")
550
- log.info(text);
551
- else if (opts?.type === "success" && opts?.quiet !== true)
552
- log.success(text);
553
- }
554
- return resolve(ExitCode2.Success);
555
- });
556
- }
557
- // src/parse.ts
558
- import process4 from "process";
559
- function isLongOption(arg) {
560
- if (!arg)
561
- return false;
562
- return arg.startsWith("--");
563
- }
564
- function isShortOption(arg) {
565
- return arg.startsWith("-") && !isLongOption(arg);
566
- }
567
- function parseValue(value) {
568
- if (value === "true")
569
- return true;
570
- if (value === "false")
571
- return false;
572
- const numberValue = Number.parseFloat(value);
573
- if (!Number.isNaN(numberValue))
574
- return numberValue;
575
- return value.replace(/"/g, "");
576
- }
577
- function parseLongOption(arg, argv, index, options) {
578
- const [key, value] = arg.slice(2).split("=");
579
- if (value !== undefined) {
580
- options[key] = parseValue(value);
581
- } else if (index + 1 < argv.length && !argv[index + 1]?.startsWith("-")) {
582
- options[key] = argv[index + 1];
583
- index++;
584
- } else {
585
- options[key] = true;
586
- }
587
- return index;
588
- }
589
- function parseShortOption(arg, argv, index, options) {
590
- const [key, value] = arg.slice(1).split("=");
591
- if (key === undefined)
592
- return index;
593
- if (value !== undefined && key !== undefined) {
594
- for (let j = 0;j < key.length; j++)
595
- options[key[j]] = parseValue(value);
596
- } else {
597
- for (let j = 0;j < key.length; j++) {
598
- if (index + 1 < argv.length && j === key.length - 1 && !argv[index + 1]?.startsWith("-")) {
599
- options[key[j]] = parseValue(argv[index + 1]);
600
- index++;
601
- } else {
602
- options[key[j]] = true;
603
- }
604
- }
605
- }
606
- return index;
607
- }
608
- function parseArgv(argv) {
609
- if (argv === undefined)
610
- argv = process4.argv.slice(2);
611
- const args = [];
612
- const options = {};
613
- for (let i = 0;i < argv.length; i++) {
614
- const arg = argv[i];
615
- if (!arg)
616
- continue;
617
- if (isLongOption(arg))
618
- i = parseLongOption(arg, argv, i, options);
619
- else if (isShortOption(arg))
620
- i = parseShortOption(arg, argv, i, options);
621
- else
622
- args.push(arg);
623
- }
624
- return { args, options };
625
- }
626
- function parseArgs(argv) {
627
- if (argv === undefined)
628
- argv = process4.argv.slice(2);
629
- return parseArgv(argv).args;
630
- }
631
- function parseOptions(options) {
632
- options = options || {};
633
- const defaults = { dryRun: false, quiet: false, verbose: false };
634
- const args = process4.argv.slice(2);
635
- for (let i = 0;i < args.length; i++) {
636
- const arg = args[i];
637
- if (arg?.startsWith("--")) {
638
- const key = arg.substring(2);
639
- const camelCaseKey = key.replace(/-([a-z])/gi, (g) => g[1] ? g[1].toUpperCase() : "");
640
- if (i + 1 < args.length && !args?.[i + 1]?.startsWith("--")) {
641
- if (args?.[i + 1] === "true" || args?.[i + 1] === "false") {
642
- options[camelCaseKey] = args[i + 1] === "true";
643
- i++;
644
- } else {
645
- options[camelCaseKey] = args[i + 1];
646
- i++;
647
- }
648
- } else {
649
- options[camelCaseKey] = true;
650
- }
651
- }
652
- }
653
- if (Object.keys(options).length === 0)
654
- return {};
655
- return { ...defaults, ...options };
656
- }
657
- function buddyOptions(options) {
658
- if (Array.isArray(options)) {
659
- options = Array.from(new Set(options));
660
- if (Array.isArray(options) && options[0] && !options[0].startsWith("-"))
661
- options.shift();
662
- return options.join(" ");
663
- }
664
- if (typeof options === "object" && options !== null) {
665
- return Object.entries(options).filter(([key, value]) => key !== "--" && key !== "_" && value !== false && value !== undefined && value !== null).map(([key, value]) => {
666
- if (value === true)
667
- return `--${key}`;
668
- return `--${key} ${value}`;
669
- }).join(" ");
670
- }
671
- return buddyOptions(process4.argv.slice(2));
672
- }
673
- // src/prompts.ts
674
- import process5 from "process";
675
- import { createInterface } from "readline";
676
- var _originalDestroy = process5.stdin.destroy;
677
- process5.stdin.destroy = function(error) {
678
- if (error) {
679
- this.emit("error", error);
680
- }
681
- return this;
682
- };
683
- process5.on("SIGINT", () => {
684
- console.log(`
685
- `);
686
- process5.exit(130);
687
- });
688
- var globalRl = null;
689
- function getGlobalRl() {
690
- if (!globalRl) {
691
- const isTTY = process5.stdin.isTTY && process5.stdout.isTTY;
692
- globalRl = createInterface({
693
- input: process5.stdin,
694
- output: process5.stdout,
695
- terminal: isTTY
696
- });
697
- if (isTTY && typeof process5.stdin.setRawMode === "function") {
698
- globalRl.on("SIGINT", () => {
699
- process5.emit("SIGINT");
700
- });
701
- }
702
- globalRl.once("close", () => {
703
- globalRl = null;
704
- });
705
- }
706
- return globalRl;
707
- }
708
- var EOF = Symbol("stdin-eof");
709
- function readLineOrEof(prompt) {
710
- return new Promise((resolve) => {
711
- const rl = getGlobalRl();
712
- let settled = false;
713
- const finish = (answer) => {
714
- if (settled)
715
- return;
716
- settled = true;
717
- rl.off("close", onClose);
718
- resolve(answer);
719
- };
720
- const onClose = () => finish(EOF);
721
- rl.once("close", onClose);
722
- try {
723
- rl.question(prompt, finish);
724
- } catch {
725
- finish(EOF);
726
- }
727
- });
728
- }
729
- async function readLine(prompt) {
730
- const answer = await readLineOrEof(prompt);
731
- return answer === EOF ? "" : answer;
732
- }
733
- function normalizeConfirm(answer, defaultValue) {
734
- const normalized = answer.toLowerCase().trim();
735
- if (!normalized)
736
- return defaultValue;
737
- if (normalized === "y" || normalized === "yes")
738
- return true;
739
- if (normalized === "n" || normalized === "no")
740
- return false;
741
- return defaultValue;
742
- }
743
- async function confirmOrNull(options) {
744
- const opts = typeof options === "string" ? { message: options } : options;
745
- const defaultValue = opts.initial ?? false;
746
- const suffix = defaultValue ? " (Y/n) " : " (y/N) ";
747
- const answer = await readLineOrEof(`${opts.message}${suffix}`);
748
- if (answer === EOF)
749
- return null;
750
- return normalizeConfirm(answer, defaultValue);
751
- }
752
- async function confirm(options) {
753
- const opts = typeof options === "string" ? { message: options } : options;
754
- const defaultValue = opts.initial ?? false;
755
- const suffix = defaultValue ? " (Y/n) " : " (y/N) ";
756
- const answer = await readLine(`${opts.message}${suffix}`);
757
- return normalizeConfirm(answer, defaultValue);
758
- }
759
- async function text(options) {
760
- const opts = typeof options === "string" ? { message: options } : options;
761
- const placeholder = opts.placeholder || opts.initial || "";
762
- const suffix = placeholder ? ` (${placeholder}) ` : " ";
763
- const answer = await readLine(`${opts.message}${suffix}`);
764
- return answer.trim() || opts.initial || "";
765
- }
766
- async function select(options) {
767
- console.log(options.message);
768
- options.choices.forEach((choice, index2) => {
769
- const marker = index2 === (options.initial ?? 0) ? ">" : " ";
770
- console.log(`${marker} ${index2 + 1}. ${choice.label}`);
771
- });
772
- const answer = await readLine("Select (number): ");
773
- const index = Number.parseInt(answer.trim(), 10) - 1;
774
- const chosen = options.choices[index] ?? options.choices[options.initial ?? 0];
775
- if (!chosen)
776
- throw new Error("select prompt: no choices available");
777
- return chosen.value;
778
- }
779
- async function multiselect(options) {
780
- console.log(options.message);
781
- console.log("(Enter numbers separated by commas)");
782
- options.choices.forEach((choice, index) => {
783
- console.log(` ${index + 1}. ${choice.label}`);
784
- });
785
- const answer = await readLine("Select (e.g., 1,3,4): ");
786
- const indices = answer.split(",").map((s) => Number.parseInt(s.trim(), 10) - 1);
787
- const selected = [];
788
- for (const i of indices) {
789
- const choice = options.choices[i];
790
- if (choice)
791
- selected.push(choice.value);
792
- }
793
- return selected;
794
- }
795
- async function password(options) {
796
- const opts = typeof options === "string" ? { message: options } : options;
797
- const answer = await readLine(`${opts.message} `);
798
- return answer.trim();
799
- }
800
- var prompts = {
801
- text,
802
- confirm,
803
- select,
804
- multiselect,
805
- password
806
- };
807
- // src/run.ts
808
- import { handleError as handleError3 } from "@stacksjs/error-handling";
809
- async function runCommand(command, options) {
810
- const opts = {
811
- ...options,
812
- stdin: options?.stdin ?? "inherit",
813
- verbose: options?.verbose ?? false
814
- };
815
- return await exec(command, opts);
816
- }
817
- async function runProcess(command, options) {
818
- const opts = {
819
- ...options,
820
- stdio: [options?.stdin ?? "inherit", "pipe", "pipe"],
821
- verbose: options?.verbose ?? false
822
- };
823
- return await exec(command, opts);
824
- }
825
- async function runCommandSync(command, options) {
826
- const opts = {
827
- ...options,
828
- stdio: [options?.stdin ?? "inherit", "pipe", "pipe"],
829
- verbose: options?.verbose ?? false
830
- };
831
- return await execSync(command, opts);
832
- }
833
- async function runCommands(commands, options) {
834
- const results = [];
835
- for (const command of commands) {
836
- const result = await runCommand(command, options);
837
- if (result.isErr) {
838
- handleError3("Error during runCommands", result.error);
839
- throw result.error;
840
- }
841
- results.push(result);
842
- }
843
- return results;
844
- }
845
- // src/signals.ts
846
- import process6 from "process";
847
- var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
848
- var handlers = new Map;
849
- var installed = false;
850
- function installOnce() {
851
- if (installed)
852
- return;
853
- installed = true;
854
- for (const sig of SIGNALS) {
855
- process6.on(sig, async () => {
856
- for (const [name, fn] of handlers) {
857
- try {
858
- await fn();
859
- } catch (err2) {
860
- console.error(`[signals] cleanup '${name}' threw:`, err2);
861
- }
862
- }
863
- });
864
- }
865
- }
866
- function onSignal(name, cleanup) {
867
- installOnce();
868
- handlers.set(name, cleanup);
869
- return () => {
870
- if (handlers.get(name) === cleanup)
871
- handlers.delete(name);
872
- };
873
- }
874
- function offSignal(name) {
875
- handlers.delete(name);
876
- }
877
- function listSignalHandlers() {
878
- return [...handlers.keys()];
879
- }
880
- // src/spinner.ts
881
- var spinnerFrames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
882
- var isInteractive = process.stdout.isTTY && !process.env.CI;
883
- function spinner(message) {
884
- let currentMessage = message || "";
885
- let frameIndex = 0;
886
- let intervalId = null;
887
- let isSpinning = false;
888
- const clearLine = () => {
889
- if (isInteractive) {
890
- process.stdout.write("\r\x1B[K");
891
- }
892
- };
893
- const render = () => {
894
- if (!isInteractive)
895
- return;
896
- clearLine();
897
- const frame = spinnerFrames[frameIndex];
898
- process.stdout.write(`${frame} ${currentMessage}`);
899
- frameIndex = (frameIndex + 1) % spinnerFrames.length;
900
- };
901
- return {
902
- start(msg) {
903
- if (msg)
904
- currentMessage = msg;
905
- if (isSpinning)
906
- return;
907
- isSpinning = true;
908
- if (isInteractive) {
909
- render();
910
- intervalId = setInterval(render, 80);
911
- } else {
912
- if (currentMessage)
913
- console.log(` ${currentMessage}`);
914
- }
915
- },
916
- stop(msg) {
917
- isSpinning = false;
918
- if (intervalId) {
919
- clearInterval(intervalId);
920
- intervalId = null;
921
- }
922
- clearLine();
923
- if (msg)
924
- console.log(msg);
925
- },
926
- update(msg) {
927
- currentMessage = msg;
928
- if (!isInteractive && isSpinning) {
929
- console.log(` ${msg}`);
930
- }
931
- },
932
- succeed(msg) {
933
- const finalMsg = msg || currentMessage;
934
- isSpinning = false;
935
- if (intervalId) {
936
- clearInterval(intervalId);
937
- intervalId = null;
938
- }
939
- clearLine();
940
- console.log(`\u2713 ${finalMsg}`);
941
- },
942
- fail(msg) {
943
- const finalMsg = msg || currentMessage;
944
- isSpinning = false;
945
- if (intervalId) {
946
- clearInterval(intervalId);
947
- intervalId = null;
948
- }
949
- clearLine();
950
- console.error(`\u2717 ${finalMsg}`);
951
- },
952
- get text() {
953
- return currentMessage;
954
- },
955
- set text(value) {
956
- currentMessage = value;
957
- if (isInteractive && isSpinning) {
958
- render();
959
- }
960
- },
961
- get isSpinning() {
962
- return isSpinning;
963
- }
964
- };
965
- }
966
- async function withSpinner(message, operation, options) {
967
- const s = spinner(message);
968
- s.start();
969
- try {
970
- const result = await operation();
971
- s.succeed(options?.successMessage || message);
972
- return result;
973
- } catch (error) {
974
- s.fail(options?.failMessage || `Failed: ${message}`);
975
- throw error;
976
- }
977
- }
978
- export {
979
- yellow,
980
- withSpinner,
981
- white,
982
- underline,
983
- trueColorBg,
984
- trueColor,
985
- text,
986
- stripColors,
987
- stripAnsi,
988
- strikethrough,
989
- spinner,
990
- select,
991
- runProcess,
992
- runCommands,
993
- runCommandSync,
994
- runCommand,
995
- rightAlign,
996
- reset,
997
- red,
998
- quotes,
999
- prompts,
1000
- password,
1001
- parseOptions,
1002
- parseArgv,
1003
- parseArgs,
1004
- outro,
1005
- onUnknownSubcommand,
1006
- onSignal,
1007
- offSignal,
1008
- multiselect,
1009
- magenta,
1010
- log,
1011
- listSignalHandlers,
1012
- link,
1013
- lightYellow,
1014
- lightRed,
1015
- lightMagenta,
1016
- lightGreen,
1017
- lightGray,
1018
- lightCyan,
1019
- lightBlue,
1020
- leftAlign,
1021
- kolorist,
1022
- italic,
1023
- inverse,
1024
- intro,
1025
- installStack,
1026
- installPackage,
1027
- hidden,
1028
- green,
1029
- gray,
1030
- getColor,
1031
- execSync,
1032
- exec,
1033
- dim,
1034
- cyan,
1035
- confirmOrNull,
1036
- confirm,
1037
- colors,
1038
- colorize,
1039
- cli,
1040
- centerAlign,
1041
- buddyOptions,
1042
- box,
1043
- bold,
1044
- blue,
1045
- black,
1046
- bgYellow,
1047
- bgWhite,
1048
- bgRed,
1049
- bgMagenta,
1050
- bgLightYellow,
1051
- bgLightRed,
1052
- bgLightMagenta,
1053
- bgLightGreen,
1054
- bgLightGray,
1055
- bgLightCyan,
1056
- bgLightBlue,
1057
- bgGreen,
1058
- bgGray,
1059
- bgCyan,
1060
- bgBlue,
1061
- bgBlack,
1062
- ansi256Bg,
1063
- ansi256,
1064
- align,
1065
- CLI
1066
- };
2
+ import Gj from"process";async function Ij(j,D={silent:!0}){let J=D.packageManager??"bun",Q=[J==="npm"?"install":"add"];if(D.dev)Q.push("-D");if(D.preferOffline&&J!=="bun")Q.push("--prefer-offline");if(D.additionalArgs)Q.push(...D.additionalArgs);Q.push(j);let Z=await Bun.spawn([J,...Q],{cwd:D.cwd??Gj.cwd(),stdout:D.silent?"ignore":"inherit",stderr:D.silent?"ignore":"inherit",stdin:"ignore",env:Gj.env}).exited;if(Z!==0)throw Error(`Failed to install ${j} (exit code ${Z})`)}async function W0(j,D){return Ij(j,D??{silent:!0})}async function k0(j,D){return Ij(`@stacksjs/${j}`,D??{silent:!0})}import{CLI as f0,cli as aj,onUnknownSubcommand as M0}from"@stacksjs/clapp";function L0(j,D){if(typeof j==="object")D=j,j=D.name;return aj(j||"buddy")}import w from"process";import{err as L,handleError as d,ok as rj}from"@stacksjs/error-handling";import{ExitCode as O}from"@stacksjs/types";async function g(j,D){let J=Array.isArray(j)?j:j.match(/(?:[^\s"]|"[^"]*")+/g);if(!J)return L(d(`Failed to parse command: ${J}`,D));let Q=D?.cwd??w.cwd(),X=D?.timeoutMs,Z=Bun.spawn(J,{stdin:D?.stdin??"inherit",stdout:D?.silent||D?.quiet?"ignore":D?.stdin?D.stdin:D?.stdout||"inherit",stderr:D?.silent||D?.quiet?"ignore":D?.stderr||"inherit",cwd:Q,env:{...w.env,...D?.env},onExit(z,kj,u,m){Mj("spawn",z,kj,u,m)}});if(D?.stdin==="pipe"&&D.input){if(Z.stdin)Z.stdin.write(D.input),Z.stdin.end()}let q,H=await Promise.race([Z.exited,new Promise((z)=>{if(!X)return;q=setTimeout(()=>{try{Z.kill()}catch{}z(O.FatalError)},X)})]);if(q)clearTimeout(q);if(X&&H===O.FatalError&&Z.exitCode===null)return L(d(`Command timed out after ${X}ms: ${N(J.join(" "))} in ${N(Q)}`,D));if(H===O.Success)return rj(Z);let K=Z.signalCode;if(K==="SIGTERM"||K==="SIGINT"||K==="SIGKILL"||Z.exitCode===null&&H!==O.Success)return L(Error(`Command terminated by ${K??"signal"}: ${J.join(" ")}`));return L(d(`Failed to execute command: ${N(J.join(" "))} in ${N(Q)}`,D))}async function fj(j,D){let J=Array.isArray(j)?j:j.match(/(?:[^\s"]|"[^"]*")+/g);if(!J)throw A.error(`Failed to parse command: ${J}`,D),Error(`Failed to parse command: ${J}`);let Q=Bun.spawnSync(J,{...D,stdin:D?.stdin??"inherit",stdout:D?.stdout??"pipe",stderr:D?.stderr??"inherit",cwd:D?.cwd??w.cwd(),env:{...w.env,...D?.env},onExit(Z,q,H,K){Mj("spawnSync",Z,q,H,K)}}),X=Q.stdout?.toString()??"";if(D?.throwOnError&&Q.exitCode!==0){let q=((Q.stderr?.toString()??"").trim()||X.trim()||"(no output)").split(`
3
+ `).slice(0,5).join(`
4
+ `);throw Error(`Command failed with exit code ${Q.exitCode}: ${J.join(" ")}
5
+ ${q}`)}return X}function Mj(j,D,J,Q,X){if(A.debug(`exitHandler: ${j}, exitCode: ${J}, signalCode: ${Q}`),X)A.debug("Process error:",X.message)}import{handleError as Q0}from"@stacksjs/error-handling";import{log as A}from"@stacksjs/logging";import{ExitCode as Rj}from"@stacksjs/types";import{collect as sj}from"@stacksjs/collections";var $=!process.env.NO_COLOR&&(process.env.FORCE_COLOR?process.env.FORCE_COLOR!=="0":!!process.stdout?.isTTY),P={reset:$?"\x1B[0m":"",black:$?"\x1B[30m":"",red:$?"\x1B[31m":"",green:$?"\x1B[32m":"",yellow:$?"\x1B[33m":"",blue:$?"\x1B[34m":"",magenta:$?"\x1B[35m":"",cyan:$?"\x1B[36m":"",white:$?"\x1B[37m":"",gray:$?"\x1B[90m":"",lightRed:$?"\x1B[91m":"",lightGreen:$?"\x1B[92m":"",lightYellow:$?"\x1B[93m":"",lightBlue:$?"\x1B[94m":"",lightMagenta:$?"\x1B[95m":"",lightCyan:$?"\x1B[96m":"",lightGray:$?"\x1B[37m":"",bgBlack:$?"\x1B[40m":"",bgRed:$?"\x1B[41m":"",bgGreen:$?"\x1B[42m":"",bgYellow:$?"\x1B[43m":"",bgBlue:$?"\x1B[44m":"",bgMagenta:$?"\x1B[45m":"",bgCyan:$?"\x1B[46m":"",bgWhite:$?"\x1B[47m":"",bgGray:$?"\x1B[100m":"",bgLightRed:$?"\x1B[101m":"",bgLightGreen:$?"\x1B[102m":"",bgLightYellow:$?"\x1B[103m":"",bgLightBlue:$?"\x1B[104m":"",bgLightMagenta:$?"\x1B[105m":"",bgLightCyan:$?"\x1B[106m":"",bgLightGray:$?"\x1B[47m":"",bold:$?"\x1B[1m":"",dim:$?"\x1B[2m":"",italic:$?"\x1B[3m":"",underline:$?"\x1B[4m":"",inverse:$?"\x1B[7m":"",hidden:$?"\x1B[8m":"",strikethrough:$?"\x1B[9m":""},y="\x1B[",tj="\x1B]8;;",ij="\x1B]8;;\x07",Lj=(j)=>String(j);function Y(j,D,J){return Math.min(Math.max(Math.floor(j),D),J)}function _(j,D=P.reset){return(J)=>{if(!$)return String(J);return`${j}${String(J)}${D}`}}function ej(j){return j.replace(/\x1B\]8;;[^\x07]*(?:\x07|\x1B\\)/g,"").replace(/\x1B\]8;;(?:\x07|\x1B\\)/g,"")}function l(j){return ej(j).replace(/\x1B\[[0-?]*[ -/]*[@-~]/g,"")}var Oj=l;function wj(j){return Array.from(l(j)).length}var p=_(P.black),a=_(P.red),V=_(P.green),r=_(P.yellow),s=_(P.blue),t=_(P.magenta),E=_(P.cyan),i=_(P.white),F=_(P.gray),e=_(P.lightRed),n=_(P.lightGreen),o=_(P.lightYellow),jj=_(P.lightBlue),Dj=_(P.lightMagenta),Jj=_(P.lightCyan),S=_(P.lightGray),Qj=_(P.bgBlack),Xj=_(P.bgRed),Zj=_(P.bgGreen),_j=_(P.bgYellow),$j=_(P.bgBlue),qj=_(P.bgMagenta),k=_(P.bgCyan),Pj=_(P.bgWhite),Hj=_(P.bgGray),Kj=_(P.bgLightRed),Nj=_(P.bgLightGreen),Aj=_(P.bgLightYellow),Tj=_(P.bgLightBlue),Uj=_(P.bgLightMagenta),zj=_(P.bgLightCyan),C=_(P.bgLightGray),U=_(P.bold),B=_(P.dim),N=_(P.italic),Yj=_(P.underline),Fj=_(P.inverse),Bj=_(P.hidden),Vj=_(P.strikethrough),Ej=_(P.reset,"");function Sj(j){return _(`${y}38;5;${Y(j,0,255)}m`)}function Cj(j){return _(`${y}48;5;${Y(j,0,255)}m`)}function yj(j,D,J){return _(`${y}38;2;${Y(j,0,255)};${Y(D,0,255)};${Y(J,0,255)}m`)}function bj(j,D,J){return _(`${y}48;2;${Y(j,0,255)};${Y(D,0,255)};${Y(J,0,255)}m`)}function vj(j,D){let J=(X,Z)=>{let q=String(X);if(!$)return q;return`${tj}${Z}\x07${q}${ij}`};if(typeof D==="string")return J(j,D);let Q=String(j);return(X)=>J(X,Q)}var nj={black:p,red:a,green:V,yellow:r,blue:s,magenta:t,cyan:E,white:i,gray:F,lightRed:e,lightGreen:n,lightYellow:o,lightBlue:jj,lightMagenta:Dj,lightCyan:Jj,lightGray:S,bgBlack:Qj,bgRed:Xj,bgGreen:Zj,bgYellow:_j,bgBlue:$j,bgMagenta:qj,bgCyan:k,bgWhite:Pj,bgGray:Hj,bgLightRed:Kj,bgLightGreen:Nj,bgLightYellow:Aj,bgLightBlue:Tj,bgLightMagenta:Uj,bgLightCyan:zj,bgLightGray:C,bold:U,dim:B,italic:N,underline:Yj,inverse:Fj,hidden:Bj,strikethrough:Vj,reset:Ej};function xj(j){return nj[j]??Lj}function x0(j,D){if(typeof D==="function")return D(j);return xj(D)(j)}function oj(){return $}var h0={black:p,red:a,green:V,yellow:r,blue:s,magenta:t,cyan:E,white:i,gray:F,lightRed:e,lightGreen:n,lightYellow:o,lightBlue:jj,lightMagenta:Dj,lightCyan:Jj,lightGray:S,bgBlack:Qj,bgRed:Xj,bgGreen:Zj,bgYellow:_j,bgBlue:$j,bgMagenta:qj,bgCyan:k,bgWhite:Pj,bgGray:Hj,bgLightRed:Kj,bgLightGreen:Nj,bgLightYellow:Aj,bgLightBlue:Tj,bgLightMagenta:Uj,bgLightCyan:zj,bgLightGray:C,bold:U,dim:B,italic:N,underline:Yj,inverse:Fj,hidden:Bj,strikethrough:Vj,reset:Ej,ansi256:Sj,ansi256Bg:Cj,trueColor:yj,trueColorBg:bj,link:vj,stripColors:Oj},u0={black:p,red:a,green:V,yellow:r,blue:s,magenta:t,cyan:E,white:i,gray:F,lightRed:e,lightGreen:n,lightYellow:o,lightBlue:jj,lightMagenta:Dj,lightCyan:Jj,lightGray:S,bgBlack:Qj,bgRed:Xj,bgGreen:Zj,bgYellow:_j,bgBlue:$j,bgMagenta:qj,bgCyan:k,bgWhite:Pj,bgGray:Hj,bgLightRed:Kj,bgLightGreen:Nj,bgLightYellow:Aj,bgLightBlue:Tj,bgLightMagenta:Uj,bgLightCyan:zj,bgLightGray:C,bold:U,dim:B,italic:N,underline:Yj,inverse:Fj,hidden:Bj,strikethrough:Vj,reset:Ej,ansi256:Sj,ansi256Bg:Cj,trueColor:yj,trueColorBg:bj,link:vj,stripColors:Oj,grey:F,lightGrey:S,bgLightGrey:C,supportsColor:oj};function j0(j,D,J,Q){let X=wj(j);if(X>=D)return j;let Z=Q[0]||" ",q=D-X;if(J==="right")return`${Z.repeat(q)}${j}`;if(J==="center"){let H=Math.floor(q/2),K=q-H;return`${Z.repeat(H)}${j}${Z.repeat(K)}`}return`${j}${Z.repeat(q)}`}function b(j){return Math.max(0,...j.map(wj))}function v(j,D,J="left"){let Q=String(j).split(/\r?\n/),X=typeof D==="object"?D:void 0,Z=typeof D==="number"?D:X?.width??b(Q),q=X?.align??J,H=X?.padChar??" ";return Q.map((K)=>j0(K,Math.max(0,Z),q,H)).join(`
6
+ `)}function m0(j,D){return v(j,D,"left")}function c0(j,D){let J=String(j).split(/\r?\n/);return v(j,D??process.stdout?.columns??b(J),"right")}function d0(j,D){let J=String(j).split(/\r?\n/);return v(j,D??process.stdout?.columns??b(J),"center")}var D0={single:{topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502"},double:{topLeft:"\u2554",topRight:"\u2557",bottomLeft:"\u255A",bottomRight:"\u255D",horizontal:"\u2550",vertical:"\u2551"},round:{topLeft:"\u256D",topRight:"\u256E",bottomLeft:"\u2570",bottomRight:"\u256F",horizontal:"\u2500",vertical:"\u2502"}};function g0(j,D={}){let J=String(j).split(/\r?\n/),Q=D0[D.borderStyle??"single"],X=Math.max(0,D.padding??1),Z=Math.max(0,D.margin??0),q=D.align??"left",H=b(J),K=H+X*2,z=typeof D.borderColor==="function"?D.borderColor:D.borderColor?xj(D.borderColor):Lj,u=z((()=>{if(!D.title)return`${Q.topLeft}${Q.horizontal.repeat(K)}${Q.topRight}`;let M=` ${l(String(D.title))} `.slice(0,K),c=Q.horizontal.repeat(Math.max(0,K-M.length));return`${Q.topLeft}${M}${c}${Q.topRight}`})()),m=z(`${Q.bottomLeft}${Q.horizontal.repeat(K)}${Q.bottomRight}`),lj=J.map((f)=>{let M=v(f,{align:q,width:H}),c=`${" ".repeat(X)}${M}${" ".repeat(X)}`;return`${z(Q.vertical)}${c}${z(Q.vertical)}`}),pj=" ".repeat(Z);return[u,...lj,m].map((f)=>`${pj}${f}`).join(`
7
+ `)}var l0=sj(["The best way to get started is to quit talking and begin doing.","The pessimist sees difficulty in every opportunity. The optimist sees opportunity in every difficulty.","Don\u2019t let yesterday take up too much of today.","You learn more from failure than from success. Don\u2019t let it stop you. Failure builds character.","It\u2019s not whether you get knocked down, it\u2019s whether you get up.","If you are working on something that you really care about, you don\u2019t have to be pushed. The vision pulls you.","People who are crazy enough to think they can change the world, are the ones who do.","Failure will never overtake me if my determination to succeed is strong enough.","Entrepreneurs are great at dealing with uncertainty and also very good at minimizing risk. That\u2019s the classic entrepreneur.","We may encounter many defeats but we must not be defeated.","Knowing is not enough; we must apply. Wishing is not enough; we must do.","Imagine your life is perfect in every respect; what would it look like?","We generate fears while we sit. We overcome them by action.","Whether you think you can or think you can\u2019t, you\u2019re right.","Security is mostly a superstition. Life is either a daring adventure or nothing."]);var hj="0.70.260";async function n0(j,D){return new Promise((J)=>{if(D?.quiet===!1)console.log(),console.log(E(U("Stacks CLI"))+B(` v${hj}`)),console.log();if(A.info(`Running ${k(N(U(` ${j} `)))}`),D?.showPerformance===!1||D?.quiet)return J(0);return J(performance.now())})}function o0(j,D,J){let Q={type:"success",useSeconds:!0,...D};return Q.message=D?.message||j,new Promise((X)=>{if(J)return Q0(J),X(Rj.FatalError);if(Q?.startTime){let Z=performance.now()-Q.startTime;if(Q.useSeconds)Z=Z/1000,Z=Math.round(Z*100)/100;if(Q.quiet===!0)return X(Rj.Success);if(J)A.error(`[${Z.toFixed(2)}${Q.useSeconds?"s":"ms"}] Failed`);else if(Q.type==="info")A.info(`${B(F(`[${Z.toFixed(2)}${Q.useSeconds?"s":"ms"}]`))} ${Q.message??"Complete"}`);else A.success(`${B(F(U(`[${Z.toFixed(2)}${Q.useSeconds?"s":"ms"}]`)))} ${U(V(Q.message??"Complete"))}`)}else if(Q?.type==="info")A.info(j);else if(Q?.type==="success"&&Q?.quiet!==!0)A.success(j);return X(Rj.Success)})}import x from"process";function uj(j){if(!j)return!1;return j.startsWith("--")}function X0(j){return j.startsWith("-")&&!uj(j)}function Wj(j){if(j==="true")return!0;if(j==="false")return!1;let D=Number.parseFloat(j);if(!Number.isNaN(D))return D;return j.replace(/"/g,"")}function Z0(j,D,J,Q){let[X,Z]=j.slice(2).split("=");if(Z!==void 0)Q[X]=Wj(Z);else if(J+1<D.length&&!D[J+1]?.startsWith("-"))Q[X]=D[J+1],J++;else Q[X]=!0;return J}function _0(j,D,J,Q){let[X,Z]=j.slice(1).split("=");if(X===void 0)return J;if(Z!==void 0&&X!==void 0)for(let q=0;q<X.length;q++)Q[X[q]]=Wj(Z);else for(let q=0;q<X.length;q++)if(J+1<D.length&&q===X.length-1&&!D[J+1]?.startsWith("-"))Q[X[q]]=Wj(D[J+1]),J++;else Q[X[q]]=!0;return J}function $0(j){if(j===void 0)j=x.argv.slice(2);let D=[],J={};for(let Q=0;Q<j.length;Q++){let X=j[Q];if(!X)continue;if(uj(X))Q=Z0(X,j,Q,J);else if(X0(X))Q=_0(X,j,Q,J);else D.push(X)}return{args:D,options:J}}function Q2(j){if(j===void 0)j=x.argv.slice(2);return $0(j).args}function X2(j){j=j||{};let D={dryRun:!1,quiet:!1,verbose:!1},J=x.argv.slice(2);for(let Q=0;Q<J.length;Q++){let X=J[Q];if(X?.startsWith("--")){let q=X.substring(2).replace(/-([a-z])/gi,(H)=>H[1]?H[1].toUpperCase():"");if(Q+1<J.length&&!J?.[Q+1]?.startsWith("--"))if(J?.[Q+1]==="true"||J?.[Q+1]==="false")j[q]=J[Q+1]==="true",Q++;else j[q]=J[Q+1],Q++;else j[q]=!0}}if(Object.keys(j).length===0)return{};return{...D,...j}}function q0(j){if(Array.isArray(j)){if(j=Array.from(new Set(j)),Array.isArray(j)&&j[0]&&!j[0].startsWith("-"))j.shift();return j.join(" ")}if(typeof j==="object"&&j!==null)return Object.entries(j).filter(([D,J])=>D!=="--"&&D!=="_"&&J!==!1&&J!==void 0&&J!==null).map(([D,J])=>{if(J===!0)return`--${D}`;return`--${D} ${J}`}).join(" ");return q0(x.argv.slice(2))}import T from"process";import{createInterface as P0}from"readline";var q2=T.stdin.destroy;T.stdin.destroy=function(j){if(j)this.emit("error",j);return this};T.on("SIGINT",()=>{console.log(`
8
+ `),T.exit(130)});var R=null;function H0(){if(!R){let j=T.stdin.isTTY&&T.stdout.isTTY;if(R=P0({input:T.stdin,output:T.stdout,terminal:j}),j&&typeof T.stdin.setRawMode==="function")R.on("SIGINT",()=>{T.emit("SIGINT")});R.once("close",()=>{R=null})}return R}var h=Symbol("stdin-eof");function mj(j){return new Promise((D)=>{let J=H0(),Q=!1,X=(q)=>{if(Q)return;Q=!0,J.off("close",Z),D(q)},Z=()=>X(h);J.once("close",Z);try{J.question(j,X)}catch{X(h)}})}async function G(j){let D=await mj(j);return D===h?"":D}function cj(j,D){let J=j.toLowerCase().trim();if(!J)return D;if(J==="y"||J==="yes")return!0;if(J==="n"||J==="no")return!1;return D}async function P2(j){let D=typeof j==="string"?{message:j}:j,J=D.initial??!1,Q=J?" (Y/n) ":" (y/N) ",X=await mj(`${D.message}${Q}`);if(X===h)return null;return cj(X,J)}async function K0(j){let D=typeof j==="string"?{message:j}:j,J=D.initial??!1,Q=J?" (Y/n) ":" (y/N) ",X=await G(`${D.message}${Q}`);return cj(X,J)}async function N0(j){let D=typeof j==="string"?{message:j}:j,J=D.placeholder||D.initial||"",Q=J?` (${J}) `:" ";return(await G(`${D.message}${Q}`)).trim()||D.initial||""}async function A0(j){console.log(j.message),j.choices.forEach((X,Z)=>{let q=Z===(j.initial??0)?">":" ";console.log(`${q} ${Z+1}. ${X.label}`)});let D=await G("Select (number): "),J=Number.parseInt(D.trim(),10)-1,Q=j.choices[J]??j.choices[j.initial??0];if(!Q)throw Error("select prompt: no choices available");return Q.value}async function T0(j){console.log(j.message),console.log("(Enter numbers separated by commas)"),j.choices.forEach((X,Z)=>{console.log(` ${Z+1}. ${X.label}`)});let J=(await G("Select (e.g., 1,3,4): ")).split(",").map((X)=>Number.parseInt(X.trim(),10)-1),Q=[];for(let X of J){let Z=j.choices[X];if(Z)Q.push(Z.value)}return Q}async function U0(j){return(await G(`${(typeof j==="string"?{message:j}:j).message} `)).trim()}var H2={text:N0,confirm:K0,select:A0,multiselect:T0,password:U0};import{handleError as z0}from"@stacksjs/error-handling";async function Y0(j,D){let J={...D,stdin:D?.stdin??"inherit",verbose:D?.verbose??!1};return await g(j,J)}async function T2(j,D){let J={...D,stdio:[D?.stdin??"inherit","pipe","pipe"],verbose:D?.verbose??!1};return await g(j,J)}async function U2(j,D){let J={...D,stdio:[D?.stdin??"inherit","pipe","pipe"],verbose:D?.verbose??!1};return await fj(j,J)}async function z2(j,D){let J=[];for(let Q of j){let X=await Y0(Q,D);if(X.isErr)throw z0("Error during runCommands",X.error),X.error;J.push(X)}return J}import F0 from"process";var B0=["SIGINT","SIGTERM","SIGHUP"],W=new Map,dj=!1;function V0(){if(dj)return;dj=!0;for(let j of B0)F0.on(j,async()=>{for(let[D,J]of W)try{await J()}catch(Q){console.error(`[signals] cleanup '${D}' threw:`,Q)}})}function B2(j,D){return V0(),W.set(j,D),()=>{if(W.get(j)===D)W.delete(j)}}function V2(j){W.delete(j)}function E2(){return[...W.keys()]}var gj=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],I=process.stdout.isTTY&&!process.env.CI;function E0(j){let D=j||"",J=0,Q=null,X=!1,Z=()=>{if(I)process.stdout.write("\r\x1B[K")},q=()=>{if(!I)return;Z();let H=gj[J];process.stdout.write(`${H} ${D}`),J=(J+1)%gj.length};return{start(H){if(H)D=H;if(X)return;if(X=!0,I)q(),Q=setInterval(q,80);else if(D)console.log(` ${D}`)},stop(H){if(X=!1,Q)clearInterval(Q),Q=null;if(Z(),H)console.log(H)},update(H){if(D=H,!I&&X)console.log(` ${H}`)},succeed(H){let K=H||D;if(X=!1,Q)clearInterval(Q),Q=null;Z(),console.log(`\u2713 ${K}`)},fail(H){let K=H||D;if(X=!1,Q)clearInterval(Q),Q=null;Z(),console.error(`\u2717 ${K}`)},get text(){return D},set text(H){if(D=H,I&&X)q()},get isSpinning(){return X}}}async function W2(j,D,J){let Q=E0(j);Q.start();try{let X=await D();return Q.succeed(J?.successMessage||j),X}catch(X){throw Q.fail(J?.failMessage||`Failed: ${j}`),X}}export{r as yellow,W2 as withSpinner,i as white,Yj as underline,bj as trueColorBg,yj as trueColor,N0 as text,Oj as stripColors,l as stripAnsi,Vj as strikethrough,E0 as spinner,A0 as select,T2 as runProcess,z2 as runCommands,U2 as runCommandSync,Y0 as runCommand,c0 as rightAlign,Ej as reset,a as red,l0 as quotes,H2 as prompts,U0 as password,X2 as parseOptions,$0 as parseArgv,Q2 as parseArgs,o0 as outro,M0 as onUnknownSubcommand,B2 as onSignal,V2 as offSignal,T0 as multiselect,t as magenta,A as log,E2 as listSignalHandlers,vj as link,o as lightYellow,e as lightRed,Dj as lightMagenta,n as lightGreen,S as lightGray,Jj as lightCyan,jj as lightBlue,m0 as leftAlign,u0 as kolorist,N as italic,Fj as inverse,n0 as intro,k0 as installStack,W0 as installPackage,Bj as hidden,V as green,F as gray,xj as getColor,fj as execSync,g as exec,B as dim,E as cyan,P2 as confirmOrNull,K0 as confirm,h0 as colors,x0 as colorize,L0 as cli,d0 as centerAlign,q0 as buddyOptions,g0 as box,U as bold,s as blue,p as black,_j as bgYellow,Pj as bgWhite,Xj as bgRed,qj as bgMagenta,Aj as bgLightYellow,Kj as bgLightRed,Uj as bgLightMagenta,Nj as bgLightGreen,C as bgLightGray,zj as bgLightCyan,Tj as bgLightBlue,Zj as bgGreen,Hj as bgGray,k as bgCyan,$j as bgBlue,Qj as bgBlack,Cj as ansi256Bg,Sj as ansi256,v as align,f0 as CLI};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/cli",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.70.258",
5
+ "version": "0.70.260",
6
6
  "description": "TypeScript framework for CLI artisans. Build beautiful console apps with ease.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -43,9 +43,16 @@
43
43
  "default": "./dist/index.js"
44
44
  },
45
45
  "./*": {
46
- "bun": "./dist/*",
47
- "import": "./dist/*",
48
- "default": "./dist/*"
46
+ "types": "./dist/*.d.ts",
47
+ "bun": "./dist/*.js",
48
+ "import": "./dist/*.js",
49
+ "default": "./dist/*.js"
50
+ },
51
+ "./*.js": {
52
+ "types": "./dist/*.d.ts",
53
+ "bun": "./dist/*.js",
54
+ "import": "./dist/*.js",
55
+ "default": "./dist/*.js"
49
56
  }
50
57
  },
51
58
  "module": "dist/index.js",
@@ -64,14 +71,14 @@
64
71
  "@stacksjs/clapp": "^0.2.12"
65
72
  },
66
73
  "devDependencies": {
67
- "@stacksjs/collections": "0.70.258",
68
- "@stacksjs/config": "0.70.258",
74
+ "@stacksjs/collections": "0.70.260",
75
+ "@stacksjs/config": "0.70.260",
69
76
  "better-dx": "^0.2.17",
70
- "@stacksjs/error-handling": "0.70.258",
71
- "@stacksjs/logging": "0.70.258",
72
- "@stacksjs/path": "0.70.258",
73
- "@stacksjs/types": "0.70.258",
74
- "@stacksjs/utils": "0.70.258",
75
- "@stacksjs/validation": "0.70.258"
77
+ "@stacksjs/error-handling": "0.70.260",
78
+ "@stacksjs/logging": "0.70.260",
79
+ "@stacksjs/path": "0.70.260",
80
+ "@stacksjs/types": "0.70.260",
81
+ "@stacksjs/utils": "0.70.260",
82
+ "@stacksjs/validation": "0.70.260"
76
83
  }
77
84
  }