@kubb/cli 5.0.0-alpha.4 → 5.0.0-alpha.40

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 (122) hide show
  1. package/bin/kubb.js +6 -0
  2. package/dist/agent-CWitLsL9.cjs +109 -0
  3. package/dist/agent-CWitLsL9.cjs.map +1 -0
  4. package/dist/{agent-CIQijRVB.cjs → agent-DKbDdi7n.cjs} +5 -5
  5. package/dist/{agent-CIQijRVB.cjs.map → agent-DKbDdi7n.cjs.map} +1 -1
  6. package/dist/{agent-BTM0c8dD.js → agent-dmYXtqBU.js} +5 -5
  7. package/dist/{agent-BTM0c8dD.js.map → agent-dmYXtqBU.js.map} +1 -1
  8. package/dist/agent-poGbscec.js +105 -0
  9. package/dist/agent-poGbscec.js.map +1 -0
  10. package/dist/{constants-BTUap0zs.cjs → constants-D0XHAHeZ.cjs} +78 -8
  11. package/dist/constants-D0XHAHeZ.cjs.map +1 -0
  12. package/dist/{constants-CM3dJzjK.js → constants-DJM9zCXm.js} +73 -9
  13. package/dist/constants-DJM9zCXm.js.map +1 -0
  14. package/dist/define-Bdn8j5VM.cjs +54 -0
  15. package/dist/define-Bdn8j5VM.cjs.map +1 -0
  16. package/dist/define-Ctii4bel.js +43 -0
  17. package/dist/define-Ctii4bel.js.map +1 -0
  18. package/dist/{errors-DBW0N9w4.cjs → errors-CLCjoSg0.cjs} +22 -6
  19. package/dist/errors-CLCjoSg0.cjs.map +1 -0
  20. package/dist/errors-CjPmyZHy.js +43 -0
  21. package/dist/errors-CjPmyZHy.js.map +1 -0
  22. package/dist/{generate-Bqt7o7A7.cjs → generate-BHQ-DUWz.cjs} +3 -3
  23. package/dist/{generate-Bqt7o7A7.cjs.map → generate-BHQ-DUWz.cjs.map} +1 -1
  24. package/dist/{generate-DRz7eCom.js → generate-C8ma2By4.js} +3 -3
  25. package/dist/{generate-DRz7eCom.js.map → generate-C8ma2By4.js.map} +1 -1
  26. package/dist/{generate-Dw5sZGB-.js → generate-ChFsLr7x.js} +473 -241
  27. package/dist/generate-ChFsLr7x.js.map +1 -0
  28. package/dist/{generate-D5CrYCLF.cjs → generate-Gt665H8d.cjs} +480 -248
  29. package/dist/generate-Gt665H8d.cjs.map +1 -0
  30. package/dist/index.cjs +49 -21
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.ts +1 -1
  33. package/dist/index.js +49 -21
  34. package/dist/index.js.map +1 -1
  35. package/dist/{init-BKo0zEUz.js → init-B3l2Owxc.js} +4 -4
  36. package/dist/{init-BKo0zEUz.js.map → init-B3l2Owxc.js.map} +1 -1
  37. package/dist/{init-BH-IuVku.cjs → init-D-2he_0A.cjs} +4 -4
  38. package/dist/{init-BH-IuVku.cjs.map → init-D-2he_0A.cjs.map} +1 -1
  39. package/dist/{init-hmolV6B4.cjs → init-cAbMOLut.cjs} +24 -9
  40. package/dist/init-cAbMOLut.cjs.map +1 -0
  41. package/dist/{init-C-InrmSY.js → init-hcm7zvPn.js} +20 -5
  42. package/dist/init-hcm7zvPn.js.map +1 -0
  43. package/dist/{mcp-D2SHEg_d.js → mcp-B_FoDCTh.js} +11 -4
  44. package/dist/mcp-B_FoDCTh.js.map +1 -0
  45. package/dist/{mcp-chxay4lz.js → mcp-CtzZpDkP.js} +4 -4
  46. package/dist/{mcp-chxay4lz.js.map → mcp-CtzZpDkP.js.map} +1 -1
  47. package/dist/{mcp-ChHFPRzD.cjs → mcp-STc97s14.cjs} +12 -6
  48. package/dist/mcp-STc97s14.cjs.map +1 -0
  49. package/dist/{mcp-BuEzqp9N.cjs → mcp-xc4fqnRw.cjs} +4 -4
  50. package/dist/{mcp-BuEzqp9N.cjs.map → mcp-xc4fqnRw.cjs.map} +1 -1
  51. package/dist/{package-D4K2izUa.cjs → package-BsynBR_p.cjs} +2 -2
  52. package/dist/package-BsynBR_p.cjs.map +1 -0
  53. package/dist/package-uxL6A6HK.js +6 -0
  54. package/dist/package-uxL6A6HK.js.map +1 -0
  55. package/dist/{shell-7HPrTCJ5.cjs → shell-475fQKaX.cjs} +8 -3
  56. package/dist/shell-475fQKaX.cjs.map +1 -0
  57. package/dist/{shell-DqqWsHCD.js → shell-DLzN4fRo.js} +8 -3
  58. package/dist/shell-DLzN4fRo.js.map +1 -0
  59. package/dist/{telemetry-DxiR7clS.js → telemetry-CBISr5w4.js} +48 -6
  60. package/dist/telemetry-CBISr5w4.js.map +1 -0
  61. package/dist/{telemetry-Cn9X1I5B.cjs → telemetry-D_Bi2E3I.cjs} +50 -8
  62. package/dist/telemetry-D_Bi2E3I.cjs.map +1 -0
  63. package/dist/{validate-BqYfMrH7.cjs → validate-Cbvb4Gne.cjs} +4 -4
  64. package/dist/{validate-BqYfMrH7.cjs.map → validate-Cbvb4Gne.cjs.map} +1 -1
  65. package/dist/{validate-Bbrn3Q-A.cjs → validate-CqwT945Z.cjs} +6 -14
  66. package/dist/validate-CqwT945Z.cjs.map +1 -0
  67. package/dist/{validate-CfeXKup1.js → validate-Dxd_xD6I.js} +4 -4
  68. package/dist/{validate-CfeXKup1.js.map → validate-Dxd_xD6I.js.map} +1 -1
  69. package/dist/{validate-l8vLmwKA.js → validate-NZ0mduJ3.js} +5 -13
  70. package/dist/validate-NZ0mduJ3.js.map +1 -0
  71. package/package.json +8 -9
  72. package/src/constants.ts +57 -10
  73. package/src/index.ts +10 -12
  74. package/src/loggers/clackLogger.ts +54 -46
  75. package/src/loggers/fileSystemLogger.ts +13 -11
  76. package/src/loggers/githubActionsLogger.ts +22 -22
  77. package/src/loggers/plainLogger.ts +21 -21
  78. package/src/runners/agent.ts +54 -31
  79. package/src/runners/generate.ts +78 -99
  80. package/src/runners/init.ts +1 -1
  81. package/src/runners/validate.ts +3 -13
  82. package/src/types.ts +11 -0
  83. package/src/utils/executeHooks.ts +11 -11
  84. package/src/utils/flags.ts +10 -0
  85. package/src/utils/getConfig.ts +10 -0
  86. package/src/utils/getCosmiConfig.ts +9 -3
  87. package/src/utils/getSummary.ts +1 -1
  88. package/src/utils/runHook.ts +9 -9
  89. package/bin/kubb.cjs +0 -18
  90. package/dist/agent-C6o_6GSJ.cjs +0 -92
  91. package/dist/agent-C6o_6GSJ.cjs.map +0 -1
  92. package/dist/agent-L50VNhXv.js +0 -88
  93. package/dist/agent-L50VNhXv.js.map +0 -1
  94. package/dist/constants-BTUap0zs.cjs.map +0 -1
  95. package/dist/constants-CM3dJzjK.js.map +0 -1
  96. package/dist/define--M_JMcDC.js +0 -25
  97. package/dist/define--M_JMcDC.js.map +0 -1
  98. package/dist/define-D6Kfm7-Z.cjs +0 -36
  99. package/dist/define-D6Kfm7-Z.cjs.map +0 -1
  100. package/dist/errors-6mF_WKxg.js +0 -27
  101. package/dist/errors-6mF_WKxg.js.map +0 -1
  102. package/dist/errors-DBW0N9w4.cjs.map +0 -1
  103. package/dist/generate-D5CrYCLF.cjs.map +0 -1
  104. package/dist/generate-Dw5sZGB-.js.map +0 -1
  105. package/dist/init-C-InrmSY.js.map +0 -1
  106. package/dist/init-hmolV6B4.cjs.map +0 -1
  107. package/dist/jiti-Cd3S0xwr.cjs +0 -16
  108. package/dist/jiti-Cd3S0xwr.cjs.map +0 -1
  109. package/dist/jiti-e08mD2Ph.js +0 -11
  110. package/dist/jiti-e08mD2Ph.js.map +0 -1
  111. package/dist/mcp-ChHFPRzD.cjs.map +0 -1
  112. package/dist/mcp-D2SHEg_d.js.map +0 -1
  113. package/dist/package-D4K2izUa.cjs.map +0 -1
  114. package/dist/package-Pd8l9DAQ.js +0 -6
  115. package/dist/package-Pd8l9DAQ.js.map +0 -1
  116. package/dist/shell-7HPrTCJ5.cjs.map +0 -1
  117. package/dist/shell-DqqWsHCD.js.map +0 -1
  118. package/dist/telemetry-Cn9X1I5B.cjs.map +0 -1
  119. package/dist/telemetry-DxiR7clS.js.map +0 -1
  120. package/dist/validate-Bbrn3Q-A.cjs.map +0 -1
  121. package/dist/validate-l8vLmwKA.js.map +0 -1
  122. package/src/utils/getIntro.ts +0 -1
