@kubb/cli 5.0.0-beta.4 → 5.0.0-beta.41

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 (157) hide show
  1. package/README.md +209 -51
  2. package/dist/agent-D3K_-kiv.js +68 -0
  3. package/dist/agent-D3K_-kiv.js.map +1 -0
  4. package/dist/agent-DTqKBULa.cjs +70 -0
  5. package/dist/agent-DTqKBULa.cjs.map +1 -0
  6. package/dist/{chunk--u3MIqq1.js → chunk-CRm0XQPb.js} +1 -0
  7. package/dist/constants-84a47qA-.js +35 -0
  8. package/dist/constants-84a47qA-.js.map +1 -0
  9. package/dist/constants-AHhyFH15.cjs +139 -0
  10. package/dist/constants-AHhyFH15.cjs.map +1 -0
  11. package/dist/constants-BtmponZ3.cjs +58 -0
  12. package/dist/constants-BtmponZ3.cjs.map +1 -0
  13. package/dist/constants-C94RKp3A.js +116 -0
  14. package/dist/constants-C94RKp3A.js.map +1 -0
  15. package/dist/{define-Bdn8j5VM.cjs → define-C4AB3POr.cjs} +2 -2
  16. package/dist/{define-Bdn8j5VM.cjs.map → define-C4AB3POr.cjs.map} +1 -1
  17. package/dist/{define-Ctii4bel.js → define-DNG1U8ha.js} +2 -2
  18. package/dist/{define-Ctii4bel.js.map → define-DNG1U8ha.js.map} +1 -1
  19. package/dist/{errors-CjPmyZHy.js → errors-CoxrNXaA.js} +2 -2
  20. package/dist/{errors-CjPmyZHy.js.map → errors-CoxrNXaA.js.map} +1 -1
  21. package/dist/{errors-CLCjoSg0.cjs → errors-DykI11xo.cjs} +2 -2
  22. package/dist/{errors-CLCjoSg0.cjs.map → errors-DykI11xo.cjs.map} +1 -1
  23. package/dist/generate-CZYIOngX.cjs +76 -0
  24. package/dist/generate-CZYIOngX.cjs.map +1 -0
  25. package/dist/generate-HcvbU80u.js +77 -0
  26. package/dist/generate-HcvbU80u.js.map +1 -0
  27. package/dist/index.cjs +23 -14
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.js +23 -14
  31. package/dist/index.js.map +1 -1
  32. package/dist/init-BMtuczv8.js +53 -0
  33. package/dist/init-BMtuczv8.js.map +1 -0
  34. package/dist/init-DybfkgNy.cjs +53 -0
  35. package/dist/init-DybfkgNy.cjs.map +1 -0
  36. package/dist/mcp-BF9dnH_F.js +39 -0
  37. package/dist/mcp-BF9dnH_F.js.map +1 -0
  38. package/dist/mcp-YzKoU6_l.cjs +39 -0
  39. package/dist/mcp-YzKoU6_l.cjs.map +1 -0
  40. package/dist/package-BCwMApnr.js +6 -0
  41. package/dist/package-BCwMApnr.js.map +1 -0
  42. package/dist/{package-BapVyQ-w.cjs → package-DPe5CA4S.cjs} +2 -2
  43. package/dist/package-DPe5CA4S.cjs.map +1 -0
  44. package/dist/{agent-sdYBBgrd.js → run-BQ3Qj0xB.js} +46 -43
  45. package/dist/run-BQ3Qj0xB.js.map +1 -0
  46. package/dist/run-BQzoaxjR.js +32 -0
  47. package/dist/run-BQzoaxjR.js.map +1 -0
  48. package/dist/run-CGf0KEts.js +51 -0
  49. package/dist/run-CGf0KEts.js.map +1 -0
  50. package/dist/{init-CZ5Xq2Hd.cjs → run-C_NMctua.cjs} +107 -149
  51. package/dist/run-C_NMctua.cjs.map +1 -0
  52. package/dist/run-CkTpemme.cjs +52 -0
  53. package/dist/run-CkTpemme.cjs.map +1 -0
  54. package/dist/run-Cl4SrSob.cjs +33 -0
  55. package/dist/run-Cl4SrSob.cjs.map +1 -0
  56. package/dist/{agent-B4cAAab2.cjs → run-D-s2LdlW.cjs} +46 -43
  57. package/dist/run-D-s2LdlW.cjs.map +1 -0
  58. package/dist/{init-eNRlotJK.js → run-D8dCWepS.js} +107 -149
  59. package/dist/run-D8dCWepS.js.map +1 -0
  60. package/dist/run-DaV_NiKR.js +1509 -0
  61. package/dist/run-DaV_NiKR.js.map +1 -0
  62. package/dist/run-UWQ9wImP.cjs +1512 -0
  63. package/dist/run-UWQ9wImP.cjs.map +1 -0
  64. package/dist/{shell-DLzN4fRo.js → shell-BrqyJdB7.js} +2 -2
  65. package/dist/{shell-DLzN4fRo.js.map → shell-BrqyJdB7.js.map} +1 -1
  66. package/dist/{shell-475fQKaX.cjs → shell-Lh-vLWwH.cjs} +2 -2
  67. package/dist/{shell-475fQKaX.cjs.map → shell-Lh-vLWwH.cjs.map} +1 -1
  68. package/dist/validate-BHc3lUKB.js +26 -0
  69. package/dist/validate-BHc3lUKB.js.map +1 -0
  70. package/dist/validate-CqRqJxmQ.cjs +26 -0
  71. package/dist/validate-CqRqJxmQ.cjs.map +1 -0
  72. package/package.json +16 -15
  73. package/src/commands/agent/start.ts +10 -7
  74. package/src/commands/agent.ts +3 -1
  75. package/src/commands/generate.ts +21 -13
  76. package/src/commands/init.ts +34 -3
  77. package/src/commands/mcp.ts +28 -4
  78. package/src/commands/validate.ts +6 -4
  79. package/src/constants.ts +3 -74
  80. package/src/index.ts +6 -4
  81. package/src/loggers/clackLogger.ts +137 -178
  82. package/src/loggers/plainLogger.ts +49 -102
  83. package/src/loggers/types.ts +6 -1
  84. package/src/loggers/utils.ts +141 -26
  85. package/src/runners/agent/run.ts +113 -0
  86. package/src/runners/agent/utils.ts +98 -0
  87. package/src/runners/generate/run.ts +404 -0
  88. package/src/runners/generate/utils.ts +219 -0
  89. package/src/runners/init/run.ts +212 -0
  90. package/src/{utils/packageManager.ts → runners/init/utils.ts} +12 -2
  91. package/src/runners/mcp/run.ts +37 -0
  92. package/src/runners/validate/run.ts +63 -0
  93. package/dist/agent-B4cAAab2.cjs.map +0 -1
  94. package/dist/agent-CR6Z96og.js +0 -56
  95. package/dist/agent-CR6Z96og.js.map +0 -1
  96. package/dist/agent-Dmxzqg4d.cjs +0 -58
  97. package/dist/agent-Dmxzqg4d.cjs.map +0 -1
  98. package/dist/agent-sdYBBgrd.js.map +0 -1
  99. package/dist/constants-CnDXa1R6.cjs +0 -148
  100. package/dist/constants-CnDXa1R6.cjs.map +0 -1
  101. package/dist/constants-aL3CP_Wq.js +0 -95
  102. package/dist/constants-aL3CP_Wq.js.map +0 -1
  103. package/dist/generate-B1Pa2ho-.cjs +0 -1756
  104. package/dist/generate-B1Pa2ho-.cjs.map +0 -1
  105. package/dist/generate-BDGOOsBM.cjs +0 -65
  106. package/dist/generate-BDGOOsBM.cjs.map +0 -1
  107. package/dist/generate-CNrRLY4n.js +0 -1753
  108. package/dist/generate-CNrRLY4n.js.map +0 -1
  109. package/dist/generate-DuhxPLGr.js +0 -66
  110. package/dist/generate-DuhxPLGr.js.map +0 -1
  111. package/dist/init-CZ5Xq2Hd.cjs.map +0 -1
  112. package/dist/init-CnZXHrbq.js +0 -25
  113. package/dist/init-CnZXHrbq.js.map +0 -1
  114. package/dist/init-NYJSZJSb.cjs +0 -25
  115. package/dist/init-NYJSZJSb.cjs.map +0 -1
  116. package/dist/init-eNRlotJK.js.map +0 -1
  117. package/dist/mcp-CYOgxB82.cjs +0 -47
  118. package/dist/mcp-CYOgxB82.cjs.map +0 -1
  119. package/dist/mcp-CdFWyrwi.cjs +0 -16
  120. package/dist/mcp-CdFWyrwi.cjs.map +0 -1
  121. package/dist/mcp-DhSxuDMD.js +0 -16
  122. package/dist/mcp-DhSxuDMD.js.map +0 -1
  123. package/dist/mcp-DmJm3TrU.js +0 -46
  124. package/dist/mcp-DmJm3TrU.js.map +0 -1
  125. package/dist/package-BapVyQ-w.cjs.map +0 -1
  126. package/dist/package-DyJE-qNq.js +0 -6
  127. package/dist/package-DyJE-qNq.js.map +0 -1
  128. package/dist/telemetry-DN95_2pF.cjs +0 -282
  129. package/dist/telemetry-DN95_2pF.cjs.map +0 -1
  130. package/dist/telemetry-LgT_sdPe.js +0 -245
  131. package/dist/telemetry-LgT_sdPe.js.map +0 -1
  132. package/dist/validate-C6npXzel.cjs +0 -25
  133. package/dist/validate-C6npXzel.cjs.map +0 -1
  134. package/dist/validate-kLJoT_hi.js +0 -33
  135. package/dist/validate-kLJoT_hi.js.map +0 -1
  136. package/dist/validate-n38Rh-Y7.js +0 -25
  137. package/dist/validate-n38Rh-Y7.js.map +0 -1
  138. package/dist/validate-yKKzqEZ5.cjs +0 -34
  139. package/dist/validate-yKKzqEZ5.cjs.map +0 -1
  140. package/src/loggers/fileSystemLogger.ts +0 -138
  141. package/src/loggers/githubActionsLogger.ts +0 -379
  142. package/src/runners/agent.ts +0 -155
  143. package/src/runners/generate.ts +0 -333
  144. package/src/runners/init.ts +0 -296
  145. package/src/runners/mcp.ts +0 -51
  146. package/src/runners/validate.ts +0 -39
  147. package/src/types.ts +0 -11
  148. package/src/utils/Writables.ts +0 -17
  149. package/src/utils/executeHooks.ts +0 -45
  150. package/src/utils/flags.ts +0 -9
  151. package/src/utils/getConfig.ts +0 -10
  152. package/src/utils/getCosmiConfig.ts +0 -80
  153. package/src/utils/getSummary.ts +0 -68
  154. package/src/utils/runHook.ts +0 -91
  155. package/src/utils/telemetry.ts +0 -273
  156. package/src/utils/watcher.ts +0 -19
  157. /package/dist/{chunk-ByKO4r7w.cjs → chunk-Bx3C2hgW.cjs} +0 -0