@@ -1,30 +1,38 @@
1
1
  import "./chunk--u3MIqq1.js";
2
- import { n as toCause, r as toError } from "./errors-6mF_WKxg.js";
3
- import { a as canUseTTY, i as executeIfOnline, o as isGitHubActions, r as sendTelemetry, t as buildTelemetryEvent } from "./telemetry-DxiR7clS.js";
4
- import { n as tokenize } from "./shell-DqqWsHCD.js";
5
- import { t as version } from "./package-Pd8l9DAQ.js";
6
- import { i as WATCHER_IGNORED_PATHS, r as SUMMARY_SEPARATOR, t as KUBB_NPM_PACKAGE_URL } from "./constants-CM3dJzjK.js";
2
+ import { n as toCause, r as toError } from "./errors-CjPmyZHy.js";
3
+ import { a as canUseTTY, i as executeIfOnline, o as isGitHubActions, r as sendTelemetry, t as buildTelemetryEvent } from "./telemetry-CBISr5w4.js";
4
+ import { n as tokenize } from "./shell-DLzN4fRo.js";
5
+ import { t as version } from "./package-uxL6A6HK.js";
6
+ import { a as WATCHER_IGNORED_PATHS, i as SUMMARY_SEPARATOR, t as KUBB_NPM_PACKAGE_URL } from "./constants-DJM9zCXm.js";
7
7
  import { styleText } from "node:util";
8
8
  import { EventEmitter } from "node:events";
9
+ import { spawn } from "node:child_process";
9
10
  import { createHash } from "node:crypto";
10
11
  import "node:fs";
11
12
  import { mkdir, readFile, writeFile } from "node:fs/promises";
12
13
  import path, { dirname, relative, resolve } from "node:path";
13
14
  import process$1 from "node:process";
14
15
  import * as clack from "@clack/prompts";
15
- import { PromiseManager, defineLogger, detectFormatter, detectLinter, formatters, getConfigs, isInputPath, linters, logLevel, safeBuild, setup } from "@kubb/core";
16
+ import { createKubb, defineLogger, isInputPath, logLevel } from "@kubb/core";
16
17
  import { NonZeroExitError, x } from "tinyexec";
17
18
  import { Writable } from "node:stream";
18
19
  import { cosmiconfig } from "cosmiconfig";
19
20
  import { createJiti } from "jiti";
20
21
  //#region ../../internals/utils/src/asyncEventEmitter.ts
21
22
  /**
22
- * A typed EventEmitter that awaits all async listeners before resolving.
23
+ * Typed `EventEmitter` that awaits all async listeners before resolving.
23
24
  * Wraps Node's `EventEmitter` with full TypeScript event-map inference.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const emitter = new AsyncEventEmitter<{ build: [name: string] }>()
29
+ * emitter.on('build', async (name) => { console.log(name) })
30
+ * await emitter.emit('build', 'petstore') // all listeners awaited
31
+ * ```
24
32
  */
25
33
  var AsyncEventEmitter = class {
26
34
  /**
27
- * `maxListener` controls the maximum number of listeners per event before Node emits a memory-leak warning.
35
+ * Maximum number of listeners per event before Node emits a memory-leak warning.
28
36
  * @default 10
29
37
  */
30
38
  constructor(maxListener = 10) {
@@ -32,31 +40,48 @@ var AsyncEventEmitter = class {
32
40
  }
33
41
  #emitter = new EventEmitter();
34
42
  /**
35
- * Emits an event and awaits all registered listeners in parallel.
43
+ * Emits `eventName` and awaits all registered listeners sequentially.
36
44
  * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * await emitter.emit('build', 'petstore')
49
+ * ```
37
50
  */
38
51
  async emit(eventName, ...eventArgs) {
39
52
  const listeners = this.#emitter.listeners(eventName);
40
53
  if (listeners.length === 0) return;
41
- await Promise.all(listeners.map(async (listener) => {
54
+ for (const listener of listeners) try {
55
+ await listener(...eventArgs);
56
+ } catch (err) {
57
+ let serializedArgs;
42
58
  try {
43
- return await listener(...eventArgs);
44
- } catch (err) {
45
- let serializedArgs;
46
- try {
47
- serializedArgs = JSON.stringify(eventArgs);
48
- } catch {
49
- serializedArgs = String(eventArgs);
50
- }
51
- throw new Error(`Error in async listener for "${eventName}" with eventArgs ${serializedArgs}`, { cause: toError(err) });
59
+ serializedArgs = JSON.stringify(eventArgs);
60
+ } catch {
61
+ serializedArgs = String(eventArgs);
52
62
  }
53
- }));
63
+ throw new Error(`Error in async listener for "${eventName}" with eventArgs ${serializedArgs}`, { cause: toError(err) });
64
+ }
54
65
  }
55
- /** Registers a persistent listener for the given event. */
66
+ /**
67
+ * Registers a persistent listener for `eventName`.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * emitter.on('build', async (name) => { console.log(name) })
72
+ * ```
73
+ */
56
74
  on(eventName, handler) {
57
75
  this.#emitter.on(eventName, handler);
58
76
  }
59
- /** Registers a one-shot listener that removes itself after the first invocation. */
77
+ /**
78
+ * Registers a one-shot listener that removes itself after the first invocation.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * emitter.onOnce('build', async (name) => { console.log(name) })
83
+ * ```
84
+ */
60
85
  onOnce(eventName, handler) {
61
86
  const wrapper = (...args) => {
62
87
  this.off(eventName, wrapper);
@@ -64,20 +89,177 @@ var AsyncEventEmitter = class {
64
89
  };
65
90
  this.on(eventName, wrapper);
66
91
  }
67
- /** Removes a previously registered listener. */
92
+ /**
93
+ * Removes a previously registered listener.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * emitter.off('build', handler)
98
+ * ```
99
+ */
68
100
  off(eventName, handler) {
69
101
  this.#emitter.off(eventName, handler);
70
102
  }
71
- /** Removes all listeners from every event channel. */
103
+ /**
104
+ * Returns the number of listeners registered for `eventName`.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * emitter.on('build', handler)
109
+ * emitter.listenerCount('build') // 1
110
+ * ```
111
+ */
112
+ listenerCount(eventName) {
113
+ return this.#emitter.listenerCount(eventName);
114
+ }
115
+ /**
116
+ * Removes all listeners from every event channel.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * emitter.removeAll()
121
+ * ```
122
+ */
72
123
  removeAll() {
73
124
  this.#emitter.removeAllListeners();
74
125
  }
75
126
  };
76
127
  //#endregion
128
+ //#region ../../internals/utils/src/formatters.ts
129
+ /**
130
+ * CLI command descriptors for each supported code formatter.
131
+ *
132
+ * Each entry contains the executable `command`, an `args` factory that maps an
133
+ * output path to the correct argument list, and an `errorMessage` shown when
134
+ * the formatter is not found.
135
+ */
136
+ const formatters = {
137
+ prettier: {
138
+ command: "prettier",
139
+ args: (outputPath) => [
140
+ "--ignore-unknown",
141
+ "--write",
142
+ outputPath
143
+ ],
144
+ errorMessage: "Prettier not found"
145
+ },
146
+ biome: {
147
+ command: "biome",
148
+ args: (outputPath) => [
149
+ "format",
150
+ "--write",
151
+ outputPath
152
+ ],
153
+ errorMessage: "Biome not found"
154
+ },
155
+ oxfmt: {
156
+ command: "oxfmt",
157
+ args: (outputPath) => [outputPath],
158
+ errorMessage: "Oxfmt not found"
159
+ }
160
+ };
161
+ async function isFormatterAvailable(formatter) {
162
+ return new Promise((resolve) => {
163
+ const child = spawn(formatter, ["--version"], { stdio: "ignore" });
164
+ child.on("close", (code) => resolve(code === 0));
165
+ child.on("error", () => resolve(false));
166
+ });
167
+ }
168
+ /**
169
+ * Detects the first available code formatter on the current system.
170
+ *
171
+ * - Checks in preference order: `biome`, `oxfmt`, `prettier`.
172
+ * - Returns `null` when none are found.
173
+ *
174
+ * @example
175
+ * ```ts
176
+ * const formatter = await detectFormatter()
177
+ * if (formatter) {
178
+ * console.log(`Using ${formatter} for formatting`)
179
+ * }
180
+ * ```
181
+ */
182
+ async function detectFormatter() {
183
+ const formatterNames = new Set([
184
+ "biome",
185
+ "oxfmt",
186
+ "prettier"
187
+ ]);
188
+ for (const formatter of formatterNames) if (await isFormatterAvailable(formatter)) return formatter;
189
+ return null;
190
+ }
191
+ //#endregion
192
+ //#region ../../internals/utils/src/linters.ts
193
+ /**
194
+ * CLI command descriptors for each supported linter.
195
+ *
196
+ * Each entry contains the executable `command`, an `args` factory that maps an
197
+ * output path to the correct argument list, and an `errorMessage` shown when
198
+ * the linter is not found.
199
+ */
200
+ const linters = {
201
+ eslint: {
202
+ command: "eslint",
203
+ args: (outputPath) => [outputPath, "--fix"],
204
+ errorMessage: "Eslint not found"
205
+ },
206
+ biome: {
207
+ command: "biome",
208
+ args: (outputPath) => [
209
+ "lint",
210
+ "--fix",
211
+ outputPath
212
+ ],
213
+ errorMessage: "Biome not found"
214
+ },
215
+ oxlint: {
216
+ command: "oxlint",
217
+ args: (outputPath) => ["--fix", outputPath],
218
+ errorMessage: "Oxlint not found"
219
+ }
220
+ };
221
+ async function isLinterAvailable(linter) {
222
+ return new Promise((resolve) => {
223
+ const child = spawn(linter, ["--version"], { stdio: "ignore" });
224
+ child.on("close", (code) => resolve(code === 0));
225
+ child.on("error", () => resolve(false));
226
+ });
227
+ }
228
+ /**
229
+ * Detects the first available linter on the current system.
230
+ *
231
+ * - Checks in preference order: `biome`, `oxlint`, `eslint`.
232
+ * - Returns `null` when none are found.
233
+ *
234
+ * @example
235
+ * ```ts
236
+ * const linter = await detectLinter()
237
+ * if (linter) {
238
+ * console.log(`Using ${linter} for linting`)
239
+ * }
240
+ * ```
241
+ */
242
+ async function detectLinter() {
243
+ const linterNames = new Set([
244
+ "biome",
245
+ "oxlint",
246
+ "eslint"
247
+ ]);
248
+ for (const linter of linterNames) if (await isLinterAvailable(linter)) return linter;
249
+ return null;
250
+ }
251
+ //#endregion
77
252
  //#region ../../internals/utils/src/time.ts
78
253
  /**
79
- * Calculates elapsed time in milliseconds from a high-resolution start time.
80
- * Rounds to 2 decimal places to provide sub-millisecond precision without noise.
254
+ * Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.
255
+ * Rounds to 2 decimal places for sub-millisecond precision without noise.
256
+ *
257
+ * @example
258
+ * ```ts
259
+ * const start = process.hrtime()
260
+ * doWork()
261
+ * getElapsedMs(start) // 42.35
262
+ * ```
81
263
  */
82
264
  function getElapsedMs(hrStart) {
83
265
  const [seconds, nanoseconds] = process.hrtime(hrStart);
@@ -85,8 +267,14 @@ function getElapsedMs(hrStart) {
85
267
  return Math.round(ms * 100) / 100;
86
268
  }
87
269
  /**
88
- * Converts a millisecond duration into a human-readable string.
89
- * Adjusts units (ms, s, m s) based on the magnitude of the duration.
270
+ * Converts a millisecond duration into a human-readable string (`ms`, `s`, or `m s`).
271
+ *
272
+ * @example
273
+ * ```ts
274
+ * formatMs(250) // '250ms'
275
+ * formatMs(1500) // '1.50s'
276
+ * formatMs(90000) // '1m 30.0s'
277
+ * ```
90
278
  */
91
279
  function formatMs(ms) {
92
280
  if (ms >= 6e4) return `${Math.floor(ms / 6e4)}m ${(ms % 6e4 / 1e3).toFixed(1)}s`;
@@ -94,7 +282,14 @@ function formatMs(ms) {
94
282
  return `${Math.round(ms)}ms`;
95
283
  }
96
284
  /**
97
- * Convenience helper: formats the elapsed time since `hrStart` in one step.
285
+ * Formats the elapsed time since `hrStart` as a human-readable string.
286
+ *
287
+ * @example
288
+ * ```ts
289
+ * const start = process.hrtime()
290
+ * doWork()
291
+ * formatHrtime(start) // '1.50s'
292
+ * ```
98
293
  */
99
294
  function formatHrtime(hrStart) {
100
295
  return formatMs(getElapsedMs(hrStart));
@@ -136,7 +331,9 @@ function gradient(colorStops, text) {
136
331
  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`;
137
332
  }).join("");
138
333
  }
139
- /** ANSI color functions for each part of the Kubb mascot illustration. */
334
+ /**
335
+ * ANSI color functions for each part of the Kubb mascot illustration.
336
+ */
140
337
  const palette = {
141
338
  lid: hex("#F55A17"),
142
339
  woodTop: hex("#F5A217"),
@@ -147,7 +344,12 @@ const palette = {
147
344
  blush: hex("#FDA4AF")
148
345
  };
149
346
  /**
150
- * Generates the Kubb mascot welcome banner.
347
+ * Generates the Kubb mascot welcome banner as an ANSI-colored string.
348
+ *
349
+ * @example
350
+ * ```ts
351
+ * console.log(getIntro({ title: 'kubb.config.ts', description: 'generating…', version: '5.0.0', areEyesOpen: true }))
352
+ * ```
151
353
  */
152
354
  function getIntro({ title, description, version, areEyesOpen }) {
153
355
  const kubbVersion = gradient([
@@ -165,7 +367,13 @@ function getIntro({ title, description, version, areEyesOpen }) {
165
367
  ${palette.woodBase("▀▀▀▀▀▀▀▀▀▀▀▀▀")}
166
368
  `;
167
369
  }
168
- /** ANSI color names available for terminal output. */
370
+ /** ANSI color names available for deterministic terminal coloring.
371
+ *
372
+ * @example
373
+ * ```ts
374
+ * const color = randomColors[2] // 'green'
375
+ * ```
376
+ */
169
377
  const randomColors = [
170
378
  "black",
171
379
  "red",
@@ -178,15 +386,27 @@ const randomColors = [
178
386
  "gray"
179
387
  ];
180
388
  /**
181
- * Returns the text wrapped in a deterministic ANSI color derived from the text's SHA-256 hash.
389
+ * Wraps `text` in a deterministic ANSI color derived from the text's SHA-256 hash.
390
+ *
391
+ * @example
392
+ * ```ts
393
+ * randomCliColor('petstore') // '\x1b[33m' + 'petstore' + '\x1b[39m' (always the same color for 'petstore')
394
+ * ```
182
395
  */
183
396
  function randomCliColor(text) {
184
397
  if (!text) return "";
185
398
  return styleText(randomColors[createHash("sha256").update(text).digest().readUInt32BE(0) % randomColors.length] ?? "white", text);
186
399
  }
187
400
  /**
188
- * Formats a millisecond duration with an ANSI color based on thresholds:
189
- * green 500 ms · yellow 1 000 ms · red > 1 000 ms
401
+ * Formats a millisecond duration with a threshold-based ANSI color.
402
+ * `≤ 500 ms` → green · `≤ 1 000 ms` → yellow · `> 1 000 ms` → red.
403
+ *
404
+ * @example
405
+ * ```ts
406
+ * formatMsWithColor(200) // '\x1b[32m200ms\x1b[39m'
407
+ * formatMsWithColor(800) // '\x1b[33m800ms\x1b[39m'
408
+ * formatMsWithColor(1500) // '\x1b[31m1.50s\x1b[39m'
409
+ * ```
190
410
  */
191
411
  function formatMsWithColor(ms) {
192
412
  const formatted = formatMs(ms);
@@ -198,24 +418,29 @@ function formatMsWithColor(ms) {
198
418
  //#region ../../internals/utils/src/fs.ts
199
419
  /**
200
420
  * Writes `data` to `path`, trimming leading/trailing whitespace before saving.
201
- * Skips the write and returns `undefined` when the trimmed content is empty or
202
- * identical to what is already on disk.
421
+ * Skips the write when the trimmed content is empty or identical to what is already on disk.
203
422
  * Creates any missing parent directories automatically.
204
- * When `sanity` is `true`, re-reads the file after writing and throws if the
205
- * content does not match.
423
+ * When `sanity` is `true`, re-reads the file after writing and throws if the content does not match.
424
+ *
425
+ * @example
426
+ * ```ts
427
+ * await write('./src/Pet.ts', source) // writes and returns trimmed content
428
+ * await write('./src/Pet.ts', source) // null — file unchanged
429
+ * await write('./src/Pet.ts', ' ') // null — empty content skipped
430
+ * ```
206
431
  */
207
432
  async function write(path, data, options = {}) {
208
433
  const trimmed = data.trim();
209
- if (trimmed === "") return void 0;
434
+ if (trimmed === "") return null;
210
435
  const resolved = resolve(path);
211
436
  if (typeof Bun !== "undefined") {
212
437
  const file = Bun.file(resolved);
213
- if ((await file.exists() ? await file.text() : null) === trimmed) return void 0;
438
+ if ((await file.exists() ? await file.text() : null) === trimmed) return null;
214
439
  await Bun.write(resolved, trimmed);
215
440
  return trimmed;
216
441
  }
217
442
  try {
218
- if (await readFile(resolved, { encoding: "utf-8" }) === trimmed) return void 0;
443
+ if (await readFile(resolved, { encoding: "utf-8" }) === trimmed) return null;
219
444
  } catch {}
220
445
  await mkdir(dirname(resolved), { recursive: true });
221
446
  await writeFile(resolved, trimmed, { encoding: "utf-8" });
@@ -237,7 +462,7 @@ function getSummary({ failedPlugins, filesCreated, status, hrStart, config, plug
237
462
  pluginsFailed: status === "failed" ? [...failedPlugins].map(({ plugin }) => randomCliColor(plugin.name)).join(", ") : void 0,
238
463
  filesCreated,
239
464
  time: styleText("green", duration),
240
- output: path.isAbsolute(config.root) ? path.resolve(config.root, config.output.path) : config.root
465
+ output: path.resolve(config.root, config.output.path)
241
466
  };
242
467
  const labels = {
243
468
  plugins: "Plugins:",
@@ -279,11 +504,11 @@ async function runHook({ id, command, args, commandWithArgs, context, stream = f
279
504
  });
280
505
  if (stream && sink?.onLine) for await (const line of proc) sink.onLine(line);
281
506
  const result = await proc;
282
- await context.emit("debug", {
507
+ await context.emit("kubb:debug", {
283
508
  date: /* @__PURE__ */ new Date(),
284
509
  logs: [result.stdout.trimEnd()]
285
510
  });
286
- await context.emit("hook:end", {
511
+ await context.emit("kubb:hook:end", {
287
512
  command,
288
513
  args,
289
514
  id,
@@ -292,33 +517,33 @@ async function runHook({ id, command, args, commandWithArgs, context, stream = f
292
517
  });
293
518
  } catch (err) {
294
519
  if (!(err instanceof NonZeroExitError)) {
295
- await context.emit("hook:end", {
520
+ await context.emit("kubb:hook:end", {
296
521
  command,
297
522
  args,
298
523
  id,
299
524
  success: false,
300
525
  error: toError(err)
301
526
  });
302
- await context.emit("error", toError(err));
527
+ await context.emit("kubb:error", toError(err));
303
528
  return;
304
529
  }
305
530
  const stderr = err.output?.stderr ?? "";
306
531
  const stdout = err.output?.stdout ?? "";
307
- await context.emit("debug", {
532
+ await context.emit("kubb:debug", {
308
533
  date: /* @__PURE__ */ new Date(),
309
534
  logs: [stdout, stderr].filter(Boolean)
310
535
  });
311
536
  if (stderr) sink?.onStderr?.(stderr);
312
537
  if (stdout) sink?.onStdout?.(stdout);
313
538
  const errorMessage = /* @__PURE__ */ new Error(`Hook execute failed: ${commandWithArgs}`);
314
- await context.emit("hook:end", {
539
+ await context.emit("kubb:hook:end", {
315
540
  command,
316
541
  args,
317
542
  id,
318
543
  success: false,
319
544
  error: errorMessage
320
545
  });
321
- await context.emit("error", errorMessage);
546
+ await context.emit("kubb:error", errorMessage);
322
547
  }
323
548
  }
324
549
  //#endregion
@@ -386,7 +611,7 @@ const clackLogger = defineLogger({
386
611
  state.spinner.stop(text);
387
612
  state.isSpinning = false;
388
613
  }
389
- context.on("info", (message, info = "") => {
614
+ context.on("kubb:info", (message, info = "") => {
390
615
  if (logLevel$8 <= logLevel.silent) return;
391
616
  const text = getMessage([
392
617
  styleText("blue", "ℹ"),
@@ -396,7 +621,7 @@ const clackLogger = defineLogger({
396
621
  if (state.isSpinning) state.spinner.message(text);
397
622
  else clack.log.info(text);
398
623
  });
399
- context.on("success", (message, info = "") => {
624
+ context.on("kubb:success", (message, info = "") => {
400
625
  if (logLevel$8 <= logLevel.silent) return;
401
626
  const text = getMessage([
402
627
  styleText("blue", "✓"),
@@ -406,7 +631,7 @@ const clackLogger = defineLogger({
406
631
  if (state.isSpinning) stopSpinner(text);
407
632
  else clack.log.success(text);
408
633
  });
409
- context.on("warn", (message, info) => {
634
+ context.on("kubb:warn", (message, info) => {
410
635
  if (logLevel$8 < logLevel.warn) return;
411
636
  const text = getMessage([
412
637
  styleText("yellow", "⚠"),
@@ -415,7 +640,7 @@ const clackLogger = defineLogger({
415
640
  ].filter(Boolean).join(" "));
416
641
  clack.log.warn(text);
417
642
  });
418
- context.on("error", (error) => {
643
+ context.on("kubb:error", (error) => {
419
644
  const caused = toCause(error);
420
645
  const text = [styleText("red", "✗"), error.message].join(" ");
421
646
  if (state.isSpinning) stopSpinner(getMessage(text));
@@ -430,19 +655,24 @@ const clackLogger = defineLogger({
430
655
  }
431
656
  }
432
657
  });
433
- context.on("version:new", (version, latestVersion) => {
658
+ context.on("kubb:version:new", (version, latestVersion) => {
434
659
  if (logLevel$8 <= logLevel.silent) return;
435
- clack.box(`\`v${version}\` → \`v${latestVersion}\`
660
+ try {
661
+ clack.box(`\`v${version}\` → \`v${latestVersion}\`
436
662
  Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
437
- width: "auto",
438
- formatBorder: (s) => styleText("yellow", s),
439
- rounded: true,
440
- withGuide: false,
441
- contentAlign: "center",
442
- titleAlign: "center"
443
- });
663
+ width: "auto",
664
+ formatBorder: (s) => styleText("yellow", s),
665
+ rounded: true,
666
+ withGuide: false,
667
+ contentAlign: "center",
668
+ titleAlign: "center"
669
+ });
670
+ } catch {
671
+ console.log(`Update available for Kubb: v${version} → v${latestVersion}`);
672
+ console.log("Run `npm install -g @kubb/cli` to update");
673
+ }
444
674
  });
445
- context.on("lifecycle:start", async (version) => {
675
+ context.on("kubb:lifecycle:start", async (version) => {
446
676
  console.log(`\n${getIntro({
447
677
  title: "The ultimate toolkit for working with APIs",
448
678
  description: "Ready to start",
@@ -451,24 +681,24 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
451
681
  })}\n`);
452
682
  reset();
453
683
  });
454
- context.on("config:start", () => {
684
+ context.on("kubb:config:start", () => {
455
685
  if (logLevel$8 <= logLevel.silent) return;
456
686
  const text = getMessage("Configuration started");
457
687
  clack.intro(text);
458
688
  startSpinner(getMessage("Configuration loading"));
459
689
  });
460
- context.on("config:end", (_configs) => {
690
+ context.on("kubb:config:end", (_configs) => {
461
691
  if (logLevel$8 <= logLevel.silent) return;
462
692
  const text = getMessage("Configuration completed");
463
693
  clack.outro(text);
464
694
  });
465
- context.on("generation:start", (config) => {
695
+ context.on("kubb:generation:start", (config) => {
466
696
  reset();
467
697
  state.totalPlugins = config.plugins?.length ?? 0;
468
698
  const text = getMessage(["Generation started", config.name ? `for ${styleText("dim", config.name)}` : void 0].filter(Boolean).join(" "));
469
699
  clack.intro(text);
470
700
  });
471
- context.on("plugin:start", (plugin) => {
701
+ context.on("kubb:plugin:start", (plugin) => {
472
702
  if (logLevel$8 <= logLevel.silent) return;
473
703
  stopSpinner();
474
704
  const progressBar = clack.progress({
@@ -486,7 +716,7 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
486
716
  interval
487
717
  });
488
718
  });
489
- context.on("plugin:end", (plugin, { duration, success }) => {
719
+ context.on("kubb:plugin:end", (plugin, { duration, success }) => {
490
720
  stopSpinner();
491
721
  const active = state.activeProgress.get(plugin.name);
492
722
  if (!active || logLevel$8 === logLevel.silent) return;
@@ -499,7 +729,7 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
499
729
  state.activeProgress.delete(plugin.name);
500
730
  showProgressStep();
501
731
  });
502
- context.on("files:processing:start", (files) => {
732
+ context.on("kubb:files:processing:start", (files) => {
503
733
  if (logLevel$8 <= logLevel.silent) return;
504
734
  stopSpinner();
505
735
  state.totalFiles = files.length;
@@ -510,11 +740,11 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
510
740
  max: files.length,
511
741
  size: 30
512
742
  });
513
- context.emit("info", text);
743
+ context.emit("kubb:info", text);
514
744
  progressBar.start(getMessage(text));
515
745
  state.activeProgress.set("files", { progressBar });
516
746
  });
517
- context.on("file:processing:update", ({ file, config }) => {
747
+ context.on("kubb:file:processing:update", ({ file, config }) => {
518
748
  if (logLevel$8 <= logLevel.silent) return;
519
749
  stopSpinner();
520
750
  state.processedFiles++;
@@ -523,7 +753,7 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
523
753
  if (!active) return;
524
754
  active.progressBar.advance(void 0, text);
525
755
  });
526
- context.on("files:processing:end", () => {
756
+ context.on("kubb:files:processing:end", () => {
527
757
  if (logLevel$8 <= logLevel.silent) return;
528
758
  stopSpinner();
529
759
  const text = getMessage("Files written successfully");
@@ -533,31 +763,31 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
533
763
  state.activeProgress.delete("files");
534
764
  showProgressStep();
535
765
  });
536
- context.on("generation:end", (config) => {
766
+ context.on("kubb:generation:end", (config) => {
537
767
  const text = getMessage(config.name ? `Generation completed for ${styleText("dim", config.name)}` : "Generation completed");
538
768
  clack.outro(text);
539
769
  });
540
- context.on("format:start", () => {
770
+ context.on("kubb:format:start", () => {
541
771
  if (logLevel$8 <= logLevel.silent) return;
542
772
  const text = getMessage("Format started");
543
773
  clack.intro(text);
544
774
  });
545
- context.on("format:end", () => {
775
+ context.on("kubb:format:end", () => {
546
776
  if (logLevel$8 <= logLevel.silent) return;
547
777
  const text = getMessage("Format completed");
548
778
  clack.outro(text);
549
779
  });
550
- context.on("lint:start", () => {
780
+ context.on("kubb:lint:start", () => {
551
781
  if (logLevel$8 <= logLevel.silent) return;
552
782
  const text = getMessage("Lint started");
553
783
  clack.intro(text);
554
784
  });
555
- context.on("lint:end", () => {
785
+ context.on("kubb:lint:end", () => {
556
786
  if (logLevel$8 <= logLevel.silent) return;
557
787
  const text = getMessage("Lint completed");
558
788
  clack.outro(text);
559
789
  });
560
- context.on("hook:start", async ({ id, command, args }) => {
790
+ context.on("kubb:hook:start", async ({ id, command, args }) => {
561
791
  const commandWithArgs = formatCommandWithArgs(command, args);
562
792
  const text = getMessage(`Hook ${styleText("dim", commandWithArgs)} started`);
563
793
  if (!id) return;
@@ -592,12 +822,12 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
592
822
  }
593
823
  });
594
824
  });
595
- context.on("hook:end", ({ command, args }) => {
825
+ context.on("kubb:hook:end", ({ command, args }) => {
596
826
  if (logLevel$8 <= logLevel.silent) return;
597
827
  const text = getMessage(`Hook ${styleText("dim", formatCommandWithArgs(command, args))} successfully executed`);
598
828
  clack.outro(text);
599
829
  });
600
- context.on("generation:summary", (config, { pluginTimings, failedPlugins, filesCreated, status, hrStart }) => {
830
+ context.on("kubb:generation:summary", (config, { pluginTimings, failedPlugins, filesCreated, status, hrStart }) => {
601
831
  const summary = getSummary({
602
832
  failedPlugins,
603
833
  filesCreated,
@@ -610,16 +840,20 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
610
840
  summary.unshift("\n");
611
841
  summary.push("\n");
612
842
  const borderColor = status === "success" ? "green" : "red";
613
- clack.box(summary.join("\n"), getMessage(title), {
614
- width: "auto",
615
- formatBorder: (s) => styleText(borderColor, s),
616
- rounded: true,
617
- withGuide: false,
618
- contentAlign: "left",
619
- titleAlign: "center"
620
- });
843
+ try {
844
+ clack.box(summary.join("\n"), getMessage(title), {
845
+ width: "auto",
846
+ formatBorder: (s) => styleText(borderColor, s),
847
+ rounded: true,
848
+ withGuide: false,
849
+ contentAlign: "left",
850
+ titleAlign: "center"
851
+ });
852
+ } catch {
853
+ console.log(summary.join("\n"));
854
+ }
621
855
  });
622
- context.on("lifecycle:end", () => {
856
+ context.on("kubb:lifecycle:end", () => {
623
857
  reset();
624
858
  });
625
859
  }
@@ -660,63 +894,63 @@ const fileSystemLogger = defineLogger({
660
894
  files[pathName].push(`[${timestamp}]\n${log.logs.join("\n")}`);
661
895
  }
662
896
  }
663
- await Promise.all(Object.entries(files).map(([fileName, logs]) => write(fileName, logs.join("\n\n"))));
897
+ for (const [fileName, logs] of Object.entries(files)) await write(fileName, logs.join("\n\n"));
664
898
  return Object.keys(files);
665
899
  }
666
- context.on("info", (message, info) => {
900
+ context.on("kubb:info", (message, info) => {
667
901
  state.cachedLogs.add({
668
902
  date: /* @__PURE__ */ new Date(),
669
903
  logs: [`ℹ ${message} ${info}`]
670
904
  });
671
905
  });
672
- context.on("success", (message, info) => {
906
+ context.on("kubb:success", (message, info) => {
673
907
  state.cachedLogs.add({
674
908
  date: /* @__PURE__ */ new Date(),
675
909
  logs: [`✓ ${message} ${info}`]
676
910
  });
677
911
  });
678
- context.on("warn", (message, info) => {
912
+ context.on("kubb:warn", (message, info) => {
679
913
  state.cachedLogs.add({
680
914
  date: /* @__PURE__ */ new Date(),
681
915
  logs: [`⚠ ${message} ${info}`]
682
916
  });
683
917
  });
684
- context.on("error", (error) => {
918
+ context.on("kubb:error", (error) => {
685
919
  state.cachedLogs.add({
686
920
  date: /* @__PURE__ */ new Date(),
687
921
  logs: [`✗ ${error.message}`, error.stack || "unknown stack"]
688
922
  });
689
923
  });
690
- context.on("debug", (message) => {
924
+ context.on("kubb:debug", (message) => {
691
925
  state.cachedLogs.add({
692
926
  date: /* @__PURE__ */ new Date(),
693
927
  logs: message.logs
694
928
  });
695
929
  });
696
- context.on("plugin:start", (plugin) => {
930
+ context.on("kubb:plugin:start", (plugin) => {
697
931
  state.cachedLogs.add({
698
932
  date: /* @__PURE__ */ new Date(),
699
933
  logs: [`Generating ${plugin.name}`]
700
934
  });
701
935
  });
702
- context.on("plugin:end", (plugin, { duration, success }) => {
936
+ context.on("kubb:plugin:end", (plugin, { duration, success }) => {
703
937
  const durationStr = formatMs(duration);
704
938
  state.cachedLogs.add({
705
939
  date: /* @__PURE__ */ new Date(),
706
940
  logs: [success ? `${plugin.name} completed in ${durationStr}` : `${plugin.name} failed in ${durationStr}`]
707
941
  });
708
942
  });
709
- context.on("files:processing:start", (files) => {
943
+ context.on("kubb:files:processing:start", (files) => {
710
944
  state.cachedLogs.add({
711
945
  date: /* @__PURE__ */ new Date(),
712
946
  logs: [`Start ${files.length} writing:`, ...files.map((file) => file.path)]
713
947
  });
714
948
  });
715
- context.on("generation:end", async (config) => {
949
+ context.on("kubb:generation:end", async (config) => {
716
950
  const writtenFilePaths = await writeLogs(config.name);
717
951
  if (writtenFilePaths.length > 0) {
718
952
  const files = writtenFilePaths.map((f) => relative(process$1.cwd(), f));
719
- await context.emit("info", "Debug files written to:", files.join(", "));
953
+ await context.emit("kubb:info", "Debug files written to:", files.join(", "));
720
954
  }
721
955
  reset();
722
956
  });
@@ -770,7 +1004,7 @@ const githubActionsLogger = defineLogger({
770
1004
  function closeGroup(_name) {
771
1005
  console.log("::endgroup::");
772
1006
  }
773
- context.on("info", (message, info = "") => {
1007
+ context.on("kubb:info", (message, info = "") => {
774
1008
  if (logLevel$7 <= logLevel.silent) return;
775
1009
  const text = getMessage([
776
1010
  styleText("blue", "ℹ"),
@@ -779,7 +1013,7 @@ const githubActionsLogger = defineLogger({
779
1013
  ].join(" "));
780
1014
  console.log(text);
781
1015
  });
782
- context.on("success", (message, info = "") => {
1016
+ context.on("kubb:success", (message, info = "") => {
783
1017
  if (logLevel$7 <= logLevel.silent) return;
784
1018
  const text = getMessage([
785
1019
  styleText("blue", "✓"),
@@ -788,7 +1022,7 @@ const githubActionsLogger = defineLogger({
788
1022
  ].filter(Boolean).join(" "));
789
1023
  console.log(text);
790
1024
  });
791
- context.on("warn", (message, info = "") => {
1025
+ context.on("kubb:warn", (message, info = "") => {
792
1026
  if (logLevel$7 <= logLevel.silent) return;
793
1027
  const text = getMessage([
794
1028
  styleText("yellow", "⚠"),
@@ -797,7 +1031,7 @@ const githubActionsLogger = defineLogger({
797
1031
  ].filter(Boolean).join(" "));
798
1032
  console.warn(`::warning::${text}`);
799
1033
  });
800
- context.on("error", (error) => {
1034
+ context.on("kubb:error", (error) => {
801
1035
  const caused = toCause(error);
802
1036
  if (logLevel$7 <= logLevel.silent) return;
803
1037
  const message = error.message || String(error);
@@ -812,37 +1046,37 @@ const githubActionsLogger = defineLogger({
812
1046
  }
813
1047
  }
814
1048
  });
815
- context.on("lifecycle:start", (version) => {
1049
+ context.on("kubb:lifecycle:start", (version) => {
816
1050
  console.log(styleText("yellow", `Kubb ${version} 🧩`));
817
1051
  reset();
818
1052
  });
819
- context.on("config:start", () => {
1053
+ context.on("kubb:config:start", () => {
820
1054
  if (logLevel$7 <= logLevel.silent) return;
821
1055
  const text = getMessage("Configuration started");
822
1056
  openGroup("Configuration");
823
1057
  console.log(text);
824
1058
  });
825
- context.on("config:end", (configs) => {
1059
+ context.on("kubb:config:end", (configs) => {
826
1060
  state.currentConfigs = configs;
827
1061
  if (logLevel$7 <= logLevel.silent) return;
828
1062
  const text = getMessage("Configuration completed");
829
1063
  console.log(text);
830
1064
  closeGroup("Configuration");
831
1065
  });
832
- context.on("generation:start", (config) => {
1066
+ context.on("kubb:generation:start", (config) => {
833
1067
  reset();
834
1068
  state.totalPlugins = config.plugins?.length ?? 0;
835
1069
  const text = config.name ? `Generation for ${styleText("bold", config.name)}` : "Generation";
836
1070
  if (state.currentConfigs.length > 1) openGroup(text);
837
1071
  if (state.currentConfigs.length === 1) console.log(getMessage(text));
838
1072
  });
839
- context.on("plugin:start", (plugin) => {
1073
+ context.on("kubb:plugin:start", (plugin) => {
840
1074
  if (logLevel$7 <= logLevel.silent) return;
841
1075
  const text = getMessage(`Generating ${styleText("bold", plugin.name)}`);
842
1076
  if (state.currentConfigs.length === 1) openGroup(`Plugin: ${plugin.name}`);
843
1077
  console.log(text);
844
1078
  });
845
- context.on("plugin:end", (plugin, { duration, success }) => {
1079
+ context.on("kubb:plugin:end", (plugin, { duration, success }) => {
846
1080
  if (logLevel$7 <= logLevel.silent) return;
847
1081
  if (success) state.completedPlugins++;
848
1082
  else state.failedPlugins++;
@@ -853,7 +1087,7 @@ const githubActionsLogger = defineLogger({
853
1087
  if (state.currentConfigs.length === 1) closeGroup(`Plugin: ${plugin.name}`);
854
1088
  showProgressStep();
855
1089
  });
856
- context.on("files:processing:start", (files) => {
1090
+ context.on("kubb:files:processing:start", (files) => {
857
1091
  if (logLevel$7 <= logLevel.silent) return;
858
1092
  state.totalFiles = files.length;
859
1093
  state.processedFiles = 0;
@@ -861,46 +1095,46 @@ const githubActionsLogger = defineLogger({
861
1095
  const text = getMessage(`Writing ${files.length} files`);
862
1096
  console.log(text);
863
1097
  });
864
- context.on("files:processing:end", () => {
1098
+ context.on("kubb:files:processing:end", () => {
865
1099
  if (logLevel$7 <= logLevel.silent) return;
866
1100
  const text = getMessage("Files written successfully");
867
1101
  console.log(text);
868
1102
  if (state.currentConfigs.length === 1) closeGroup("File Generation");
869
1103
  showProgressStep();
870
1104
  });
871
- context.on("file:processing:update", () => {
1105
+ context.on("kubb:file:processing:update", () => {
872
1106
  if (logLevel$7 <= logLevel.silent) return;
873
1107
  state.processedFiles++;
874
1108
  });
875
- context.on("generation:end", (config) => {
1109
+ context.on("kubb:generation:end", (config) => {
876
1110
  const text = getMessage(config.name ? `${styleText("blue", "✓")} Generation completed for ${styleText("dim", config.name)}` : `${styleText("blue", "✓")} Generation completed`);
877
1111
  console.log(text);
878
1112
  });
879
- context.on("format:start", () => {
1113
+ context.on("kubb:format:start", () => {
880
1114
  if (logLevel$7 <= logLevel.silent) return;
881
1115
  const text = getMessage("Format started");
882
1116
  if (state.currentConfigs.length === 1) openGroup("Formatting");
883
1117
  console.log(text);
884
1118
  });
885
- context.on("format:end", () => {
1119
+ context.on("kubb:format:end", () => {
886
1120
  if (logLevel$7 <= logLevel.silent) return;
887
1121
  const text = getMessage("Format completed");
888
1122
  console.log(text);
889
1123
  if (state.currentConfigs.length === 1) closeGroup("Formatting");
890
1124
  });
891
- context.on("lint:start", () => {
1125
+ context.on("kubb:lint:start", () => {
892
1126
  if (logLevel$7 <= logLevel.silent) return;
893
1127
  const text = getMessage("Lint started");
894
1128
  if (state.currentConfigs.length === 1) openGroup("Linting");
895
1129
  console.log(text);
896
1130
  });
897
- context.on("lint:end", () => {
1131
+ context.on("kubb:lint:end", () => {
898
1132
  if (logLevel$7 <= logLevel.silent) return;
899
1133
  const text = getMessage("Lint completed");
900
1134
  console.log(text);
901
1135
  if (state.currentConfigs.length === 1) closeGroup("Linting");
902
1136
  });
903
- context.on("hook:start", async ({ id, command, args }) => {
1137
+ context.on("kubb:hook:start", async ({ id, command, args }) => {
904
1138
  const commandWithArgs = formatCommandWithArgs(command, args);
905
1139
  const text = getMessage(`Hook ${styleText("dim", commandWithArgs)} started`);
906
1140
  if (logLevel$7 > logLevel.silent) {
@@ -920,14 +1154,14 @@ const githubActionsLogger = defineLogger({
920
1154
  }
921
1155
  });
922
1156
  });
923
- context.on("hook:end", ({ command, args }) => {
1157
+ context.on("kubb:hook:end", ({ command, args }) => {
924
1158
  if (logLevel$7 <= logLevel.silent) return;
925
1159
  const commandWithArgs = formatCommandWithArgs(command, args);
926
1160
  const text = getMessage(`Hook ${styleText("dim", commandWithArgs)} completed`);
927
1161
  console.log(text);
928
1162
  if (state.currentConfigs.length === 1) closeGroup(`Hook ${commandWithArgs}`);
929
1163
  });
930
- context.on("generation:summary", (config, { status, hrStart, failedPlugins }) => {
1164
+ context.on("kubb:generation:summary", (config, { status, hrStart, failedPlugins }) => {
931
1165
  const pluginsCount = config.plugins?.length ?? 0;
932
1166
  const successCount = pluginsCount - failedPlugins.size;
933
1167
  const duration = formatHrtime(hrStart);
@@ -935,7 +1169,7 @@ const githubActionsLogger = defineLogger({
935
1169
  console.log(status === "success" ? `Kubb Summary: ${styleText("blue", "✓")} ${`${successCount} successful`}, ${pluginsCount} total, ${styleText("green", duration)}` : `Kubb Summary: ${styleText("blue", "✓")} ${`${successCount} successful`}, ✗ ${`${failedPlugins.size} failed`}, ${pluginsCount} total, ${styleText("green", duration)}`);
936
1170
  if (state.currentConfigs.length > 1) closeGroup(config.name ? `Generation for ${styleText("bold", config.name)}` : "Generation");
937
1171
  });
938
- context.on("lifecycle:end", () => {
1172
+ context.on("kubb:lifecycle:end", () => {
939
1173
  reset();
940
1174
  });
941
1175
  }
@@ -953,7 +1187,7 @@ const plainLogger = defineLogger({
953
1187
  function getMessage(message) {
954
1188
  return formatMessage(message, logLevel$6);
955
1189
  }
956
- context.on("info", (message, info) => {
1190
+ context.on("kubb:info", (message, info) => {
957
1191
  if (logLevel$6 <= logLevel.silent) return;
958
1192
  const text = getMessage([
959
1193
  "ℹ",
@@ -962,7 +1196,7 @@ const plainLogger = defineLogger({
962
1196
  ].join(" "));
963
1197
  console.log(text);
964
1198
  });
965
- context.on("success", (message, info = "") => {
1199
+ context.on("kubb:success", (message, info = "") => {
966
1200
  if (logLevel$6 <= logLevel.silent) return;
967
1201
  const text = getMessage([
968
1202
  "✓",
@@ -971,7 +1205,7 @@ const plainLogger = defineLogger({
971
1205
  ].filter(Boolean).join(" "));
972
1206
  console.log(text);
973
1207
  });
974
- context.on("warn", (message, info) => {
1208
+ context.on("kubb:warn", (message, info) => {
975
1209
  if (logLevel$6 < logLevel.warn) return;
976
1210
  const text = getMessage([
977
1211
  "⚠",
@@ -980,7 +1214,7 @@ const plainLogger = defineLogger({
980
1214
  ].filter(Boolean).join(" "));
981
1215
  console.log(text);
982
1216
  });
983
- context.on("error", (error) => {
1217
+ context.on("kubb:error", (error) => {
984
1218
  const caused = toCause(error);
985
1219
  const text = getMessage(["✗", error.message].join(" "));
986
1220
  console.log(text);
@@ -994,74 +1228,74 @@ const plainLogger = defineLogger({
994
1228
  }
995
1229
  }
996
1230
  });
997
- context.on("lifecycle:start", () => {
1231
+ context.on("kubb:lifecycle:start", () => {
998
1232
  console.log("Kubb CLI 🧩");
999
1233
  });
1000
- context.on("config:start", () => {
1234
+ context.on("kubb:config:start", () => {
1001
1235
  if (logLevel$6 <= logLevel.silent) return;
1002
1236
  const text = getMessage("Configuration started");
1003
1237
  console.log(text);
1004
1238
  });
1005
- context.on("config:end", () => {
1239
+ context.on("kubb:config:end", () => {
1006
1240
  if (logLevel$6 <= logLevel.silent) return;
1007
1241
  const text = getMessage("Configuration completed");
1008
1242
  console.log(text);
1009
1243
  });
1010
- context.on("generation:start", () => {
1244
+ context.on("kubb:generation:start", () => {
1011
1245
  const text = getMessage("Generation started");
1012
1246
  console.log(text);
1013
1247
  });
1014
- context.on("plugin:start", (plugin) => {
1248
+ context.on("kubb:plugin:start", (plugin) => {
1015
1249
  if (logLevel$6 <= logLevel.silent) return;
1016
1250
  const text = getMessage(`Generating ${plugin.name}`);
1017
1251
  console.log(text);
1018
1252
  });
1019
- context.on("plugin:end", (plugin, { duration, success }) => {
1253
+ context.on("kubb:plugin:end", (plugin, { duration, success }) => {
1020
1254
  if (logLevel$6 <= logLevel.silent) return;
1021
1255
  const durationStr = formatMs(duration);
1022
1256
  const text = getMessage(success ? `${plugin.name} completed in ${durationStr}` : `${plugin.name} failed in ${durationStr}`);
1023
1257
  console.log(text);
1024
1258
  });
1025
- context.on("files:processing:start", (files) => {
1259
+ context.on("kubb:files:processing:start", (files) => {
1026
1260
  if (logLevel$6 <= logLevel.silent) return;
1027
1261
  const text = getMessage(`Writing ${files.length} files`);
1028
1262
  console.log(text);
1029
1263
  });
1030
- context.on("file:processing:update", ({ file, config }) => {
1264
+ context.on("kubb:file:processing:update", ({ file, config }) => {
1031
1265
  if (logLevel$6 <= logLevel.silent) return;
1032
1266
  const text = getMessage(`Writing ${relative(config.root, file.path)}`);
1033
1267
  console.log(text);
1034
1268
  });
1035
- context.on("files:processing:end", () => {
1269
+ context.on("kubb:files:processing:end", () => {
1036
1270
  if (logLevel$6 <= logLevel.silent) return;
1037
1271
  const text = getMessage("Files written successfully");
1038
1272
  console.log(text);
1039
1273
  });
1040
- context.on("generation:end", (config) => {
1274
+ context.on("kubb:generation:end", (config) => {
1041
1275
  const text = getMessage(config.name ? `Generation completed for ${config.name}` : "Generation completed");
1042
1276
  console.log(text);
1043
1277
  });
1044
- context.on("format:start", () => {
1278
+ context.on("kubb:format:start", () => {
1045
1279
  if (logLevel$6 <= logLevel.silent) return;
1046
1280
  const text = getMessage("Format started");
1047
1281
  console.log(text);
1048
1282
  });
1049
- context.on("format:end", () => {
1283
+ context.on("kubb:format:end", () => {
1050
1284
  if (logLevel$6 <= logLevel.silent) return;
1051
1285
  const text = getMessage("Format completed");
1052
1286
  console.log(text);
1053
1287
  });
1054
- context.on("lint:start", () => {
1288
+ context.on("kubb:lint:start", () => {
1055
1289
  if (logLevel$6 <= logLevel.silent) return;
1056
1290
  const text = getMessage("Lint started");
1057
1291
  console.log(text);
1058
1292
  });
1059
- context.on("lint:end", () => {
1293
+ context.on("kubb:lint:end", () => {
1060
1294
  if (logLevel$6 <= logLevel.silent) return;
1061
1295
  const text = getMessage("Lint completed");
1062
1296
  console.log(text);
1063
1297
  });
1064
- context.on("hook:start", async ({ id, command, args }) => {
1298
+ context.on("kubb:hook:start", async ({ id, command, args }) => {
1065
1299
  const commandWithArgs = formatCommandWithArgs(command, args);
1066
1300
  const text = getMessage(`Hook ${commandWithArgs} started`);
1067
1301
  if (logLevel$6 > logLevel.silent) console.log(text);
@@ -1078,12 +1312,12 @@ const plainLogger = defineLogger({
1078
1312
  }
1079
1313
  });
1080
1314
  });
1081
- context.on("hook:end", ({ command, args }) => {
1315
+ context.on("kubb:hook:end", ({ command, args }) => {
1082
1316
  if (logLevel$6 <= logLevel.silent) return;
1083
1317
  const text = getMessage(`Hook ${formatCommandWithArgs(command, args)} completed`);
1084
1318
  console.log(text);
1085
1319
  });
1086
- context.on("generation:summary", (config, { pluginTimings, status, hrStart, failedPlugins, filesCreated }) => {
1320
+ context.on("kubb:generation:summary", (config, { pluginTimings, status, hrStart, failedPlugins, filesCreated }) => {
1087
1321
  const summary = getSummary({
1088
1322
  failedPlugins,
1089
1323
  filesCreated,
@@ -1156,8 +1390,8 @@ async function setupLogger(context, { logLevel: logLevel$5 }) {
1156
1390
  }
1157
1391
  //#endregion
1158
1392
  //#region src/utils/executeHooks.ts
1159
- async function executeHooks({ hooks, events }) {
1160
- const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done].filter(Boolean);
1393
+ async function executeHooks({ configHooks, hooks }) {
1394
+ const commands = Array.isArray(configHooks.done) ? configHooks.done : [configHooks.done].filter(Boolean);
1161
1395
  for (const command of commands) {
1162
1396
  const [cmd, ...args] = tokenize(command);
1163
1397
  if (!cmd) continue;
@@ -1165,16 +1399,16 @@ async function executeHooks({ hooks, events }) {
1165
1399
  const hookEndPromise = new Promise((resolve, reject) => {
1166
1400
  const handler = ({ id, success, error }) => {
1167
1401
  if (id !== hookId) return;
1168
- events.off("hook:end", handler);
1402
+ hooks.off("kubb:hook:end", handler);
1169
1403
  if (!success) {
1170
1404
  reject(error ?? /* @__PURE__ */ new Error(`Hook failed: ${command}`));
1171
1405
  return;
1172
1406
  }
1173
- events.emit("success", `${styleText("dim", command)} successfully executed`).then(resolve).catch(reject);
1407
+ hooks.emit("kubb:success", `${styleText("dim", command)} successfully executed`).then(resolve).catch(reject);
1174
1408
  };
1175
- events.on("hook:end", handler);
1409
+ hooks.on("kubb:hook:end", handler);
1176
1410
  });
1177
- await events.emit("hook:start", {
1411
+ await hooks.emit("kubb:hook:start", {
1178
1412
  id: hookId,
1179
1413
  command: cmd,
1180
1414
  args
@@ -1183,11 +1417,20 @@ async function executeHooks({ hooks, events }) {
1183
1417
  }
1184
1418
  }
1185
1419
  //#endregion
1420
+ //#region src/utils/getConfig.ts
1421
+ async function getConfigs(config, args) {
1422
+ const resolved = await (typeof config === "function" ? config(args) : config);
1423
+ return (Array.isArray(resolved) ? resolved : [resolved]).map((item) => ({
1424
+ ...item,
1425
+ plugins: item.plugins ?? []
1426
+ }));
1427
+ }
1428
+ //#endregion
1186
1429
  //#region src/utils/getCosmiConfig.ts
1187
1430
  const jiti = createJiti(import.meta.url, {
1188
1431
  jsx: {
1189
1432
  runtime: "automatic",
1190
- importSource: "@kubb/react-fabric"
1433
+ importSource: "@kubb/renderer-jsx"
1191
1434
  },
1192
1435
  sourceMaps: true,
1193
1436
  interopDefault: true
@@ -1204,10 +1447,14 @@ async function getCosmiConfig(moduleName, config) {
1204
1447
  `.${moduleName}rc.yaml`,
1205
1448
  `.${moduleName}rc.yml`,
1206
1449
  `.${moduleName}rc.ts`,
1450
+ `.${moduleName}rc.mts`,
1451
+ `.${moduleName}rc.cts`,
1207
1452
  `.${moduleName}rc.js`,
1208
1453
  `.${moduleName}rc.mjs`,
1209
1454
  `.${moduleName}rc.cjs`,
1210
1455
  `${moduleName}.config.ts`,
1456
+ `${moduleName}.config.mts`,
1457
+ `${moduleName}.config.cts`,
1211
1458
  `${moduleName}.config.js`,
1212
1459
  `${moduleName}.config.mjs`,
1213
1460
  `${moduleName}.config.cjs`
@@ -1223,7 +1470,11 @@ async function getCosmiConfig(moduleName, config) {
1223
1470
  }),
1224
1471
  ...searchPlaces
1225
1472
  ],
1226
- loaders: { ".ts": tsLoader }
1473
+ loaders: {
1474
+ ".ts": tsLoader,
1475
+ ".mts": tsLoader,
1476
+ ".cts": tsLoader
1477
+ }
1227
1478
  });
1228
1479
  try {
1229
1480
  result = config ? await explorer.load(config) : await explorer.search();
@@ -1251,17 +1502,18 @@ async function startWatcher(path, cb) {
1251
1502
  }
1252
1503
  //#endregion
1253
1504
  //#region src/runners/generate.ts
1254
- async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefix, noToolMessage, configName, outputPath, logLevel: logLevel$1, events, onStart, onEnd }) {
1505
+ async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefix, noToolMessage, configName, outputPath, logLevel: logLevel$1, hooks, onStart, onEnd }) {
1255
1506
  await onStart();
1256
1507
  let resolvedTool = toolValue;
1257
1508
  if (resolvedTool === "auto") {
1258
1509
  const detected = await detect();
1259
- if (!detected) await events.emit("warn", noToolMessage);
1510
+ if (!detected) await hooks.emit("kubb:warn", noToolMessage);
1260
1511
  else {
1261
1512
  resolvedTool = detected;
1262
- await events.emit("info", `Auto-detected ${toolLabel}: ${styleText("dim", resolvedTool)}`);
1513
+ await hooks.emit("kubb:info", `Auto-detected ${toolLabel}: ${styleText("dim", resolvedTool)}`);
1263
1514
  }
1264
1515
  }
1516
+ let toolError;
1265
1517
  if (resolvedTool && resolvedTool !== "auto" && resolvedTool in toolMap) {
1266
1518
  const toolConfig = toolMap[resolvedTool];
1267
1519
  try {
@@ -1269,20 +1521,20 @@ async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefi
1269
1521
  const hookEndPromise = new Promise((resolve, reject) => {
1270
1522
  const handler = ({ id, success, error }) => {
1271
1523
  if (id !== hookId) return;
1272
- events.off("hook:end", handler);
1524
+ hooks.off("kubb:hook:end", handler);
1273
1525
  if (!success) {
1274
1526
  reject(error ?? /* @__PURE__ */ new Error(`${toolConfig.errorMessage}`));
1275
1527
  return;
1276
1528
  }
1277
- events.emit("success", [
1529
+ hooks.emit("kubb:success", [
1278
1530
  `${successPrefix} with ${styleText("dim", resolvedTool)}`,
1279
1531
  logLevel$1 >= logLevel.info ? `on ${styleText("dim", outputPath)}` : void 0,
1280
1532
  "successfully"
1281
1533
  ].filter(Boolean).join(" ")).then(resolve).catch(reject);
1282
1534
  };
1283
- events.on("hook:end", handler);
1535
+ hooks.on("kubb:hook:end", handler);
1284
1536
  });
1285
- await events.emit("hook:start", {
1537
+ await hooks.emit("kubb:hook:start", {
1286
1538
  id: hookId,
1287
1539
  command: toolConfig.command,
1288
1540
  args: toolConfig.args(outputPath)
@@ -1291,51 +1543,40 @@ async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefi
1291
1543
  } catch (caughtError) {
1292
1544
  const err = new Error(toolConfig.errorMessage);
1293
1545
  err.cause = caughtError;
1294
- await events.emit("error", err);
1546
+ await hooks.emit("kubb:error", err);
1547
+ toolError = err;
1295
1548
  }
1296
1549
  }
1297
1550
  await onEnd();
1551
+ if (toolError) throw toolError;
1298
1552
  }
1299
- async function generate({ input, config: userConfig, events, logLevel: logLevel$2 }) {
1300
- const inputPath = input ?? ("path" in userConfig.input ? userConfig.input.path : void 0);
1553
+ async function generate(options) {
1554
+ const { input, hooks, logLevel: logLevel$2 } = options;
1301
1555
  const hrStart = process$1.hrtime();
1556
+ const inputPath = input ?? ("path" in options.config.input ? options.config.input.path : void 0);
1302
1557
  const config = {
1303
- ...userConfig,
1304
- root: userConfig.root || process$1.cwd(),
1558
+ ...options.config,
1305
1559
  input: inputPath ? {
1306
- ...userConfig.input,
1560
+ ...options.config.input,
1307
1561
  path: inputPath
1308
- } : userConfig.input,
1309
- output: {
1310
- write: true,
1311
- barrelType: "named",
1312
- extension: { ".ts": ".ts" },
1313
- format: "prettier",
1314
- ...userConfig.output
1315
- }
1562
+ } : options.config.input,
1563
+ ...options.config.output
1316
1564
  };
1317
- await events.emit("generation:start", config);
1318
- await events.emit("info", config.name ? `Setup generation ${styleText("bold", config.name)}` : "Setup generation", inputPath);
1319
- const { sources, fabric, pluginManager } = await setup({
1320
- config,
1321
- events
1322
- });
1323
- await events.emit("info", config.name ? `Build generation ${styleText("bold", config.name)}` : "Build generation", inputPath);
1324
- const { files, failedPlugins, pluginTimings, error } = await safeBuild({
1565
+ const kubb = createKubb({
1325
1566
  config,
1326
- events
1327
- }, {
1328
- pluginManager,
1329
- fabric,
1330
- events,
1331
- sources
1567
+ hooks
1332
1568
  });
1333
- await events.emit("info", "Load summary");
1569
+ await kubb.setup();
1570
+ await hooks.emit("kubb:generation:start", config);
1571
+ await hooks.emit("kubb:info", config.name ? `Setup generation ${styleText("bold", config.name)}` : "Setup generation", inputPath);
1572
+ await hooks.emit("kubb:info", config.name ? `Build generation ${styleText("bold", config.name)}` : "Build generation", inputPath);
1573
+ const { files, failedPlugins, pluginTimings, error, driver } = await kubb.safeBuild();
1574
+ await hooks.emit("kubb:info", "Load summary");
1334
1575
  if (failedPlugins.size > 0 || error) {
1335
1576
  const allErrors = [error, ...Array.from(failedPlugins).filter((it) => it.error).map((it) => it.error)].filter(Boolean);
1336
- for (const err of allErrors) await events.emit("error", err);
1337
- await events.emit("generation:end", config, files, sources);
1338
- await events.emit("generation:summary", config, {
1577
+ for (const err of allErrors) await hooks.emit("kubb:error", err);
1578
+ await hooks.emit("kubb:generation:end", config, files, kubb.sources);
1579
+ await hooks.emit("kubb:generation:summary", config, {
1339
1580
  failedPlugins,
1340
1581
  filesCreated: files.length,
1341
1582
  status: "failed",
@@ -1345,7 +1586,7 @@ async function generate({ input, config: userConfig, events, logLevel: logLevel$
1345
1586
  await sendTelemetry(buildTelemetryEvent({
1346
1587
  command: "generate",
1347
1588
  kubbVersion: version,
1348
- plugins: pluginManager.plugins.map((p) => ({
1589
+ plugins: Array.from(driver.plugins.values(), (p) => ({
1349
1590
  name: p.name,
1350
1591
  options: p.options
1351
1592
  })),
@@ -1355,8 +1596,8 @@ async function generate({ input, config: userConfig, events, logLevel: logLevel$
1355
1596
  }));
1356
1597
  process$1.exit(1);
1357
1598
  }
1358
- await events.emit("success", "Generation successfully", inputPath);
1359
- await events.emit("generation:end", config, files, sources);
1599
+ await hooks.emit("kubb:success", "Generation successfully", inputPath);
1600
+ await hooks.emit("kubb:generation:end", config, files, kubb.sources);
1360
1601
  const outputPath = path.resolve(config.root, config.output.path);
1361
1602
  if (config.output.format) await runToolPass({
1362
1603
  toolValue: config.output.format,
@@ -1368,9 +1609,9 @@ async function generate({ input, config: userConfig, events, logLevel: logLevel$
1368
1609
  configName: config.name,
1369
1610
  outputPath,
1370
1611
  logLevel: logLevel$2,
1371
- events,
1372
- onStart: () => events.emit("format:start"),
1373
- onEnd: () => events.emit("format:end")
1612
+ hooks,
1613
+ onStart: () => hooks.emit("kubb:format:start"),
1614
+ onEnd: () => hooks.emit("kubb:format:end")
1374
1615
  });
1375
1616
  if (config.output.lint) await runToolPass({
1376
1617
  toolValue: config.output.lint,
@@ -1382,19 +1623,19 @@ async function generate({ input, config: userConfig, events, logLevel: logLevel$
1382
1623
  configName: config.name,
1383
1624
  outputPath,
1384
1625
  logLevel: logLevel$2,
1385
- events,
1386
- onStart: () => events.emit("lint:start"),
1387
- onEnd: () => events.emit("lint:end")
1626
+ hooks,
1627
+ onStart: () => hooks.emit("kubb:lint:start"),
1628
+ onEnd: () => hooks.emit("kubb:lint:end")
1388
1629
  });
1389
1630
  if (config.hooks) {
1390
- await events.emit("hooks:start");
1631
+ await hooks.emit("kubb:hooks:start");
1391
1632
  await executeHooks({
1392
- hooks: config.hooks,
1393
- events
1633
+ configHooks: config.hooks,
1634
+ hooks
1394
1635
  });
1395
- await events.emit("hooks:end");
1636
+ await hooks.emit("kubb:hooks:end");
1396
1637
  }
1397
- await events.emit("generation:summary", config, {
1638
+ await hooks.emit("kubb:generation:summary", config, {
1398
1639
  failedPlugins,
1399
1640
  filesCreated: files.length,
1400
1641
  status: "success",
@@ -1404,7 +1645,7 @@ async function generate({ input, config: userConfig, events, logLevel: logLevel$
1404
1645
  await sendTelemetry(buildTelemetryEvent({
1405
1646
  command: "generate",
1406
1647
  kubbVersion: version,
1407
- plugins: pluginManager.plugins.map((p) => ({
1648
+ plugins: Array.from(driver.plugins.values(), (p) => ({
1408
1649
  name: p.name,
1409
1650
  options: p.options
1410
1651
  })),
@@ -1415,54 +1656,45 @@ async function generate({ input, config: userConfig, events, logLevel: logLevel$
1415
1656
  }
1416
1657
  async function runGenerateCommand({ input, configPath, logLevel: logLevelKey, watch }) {
1417
1658
  const logLevel$3 = logLevel[logLevelKey] ?? logLevel.info;
1418
- const events = new AsyncEventEmitter();
1419
- const promiseManager = new PromiseManager();
1420
- await setupLogger(events, { logLevel: logLevel$3 });
1659
+ const hooks = new AsyncEventEmitter();
1660
+ await setupLogger(hooks, { logLevel: logLevel$3 });
1421
1661
  await executeIfOnline(async () => {
1422
1662
  try {
1423
1663
  const latestVersion = (await (await fetch(KUBB_NPM_PACKAGE_URL)).json()).version;
1424
- if (latestVersion && version < latestVersion) await events.emit("version:new", version, latestVersion);
1664
+ if (latestVersion && version < latestVersion) await hooks.emit("kubb:version:new", version, latestVersion);
1425
1665
  } catch {}
1426
1666
  });
1427
1667
  try {
1428
1668
  const result = await getCosmiConfig("kubb", configPath);
1429
1669
  const configs = await getConfigs(result.config, { input });
1430
- await events.emit("config:start");
1431
- await events.emit("info", "Config loaded", path.relative(process$1.cwd(), result.filepath));
1432
- await events.emit("success", "Config loaded successfully", path.relative(process$1.cwd(), result.filepath));
1433
- await events.emit("config:end", configs);
1434
- await events.emit("lifecycle:start", version);
1435
- const promises = configs.map((config) => {
1436
- return async () => {
1437
- if (isInputPath(config) && watch) {
1438
- await startWatcher([input || config.input.path], async (paths) => {
1439
- events.removeAll();
1440
- await generate({
1441
- input,
1442
- config,
1443
- logLevel: logLevel$3,
1444
- events
1445
- });
1446
- clack.log.step(styleText("yellow", `Watching for changes in ${paths.join(" and ")}`));
1447
- });
1448
- return;
1449
- }
1450
- await generate({
1451
- input,
1452
- config,
1453
- logLevel: logLevel$3,
1454
- events
1455
- });
1456
- };
1670
+ await hooks.emit("kubb:config:start");
1671
+ await hooks.emit("kubb:info", "Config loaded", path.relative(process$1.cwd(), result.filepath));
1672
+ await hooks.emit("kubb:success", "Config loaded successfully", path.relative(process$1.cwd(), result.filepath));
1673
+ await hooks.emit("kubb:config:end", configs);
1674
+ await hooks.emit("kubb:lifecycle:start", version);
1675
+ for (const config of configs) if (isInputPath(config) && watch) await startWatcher([input || config.input.path], async (paths) => {
1676
+ hooks.removeAll();
1677
+ await generate({
1678
+ input,
1679
+ config,
1680
+ logLevel: logLevel$3,
1681
+ hooks
1682
+ });
1683
+ clack.log.step(styleText("yellow", `Watching for changes in ${paths.join(" and ")}`));
1684
+ });
1685
+ else await generate({
1686
+ input,
1687
+ config,
1688
+ logLevel: logLevel$3,
1689
+ hooks
1457
1690
  });
1458
- await promiseManager.run("seq", promises);
1459
- await events.emit("lifecycle:end");
1691
+ await hooks.emit("kubb:lifecycle:end");
1460
1692
  } catch (error) {
1461
- await events.emit("error", toError(error));
1693
+ await hooks.emit("kubb:error", toError(error));
1462
1694
  process$1.exit(1);
1463
1695
  }
1464
1696
  }
1465
1697
  //#endregion
1466
1698
  export { runGenerateCommand };
1467
1699
 
1468
- //# sourceMappingURL=generate-Dw5sZGB-.js.map
1700
+ //# sourceMappingURL=generate-ChFsLr7x.js.map