@@ -0,0 +1,1509 @@
1
+ import "./chunk-CRm0XQPb.js";
2
+ import { n as toCause, r as toError } from "./errors-CoxrNXaA.js";
3
+ import { n as tokenize } from "./shell-BrqyJdB7.js";
4
+ import { t as version } from "./package-BCwMApnr.js";
5
+ import { r as WATCHER_IGNORED_PATHS, t as KUBB_NPM_PACKAGE_URL } from "./constants-84a47qA-.js";
6
+ import { styleText } from "node:util";
7
+ import { EventEmitter } from "node:events";
8
+ import { createHash } from "node:crypto";
9
+ import { spawn } from "node:child_process";
10
+ import { existsSync } from "node:fs";
11
+ import path, { relative } from "node:path";
12
+ import { promises } from "node:dns";
13
+ import { Diagnostics, Telemetry, cliReporter, createKubb, defineLogger, logLevel, selectReporters } from "@kubb/core";
14
+ import process$1 from "node:process";
15
+ import * as clack from "@clack/prompts";
16
+ import { cosmiconfig } from "cosmiconfig";
17
+ import { createJiti } from "jiti";
18
+ import { NonZeroExitError, x } from "tinyexec";
19
+ //#region ../../internals/utils/src/asyncEventEmitter.ts
20
+ /**
21
+ * Typed `EventEmitter` that awaits all async listeners before resolving.
22
+ * Wraps Node's `EventEmitter` with full TypeScript event-map inference.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const emitter = new AsyncEventEmitter<{ build: [name: string] }>()
27
+ * emitter.on('build', async (name) => { console.log(name) })
28
+ * await emitter.emit('build', 'petstore') // all listeners awaited
29
+ * ```
30
+ */
31
+ var AsyncEventEmitter = class {
32
+ /**
33
+ * Maximum number of listeners per event before Node emits a memory-leak warning.
34
+ * @default 10
35
+ */
36
+ constructor(maxListener = 10) {
37
+ this.#emitter.setMaxListeners(maxListener);
38
+ }
39
+ #emitter = new EventEmitter();
40
+ /**
41
+ * Emits `eventName` and awaits all registered listeners sequentially.
42
+ * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * await emitter.emit('build', 'petstore')
47
+ * ```
48
+ */
49
+ emit(eventName, ...eventArgs) {
50
+ const listeners = this.#emitter.listeners(eventName);
51
+ if (listeners.length === 0) return;
52
+ return this.#emitAll(eventName, listeners, eventArgs);
53
+ }
54
+ async #emitAll(eventName, listeners, eventArgs) {
55
+ for (const listener of listeners) try {
56
+ await listener(...eventArgs);
57
+ } catch (err) {
58
+ let serializedArgs;
59
+ try {
60
+ serializedArgs = JSON.stringify(eventArgs);
61
+ } catch {
62
+ serializedArgs = String(eventArgs);
63
+ }
64
+ throw new Error(`Error in async listener for "${eventName}" with eventArgs ${serializedArgs}`, { cause: toError(err) });
65
+ }
66
+ }
67
+ /**
68
+ * Registers a persistent listener for `eventName`.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * emitter.on('build', async (name) => { console.log(name) })
73
+ * ```
74
+ */
75
+ on(eventName, handler) {
76
+ this.#emitter.on(eventName, handler);
77
+ }
78
+ /**
79
+ * Registers a one-shot listener that removes itself after the first invocation.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * emitter.onOnce('build', async (name) => { console.log(name) })
84
+ * ```
85
+ */
86
+ onOnce(eventName, handler) {
87
+ const wrapper = (...args) => {
88
+ this.off(eventName, wrapper);
89
+ return handler(...args);
90
+ };
91
+ this.on(eventName, wrapper);
92
+ }
93
+ /**
94
+ * Removes a previously registered listener.
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * emitter.off('build', handler)
99
+ * ```
100
+ */
101
+ off(eventName, handler) {
102
+ this.#emitter.off(eventName, handler);
103
+ }
104
+ /**
105
+ * Returns the number of listeners registered for `eventName`.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * emitter.on('build', handler)
110
+ * emitter.listenerCount('build') // 1
111
+ * ```
112
+ */
113
+ listenerCount(eventName) {
114
+ return this.#emitter.listenerCount(eventName);
115
+ }
116
+ /**
117
+ * Raises or lowers the per-event listener ceiling before Node warns about a memory leak.
118
+ * Set this above the expected listener count when many listeners attach by design.
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * emitter.setMaxListeners(40)
123
+ * ```
124
+ */
125
+ setMaxListeners(max) {
126
+ this.#emitter.setMaxListeners(max);
127
+ }
128
+ /**
129
+ * Returns the current per-event listener ceiling.
130
+ */
131
+ getMaxListeners() {
132
+ return this.#emitter.getMaxListeners();
133
+ }
134
+ /**
135
+ * Removes all listeners from every event channel.
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * emitter.removeAll()
140
+ * ```
141
+ */
142
+ removeAll() {
143
+ this.#emitter.removeAllListeners();
144
+ }
145
+ };
146
+ //#endregion
147
+ //#region ../../internals/utils/src/time.ts
148
+ /**
149
+ * Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.
150
+ * Rounds to 2 decimal places for sub-millisecond precision without noise.
151
+ *
152
+ * @example
153
+ * ```ts
154
+ * const start = process.hrtime()
155
+ * doWork()
156
+ * getElapsedMs(start) // 42.35
157
+ * ```
158
+ */
159
+ function getElapsedMs(hrStart) {
160
+ const [seconds, nanoseconds] = process.hrtime(hrStart);
161
+ const ms = seconds * 1e3 + nanoseconds / 1e6;
162
+ return Math.round(ms * 100) / 100;
163
+ }
164
+ /**
165
+ * Converts a millisecond duration into a human-readable string (`ms`, `s`, or `m s`).
166
+ *
167
+ * @example
168
+ * ```ts
169
+ * formatMs(250) // '250ms'
170
+ * formatMs(1500) // '1.50s'
171
+ * formatMs(90000) // '1m 30.0s'
172
+ * ```
173
+ */
174
+ function formatMs(ms) {
175
+ if (ms >= 6e4) return `${Math.floor(ms / 6e4)}m ${(ms % 6e4 / 1e3).toFixed(1)}s`;
176
+ if (ms >= 1e3) return `${(ms / 1e3).toFixed(2)}s`;
177
+ return `${Math.round(ms)}ms`;
178
+ }
179
+ /**
180
+ * Formats the elapsed time since `hrStart` as a human-readable string.
181
+ *
182
+ * @example
183
+ * ```ts
184
+ * const start = process.hrtime()
185
+ * doWork()
186
+ * formatHrtime(start) // '1.50s'
187
+ * ```
188
+ */
189
+ function formatHrtime(hrStart) {
190
+ return formatMs(getElapsedMs(hrStart));
191
+ }
192
+ //#endregion
193
+ //#region ../../internals/utils/src/colors.ts
194
+ /**
195
+ * Parses a CSS hex color string (`#RGB`) into its RGB channels.
196
+ * Falls back to `255` for any channel that cannot be parsed.
197
+ */
198
+ function parseHex(color) {
199
+ const int = Number.parseInt(color.replace("#", ""), 16);
200
+ return Number.isNaN(int) ? {
201
+ r: 255,
202
+ g: 255,
203
+ b: 255
204
+ } : {
205
+ r: int >> 16 & 255,
206
+ g: int >> 8 & 255,
207
+ b: int & 255
208
+ };
209
+ }
210
+ /**
211
+ * Returns a function that wraps a string in a 24-bit ANSI true-color escape sequence
212
+ * for the given hex color.
213
+ */
214
+ function hex(color) {
215
+ const { r, g, b } = parseHex(color);
216
+ return (text) => `\x1b[38;2;${r};${g};${b}m${text}\x1b[0m`;
217
+ }
218
+ function gradient(colorStops, text) {
219
+ const chars = text.split("");
220
+ return chars.map((char, i) => {
221
+ const t = chars.length <= 1 ? 0 : i / (chars.length - 1);
222
+ const seg = Math.min(Math.floor(t * (colorStops.length - 1)), colorStops.length - 2);
223
+ const lt = t * (colorStops.length - 1) - seg;
224
+ const from = parseHex(colorStops[seg]);
225
+ const to = parseHex(colorStops[seg + 1]);
226
+ return `\x1b[38;2;${Math.round(from.r + (to.r - from.r) * lt)};${Math.round(from.g + (to.g - from.g) * lt)};${Math.round(from.b + (to.b - from.b) * lt)}m${char}\x1b[0m`;
227
+ }).join("");
228
+ }
229
+ /**
230
+ * ANSI color functions for each part of the Kubb mascot illustration.
231
+ */
232
+ const palette = {
233
+ /**
234
+ * Top cap of the skittle.
235
+ */
236
+ lid: hex("#F55A17"),
237
+ /**
238
+ * Upper wood body.
239
+ */
240
+ woodTop: hex("#F5A217"),
241
+ /**
242
+ * Middle wood body.
243
+ */
244
+ woodMid: hex("#F58517"),
245
+ /**
246
+ * Base wood body.
247
+ */
248
+ woodBase: hex("#B45309"),
249
+ /**
250
+ * Eye whites.
251
+ */
252
+ eye: hex("#FFFFFF"),
253
+ /**
254
+ * Highlight accent.
255
+ */
256
+ highlight: hex("#adadc6"),
257
+ /**
258
+ * Cheek blush.
259
+ */
260
+ blush: hex("#FDA4AF")
261
+ };
262
+ /**
263
+ * Generates the Kubb mascot welcome banner as an ANSI-colored string.
264
+ *
265
+ * @example
266
+ * ```ts
267
+ * console.log(getIntro({ title: 'kubb.config.ts', description: 'generating…', version: '5.0.0', areEyesOpen: true }))
268
+ * ```
269
+ */
270
+ function getIntro({ title, description, version, areEyesOpen }) {
271
+ const kubbVersion = gradient([
272
+ "#F58517",
273
+ "#F5A217",
274
+ "#F55A17"
275
+ ], `KUBB v${version}`);
276
+ const eyeTop = areEyesOpen ? palette.eye("█▀█") : palette.eye("───");
277
+ const eyeBottom = areEyesOpen ? palette.eye("▀▀▀") : palette.eye("───");
278
+ return `
279
+ ${palette.lid("▄▄▄▄▄▄▄▄▄▄▄▄▄")}
280
+ ${palette.woodTop("█ ")}${palette.highlight("▄▄")}${palette.woodTop(" ")}${palette.highlight("▄▄")}${palette.woodTop(" █")} ${kubbVersion}
281
+ ${palette.woodMid("█ ")}${eyeTop}${palette.woodMid(" ")}${eyeTop}${palette.woodMid(" █")} ${styleText("gray", title)}
282
+ ${palette.woodMid("█ ")}${eyeBottom}${palette.woodMid(" ")}${palette.blush("◡")}${palette.woodMid(" ")}${eyeBottom}${palette.woodMid(" █")} ${styleText("yellow", "➜")} ${styleText("white", description)}
283
+ ${palette.woodBase("▀▀▀▀▀▀▀▀▀▀▀▀▀")}
284
+ `;
285
+ }
286
+ /**
287
+ * Formats a millisecond duration with a threshold-based ANSI color.
288
+ * `≤ 500 ms` → green · `≤ 1 000 ms` → yellow · `> 1 000 ms` → red.
289
+ *
290
+ * @example
291
+ * ```ts
292
+ * formatMsWithColor(200) // '\x1b[32m200ms\x1b[39m'
293
+ * formatMsWithColor(800) // '\x1b[33m800ms\x1b[39m'
294
+ * formatMsWithColor(1500) // '\x1b[31m1.50s\x1b[39m'
295
+ * ```
296
+ */
297
+ function formatMsWithColor(ms) {
298
+ const formatted = formatMs(ms);
299
+ if (ms <= 500) return styleText("green", formatted);
300
+ if (ms <= 1e3) return styleText("yellow", formatted);
301
+ return styleText("red", formatted);
302
+ }
303
+ //#endregion
304
+ //#region ../../internals/utils/src/env.ts
305
+ /**
306
+ * Returns `true` when the process is running in a CI environment.
307
+ * Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,
308
+ * TeamCity, Buildkite, and Azure Pipelines.
309
+ *
310
+ * @example
311
+ * ```ts
312
+ * if (isCIEnvironment()) {
313
+ * logger.level = 'error'
314
+ * }
315
+ * ```
316
+ */
317
+ function isCIEnvironment() {
318
+ return !!(process.env.CI || process.env.GITHUB_ACTIONS || process.env.GITLAB_CI || process.env.BITBUCKET_BUILD_NUMBER || process.env.JENKINS_URL || process.env.CIRCLECI || process.env.TRAVIS || process.env.TEAMCITY_VERSION || process.env.BUILDKITE || process.env.TF_BUILD);
319
+ }
320
+ /**
321
+ * Returns `true` when the process has an interactive TTY with a valid terminal
322
+ * width and is not running in CI.
323
+ *
324
+ * Some IDE-embedded terminals report `isTTY = true` but set `columns` to `0`,
325
+ * which breaks clack's box-drawing helpers (they call `String.prototype.repeat`
326
+ * with a negative count and throw a `RangeError`). We therefore require a
327
+ * positive column count before declaring the TTY usable.
328
+ *
329
+ * @example
330
+ * ```ts
331
+ * if (canUseTTY()) {
332
+ * renderProgressBar()
333
+ * }
334
+ * ```
335
+ */
336
+ function canUseTTY() {
337
+ return !!process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment();
338
+ }
339
+ //#endregion
340
+ //#region ../../internals/utils/src/formatters.ts
341
+ /**
342
+ * CLI command descriptors for each supported code formatter.
343
+ *
344
+ * Each entry contains the executable `command`, an `args` factory that maps an
345
+ * output path to the correct argument list, and an `errorMessage` shown when
346
+ * the formatter is not found.
347
+ */
348
+ const formatters = {
349
+ prettier: {
350
+ command: "prettier",
351
+ args: (outputPath) => [
352
+ "--ignore-unknown",
353
+ "--write",
354
+ outputPath
355
+ ],
356
+ errorMessage: "Prettier not found"
357
+ },
358
+ biome: {
359
+ command: "biome",
360
+ args: (outputPath) => [
361
+ "format",
362
+ "--write",
363
+ outputPath
364
+ ],
365
+ errorMessage: "Biome not found"
366
+ },
367
+ oxfmt: {
368
+ command: "oxfmt",
369
+ args: (outputPath) => [outputPath],
370
+ errorMessage: "Oxfmt not found"
371
+ }
372
+ };
373
+ async function isFormatterAvailable(formatter) {
374
+ return new Promise((resolve) => {
375
+ const child = spawn(formatter, ["--version"], { stdio: "ignore" });
376
+ child.on("close", (code) => resolve(code === 0));
377
+ child.on("error", () => resolve(false));
378
+ });
379
+ }
380
+ /**
381
+ * Detects the first available code formatter on the current system.
382
+ *
383
+ * - Checks in preference order: `oxfmt`, `biome`, `prettier`.
384
+ * - Returns `null` when none are found.
385
+ *
386
+ * @example
387
+ * ```ts
388
+ * const formatter = await detectFormatter()
389
+ * if (formatter) {
390
+ * console.log(`Using ${formatter} for formatting`)
391
+ * }
392
+ * ```
393
+ */
394
+ async function detectFormatter() {
395
+ const formatterNames = new Set([
396
+ "oxfmt",
397
+ "biome",
398
+ "prettier"
399
+ ]);
400
+ for (const formatter of formatterNames) if (await isFormatterAvailable(formatter)) return formatter;
401
+ return null;
402
+ }
403
+ //#endregion
404
+ //#region ../../internals/utils/src/linters.ts
405
+ /**
406
+ * CLI command descriptors for each supported linter.
407
+ *
408
+ * Each entry contains the executable `command`, an `args` factory that maps an
409
+ * output path to the correct argument list, and an `errorMessage` shown when
410
+ * the linter is not found.
411
+ */
412
+ const linters = {
413
+ eslint: {
414
+ command: "eslint",
415
+ args: (outputPath) => [outputPath, "--fix"],
416
+ errorMessage: "Eslint not found"
417
+ },
418
+ biome: {
419
+ command: "biome",
420
+ args: (outputPath) => [
421
+ "lint",
422
+ "--fix",
423
+ outputPath
424
+ ],
425
+ errorMessage: "Biome not found"
426
+ },
427
+ oxlint: {
428
+ command: "oxlint",
429
+ args: (outputPath) => [
430
+ "--fix",
431
+ "--no-ignore",
432
+ outputPath
433
+ ],
434
+ errorMessage: "Oxlint not found"
435
+ }
436
+ };
437
+ async function isLinterAvailable(linter) {
438
+ return new Promise((resolve) => {
439
+ const child = spawn(linter, ["--version"], { stdio: "ignore" });
440
+ child.on("close", (code) => resolve(code === 0));
441
+ child.on("error", () => resolve(false));
442
+ });
443
+ }
444
+ /**
445
+ * Detects the first available linter on the current system.
446
+ *
447
+ * - Checks in preference order: `oxlint`, `biome`, `eslint`.
448
+ * - Returns `null` when none are found.
449
+ *
450
+ * @example
451
+ * ```ts
452
+ * const linter = await detectLinter()
453
+ * if (linter) {
454
+ * console.log(`Using ${linter} for linting`)
455
+ * }
456
+ * ```
457
+ */
458
+ async function detectLinter() {
459
+ const linterNames = new Set([
460
+ "oxlint",
461
+ "biome",
462
+ "eslint"
463
+ ]);
464
+ for (const linter of linterNames) if (await isLinterAvailable(linter)) return linter;
465
+ return null;
466
+ }
467
+ //#endregion
468
+ //#region ../../internals/utils/src/network.ts
469
+ /**
470
+ * Well-known stable domains used as DNS probes to check internet connectivity.
471
+ */
472
+ const TEST_DOMAINS = [
473
+ "dns.google.com",
474
+ "cloudflare.com",
475
+ "one.one.one.one"
476
+ ];
477
+ /**
478
+ * Returns `true` when the system has internet connectivity.
479
+ * Probes DNS resolution against well-known stable domains.
480
+ *
481
+ * @example
482
+ * ```ts
483
+ * if (await isOnline()) {
484
+ * await fetchLatestVersion()
485
+ * }
486
+ * ```
487
+ */
488
+ async function isOnline() {
489
+ for (const domain of TEST_DOMAINS) try {
490
+ await promises.resolve(domain);
491
+ return true;
492
+ } catch {}
493
+ return false;
494
+ }
495
+ /**
496
+ * Executes `fn` only when the system is online. Returns `null` when offline or on error.
497
+ *
498
+ * @example
499
+ * ```ts
500
+ * const version = await executeIfOnline(() => fetchLatestVersion('kubb'))
501
+ * // null when offline
502
+ * ```
503
+ */
504
+ async function executeIfOnline(fn) {
505
+ if (!await isOnline()) return null;
506
+ try {
507
+ return await fn();
508
+ } catch {
509
+ return null;
510
+ }
511
+ }
512
+ //#endregion
513
+ //#region src/loggers/clackLogger.ts
514
+ /**
515
+ * TTY logger with beautiful UI and progress indicators for local development.
516
+ */
517
+ const clackLogger = defineLogger({
518
+ name: "clack",
519
+ install(context, options) {
520
+ const logLevel$5 = options?.logLevel ?? logLevel.info;
521
+ const state = {
522
+ ...createProgressCounters(),
523
+ spinner: clack.spinner(),
524
+ isSpinning: false,
525
+ runningPlugins: /* @__PURE__ */ new Set(),
526
+ activeProgress: /* @__PURE__ */ new Map(),
527
+ activeHookLogs: /* @__PURE__ */ new Map()
528
+ };
529
+ function stopActiveProgress() {
530
+ for (const [, active] of state.activeProgress) {
531
+ if (active.interval) clearInterval(active.interval);
532
+ active.progressBar?.stop();
533
+ }
534
+ state.activeProgress.clear();
535
+ }
536
+ function reset() {
537
+ stopActiveProgress();
538
+ resetProgressCounters(state);
539
+ state.spinner = clack.spinner();
540
+ state.isSpinning = false;
541
+ state.runningPlugins.clear();
542
+ state.activeHookLogs.clear();
543
+ }
544
+ function pluginProgressText() {
545
+ const running = [...state.runningPlugins].map((name) => styleText("bold", name));
546
+ return getMessage(running.length > 0 ? `Generating ${running.join(", ")}` : "Generating plugins");
547
+ }
548
+ function showProgressStep() {
549
+ if (logLevel$5 <= logLevel.silent) return;
550
+ const line = buildProgressLine(state);
551
+ if (line) clack.log.step(getMessage(line));
552
+ }
553
+ function getMessage(message) {
554
+ return formatMessage(message, logLevel$5);
555
+ }
556
+ function onStep(event, message) {
557
+ context.on(event, () => {
558
+ if (logLevel$5 <= logLevel.silent) return;
559
+ clack.log.step(getMessage(message));
560
+ });
561
+ }
562
+ function startSpinner(text) {
563
+ state.spinner.start(text);
564
+ state.isSpinning = true;
565
+ }
566
+ function stopSpinner(text) {
567
+ if (!state.isSpinning) return;
568
+ state.spinner.stop(text);
569
+ state.isSpinning = false;
570
+ }
571
+ context.on("kubb:info", ({ message, info = "" }) => {
572
+ if (logLevel$5 <= logLevel.silent) return;
573
+ const text = getMessage([
574
+ styleText("blue", "ℹ"),
575
+ message,
576
+ info ? styleText("dim", info) : void 0
577
+ ].filter(Boolean).join(" "));
578
+ if (state.isSpinning) {
579
+ state.spinner.message(text);
580
+ return;
581
+ }
582
+ clack.log.info(text);
583
+ });
584
+ context.on("kubb:success", ({ message, info = "" }) => {
585
+ if (logLevel$5 <= logLevel.silent) return;
586
+ const text = getMessage([
587
+ styleText("blue", "✓"),
588
+ message,
589
+ logLevel$5 >= logLevel.info ? styleText("dim", info) : void 0
590
+ ].filter(Boolean).join(" "));
591
+ if (state.isSpinning) {
592
+ stopSpinner(text);
593
+ return;
594
+ }
595
+ clack.log.success(text);
596
+ });
597
+ context.on("kubb:warn", ({ message, info }) => {
598
+ if (logLevel$5 < logLevel.warn) return;
599
+ const text = getMessage([
600
+ styleText("yellow", "⚠"),
601
+ message,
602
+ logLevel$5 >= logLevel.info && info ? styleText("dim", info) : void 0
603
+ ].filter(Boolean).join(" "));
604
+ clack.log.warn(text);
605
+ });
606
+ context.on("kubb:error", ({ error }) => {
607
+ const caused = toCause(error);
608
+ const text = [styleText("red", "✗"), error.message].join(" ");
609
+ if (state.isSpinning) {
610
+ stopSpinner(getMessage(text));
611
+ return;
612
+ }
613
+ clack.log.error(getMessage(text));
614
+ if (logLevel$5 >= logLevel.verbose && error.stack) {
615
+ const frames = error.stack.split("\n").slice(1, 4);
616
+ for (const frame of frames) clack.log.message(getMessage(styleText("dim", frame.trim())));
617
+ if (caused?.stack) {
618
+ clack.log.message(styleText("dim", `└─ caused by ${caused.message}`));
619
+ const frames = caused.stack.split("\n").slice(1, 4);
620
+ for (const frame of frames) clack.log.message(getMessage(` ${styleText("dim", frame.trim())}`));
621
+ }
622
+ }
623
+ });
624
+ context.on("kubb:diagnostic", ({ diagnostic }) => {
625
+ if (logLevel$5 <= logLevel.silent && diagnostic.severity !== "error") return;
626
+ stopSpinner();
627
+ stopActiveProgress();
628
+ if (Diagnostics.isUpdate(diagnostic)) {
629
+ clack.box(`\`v${diagnostic.currentVersion}\` → \`v${diagnostic.latestVersion}\`
630
+ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
631
+ width: "auto",
632
+ formatBorder: (s) => styleText("yellow", s),
633
+ rounded: true,
634
+ withGuide: false,
635
+ contentAlign: "center",
636
+ titleAlign: "center"
637
+ });
638
+ return;
639
+ }
640
+ const { symbol, headline, details } = Diagnostics.format(diagnostic);
641
+ clack.log.message([headline, ...details], { symbol });
642
+ });
643
+ context.on("kubb:lifecycle:start", async ({ version }) => {
644
+ console.log(`\n${getIntro({
645
+ title: "The meta framework for code generation",
646
+ description: "Ready to start",
647
+ version,
648
+ areEyesOpen: true
649
+ })}\n`);
650
+ reset();
651
+ });
652
+ context.on("kubb:config:start", () => {
653
+ if (logLevel$5 <= logLevel.silent) return;
654
+ const text = getMessage("Configuration started");
655
+ clack.intro(text);
656
+ startSpinner(getMessage("Configuration loading"));
657
+ });
658
+ context.on("kubb:config:end", () => {
659
+ if (logLevel$5 <= logLevel.silent) return;
660
+ const text = getMessage("Configuration completed");
661
+ clack.outro(text);
662
+ });
663
+ context.on("kubb:generation:start", ({ config }) => {
664
+ reset();
665
+ state.totalPlugins = config.plugins?.length ?? 0;
666
+ if (logLevel$5 <= logLevel.silent) return;
667
+ const text = getMessage(["Generation started", config.name ? `for ${styleText("dim", config.name)}` : void 0].filter(Boolean).join(" "));
668
+ clack.intro(text);
669
+ });
670
+ context.on("kubb:plugin:start", ({ plugin }) => {
671
+ if (logLevel$5 <= logLevel.silent) return;
672
+ stopSpinner();
673
+ state.runningPlugins.add(plugin.name);
674
+ const active = state.activeProgress.get("plugins");
675
+ if (active) {
676
+ active.progressBar.advance(0, pluginProgressText());
677
+ return;
678
+ }
679
+ const progressBar = clack.progress({
680
+ style: "block",
681
+ max: Math.max(state.totalPlugins, 1),
682
+ size: 30
683
+ });
684
+ progressBar.start(pluginProgressText());
685
+ progressBar.advance(state.completedPlugins + state.failedPlugins, pluginProgressText());
686
+ state.activeProgress.set("plugins", { progressBar });
687
+ });
688
+ context.on("kubb:plugin:end", ({ plugin, success }) => {
689
+ stopSpinner();
690
+ const active = state.activeProgress.get("plugins");
691
+ if (!active || logLevel$5 === logLevel.silent) return;
692
+ state.runningPlugins.delete(plugin.name);
693
+ recordPluginResult(state, success);
694
+ active.progressBar.advance(1, pluginProgressText());
695
+ if (state.runningPlugins.size === 0) {
696
+ active.progressBar.stop(getMessage("Plugins generated"));
697
+ state.activeProgress.delete("plugins");
698
+ showProgressStep();
699
+ }
700
+ });
701
+ context.on("kubb:files:processing:start", ({ files }) => {
702
+ if (logLevel$5 <= logLevel.silent) return;
703
+ stopSpinner();
704
+ state.totalFiles = files.length;
705
+ state.processedFiles = 0;
706
+ const text = `Writing ${files.length} files`;
707
+ const progressBar = clack.progress({
708
+ style: "block",
709
+ max: files.length,
710
+ size: 30
711
+ });
712
+ context.emit("kubb:info", { message: text });
713
+ progressBar.start(getMessage(text));
714
+ state.activeProgress.set("files", { progressBar });
715
+ });
716
+ context.on("kubb:files:processing:update", ({ files }) => {
717
+ if (logLevel$5 <= logLevel.silent) return;
718
+ stopSpinner();
719
+ const active = state.activeProgress.get("files");
720
+ for (const { file, config } of files) {
721
+ state.processedFiles++;
722
+ if (active) active.progressBar.advance(void 0, `Writing ${relative(config.root, file.path)}`);
723
+ }
724
+ });
725
+ context.on("kubb:files:processing:end", () => {
726
+ if (logLevel$5 <= logLevel.silent) return;
727
+ stopSpinner();
728
+ const text = getMessage("Files written successfully");
729
+ const active = state.activeProgress.get("files");
730
+ if (!active) return;
731
+ active.progressBar.stop(text);
732
+ state.activeProgress.delete("files");
733
+ showProgressStep();
734
+ });
735
+ context.on("kubb:generation:end", ({ config }) => {
736
+ stopSpinner();
737
+ const text = getMessage(config.name ? `Generation completed for ${styleText("dim", config.name)}` : "Generation completed");
738
+ clack.outro(text);
739
+ });
740
+ onStep("kubb:format:start", "Formatting");
741
+ onStep("kubb:lint:start", "Linting");
742
+ onStep("kubb:hooks:start", "Running hooks");
743
+ context.on("kubb:hook:start", ({ id, command, args }) => {
744
+ if (logLevel$5 <= logLevel.silent || !id) return;
745
+ stopSpinner();
746
+ const title = getMessage(`Running ${styleText("dim", formatCommandWithArgs(command, args))}`);
747
+ const taskLog = clack.taskLog({ title });
748
+ state.activeHookLogs.set(id, {
749
+ taskLog,
750
+ hrStart: process$1.hrtime()
751
+ });
752
+ });
753
+ if (logLevel$5 > logLevel.silent) context.on("kubb:hook:line", ({ id, line }) => {
754
+ state.activeHookLogs.get(id)?.taskLog.message(styleText("dim", line));
755
+ });
756
+ context.on("kubb:hook:end", ({ id, command, args, success, error, stdout, stderr }) => {
757
+ if (!id) return;
758
+ if (logLevel$5 <= logLevel.silent) {
759
+ if (!success) {
760
+ if (stdout) console.log(stdout);
761
+ if (stderr) console.error(stderr);
762
+ }
763
+ return;
764
+ }
765
+ const active = state.activeHookLogs.get(id);
766
+ if (!active) return;
767
+ state.activeHookLogs.delete(id);
768
+ const commandWithArgs = formatCommandWithArgs(command, args);
769
+ const duration = formatMsWithColor(getElapsedMs(active.hrStart));
770
+ if (success) active.taskLog.success(getMessage(`${styleText("dim", commandWithArgs)} completed in ${duration}`));
771
+ else {
772
+ const reason = error?.message ? ` (${error.message})` : "";
773
+ active.taskLog.error(getMessage(`${styleText("dim", commandWithArgs)} failed${reason}`), { showLog: true });
774
+ }
775
+ });
776
+ context.on("kubb:lifecycle:end", () => {
777
+ reset();
778
+ });
779
+ }
780
+ });
781
+ //#endregion
782
+ //#region src/loggers/plainLogger.ts
783
+ /**
784
+ * Plain console adapter for non-TTY environments with simple `console.log` output.
785
+ */
786
+ const plainLogger = defineLogger({
787
+ name: "plain",
788
+ install(context, options) {
789
+ const logLevel$4 = options?.logLevel ?? logLevel.info;
790
+ const hookTimer = createHookTimer();
791
+ function getMessage(message) {
792
+ return formatMessage(message, logLevel$4);
793
+ }
794
+ function onStep(event, message) {
795
+ context.on(event, () => {
796
+ if (logLevel$4 <= logLevel.silent) return;
797
+ console.log(getMessage(message));
798
+ });
799
+ }
800
+ context.on("kubb:info", ({ message, info }) => {
801
+ if (logLevel$4 <= logLevel.silent) return;
802
+ const text = getMessage([
803
+ "ℹ",
804
+ message,
805
+ info
806
+ ].join(" "));
807
+ console.log(text);
808
+ });
809
+ context.on("kubb:success", ({ message, info = "" }) => {
810
+ if (logLevel$4 <= logLevel.silent) return;
811
+ const text = getMessage([
812
+ "✓",
813
+ message,
814
+ logLevel$4 >= logLevel.info ? info : void 0
815
+ ].filter(Boolean).join(" "));
816
+ console.log(text);
817
+ });
818
+ context.on("kubb:warn", ({ message, info }) => {
819
+ if (logLevel$4 < logLevel.warn) return;
820
+ const text = getMessage([
821
+ "⚠",
822
+ message,
823
+ logLevel$4 >= logLevel.info ? info : void 0
824
+ ].filter(Boolean).join(" "));
825
+ console.log(text);
826
+ });
827
+ context.on("kubb:error", ({ error }) => {
828
+ const caused = toCause(error);
829
+ const text = getMessage(["✗", error.message].join(" "));
830
+ console.log(text);
831
+ if (logLevel$4 >= logLevel.verbose && error.stack) {
832
+ const frames = error.stack.split("\n").slice(1, 4);
833
+ for (const frame of frames) console.log(getMessage(frame.trim()));
834
+ if (caused?.stack) {
835
+ console.log(`└─ caused by ${caused.message}`);
836
+ const frames = caused.stack.split("\n").slice(1, 4);
837
+ for (const frame of frames) console.log(getMessage(` ${frame.trim()}`));
838
+ }
839
+ }
840
+ });
841
+ context.on("kubb:diagnostic", ({ diagnostic }) => {
842
+ if (logLevel$4 <= logLevel.silent && diagnostic.severity !== "error") return;
843
+ console.log(getMessage(Diagnostics.formatLines(diagnostic).join("\n")));
844
+ });
845
+ context.on("kubb:lifecycle:start", ({ version }) => {
846
+ console.log(`Kubb CLI v${version}`);
847
+ });
848
+ onStep("kubb:config:start", "Configuration started");
849
+ onStep("kubb:config:end", "Configuration completed");
850
+ context.on("kubb:generation:start", () => {
851
+ const text = getMessage("Generation started");
852
+ console.log(text);
853
+ });
854
+ context.on("kubb:plugin:start", ({ plugin }) => {
855
+ if (logLevel$4 <= logLevel.silent) return;
856
+ const text = getMessage(`Generating ${plugin.name}`);
857
+ console.log(text);
858
+ });
859
+ context.on("kubb:plugin:end", ({ plugin, duration, success }) => {
860
+ if (logLevel$4 <= logLevel.silent) return;
861
+ const durationStr = formatMs(duration);
862
+ const text = getMessage(success ? `${plugin.name} completed in ${durationStr}` : `${plugin.name} failed in ${durationStr}`);
863
+ console.log(text);
864
+ });
865
+ context.on("kubb:files:processing:start", ({ files }) => {
866
+ if (logLevel$4 <= logLevel.silent) return;
867
+ const text = getMessage(`Writing ${files.length} files`);
868
+ console.log(text);
869
+ });
870
+ context.on("kubb:files:processing:update", ({ files }) => {
871
+ if (logLevel$4 <= logLevel.silent) return;
872
+ for (const { file, config } of files) console.log(getMessage(`Writing ${relative(config.root, file.path)}`));
873
+ });
874
+ context.on("kubb:files:processing:end", () => {
875
+ if (logLevel$4 <= logLevel.silent) return;
876
+ const text = getMessage("Files written successfully");
877
+ console.log(text);
878
+ });
879
+ context.on("kubb:generation:end", ({ config }) => {
880
+ const text = getMessage(config.name ? `Generation completed for ${config.name}` : "Generation completed");
881
+ console.log(text);
882
+ });
883
+ onStep("kubb:format:start", "Format started");
884
+ onStep("kubb:format:end", "Format completed");
885
+ onStep("kubb:lint:start", "Lint started");
886
+ onStep("kubb:lint:end", "Lint completed");
887
+ onStep("kubb:hooks:start", "Hooks started");
888
+ onStep("kubb:hooks:end", "Hooks completed");
889
+ context.on("kubb:hook:start", ({ id, command, args }) => {
890
+ if (logLevel$4 <= logLevel.silent) return;
891
+ if (id) hookTimer.start(id);
892
+ const commandWithArgs = formatCommandWithArgs(command, args);
893
+ console.log(getMessage(`Hook ${commandWithArgs} started`));
894
+ });
895
+ context.on("kubb:hook:end", ({ id, command, args, success, error, stdout, stderr }) => {
896
+ if (logLevel$4 <= logLevel.silent) return;
897
+ const ms = id ? hookTimer.end(id) : void 0;
898
+ const durationStr = ms !== void 0 ? ` in ${formatMs(ms)}` : "";
899
+ const commandWithArgs = formatCommandWithArgs(command, args);
900
+ if (success) console.log(getMessage(`✓ Hook ${commandWithArgs} completed${durationStr}`));
901
+ else {
902
+ if (stdout) console.log(stdout);
903
+ if (stderr) console.error(stderr);
904
+ const reason = error?.message ? ` (${error.message})` : "";
905
+ console.log(getMessage(`✗ Hook ${commandWithArgs} failed${durationStr}${reason}`));
906
+ }
907
+ });
908
+ }
909
+ });
910
+ //#endregion
911
+ //#region src/loggers/utils.ts
912
+ /**
913
+ * Optionally prefix a message with a [HH:MM:SS] timestamp when logLevel >= verbose.
914
+ * Shared across all logger adapters to avoid duplication.
915
+ */
916
+ function formatMessage(message, logLevel$3) {
917
+ if (logLevel$3 >= logLevel.verbose) return `${styleText("dim", `[${(/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", {
918
+ hour12: false,
919
+ hour: "2-digit",
920
+ minute: "2-digit",
921
+ second: "2-digit"
922
+ })}]`)} ${message}`;
923
+ return message;
924
+ }
925
+ /**
926
+ * Build the progress summary line shown by the clack logger.
927
+ * Returns null when there is nothing to display.
928
+ */
929
+ function buildProgressLine(state) {
930
+ const parts = [];
931
+ const duration = formatHrtime(state.hrStart);
932
+ if (state.totalPlugins > 0) {
933
+ const pluginStr = state.failedPlugins > 0 ? `Plugins ${styleText("green", state.completedPlugins.toString())}/${state.totalPlugins} ${styleText("red", `(${state.failedPlugins} failed)`)}` : `Plugins ${styleText("green", state.completedPlugins.toString())}/${state.totalPlugins}`;
934
+ parts.push(pluginStr);
935
+ }
936
+ if (state.totalFiles > 0) parts.push(`Files ${styleText("green", state.processedFiles.toString())}/${state.totalFiles}`);
937
+ if (parts.length === 0) return null;
938
+ parts.push(`${styleText("green", duration)} elapsed`);
939
+ return parts.join(styleText("dim", " | "));
940
+ }
941
+ /**
942
+ * Creates the per-run progress counters used by the clack logger.
943
+ */
944
+ function createProgressCounters() {
945
+ return {
946
+ totalPlugins: 0,
947
+ completedPlugins: 0,
948
+ failedPlugins: 0,
949
+ totalFiles: 0,
950
+ processedFiles: 0,
951
+ hrStart: process$1.hrtime()
952
+ };
953
+ }
954
+ /**
955
+ * Resets the progress counters in place at the start/end of a generation run.
956
+ */
957
+ function resetProgressCounters(state) {
958
+ state.totalPlugins = 0;
959
+ state.completedPlugins = 0;
960
+ state.failedPlugins = 0;
961
+ state.totalFiles = 0;
962
+ state.processedFiles = 0;
963
+ state.hrStart = process$1.hrtime();
964
+ }
965
+ /**
966
+ * Records a finished plugin against the progress counters.
967
+ */
968
+ function recordPluginResult(state, success) {
969
+ if (success) state.completedPlugins++;
970
+ else state.failedPlugins++;
971
+ }
972
+ /**
973
+ * Creates a {@link HookTimer} backed by a private `id → hrtime` map.
974
+ */
975
+ function createHookTimer() {
976
+ const starts = /* @__PURE__ */ new Map();
977
+ return {
978
+ start(id) {
979
+ starts.set(id, process$1.hrtime());
980
+ },
981
+ end(id) {
982
+ const hrStart = starts.get(id);
983
+ if (!hrStart) return;
984
+ starts.delete(id);
985
+ return getElapsedMs(hrStart);
986
+ },
987
+ clear() {
988
+ starts.clear();
989
+ }
990
+ };
991
+ }
992
+ /**
993
+ * Join a command and its optional args into a single display string.
994
+ * e.g. ("prettier", ["--write", "."]) → "prettier --write ."
995
+ */
996
+ function formatCommandWithArgs(command, args) {
997
+ return args?.length ? `${command} ${args.join(" ")}` : command;
998
+ }
999
+ function detectLogger() {
1000
+ if (canUseTTY()) return "clack";
1001
+ return "plain";
1002
+ }
1003
+ const logMapper = {
1004
+ clack: clackLogger,
1005
+ plain: plainLogger
1006
+ };
1007
+ /**
1008
+ * Bridges a {@link Reporter} onto the run's event emitter: calls `report` with each config's
1009
+ * {@link GenerationResult} on `kubb:generation:end`. The reporter never touches the emitter.
1010
+ */
1011
+ function installReporter(context, reporter, ctx) {
1012
+ context.on("kubb:generation:end", async ({ config, diagnostics = [], filesCreated = 0, status = "success", hrStart = process$1.hrtime() }) => {
1013
+ await reporter.report({
1014
+ config,
1015
+ diagnostics,
1016
+ filesCreated,
1017
+ status,
1018
+ hrStart
1019
+ }, ctx);
1020
+ });
1021
+ if (reporter.drain) context.on("kubb:lifecycle:end", () => reporter.drain?.(ctx));
1022
+ }
1023
+ /**
1024
+ * Installs the live logger (the TUI view) and the given reporters (the output). The reporters are
1025
+ * already selected by the caller (the CLI maps `--reporter` to names via `selectReporters`); this
1026
+ * only wires them. Loggers receive hook subprocess output through `kubb:hook:line` and the
1027
+ * `stdout`/`stderr` on `kubb:hook:end`, so nothing is returned here.
1028
+ *
1029
+ * Loggers and reporters are independent: the `cli` reporter also activates the env logger summary.
1030
+ * The `json` reporter owns stdout, so the live logger and the `cli` summary are suppressed whenever
1031
+ * `json` is among the reporters, even if `cli` is also listed.
1032
+ */
1033
+ async function setupReporters(context, { logLevel, reporters }) {
1034
+ const hasJson = reporters.some((reporter) => reporter.name === "json");
1035
+ const ctx = { logLevel };
1036
+ for (const reporter of reporters) {
1037
+ if (reporter.name === "cli") {
1038
+ if (hasJson) continue;
1039
+ const type = detectLogger();
1040
+ const logger = logMapper[type];
1041
+ if (!logger) throw new Error(`Unknown adapter type: ${type}`);
1042
+ await logger.install(context, { logLevel });
1043
+ }
1044
+ installReporter(context, reporter, ctx);
1045
+ }
1046
+ }
1047
+ //#endregion
1048
+ //#region src/runners/generate/utils.ts
1049
+ const jiti = createJiti(import.meta.url, {
1050
+ jsx: {
1051
+ runtime: "automatic",
1052
+ importSource: "@kubb/renderer-jsx"
1053
+ },
1054
+ moduleCache: false
1055
+ });
1056
+ const tsLoader = (configFile) => jiti.import(configFile, { default: true });
1057
+ const MODULE_NAME = "kubb";
1058
+ const BASE_SEARCH_PLACES = [
1059
+ "package.json",
1060
+ `.${MODULE_NAME}rc`,
1061
+ `.${MODULE_NAME}rc.json`,
1062
+ `.${MODULE_NAME}rc.yaml`,
1063
+ `.${MODULE_NAME}rc.yml`,
1064
+ `.${MODULE_NAME}rc.ts`,
1065
+ `.${MODULE_NAME}rc.mts`,
1066
+ `.${MODULE_NAME}rc.cts`,
1067
+ `.${MODULE_NAME}rc.js`,
1068
+ `.${MODULE_NAME}rc.mjs`,
1069
+ `.${MODULE_NAME}rc.cjs`,
1070
+ `${MODULE_NAME}.config.ts`,
1071
+ `${MODULE_NAME}.config.mts`,
1072
+ `${MODULE_NAME}.config.cts`,
1073
+ `${MODULE_NAME}.config.js`,
1074
+ `${MODULE_NAME}.config.mjs`,
1075
+ `${MODULE_NAME}.config.cjs`
1076
+ ];
1077
+ const SEARCH_PLACES = [
1078
+ "",
1079
+ ".config/",
1080
+ "configs/"
1081
+ ].flatMap((prefix) => BASE_SEARCH_PLACES.map((p) => `${prefix}${p}`));
1082
+ async function getCosmiConfig(configFile) {
1083
+ const explorer = cosmiconfig(MODULE_NAME, {
1084
+ cache: false,
1085
+ searchPlaces: SEARCH_PLACES,
1086
+ loaders: {
1087
+ ".ts": tsLoader,
1088
+ ".mts": tsLoader,
1089
+ ".cts": tsLoader
1090
+ }
1091
+ });
1092
+ let result;
1093
+ try {
1094
+ result = configFile ? await explorer.load(configFile) : await explorer.search();
1095
+ } catch (error) {
1096
+ throw new Error("Config failed loading", { cause: error });
1097
+ }
1098
+ if (!result?.config || result.isEmpty) throw new Error("Config not defined, create a kubb.config.js or pass through your config with the option --config");
1099
+ return result;
1100
+ }
1101
+ /**
1102
+ * Discovers the Kubb config via cosmiconfig and resolves it into a normalized array of configs.
1103
+ * Every config in the result is guaranteed to have a `plugins` array.
1104
+ */
1105
+ async function getConfigs({ configPath, input, watch, logLevel }) {
1106
+ const result = await getCosmiConfig(configPath);
1107
+ const cli = {
1108
+ config: configPath,
1109
+ input,
1110
+ watch,
1111
+ logLevel
1112
+ };
1113
+ const resolved = await (typeof result.config === "function" ? result.config(cli) : result.config);
1114
+ const userConfigs = Array.isArray(resolved) ? resolved : [resolved];
1115
+ return {
1116
+ configPath: result.filepath,
1117
+ configs: userConfigs.map((item) => ({
1118
+ ...item,
1119
+ plugins: item.plugins ?? []
1120
+ }))
1121
+ };
1122
+ }
1123
+ /**
1124
+ * Runs the `done` hooks defined in a Kubb config in sequence.
1125
+ */
1126
+ async function executeHooks({ configHooks, hooks }) {
1127
+ const commands = Array.isArray(configHooks.done) ? configHooks.done : [configHooks.done].filter(Boolean);
1128
+ for (const command of commands) {
1129
+ const [cmd, ...args] = tokenize(command);
1130
+ if (!cmd) continue;
1131
+ const hookId = createHash("sha256").update(command).digest("hex");
1132
+ const commandWithArgs = [cmd, ...args].join(" ");
1133
+ await hooks.emit("kubb:hook:start", {
1134
+ id: hookId,
1135
+ command: cmd,
1136
+ args
1137
+ });
1138
+ await runHook({
1139
+ id: hookId,
1140
+ command: cmd,
1141
+ args,
1142
+ commandWithArgs,
1143
+ hooks
1144
+ });
1145
+ }
1146
+ }
1147
+ async function runHook({ id, command, args, commandWithArgs, hooks }) {
1148
+ const emitEnd = (success, error, output) => hooks.emit("kubb:hook:end", {
1149
+ command,
1150
+ args,
1151
+ id,
1152
+ success,
1153
+ error,
1154
+ ...output
1155
+ });
1156
+ const stream = hooks.listenerCount("kubb:hook:line") > 0;
1157
+ try {
1158
+ const proc = x(command, [...args ?? []], {
1159
+ nodeOptions: { detached: process.platform !== "win32" },
1160
+ throwOnError: true
1161
+ });
1162
+ if (stream) for await (const line of proc) await hooks.emit("kubb:hook:line", {
1163
+ id,
1164
+ line
1165
+ });
1166
+ await proc;
1167
+ await hooks.emit("kubb:success", { message: `${styleText("dim", commandWithArgs)} successfully executed` });
1168
+ await emitEnd(true, null);
1169
+ } catch (err) {
1170
+ if (!(err instanceof NonZeroExitError)) {
1171
+ await emitEnd(false, toError(err));
1172
+ return;
1173
+ }
1174
+ const stderr = err.output?.stderr ?? "";
1175
+ const stdout = err.output?.stdout ?? "";
1176
+ await emitEnd(false, /* @__PURE__ */ new Error(`Hook execute failed: ${commandWithArgs}`), {
1177
+ stdout,
1178
+ stderr
1179
+ });
1180
+ }
1181
+ }
1182
+ /**
1183
+ * Starts a file watcher on the given paths and calls `cb` on any change.
1184
+ * Ignores `.git` and `node_modules` directories.
1185
+ */
1186
+ async function startWatcher(path, cb, log = {
1187
+ info: console.log,
1188
+ error: console.log
1189
+ }) {
1190
+ const { watch } = await import("chokidar");
1191
+ const watcher = watch(path, {
1192
+ ignorePermissionErrors: true,
1193
+ ignored: WATCHER_IGNORED_PATHS
1194
+ });
1195
+ process.once("SIGINT", () => {
1196
+ watcher.close();
1197
+ });
1198
+ process.once("SIGTERM", () => {
1199
+ watcher.close();
1200
+ });
1201
+ watcher.on("all", async (type, file) => {
1202
+ log.info(styleText("yellow", styleText("bold", `Change detected: ${type} ${file}`)));
1203
+ try {
1204
+ await cb(path);
1205
+ } catch (_e) {
1206
+ log.error(styleText("red", "Watcher failed"));
1207
+ }
1208
+ });
1209
+ }
1210
+ //#endregion
1211
+ //#region src/runners/generate/run.ts
1212
+ /**
1213
+ * Registers a one-shot `kubb:hook:end` listener for `hookId` BEFORE the caller emits `kubb:hook:start`,
1214
+ * avoiding the race where a synchronous emitter fires end before the listener is attached.
1215
+ */
1216
+ function waitForHookEnd(hooks, hookId, onSuccess, fallbackErrorMessage) {
1217
+ return new Promise((resolve, reject) => {
1218
+ const handler = (ctx) => {
1219
+ if (ctx.id !== hookId) return;
1220
+ hooks.off("kubb:hook:end", handler);
1221
+ if (!ctx.success) {
1222
+ reject(ctx.error ?? new Error(fallbackErrorMessage));
1223
+ return;
1224
+ }
1225
+ Promise.resolve(onSuccess()).then(resolve).catch(reject);
1226
+ };
1227
+ hooks.on("kubb:hook:end", handler);
1228
+ });
1229
+ }
1230
+ async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefix, noToolMessage, configName, outputPath, logLevel: logLevel$1, hooks, onStart, onEnd }) {
1231
+ await onStart();
1232
+ let resolvedTool = toolValue;
1233
+ if (resolvedTool === "auto") {
1234
+ const detected = await detect();
1235
+ if (!detected) await hooks.emit("kubb:warn", { message: noToolMessage });
1236
+ else {
1237
+ resolvedTool = detected;
1238
+ await hooks.emit("kubb:info", { message: `Auto-detected ${toolLabel}: ${styleText("dim", resolvedTool)}` });
1239
+ }
1240
+ }
1241
+ let toolError;
1242
+ if (resolvedTool && resolvedTool !== "auto" && resolvedTool in toolMap && existsSync(outputPath)) {
1243
+ const toolConfig = toolMap[resolvedTool];
1244
+ const hookId = createHash("sha256").update([configName, resolvedTool].filter(Boolean).join("-")).digest("hex");
1245
+ const successMessage = [
1246
+ `${successPrefix} with ${styleText("dim", resolvedTool)}`,
1247
+ logLevel$1 >= logLevel.info ? `on ${styleText("dim", outputPath)}` : void 0,
1248
+ "successfully"
1249
+ ].filter(Boolean).join(" ");
1250
+ try {
1251
+ const hookArgs = toolConfig.args(outputPath);
1252
+ const commandWithArgs = [toolConfig.command, ...hookArgs].join(" ");
1253
+ const hookEndPromise = waitForHookEnd(hooks, hookId, () => hooks.emit("kubb:success", { message: successMessage }), toolConfig.errorMessage);
1254
+ await hooks.emit("kubb:hook:start", {
1255
+ id: hookId,
1256
+ command: toolConfig.command,
1257
+ args: hookArgs
1258
+ });
1259
+ runHook({
1260
+ id: hookId,
1261
+ command: toolConfig.command,
1262
+ args: hookArgs,
1263
+ commandWithArgs,
1264
+ hooks
1265
+ }).catch(() => {});
1266
+ await hookEndPromise;
1267
+ } catch (caughtError) {
1268
+ toolError = toError(caughtError);
1269
+ }
1270
+ }
1271
+ await onEnd();
1272
+ if (toolError) throw toolError;
1273
+ }
1274
+ async function generate(options) {
1275
+ const { input, hooks, logLevel } = options;
1276
+ const hrStart = process$1.hrtime();
1277
+ const inputPath = input ?? (options.config.input && "path" in options.config.input ? options.config.input.path : void 0);
1278
+ const config = {
1279
+ ...options.config,
1280
+ input: inputPath ? {
1281
+ ...options.config.input,
1282
+ path: inputPath
1283
+ } : options.config.input,
1284
+ ...options.config.output
1285
+ };
1286
+ const kubb = createKubb(config, { hooks });
1287
+ await hooks.emit("kubb:generation:start", { config });
1288
+ await hooks.emit("kubb:info", {
1289
+ message: config.name ? `Setup generation ${styleText("bold", config.name)}` : "Setup generation",
1290
+ info: inputPath
1291
+ });
1292
+ await kubb.setup();
1293
+ await hooks.emit("kubb:info", {
1294
+ message: config.name ? `Build generation ${styleText("bold", config.name)}` : "Build generation",
1295
+ info: inputPath
1296
+ });
1297
+ const { files, diagnostics, driver } = await kubb.safeBuild();
1298
+ await hooks.emit("kubb:info", { message: "Load summary" });
1299
+ const telemetryPlugins = Array.from(driver.plugins.values(), (p) => ({
1300
+ name: p.name,
1301
+ options: p.options
1302
+ }));
1303
+ const reportTelemetry = (status) => Telemetry.send(Telemetry.build({
1304
+ command: "generate",
1305
+ kubbVersion: version,
1306
+ plugins: telemetryPlugins,
1307
+ hrStart,
1308
+ filesCreated: files.length,
1309
+ status
1310
+ }));
1311
+ for (const diagnostic of diagnostics) {
1312
+ if (!Diagnostics.isProblem(diagnostic)) continue;
1313
+ const unknown = Diagnostics.narrow(diagnostic, Diagnostics.code.unknown);
1314
+ if (unknown) await hooks.emit("kubb:error", { error: unknown.cause ?? new Error(unknown.message) });
1315
+ else await Diagnostics.emit(hooks, diagnostic);
1316
+ }
1317
+ if (Diagnostics.hasError(diagnostics)) {
1318
+ await hooks.emit("kubb:generation:end", {
1319
+ config,
1320
+ storage: kubb.storage,
1321
+ diagnostics,
1322
+ filesCreated: files.length,
1323
+ status: "failed",
1324
+ hrStart
1325
+ });
1326
+ await reportTelemetry("failed");
1327
+ return false;
1328
+ }
1329
+ const outputPath = path.resolve(config.root, config.output.path);
1330
+ const outputDiagnostics = [];
1331
+ const toolPasses = [config.output.format && {
1332
+ code: Diagnostics.code.formatFailed,
1333
+ toolValue: config.output.format,
1334
+ detect: detectFormatter,
1335
+ toolMap: formatters,
1336
+ toolLabel: "formatter",
1337
+ successPrefix: "Formatting",
1338
+ noToolMessage: "No formatter found (oxfmt, biome, or prettier). Skipping formatting.",
1339
+ onStart: () => hooks.emit("kubb:format:start"),
1340
+ onEnd: () => hooks.emit("kubb:format:end")
1341
+ }, config.output.lint && {
1342
+ code: Diagnostics.code.lintFailed,
1343
+ toolValue: config.output.lint,
1344
+ detect: detectLinter,
1345
+ toolMap: linters,
1346
+ toolLabel: "linter",
1347
+ successPrefix: "Linting",
1348
+ noToolMessage: "No linter found (oxlint, biome, or eslint). Skipping linting.",
1349
+ onStart: () => hooks.emit("kubb:lint:start"),
1350
+ onEnd: () => hooks.emit("kubb:lint:end")
1351
+ }].filter(Boolean);
1352
+ for (const { code, ...pass } of toolPasses) try {
1353
+ await runToolPass({
1354
+ ...pass,
1355
+ configName: config.name,
1356
+ outputPath,
1357
+ logLevel,
1358
+ hooks
1359
+ });
1360
+ } catch (caughtError) {
1361
+ const diagnostic = outputDiagnostic(code, pass.toolLabel, caughtError);
1362
+ outputDiagnostics.push(diagnostic);
1363
+ await Diagnostics.emit(hooks, diagnostic);
1364
+ }
1365
+ if (config.hooks) {
1366
+ await hooks.emit("kubb:hooks:start");
1367
+ const hookFailures = [];
1368
+ const onHookEnd = (ctx) => {
1369
+ if (!ctx.success) hookFailures.push(ctx.error ?? /* @__PURE__ */ new Error("Post-generate hook failed"));
1370
+ };
1371
+ hooks.on("kubb:hook:end", onHookEnd);
1372
+ try {
1373
+ await executeHooks({
1374
+ configHooks: config.hooks,
1375
+ hooks
1376
+ });
1377
+ } finally {
1378
+ hooks.off("kubb:hook:end", onHookEnd);
1379
+ }
1380
+ for (const error of hookFailures) {
1381
+ const diagnostic = outputDiagnostic(Diagnostics.code.hookFailed, "Post-generate hook", error);
1382
+ outputDiagnostics.push(diagnostic);
1383
+ await Diagnostics.emit(hooks, diagnostic);
1384
+ }
1385
+ await hooks.emit("kubb:hooks:end");
1386
+ }
1387
+ const finalDiagnostics = [...diagnostics, ...outputDiagnostics];
1388
+ const failed = Diagnostics.hasError(outputDiagnostics);
1389
+ if (!failed) await hooks.emit("kubb:success", {
1390
+ message: "Generation succeeded",
1391
+ info: inputPath
1392
+ });
1393
+ await hooks.emit("kubb:generation:end", {
1394
+ config,
1395
+ storage: kubb.storage,
1396
+ diagnostics: finalDiagnostics,
1397
+ filesCreated: files.length,
1398
+ status: failed ? "failed" : "success",
1399
+ hrStart
1400
+ });
1401
+ await reportTelemetry(failed ? "failed" : "success");
1402
+ return !failed;
1403
+ }
1404
+ /**
1405
+ * Builds a coded diagnostic for an output-phase failure (formatter, linter, or `done` hook).
1406
+ */
1407
+ function outputDiagnostic(code, label, caughtError) {
1408
+ const error = toError(caughtError);
1409
+ return {
1410
+ code,
1411
+ severity: "error",
1412
+ message: `${label} failed: ${error.message}`,
1413
+ help: "Check that the tool is installed and that the command and its config are correct.",
1414
+ location: { kind: "config" },
1415
+ cause: error
1416
+ };
1417
+ }
1418
+ async function checkForUpdate(hooks) {
1419
+ await executeIfOnline(async () => {
1420
+ try {
1421
+ const data = await (await fetch(KUBB_NPM_PACKAGE_URL)).json();
1422
+ if (data.version && version < data.version) await Diagnostics.emit(hooks, Diagnostics.update({
1423
+ currentVersion: version,
1424
+ latestVersion: data.version
1425
+ }));
1426
+ } catch {}
1427
+ });
1428
+ }
1429
+ /**
1430
+ * Runs the full Kubb generation lifecycle for the given CLI options.
1431
+ * Loads configs, sets up the selected reporters (CLI `--reporter` overrides `config.reporters`),
1432
+ * checks for a newer version, and calls `generate` for each config entry.
1433
+ */
1434
+ async function run({ input, configPath, logLevel: logLevelKey, watch, reporters: cliReporters }) {
1435
+ const logLevel$2 = logLevel[logLevelKey] ?? logLevel.info;
1436
+ const hooks = new AsyncEventEmitter();
1437
+ let configs;
1438
+ let resolvedConfigPath;
1439
+ try {
1440
+ const loaded = await getConfigs({
1441
+ configPath,
1442
+ input,
1443
+ watch,
1444
+ logLevel: logLevelKey
1445
+ });
1446
+ configs = loaded.configs;
1447
+ resolvedConfigPath = loaded.configPath;
1448
+ } catch (error) {
1449
+ await setupReporters(hooks, {
1450
+ logLevel: logLevel$2,
1451
+ reporters: [cliReporter]
1452
+ });
1453
+ await hooks.emit("kubb:error", { error: toError(error) });
1454
+ process$1.exit(1);
1455
+ }
1456
+ const requestedNames = cliReporters?.length ? cliReporters : ["cli"];
1457
+ await setupReporters(hooks, {
1458
+ logLevel: logLevel$2,
1459
+ reporters: selectReporters(configs[0]?.reporters ?? [], requestedNames)
1460
+ });
1461
+ await hooks.emit("kubb:lifecycle:start", { version });
1462
+ await checkForUpdate(hooks);
1463
+ try {
1464
+ const relativeConfigPath = path.relative(process$1.cwd(), resolvedConfigPath);
1465
+ await hooks.emit("kubb:config:start");
1466
+ await hooks.emit("kubb:info", {
1467
+ message: "Config loaded",
1468
+ info: relativeConfigPath
1469
+ });
1470
+ await hooks.emit("kubb:success", {
1471
+ message: "Config loaded successfully",
1472
+ info: relativeConfigPath
1473
+ });
1474
+ await hooks.emit("kubb:config:end", { configs });
1475
+ let anyFailed = false;
1476
+ for (const config of configs) if (config.input && "path" in config.input && watch) await startWatcher([input || config.input.path], async (paths) => {
1477
+ await generate({
1478
+ input,
1479
+ config,
1480
+ logLevel: logLevel$2,
1481
+ hooks
1482
+ });
1483
+ clack.log.step(styleText("yellow", `Watching for changes in ${paths.join(" and ")}`));
1484
+ }, {
1485
+ info: (msg) => clack.log.info(msg),
1486
+ error: (msg) => clack.log.error(msg)
1487
+ });
1488
+ else try {
1489
+ if (!await generate({
1490
+ input,
1491
+ config,
1492
+ logLevel: logLevel$2,
1493
+ hooks
1494
+ })) anyFailed = true;
1495
+ } catch (configError) {
1496
+ await hooks.emit("kubb:error", { error: toError(configError) });
1497
+ anyFailed = true;
1498
+ }
1499
+ await hooks.emit("kubb:lifecycle:end");
1500
+ if (anyFailed) process$1.exit(1);
1501
+ } catch (error) {
1502
+ await hooks.emit("kubb:error", { error: toError(error) });
1503
+ process$1.exit(1);
1504
+ }
1505
+ }
1506
+ //#endregion
1507
+ export { run };
1508
+
1509
+ //# sourceMappingURL=run-DaV_NiKR.js.map