@kubb/cli 5.0.0-beta.7 → 5.0.0-beta.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +17 -10
- package/README.md +45 -77
- package/bin/kubb.js +9 -3
- package/dist/Telemetry-CfPP7MYq.cjs +321 -0
- package/dist/Telemetry-CfPP7MYq.cjs.map +1 -0
- package/dist/Telemetry-uAr3lK_-.js +284 -0
- package/dist/Telemetry-uAr3lK_-.js.map +1 -0
- package/dist/{define-Bdn8j5VM.cjs → defineCommand-Bo3yZTWI.cjs} +3 -21
- package/dist/defineCommand-Bo3yZTWI.cjs.map +1 -0
- package/dist/{define-m_fp-Aqm.js → defineCommand-DMEeqliP.js} +4 -16
- package/dist/defineCommand-DMEeqliP.js.map +1 -0
- package/dist/{errors-CINO1EIv.js → errors-Dc_d7BfX.js} +2 -2
- package/dist/{errors-CINO1EIv.js.map → errors-Dc_d7BfX.js.map} +1 -1
- package/dist/{errors-CLCjoSg0.cjs → errors-gxFK0vrp.cjs} +2 -2
- package/dist/{errors-CLCjoSg0.cjs.map → errors-gxFK0vrp.cjs.map} +1 -1
- package/dist/{generate-Bod9YCbF.cjs → generate-Dj_ztXAk.cjs} +21 -16
- package/dist/generate-Dj_ztXAk.cjs.map +1 -0
- package/dist/{generate-BY-juRdH.js → generate-DqE96-AW.js} +21 -16
- package/dist/generate-DqE96-AW.js.map +1 -0
- package/dist/index.cjs +34 -81
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +34 -81
- package/dist/index.js.map +1 -1
- package/dist/{init-BIkZU6mB.cjs → init-CT0QBOJR.cjs} +6 -6
- package/dist/{init-BIkZU6mB.cjs.map → init-CT0QBOJR.cjs.map} +1 -1
- package/dist/{init-Cs3Fp6nN.js → init-Dj-yuBT4.js} +5 -5
- package/dist/{init-Cs3Fp6nN.js.map → init-Dj-yuBT4.js.map} +1 -1
- package/dist/mcp-Bx5bWdkI.cjs +21 -0
- package/dist/mcp-Bx5bWdkI.cjs.map +1 -0
- package/dist/mcp-Dgf2OtCy.js +21 -0
- package/dist/mcp-Dgf2OtCy.js.map +1 -0
- package/dist/{package-DrUndPET.cjs → package-CK8o-iEe.cjs} +2 -2
- package/dist/package-CK8o-iEe.cjs.map +1 -0
- package/dist/package-DC0ALWof.js +6 -0
- package/dist/package-DC0ALWof.js.map +1 -0
- package/dist/{chunk-BvFE5Tac.js → rolldown-runtime-C0LytTxp.js} +0 -1
- package/dist/{run-YsoCk5we.cjs → run-AYlRjIX5.cjs} +136 -98
- package/dist/run-AYlRjIX5.cjs.map +1 -0
- package/dist/run-B9R0rCqJ.cjs +1380 -0
- package/dist/run-B9R0rCqJ.cjs.map +1 -0
- package/dist/run-BM1t8CSM.cjs +33 -0
- package/dist/run-BM1t8CSM.cjs.map +1 -0
- package/dist/run-BlFVmIJl.js +32 -0
- package/dist/run-BlFVmIJl.js.map +1 -0
- package/dist/{run-CQbj3ley.cjs → run-CBc896in.cjs} +6 -6
- package/dist/run-CBc896in.cjs.map +1 -0
- package/dist/run-CxPZ9S4b.js +1377 -0
- package/dist/run-CxPZ9S4b.js.map +1 -0
- package/dist/{run-CF97BWVa.js → run-D9mQoQHA.js} +123 -85
- package/dist/run-D9mQoQHA.js.map +1 -0
- package/dist/{run-CCZ24VKk.js → run-D_dWNFhX.js} +5 -5
- package/dist/run-D_dWNFhX.js.map +1 -0
- package/dist/tools-CZT9wSA6.cjs +175 -0
- package/dist/tools-CZT9wSA6.cjs.map +1 -0
- package/dist/tools-D0UogMU3.js +152 -0
- package/dist/tools-D0UogMU3.js.map +1 -0
- package/dist/{validate-lbUkWQ5o.js → validate-CRXa_v3l.js} +5 -5
- package/dist/{validate-lbUkWQ5o.js.map → validate-CRXa_v3l.js.map} +1 -1
- package/dist/{validate-Bfpf_UIh.cjs → validate-CVqbA1lL.cjs} +6 -6
- package/dist/{validate-Bfpf_UIh.cjs.map → validate-CVqbA1lL.cjs.map} +1 -1
- package/package.json +13 -25
- package/dist/agent-DN7o8nlE.js +0 -68
- package/dist/agent-DN7o8nlE.js.map +0 -1
- package/dist/agent-Fm9_8BBH.cjs +0 -70
- package/dist/agent-Fm9_8BBH.cjs.map +0 -1
- package/dist/constants-B2JTeRBb.js +0 -42
- package/dist/constants-B2JTeRBb.js.map +0 -1
- package/dist/constants-BINTA5VZ.cjs +0 -77
- package/dist/constants-BINTA5VZ.cjs.map +0 -1
- package/dist/constants-BYGmiFs0.cjs +0 -139
- package/dist/constants-BYGmiFs0.cjs.map +0 -1
- package/dist/constants-DSJ-Xrbv.js +0 -116
- package/dist/constants-DSJ-Xrbv.js.map +0 -1
- package/dist/define-Bdn8j5VM.cjs.map +0 -1
- package/dist/define-m_fp-Aqm.js.map +0 -1
- package/dist/generate-BY-juRdH.js.map +0 -1
- package/dist/generate-Bod9YCbF.cjs.map +0 -1
- package/dist/mcp-BSNulBcC.js +0 -39
- package/dist/mcp-BSNulBcC.js.map +0 -1
- package/dist/mcp-DcSrFhhP.cjs +0 -39
- package/dist/mcp-DcSrFhhP.cjs.map +0 -1
- package/dist/package-D5wmvFl4.js +0 -6
- package/dist/package-D5wmvFl4.js.map +0 -1
- package/dist/package-DrUndPET.cjs.map +0 -1
- package/dist/run-BAJubgdA.js +0 -1735
- package/dist/run-BAJubgdA.js.map +0 -1
- package/dist/run-BzpYYOQs.js +0 -121
- package/dist/run-BzpYYOQs.js.map +0 -1
- package/dist/run-CCZ24VKk.js.map +0 -1
- package/dist/run-CF97BWVa.js.map +0 -1
- package/dist/run-CQbj3ley.cjs.map +0 -1
- package/dist/run-CqKd6JNc.cjs +0 -1738
- package/dist/run-CqKd6JNc.cjs.map +0 -1
- package/dist/run-D0hmRpHy.js +0 -49
- package/dist/run-D0hmRpHy.js.map +0 -1
- package/dist/run-DwdAwnLG.cjs +0 -125
- package/dist/run-DwdAwnLG.cjs.map +0 -1
- package/dist/run-Lr0Ctnu0.cjs +0 -50
- package/dist/run-Lr0Ctnu0.cjs.map +0 -1
- package/dist/run-YsoCk5we.cjs.map +0 -1
- package/dist/shell-475fQKaX.cjs +0 -62
- package/dist/shell-475fQKaX.cjs.map +0 -1
- package/dist/shell-CN6DNqeC.js +0 -51
- package/dist/shell-CN6DNqeC.js.map +0 -1
- package/dist/telemetry-B2iWkY5e.cjs +0 -280
- package/dist/telemetry-B2iWkY5e.cjs.map +0 -1
- package/dist/telemetry-BkektVz6.js +0 -243
- package/dist/telemetry-BkektVz6.js.map +0 -1
- package/src/commands/agent/start.ts +0 -50
- package/src/commands/agent.ts +0 -10
- package/src/commands/generate.ts +0 -59
- package/src/commands/init.ts +0 -51
- package/src/commands/mcp.ts +0 -36
- package/src/commands/validate.ts +0 -22
- package/src/constants.ts +0 -48
- package/src/index.ts +0 -45
- package/src/loggers/clackLogger.ts +0 -460
- package/src/loggers/fileSystemLogger.ts +0 -148
- package/src/loggers/githubActionsLogger.ts +0 -367
- package/src/loggers/plainLogger.ts +0 -243
- package/src/loggers/types.ts +0 -7
- package/src/loggers/utils.ts +0 -252
- package/src/runners/agent/run.ts +0 -113
- package/src/runners/agent/utils.ts +0 -98
- package/src/runners/generate/run.ts +0 -276
- package/src/runners/generate/utils.ts +0 -209
- package/src/runners/init/run.ts +0 -211
- package/src/runners/init/utils.ts +0 -33
- package/src/runners/mcp/run.ts +0 -55
- package/src/runners/validate/run.ts +0 -63
- package/src/telemetry.ts +0 -280
- /package/dist/{chunk-ByKO4r7w.cjs → rolldown-runtime-Bx3C2hgW.cjs} +0 -0
|
@@ -0,0 +1,1380 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-Bx3C2hgW.cjs");
|
|
2
|
+
const require_errors = require("./errors-gxFK0vrp.cjs");
|
|
3
|
+
const require_Telemetry = require("./Telemetry-CfPP7MYq.cjs");
|
|
4
|
+
const require_tools = require("./tools-CZT9wSA6.cjs");
|
|
5
|
+
const require_package = require("./package-CK8o-iEe.cjs");
|
|
6
|
+
let node_util = require("node:util");
|
|
7
|
+
let node_events = require("node:events");
|
|
8
|
+
let node_crypto = require("node:crypto");
|
|
9
|
+
let node_fs = require("node:fs");
|
|
10
|
+
let node_path = require("node:path");
|
|
11
|
+
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
12
|
+
let node_process = require("node:process");
|
|
13
|
+
node_process = require_rolldown_runtime.__toESM(node_process, 1);
|
|
14
|
+
let _clack_prompts = require("@clack/prompts");
|
|
15
|
+
_clack_prompts = require_rolldown_runtime.__toESM(_clack_prompts, 1);
|
|
16
|
+
let _kubb_core = require("@kubb/core");
|
|
17
|
+
let node_url = require("node:url");
|
|
18
|
+
let jiti = require("jiti");
|
|
19
|
+
let tinyexec = require("tinyexec");
|
|
20
|
+
let unconfig = require("unconfig");
|
|
21
|
+
//#region ../../internals/utils/src/asyncEventEmitter.ts
|
|
22
|
+
/**
|
|
23
|
+
* Typed `EventEmitter` that awaits all async listeners before resolving.
|
|
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
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
var AsyncEventEmitter = class {
|
|
34
|
+
/**
|
|
35
|
+
* Maximum number of listeners per event before Node emits a memory-leak warning.
|
|
36
|
+
* @default 10
|
|
37
|
+
*/
|
|
38
|
+
constructor(maxListener = 10) {
|
|
39
|
+
this.#emitter.setMaxListeners(maxListener);
|
|
40
|
+
}
|
|
41
|
+
#emitter = new node_events.EventEmitter();
|
|
42
|
+
/**
|
|
43
|
+
* Emits `eventName` and awaits all registered listeners sequentially.
|
|
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
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
emit(eventName, ...eventArgs) {
|
|
52
|
+
const listeners = this.#emitter.listeners(eventName);
|
|
53
|
+
if (listeners.length === 0) return;
|
|
54
|
+
return this.#emitAll(eventName, listeners, eventArgs);
|
|
55
|
+
}
|
|
56
|
+
async #emitAll(eventName, listeners, eventArgs) {
|
|
57
|
+
for (const listener of listeners) try {
|
|
58
|
+
await listener(...eventArgs);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
let serializedArgs;
|
|
61
|
+
try {
|
|
62
|
+
serializedArgs = JSON.stringify(eventArgs);
|
|
63
|
+
} catch {
|
|
64
|
+
serializedArgs = String(eventArgs);
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`Error in async listener for "${eventName}" with eventArgs ${serializedArgs}`, { cause: require_errors.toError(err) });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Registers a persistent listener for `eventName`.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* emitter.on('build', async (name) => { console.log(name) })
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
on(eventName, handler) {
|
|
78
|
+
this.#emitter.on(eventName, handler);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Registers a one-shot listener that removes itself after the first invocation.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* emitter.onOnce('build', async (name) => { console.log(name) })
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
onOnce(eventName, handler) {
|
|
89
|
+
const wrapper = (...args) => {
|
|
90
|
+
this.off(eventName, wrapper);
|
|
91
|
+
return handler(...args);
|
|
92
|
+
};
|
|
93
|
+
this.on(eventName, wrapper);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Removes a previously registered listener.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* emitter.off('build', handler)
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
off(eventName, handler) {
|
|
104
|
+
this.#emitter.off(eventName, handler);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Returns the number of listeners registered for `eventName`.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* emitter.on('build', handler)
|
|
112
|
+
* emitter.listenerCount('build') // 1
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
listenerCount(eventName) {
|
|
116
|
+
return this.#emitter.listenerCount(eventName);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Raises or lowers the per-event listener ceiling before Node warns about a memory leak.
|
|
120
|
+
* Set this above the expected listener count when many listeners attach by design.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* emitter.setMaxListeners(40)
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
setMaxListeners(max) {
|
|
128
|
+
this.#emitter.setMaxListeners(max);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Returns the current per-event listener ceiling.
|
|
132
|
+
*/
|
|
133
|
+
getMaxListeners() {
|
|
134
|
+
return this.#emitter.getMaxListeners();
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Removes all listeners from every event channel.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* emitter.removeAll()
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
removeAll() {
|
|
145
|
+
this.#emitter.removeAllListeners();
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region ../../internals/utils/src/time.ts
|
|
150
|
+
/**
|
|
151
|
+
* Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.
|
|
152
|
+
* Rounds to 2 decimal places for sub-millisecond precision without noise.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* const start = process.hrtime()
|
|
157
|
+
* doWork()
|
|
158
|
+
* getElapsedMs(start) // 42.35
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
function getElapsedMs(hrStart) {
|
|
162
|
+
const [seconds, nanoseconds] = process.hrtime(hrStart);
|
|
163
|
+
const ms = seconds * 1e3 + nanoseconds / 1e6;
|
|
164
|
+
return Math.round(ms * 100) / 100;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Converts a millisecond duration into a human-readable string (`ms`, `s`, or `m s`).
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* formatMs(250) // '250ms'
|
|
172
|
+
* formatMs(1500) // '1.50s'
|
|
173
|
+
* formatMs(90000) // '1m 30.0s'
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
function formatMs(ms) {
|
|
177
|
+
if (ms >= 6e4) return `${Math.floor(ms / 6e4)}m ${(ms % 6e4 / 1e3).toFixed(1)}s`;
|
|
178
|
+
if (ms >= 1e3) return `${(ms / 1e3).toFixed(2)}s`;
|
|
179
|
+
return `${Math.round(ms)}ms`;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Formats the elapsed time since `hrStart` as a human-readable string.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* const start = process.hrtime()
|
|
187
|
+
* doWork()
|
|
188
|
+
* formatHrtime(start) // '1.50s'
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
function formatHrtime(hrStart) {
|
|
192
|
+
return formatMs(getElapsedMs(hrStart));
|
|
193
|
+
}
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region ../../internals/utils/src/colors.ts
|
|
196
|
+
/**
|
|
197
|
+
* Parses a CSS hex color string (`#RGB`) into its RGB channels.
|
|
198
|
+
* Falls back to `255` for any channel that cannot be parsed.
|
|
199
|
+
*/
|
|
200
|
+
function parseHex(color) {
|
|
201
|
+
const int = Number.parseInt(color.replace("#", ""), 16);
|
|
202
|
+
return Number.isNaN(int) ? {
|
|
203
|
+
r: 255,
|
|
204
|
+
g: 255,
|
|
205
|
+
b: 255
|
|
206
|
+
} : {
|
|
207
|
+
r: int >> 16 & 255,
|
|
208
|
+
g: int >> 8 & 255,
|
|
209
|
+
b: int & 255
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Returns a function that wraps a string in a 24-bit ANSI true-color escape sequence
|
|
214
|
+
* for the given hex color.
|
|
215
|
+
*/
|
|
216
|
+
function hex(color) {
|
|
217
|
+
const { r, g, b } = parseHex(color);
|
|
218
|
+
return (text) => `\x1b[38;2;${r};${g};${b}m${text}\x1b[0m`;
|
|
219
|
+
}
|
|
220
|
+
function gradient(colorStops, text) {
|
|
221
|
+
const chars = text.split("");
|
|
222
|
+
return chars.map((char, i) => {
|
|
223
|
+
const t = chars.length <= 1 ? 0 : i / (chars.length - 1);
|
|
224
|
+
const seg = Math.min(Math.floor(t * (colorStops.length - 1)), colorStops.length - 2);
|
|
225
|
+
const lt = t * (colorStops.length - 1) - seg;
|
|
226
|
+
const from = parseHex(colorStops[seg]);
|
|
227
|
+
const to = parseHex(colorStops[seg + 1]);
|
|
228
|
+
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`;
|
|
229
|
+
}).join("");
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* ANSI color functions for each part of the Kubb mascot illustration.
|
|
233
|
+
*/
|
|
234
|
+
const palette = {
|
|
235
|
+
/**
|
|
236
|
+
* Top cap of the skittle.
|
|
237
|
+
*/
|
|
238
|
+
lid: hex("#F55A17"),
|
|
239
|
+
/**
|
|
240
|
+
* Upper wood body.
|
|
241
|
+
*/
|
|
242
|
+
woodTop: hex("#F5A217"),
|
|
243
|
+
/**
|
|
244
|
+
* Middle wood body.
|
|
245
|
+
*/
|
|
246
|
+
woodMid: hex("#F58517"),
|
|
247
|
+
/**
|
|
248
|
+
* Base wood body.
|
|
249
|
+
*/
|
|
250
|
+
woodBase: hex("#B45309"),
|
|
251
|
+
/**
|
|
252
|
+
* Eye whites.
|
|
253
|
+
*/
|
|
254
|
+
eye: hex("#FFFFFF"),
|
|
255
|
+
/**
|
|
256
|
+
* Highlight accent.
|
|
257
|
+
*/
|
|
258
|
+
highlight: hex("#adadc6"),
|
|
259
|
+
/**
|
|
260
|
+
* Cheek blush.
|
|
261
|
+
*/
|
|
262
|
+
blush: hex("#FDA4AF")
|
|
263
|
+
};
|
|
264
|
+
/**
|
|
265
|
+
* Generates the Kubb mascot welcome banner as an ANSI-colored string.
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* console.log(getIntro({ title: 'kubb.config.ts', description: 'generating…', version: '5.0.0', areEyesOpen: true }))
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
function getIntro({ title, description, version, areEyesOpen }) {
|
|
273
|
+
const kubbVersion = gradient([
|
|
274
|
+
"#F58517",
|
|
275
|
+
"#F5A217",
|
|
276
|
+
"#F55A17"
|
|
277
|
+
], `KUBB v${version}`);
|
|
278
|
+
const eyeTop = areEyesOpen ? palette.eye("█▀█") : palette.eye("───");
|
|
279
|
+
const eyeBottom = areEyesOpen ? palette.eye("▀▀▀") : palette.eye("───");
|
|
280
|
+
return `
|
|
281
|
+
${palette.lid("▄▄▄▄▄▄▄▄▄▄▄▄▄")}
|
|
282
|
+
${palette.woodTop("█ ")}${palette.highlight("▄▄")}${palette.woodTop(" ")}${palette.highlight("▄▄")}${palette.woodTop(" █")} ${kubbVersion}
|
|
283
|
+
${palette.woodMid("█ ")}${eyeTop}${palette.woodMid(" ")}${eyeTop}${palette.woodMid(" █")} ${(0, node_util.styleText)("gray", title)}
|
|
284
|
+
${palette.woodMid("█ ")}${eyeBottom}${palette.woodMid(" ")}${palette.blush("◡")}${palette.woodMid(" ")}${eyeBottom}${palette.woodMid(" █")} ${(0, node_util.styleText)("yellow", "➜")} ${(0, node_util.styleText)("white", description)}
|
|
285
|
+
${palette.woodBase("▀▀▀▀▀▀▀▀▀▀▀▀▀")}
|
|
286
|
+
`;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Formats a millisecond duration with a threshold-based ANSI color.
|
|
290
|
+
* `≤ 500 ms` → green · `≤ 1 000 ms` → yellow · `> 1 000 ms` → red.
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```ts
|
|
294
|
+
* formatMsWithColor(200) // '\x1b[32m200ms\x1b[39m'
|
|
295
|
+
* formatMsWithColor(800) // '\x1b[33m800ms\x1b[39m'
|
|
296
|
+
* formatMsWithColor(1500) // '\x1b[31m1.50s\x1b[39m'
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
function formatMsWithColor(ms) {
|
|
300
|
+
const formatted = formatMs(ms);
|
|
301
|
+
if (ms <= 500) return (0, node_util.styleText)("green", formatted);
|
|
302
|
+
if (ms <= 1e3) return (0, node_util.styleText)("yellow", formatted);
|
|
303
|
+
return (0, node_util.styleText)("red", formatted);
|
|
304
|
+
}
|
|
305
|
+
//#endregion
|
|
306
|
+
//#region src/loggers/defineLogger.ts
|
|
307
|
+
/**
|
|
308
|
+
* Defines a typed logger. The `install` method subscribes to lifecycle events
|
|
309
|
+
* on the shared emitter and forwards them to the logger's destination.
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```ts
|
|
313
|
+
* import { defineLogger } from '@kubb/cli'
|
|
314
|
+
*
|
|
315
|
+
* export const myLogger = defineLogger({
|
|
316
|
+
* name: 'my-logger',
|
|
317
|
+
* install(context) {
|
|
318
|
+
* context.on('kubb:info', ({ message }) => console.log('ℹ', message))
|
|
319
|
+
* context.on('kubb:error', ({ error }) => console.error('✗', error.message))
|
|
320
|
+
* },
|
|
321
|
+
* })
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
function defineLogger(logger) {
|
|
325
|
+
return logger;
|
|
326
|
+
}
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region src/loggers/clackLogger.ts
|
|
329
|
+
/**
|
|
330
|
+
* TTY logger for local development, with spinners and progress bars.
|
|
331
|
+
*/
|
|
332
|
+
const clackLogger = defineLogger({
|
|
333
|
+
name: "clack",
|
|
334
|
+
install(context, options) {
|
|
335
|
+
const logLevel = options?.logLevel ?? _kubb_core.logLevel.info;
|
|
336
|
+
const state = {
|
|
337
|
+
...createProgressCounters(),
|
|
338
|
+
spinner: _clack_prompts.spinner(),
|
|
339
|
+
isSpinning: false,
|
|
340
|
+
runningPlugins: /* @__PURE__ */ new Set(),
|
|
341
|
+
activeProgress: /* @__PURE__ */ new Map(),
|
|
342
|
+
activeHookLogs: /* @__PURE__ */ new Map()
|
|
343
|
+
};
|
|
344
|
+
function stopActiveProgress() {
|
|
345
|
+
for (const [, active] of state.activeProgress) {
|
|
346
|
+
if (active.interval) clearInterval(active.interval);
|
|
347
|
+
active.progressBar?.stop();
|
|
348
|
+
}
|
|
349
|
+
state.activeProgress.clear();
|
|
350
|
+
}
|
|
351
|
+
function reset() {
|
|
352
|
+
stopActiveProgress();
|
|
353
|
+
resetProgressCounters(state);
|
|
354
|
+
state.spinner = _clack_prompts.spinner();
|
|
355
|
+
state.isSpinning = false;
|
|
356
|
+
state.runningPlugins.clear();
|
|
357
|
+
state.activeHookLogs.clear();
|
|
358
|
+
}
|
|
359
|
+
function pluginProgressText() {
|
|
360
|
+
const running = [...state.runningPlugins].map((name) => (0, node_util.styleText)("bold", name));
|
|
361
|
+
return getMessage(running.length > 0 ? `Generating ${running.join(", ")}` : "Generating plugins");
|
|
362
|
+
}
|
|
363
|
+
function showProgressStep() {
|
|
364
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
365
|
+
const line = buildProgressLine(state);
|
|
366
|
+
if (line) _clack_prompts.log.step(getMessage(line));
|
|
367
|
+
}
|
|
368
|
+
function getMessage(message) {
|
|
369
|
+
return formatMessage(message, logLevel);
|
|
370
|
+
}
|
|
371
|
+
function onStep(event, message) {
|
|
372
|
+
context.on(event, () => {
|
|
373
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
374
|
+
_clack_prompts.log.step(getMessage(message));
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
function stopSpinner(text) {
|
|
378
|
+
if (!state.isSpinning) return;
|
|
379
|
+
state.spinner.stop(text);
|
|
380
|
+
state.isSpinning = false;
|
|
381
|
+
}
|
|
382
|
+
context.on("kubb:info", ({ message, info = "" }) => {
|
|
383
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
384
|
+
const text = getMessage([
|
|
385
|
+
(0, node_util.styleText)("blue", "ℹ"),
|
|
386
|
+
message,
|
|
387
|
+
info ? (0, node_util.styleText)("dim", info) : void 0
|
|
388
|
+
].filter(Boolean).join(" "));
|
|
389
|
+
if (state.isSpinning) {
|
|
390
|
+
state.spinner.message(text);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
_clack_prompts.log.info(text);
|
|
394
|
+
});
|
|
395
|
+
context.on("kubb:success", ({ message, info = "" }) => {
|
|
396
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
397
|
+
const text = getMessage([
|
|
398
|
+
(0, node_util.styleText)("blue", "✓"),
|
|
399
|
+
message,
|
|
400
|
+
logLevel >= _kubb_core.logLevel.info ? (0, node_util.styleText)("dim", info) : void 0
|
|
401
|
+
].filter(Boolean).join(" "));
|
|
402
|
+
if (state.isSpinning) {
|
|
403
|
+
stopSpinner(text);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
_clack_prompts.log.success(text);
|
|
407
|
+
});
|
|
408
|
+
context.on("kubb:warn", ({ message, info }) => {
|
|
409
|
+
if (logLevel < _kubb_core.logLevel.warn) return;
|
|
410
|
+
const text = getMessage([
|
|
411
|
+
(0, node_util.styleText)("yellow", "⚠"),
|
|
412
|
+
message,
|
|
413
|
+
logLevel >= _kubb_core.logLevel.info && info ? (0, node_util.styleText)("dim", info) : void 0
|
|
414
|
+
].filter(Boolean).join(" "));
|
|
415
|
+
_clack_prompts.log.warn(text);
|
|
416
|
+
});
|
|
417
|
+
context.on("kubb:error", ({ error }) => {
|
|
418
|
+
const caused = require_errors.toCause(error);
|
|
419
|
+
const text = [(0, node_util.styleText)("red", "✗"), error.message].join(" ");
|
|
420
|
+
if (state.isSpinning) {
|
|
421
|
+
stopSpinner(getMessage(text));
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
_clack_prompts.log.error(getMessage(text));
|
|
425
|
+
if (logLevel >= _kubb_core.logLevel.verbose && error.stack) {
|
|
426
|
+
const frames = error.stack.split("\n").slice(1, 4);
|
|
427
|
+
for (const frame of frames) _clack_prompts.log.message(getMessage((0, node_util.styleText)("dim", frame.trim())));
|
|
428
|
+
if (caused?.stack) {
|
|
429
|
+
_clack_prompts.log.message((0, node_util.styleText)("dim", `└─ caused by ${caused.message}`));
|
|
430
|
+
const frames = caused.stack.split("\n").slice(1, 4);
|
|
431
|
+
for (const frame of frames) _clack_prompts.log.message(getMessage(` ${(0, node_util.styleText)("dim", frame.trim())}`));
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
context.on("kubb:diagnostic", ({ diagnostic }) => {
|
|
436
|
+
if (logLevel <= _kubb_core.logLevel.silent && diagnostic.severity !== "error") return;
|
|
437
|
+
stopSpinner();
|
|
438
|
+
stopActiveProgress();
|
|
439
|
+
if (_kubb_core.Diagnostics.isUpdate(diagnostic)) {
|
|
440
|
+
_clack_prompts.box(`\`v${diagnostic.currentVersion}\` → \`v${diagnostic.latestVersion}\`
|
|
441
|
+
Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
442
|
+
width: "auto",
|
|
443
|
+
formatBorder: (s) => (0, node_util.styleText)("yellow", s),
|
|
444
|
+
rounded: true,
|
|
445
|
+
withGuide: false,
|
|
446
|
+
contentAlign: "center",
|
|
447
|
+
titleAlign: "center"
|
|
448
|
+
});
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
const { headline, details } = _kubb_core.Diagnostics.format(diagnostic);
|
|
452
|
+
_clack_prompts.log.message([headline, ...details], {
|
|
453
|
+
symbol: "",
|
|
454
|
+
secondarySymbol: ""
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
context.on("kubb:lifecycle:start", async ({ version }) => {
|
|
458
|
+
console.log(`\n${getIntro({
|
|
459
|
+
title: "The meta framework for code generation",
|
|
460
|
+
description: "Ready to start",
|
|
461
|
+
version,
|
|
462
|
+
areEyesOpen: true
|
|
463
|
+
})}\n`);
|
|
464
|
+
reset();
|
|
465
|
+
});
|
|
466
|
+
context.on("kubb:generation:start", ({ config }) => {
|
|
467
|
+
reset();
|
|
468
|
+
state.totalPlugins = config.plugins?.length ?? 0;
|
|
469
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
470
|
+
const text = getMessage(["Generation started", config.name ? `for ${(0, node_util.styleText)("dim", config.name)}` : void 0].filter(Boolean).join(" "));
|
|
471
|
+
_clack_prompts.intro(text);
|
|
472
|
+
});
|
|
473
|
+
context.on("kubb:plugin:start", ({ plugin }) => {
|
|
474
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
475
|
+
stopSpinner();
|
|
476
|
+
state.runningPlugins.add(plugin.name);
|
|
477
|
+
const active = state.activeProgress.get("plugins");
|
|
478
|
+
if (active) {
|
|
479
|
+
active.progressBar.advance(0, pluginProgressText());
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
const progressBar = _clack_prompts.progress({
|
|
483
|
+
style: "block",
|
|
484
|
+
max: Math.max(state.totalPlugins, 1),
|
|
485
|
+
size: 30
|
|
486
|
+
});
|
|
487
|
+
progressBar.start(pluginProgressText());
|
|
488
|
+
progressBar.advance(state.completedPlugins + state.failedPlugins, pluginProgressText());
|
|
489
|
+
state.activeProgress.set("plugins", { progressBar });
|
|
490
|
+
});
|
|
491
|
+
context.on("kubb:plugin:end", ({ plugin, success }) => {
|
|
492
|
+
stopSpinner();
|
|
493
|
+
const active = state.activeProgress.get("plugins");
|
|
494
|
+
if (!active || logLevel === _kubb_core.logLevel.silent) return;
|
|
495
|
+
state.runningPlugins.delete(plugin.name);
|
|
496
|
+
recordPluginResult(state, success);
|
|
497
|
+
active.progressBar.advance(1, pluginProgressText());
|
|
498
|
+
if (state.runningPlugins.size === 0) {
|
|
499
|
+
active.progressBar.stop(getMessage("Plugins generated"));
|
|
500
|
+
state.activeProgress.delete("plugins");
|
|
501
|
+
showProgressStep();
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
context.on("kubb:files:processing:start", ({ files }) => {
|
|
505
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
506
|
+
stopSpinner();
|
|
507
|
+
state.totalFiles = files.length;
|
|
508
|
+
state.processedFiles = 0;
|
|
509
|
+
const text = `Writing ${files.length} files`;
|
|
510
|
+
const progressBar = _clack_prompts.progress({
|
|
511
|
+
style: "block",
|
|
512
|
+
max: files.length,
|
|
513
|
+
size: 30
|
|
514
|
+
});
|
|
515
|
+
context.emit("kubb:info", { message: text });
|
|
516
|
+
progressBar.start(getMessage(text));
|
|
517
|
+
state.activeProgress.set("files", { progressBar });
|
|
518
|
+
});
|
|
519
|
+
context.on("kubb:files:processing:update", ({ files }) => {
|
|
520
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
521
|
+
stopSpinner();
|
|
522
|
+
const active = state.activeProgress.get("files");
|
|
523
|
+
for (const { file, config } of files) {
|
|
524
|
+
state.processedFiles++;
|
|
525
|
+
if (active) active.progressBar.advance(void 0, `Writing ${(0, node_path.relative)(config.root, file.path)}`);
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
context.on("kubb:files:processing:end", () => {
|
|
529
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
530
|
+
stopSpinner();
|
|
531
|
+
const text = getMessage("Files written successfully");
|
|
532
|
+
const active = state.activeProgress.get("files");
|
|
533
|
+
if (!active) return;
|
|
534
|
+
active.progressBar.stop(text);
|
|
535
|
+
state.activeProgress.delete("files");
|
|
536
|
+
showProgressStep();
|
|
537
|
+
});
|
|
538
|
+
context.on("kubb:generation:end", ({ config }) => {
|
|
539
|
+
stopSpinner();
|
|
540
|
+
const text = getMessage(config.name ? `Generation completed for ${(0, node_util.styleText)("dim", config.name)}` : "Generation completed");
|
|
541
|
+
_clack_prompts.outro(text);
|
|
542
|
+
});
|
|
543
|
+
onStep("kubb:format:start", "Formatting");
|
|
544
|
+
onStep("kubb:lint:start", "Linting");
|
|
545
|
+
onStep("kubb:hooks:start", "Running hooks");
|
|
546
|
+
context.on("kubb:hook:start", ({ id, command, args }) => {
|
|
547
|
+
if (logLevel <= _kubb_core.logLevel.silent || !id) return;
|
|
548
|
+
stopSpinner();
|
|
549
|
+
const title = getMessage(`Running ${(0, node_util.styleText)("dim", formatCommandWithArgs(command, args))}`);
|
|
550
|
+
const taskLog = _clack_prompts.taskLog({ title });
|
|
551
|
+
state.activeHookLogs.set(id, {
|
|
552
|
+
taskLog,
|
|
553
|
+
hrStart: node_process.default.hrtime()
|
|
554
|
+
});
|
|
555
|
+
});
|
|
556
|
+
if (logLevel > _kubb_core.logLevel.silent) context.on("kubb:hook:line", ({ id, line }) => {
|
|
557
|
+
state.activeHookLogs.get(id)?.taskLog.message((0, node_util.styleText)("dim", line));
|
|
558
|
+
});
|
|
559
|
+
context.on("kubb:hook:end", ({ id, command, args, success, error, stdout, stderr }) => {
|
|
560
|
+
if (!id) return;
|
|
561
|
+
if (logLevel <= _kubb_core.logLevel.silent) {
|
|
562
|
+
if (!success) {
|
|
563
|
+
if (stdout) console.log(stdout);
|
|
564
|
+
if (stderr) console.error(stderr);
|
|
565
|
+
}
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
const active = state.activeHookLogs.get(id);
|
|
569
|
+
if (!active) return;
|
|
570
|
+
state.activeHookLogs.delete(id);
|
|
571
|
+
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
572
|
+
const duration = formatMsWithColor(getElapsedMs(active.hrStart));
|
|
573
|
+
if (success) active.taskLog.success(getMessage(`${(0, node_util.styleText)("dim", commandWithArgs)} completed in ${duration}`));
|
|
574
|
+
else {
|
|
575
|
+
const reason = error?.message ? ` (${error.message})` : "";
|
|
576
|
+
active.taskLog.error(getMessage(`${(0, node_util.styleText)("dim", commandWithArgs)} failed${reason}`), { showLog: true });
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
context.on("kubb:lifecycle:end", () => {
|
|
580
|
+
reset();
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
//#endregion
|
|
585
|
+
//#region src/loggers/plainLogger.ts
|
|
586
|
+
/**
|
|
587
|
+
* Plain console adapter for non-TTY environments, built on `console.log`.
|
|
588
|
+
*/
|
|
589
|
+
const plainLogger = defineLogger({
|
|
590
|
+
name: "plain",
|
|
591
|
+
install(context, options) {
|
|
592
|
+
const logLevel = options?.logLevel ?? _kubb_core.logLevel.info;
|
|
593
|
+
const hookTimer = createHookTimer();
|
|
594
|
+
function getMessage(message) {
|
|
595
|
+
return formatMessage(message, logLevel);
|
|
596
|
+
}
|
|
597
|
+
function onStep(event, message) {
|
|
598
|
+
context.on(event, () => {
|
|
599
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
600
|
+
console.log(getMessage(message));
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
context.on("kubb:info", ({ message, info }) => {
|
|
604
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
605
|
+
const text = getMessage([
|
|
606
|
+
"ℹ",
|
|
607
|
+
message,
|
|
608
|
+
info
|
|
609
|
+
].join(" "));
|
|
610
|
+
console.log(text);
|
|
611
|
+
});
|
|
612
|
+
context.on("kubb:success", ({ message, info = "" }) => {
|
|
613
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
614
|
+
const text = getMessage([
|
|
615
|
+
"✓",
|
|
616
|
+
message,
|
|
617
|
+
logLevel >= _kubb_core.logLevel.info ? info : void 0
|
|
618
|
+
].filter(Boolean).join(" "));
|
|
619
|
+
console.log(text);
|
|
620
|
+
});
|
|
621
|
+
context.on("kubb:warn", ({ message, info }) => {
|
|
622
|
+
if (logLevel < _kubb_core.logLevel.warn) return;
|
|
623
|
+
const text = getMessage([
|
|
624
|
+
"⚠",
|
|
625
|
+
message,
|
|
626
|
+
logLevel >= _kubb_core.logLevel.info ? info : void 0
|
|
627
|
+
].filter(Boolean).join(" "));
|
|
628
|
+
console.log(text);
|
|
629
|
+
});
|
|
630
|
+
context.on("kubb:error", ({ error }) => {
|
|
631
|
+
const caused = require_errors.toCause(error);
|
|
632
|
+
const text = getMessage(["✗", error.message].join(" "));
|
|
633
|
+
console.log(text);
|
|
634
|
+
if (logLevel >= _kubb_core.logLevel.verbose && error.stack) {
|
|
635
|
+
const frames = error.stack.split("\n").slice(1, 4);
|
|
636
|
+
for (const frame of frames) console.log(getMessage(frame.trim()));
|
|
637
|
+
if (caused?.stack) {
|
|
638
|
+
console.log(`└─ caused by ${caused.message}`);
|
|
639
|
+
const frames = caused.stack.split("\n").slice(1, 4);
|
|
640
|
+
for (const frame of frames) console.log(getMessage(` ${frame.trim()}`));
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
context.on("kubb:diagnostic", ({ diagnostic }) => {
|
|
645
|
+
if (logLevel <= _kubb_core.logLevel.silent && diagnostic.severity !== "error") return;
|
|
646
|
+
console.log(getMessage(_kubb_core.Diagnostics.formatLines(diagnostic).join("\n")));
|
|
647
|
+
});
|
|
648
|
+
context.on("kubb:lifecycle:start", ({ version }) => {
|
|
649
|
+
console.log(`Kubb CLI v${version}`);
|
|
650
|
+
});
|
|
651
|
+
context.on("kubb:generation:start", () => {
|
|
652
|
+
const text = getMessage("Generation started");
|
|
653
|
+
console.log(text);
|
|
654
|
+
});
|
|
655
|
+
context.on("kubb:plugin:start", ({ plugin }) => {
|
|
656
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
657
|
+
const text = getMessage(`Generating ${plugin.name}`);
|
|
658
|
+
console.log(text);
|
|
659
|
+
});
|
|
660
|
+
context.on("kubb:plugin:end", ({ plugin, duration, success }) => {
|
|
661
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
662
|
+
const durationStr = formatMs(duration);
|
|
663
|
+
const text = getMessage(success ? `${plugin.name} completed in ${durationStr}` : `${plugin.name} failed in ${durationStr}`);
|
|
664
|
+
console.log(text);
|
|
665
|
+
});
|
|
666
|
+
context.on("kubb:files:processing:start", ({ files }) => {
|
|
667
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
668
|
+
const text = getMessage(`Writing ${files.length} files`);
|
|
669
|
+
console.log(text);
|
|
670
|
+
});
|
|
671
|
+
context.on("kubb:files:processing:update", ({ files }) => {
|
|
672
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
673
|
+
for (const { file, config } of files) console.log(getMessage(`Writing ${(0, node_path.relative)(config.root, file.path)}`));
|
|
674
|
+
});
|
|
675
|
+
context.on("kubb:files:processing:end", () => {
|
|
676
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
677
|
+
const text = getMessage("Files written successfully");
|
|
678
|
+
console.log(text);
|
|
679
|
+
});
|
|
680
|
+
context.on("kubb:generation:end", ({ config }) => {
|
|
681
|
+
const text = getMessage(config.name ? `Generation completed for ${config.name}` : "Generation completed");
|
|
682
|
+
console.log(text);
|
|
683
|
+
});
|
|
684
|
+
onStep("kubb:format:start", "Format started");
|
|
685
|
+
onStep("kubb:format:end", "Format completed");
|
|
686
|
+
onStep("kubb:lint:start", "Lint started");
|
|
687
|
+
onStep("kubb:lint:end", "Lint completed");
|
|
688
|
+
onStep("kubb:hooks:start", "Hooks started");
|
|
689
|
+
onStep("kubb:hooks:end", "Hooks completed");
|
|
690
|
+
context.on("kubb:hook:start", ({ id, command, args }) => {
|
|
691
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
692
|
+
if (id) hookTimer.start(id);
|
|
693
|
+
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
694
|
+
console.log(getMessage(`Hook ${commandWithArgs} started`));
|
|
695
|
+
});
|
|
696
|
+
context.on("kubb:hook:end", ({ id, command, args, success, error, stdout, stderr }) => {
|
|
697
|
+
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
698
|
+
const ms = id ? hookTimer.end(id) : void 0;
|
|
699
|
+
const durationStr = ms !== void 0 ? ` in ${formatMs(ms)}` : "";
|
|
700
|
+
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
701
|
+
if (success) console.log(getMessage(`✓ Hook ${commandWithArgs} completed${durationStr}`));
|
|
702
|
+
else {
|
|
703
|
+
if (stdout) console.log(stdout);
|
|
704
|
+
if (stderr) console.error(stderr);
|
|
705
|
+
const reason = error?.message ? ` (${error.message})` : "";
|
|
706
|
+
console.log(getMessage(`✗ Hook ${commandWithArgs} failed${durationStr}${reason}`));
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
});
|
|
711
|
+
//#endregion
|
|
712
|
+
//#region src/loggers/utils.ts
|
|
713
|
+
/**
|
|
714
|
+
* Optionally prefix a message with a [HH:MM:SS] timestamp when logLevel >= verbose.
|
|
715
|
+
* Shared across all logger adapters to avoid duplication.
|
|
716
|
+
*/
|
|
717
|
+
function formatMessage(message, logLevel) {
|
|
718
|
+
if (logLevel >= _kubb_core.logLevel.verbose) return `${(0, node_util.styleText)("dim", `[${(/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", {
|
|
719
|
+
hour12: false,
|
|
720
|
+
hour: "2-digit",
|
|
721
|
+
minute: "2-digit",
|
|
722
|
+
second: "2-digit"
|
|
723
|
+
})}]`)} ${message}`;
|
|
724
|
+
return message;
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Build the progress summary line shown by the clack logger.
|
|
728
|
+
* Returns null when there is nothing to display.
|
|
729
|
+
*/
|
|
730
|
+
function buildProgressLine(state) {
|
|
731
|
+
const parts = [];
|
|
732
|
+
const duration = formatHrtime(state.hrStart);
|
|
733
|
+
if (state.totalPlugins > 0) {
|
|
734
|
+
const pluginStr = state.failedPlugins > 0 ? `Plugins ${(0, node_util.styleText)("green", state.completedPlugins.toString())}/${state.totalPlugins} ${(0, node_util.styleText)("red", `(${state.failedPlugins} failed)`)}` : `Plugins ${(0, node_util.styleText)("green", state.completedPlugins.toString())}/${state.totalPlugins}`;
|
|
735
|
+
parts.push(pluginStr);
|
|
736
|
+
}
|
|
737
|
+
if (state.totalFiles > 0) parts.push(`Files ${(0, node_util.styleText)("green", state.processedFiles.toString())}/${state.totalFiles}`);
|
|
738
|
+
if (parts.length === 0) return null;
|
|
739
|
+
parts.push(`${(0, node_util.styleText)("green", duration)} elapsed`);
|
|
740
|
+
return parts.join((0, node_util.styleText)("dim", " | "));
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Creates the per-run progress counters used by the clack logger.
|
|
744
|
+
*/
|
|
745
|
+
function createProgressCounters() {
|
|
746
|
+
return {
|
|
747
|
+
totalPlugins: 0,
|
|
748
|
+
completedPlugins: 0,
|
|
749
|
+
failedPlugins: 0,
|
|
750
|
+
totalFiles: 0,
|
|
751
|
+
processedFiles: 0,
|
|
752
|
+
hrStart: node_process.default.hrtime()
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Resets the progress counters in place at the start/end of a generation run.
|
|
757
|
+
*/
|
|
758
|
+
function resetProgressCounters(state) {
|
|
759
|
+
state.totalPlugins = 0;
|
|
760
|
+
state.completedPlugins = 0;
|
|
761
|
+
state.failedPlugins = 0;
|
|
762
|
+
state.totalFiles = 0;
|
|
763
|
+
state.processedFiles = 0;
|
|
764
|
+
state.hrStart = node_process.default.hrtime();
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Records a finished plugin against the progress counters.
|
|
768
|
+
*/
|
|
769
|
+
function recordPluginResult(state, success) {
|
|
770
|
+
if (success) state.completedPlugins++;
|
|
771
|
+
else state.failedPlugins++;
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* Creates a {@link HookTimer} backed by a private `id → hrtime` map.
|
|
775
|
+
*/
|
|
776
|
+
function createHookTimer() {
|
|
777
|
+
const starts = /* @__PURE__ */ new Map();
|
|
778
|
+
return {
|
|
779
|
+
start(id) {
|
|
780
|
+
starts.set(id, node_process.default.hrtime());
|
|
781
|
+
},
|
|
782
|
+
end(id) {
|
|
783
|
+
const hrStart = starts.get(id);
|
|
784
|
+
if (!hrStart) return;
|
|
785
|
+
starts.delete(id);
|
|
786
|
+
return getElapsedMs(hrStart);
|
|
787
|
+
},
|
|
788
|
+
clear() {
|
|
789
|
+
starts.clear();
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Join a command and its optional args into a single display string.
|
|
795
|
+
*
|
|
796
|
+
* @example With args
|
|
797
|
+
* `formatCommandWithArgs('prettier', ['--write', '.'])` returns `'prettier --write .'`
|
|
798
|
+
*/
|
|
799
|
+
function formatCommandWithArgs(command, args) {
|
|
800
|
+
return args?.length ? `${command} ${args.join(" ")}` : command;
|
|
801
|
+
}
|
|
802
|
+
function detectLogger() {
|
|
803
|
+
if (require_Telemetry.canUseTTY()) return "clack";
|
|
804
|
+
return "plain";
|
|
805
|
+
}
|
|
806
|
+
const logMapper = {
|
|
807
|
+
clack: clackLogger,
|
|
808
|
+
plain: plainLogger
|
|
809
|
+
};
|
|
810
|
+
/**
|
|
811
|
+
* Bridges a {@link Reporter} onto the run's event emitter: calls `report` with each config's
|
|
812
|
+
* {@link GenerationResult} on `kubb:generation:end`. The reporter never touches the emitter.
|
|
813
|
+
*/
|
|
814
|
+
function installReporter(context, reporter, ctx) {
|
|
815
|
+
context.on("kubb:generation:end", async ({ config, diagnostics = [], filesCreated = 0, status = "success", hrStart = node_process.default.hrtime() }) => {
|
|
816
|
+
await reporter.report({
|
|
817
|
+
config,
|
|
818
|
+
diagnostics,
|
|
819
|
+
filesCreated,
|
|
820
|
+
status,
|
|
821
|
+
hrStart
|
|
822
|
+
}, ctx);
|
|
823
|
+
});
|
|
824
|
+
if (reporter.drain) context.on("kubb:lifecycle:end", () => reporter.drain?.(ctx));
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Installs the live logger (the TUI view) and the given reporters (the output). The reporters are
|
|
828
|
+
* already selected by the caller (the CLI maps `--reporter` to names via `selectReporters`). This
|
|
829
|
+
* only wires them. Loggers receive hook subprocess output through `kubb:hook:line` and the
|
|
830
|
+
* `stdout`/`stderr` on `kubb:hook:end`, so nothing is returned here.
|
|
831
|
+
*
|
|
832
|
+
* Loggers and reporters are independent, except for `cli`: it both installs the live logger view
|
|
833
|
+
* here and registers as a reporter that prints the per-config summary. The `json` reporter owns
|
|
834
|
+
* stdout, so the whole `cli` reporter (live logger and summary) is skipped whenever `json` is
|
|
835
|
+
* among the reporters, even if `cli` is also listed.
|
|
836
|
+
*/
|
|
837
|
+
async function setupReporters(context, { logLevel, reporters }) {
|
|
838
|
+
const hasJson = reporters.some((reporter) => reporter.name === "json");
|
|
839
|
+
const ctx = { logLevel };
|
|
840
|
+
for (const reporter of reporters) {
|
|
841
|
+
if (reporter.name === "cli") {
|
|
842
|
+
if (hasJson) continue;
|
|
843
|
+
const type = detectLogger();
|
|
844
|
+
const logger = logMapper[type];
|
|
845
|
+
if (!logger) throw new Error(`Unknown adapter type: ${type}`);
|
|
846
|
+
await logger.install(context, { logLevel });
|
|
847
|
+
}
|
|
848
|
+
installReporter(context, reporter, ctx);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* Picks the reporters whose `name` matches one of `names`, in the order the names are given.
|
|
853
|
+
* The config carries every available reporter, and the host selects which to activate by name
|
|
854
|
+
* (the CLI maps `--reporter` to this). Duplicate names and names without a matching reporter are
|
|
855
|
+
* skipped.
|
|
856
|
+
*/
|
|
857
|
+
function selectReporters(reporters, names) {
|
|
858
|
+
const seen = /* @__PURE__ */ new Set();
|
|
859
|
+
const selected = [];
|
|
860
|
+
for (const name of names) {
|
|
861
|
+
if (seen.has(name)) continue;
|
|
862
|
+
seen.add(name);
|
|
863
|
+
const reporter = reporters.find((candidate) => candidate.name === name);
|
|
864
|
+
if (reporter) selected.push(reporter);
|
|
865
|
+
}
|
|
866
|
+
return selected;
|
|
867
|
+
}
|
|
868
|
+
//#endregion
|
|
869
|
+
//#region ../../internals/shared/src/loader.ts
|
|
870
|
+
/**
|
|
871
|
+
* jiti options for loading Kubb config modules: the automatic JSX runtime pointed at
|
|
872
|
+
* `@kubb/renderer-jsx`, and `moduleCache` off so a re-load re-evaluates the file.
|
|
873
|
+
*/
|
|
874
|
+
const JITI_OPTIONS = {
|
|
875
|
+
jsx: {
|
|
876
|
+
runtime: "automatic",
|
|
877
|
+
importSource: "@kubb/renderer-jsx"
|
|
878
|
+
},
|
|
879
|
+
moduleCache: false
|
|
880
|
+
};
|
|
881
|
+
/**
|
|
882
|
+
* Creates a runtime-aware loader for Kubb's TypeScript and JavaScript config modules.
|
|
883
|
+
*
|
|
884
|
+
* On Bun and Deno it imports the file natively, skipping jiti's transform step, and falls back to
|
|
885
|
+
* jiti only when the native import throws. On Node it always uses jiti, which transpiles TypeScript
|
|
886
|
+
* and the `@kubb/renderer-jsx` JSX runtime on the fly. The jiti instance is created lazily, so the
|
|
887
|
+
* Bun/Deno happy path never pays for it.
|
|
888
|
+
*
|
|
889
|
+
* @example
|
|
890
|
+
* ```ts
|
|
891
|
+
* const config = await createModuleLoader().load('/abs/kubb.config.ts', { default: true })
|
|
892
|
+
* ```
|
|
893
|
+
*/
|
|
894
|
+
function createModuleLoader() {
|
|
895
|
+
let jiti$1;
|
|
896
|
+
const getJiti = () => jiti$1 ??= (0, jiti.createJiti)(require("url").pathToFileURL(__filename).href, JITI_OPTIONS);
|
|
897
|
+
const viaJiti = (filePath, options) => options?.default ? getJiti().import(filePath, { default: true }) : getJiti().import(filePath);
|
|
898
|
+
const viaNative = async (filePath, options) => {
|
|
899
|
+
const href = (0, node_url.pathToFileURL)(filePath).href;
|
|
900
|
+
const mod = await (options?.bust != null ? import(`${href}?t=${options.bust}`) : import(href));
|
|
901
|
+
return options?.default ? mod.default ?? mod : mod;
|
|
902
|
+
};
|
|
903
|
+
return { async load(filePath, options) {
|
|
904
|
+
if (require_Telemetry.runtime.isBun || require_Telemetry.runtime.isDeno) try {
|
|
905
|
+
return await viaNative(filePath, options);
|
|
906
|
+
} catch {
|
|
907
|
+
return viaJiti(filePath, options);
|
|
908
|
+
}
|
|
909
|
+
return viaJiti(filePath, options);
|
|
910
|
+
} };
|
|
911
|
+
}
|
|
912
|
+
//#endregion
|
|
913
|
+
//#region src/runners/generate/utils.ts
|
|
914
|
+
const loader = createModuleLoader();
|
|
915
|
+
const tsLoader = (configFile) => loader.load(configFile, { default: true });
|
|
916
|
+
const MODULE_NAME = "kubb";
|
|
917
|
+
const SEARCH_FILES = [
|
|
918
|
+
"",
|
|
919
|
+
".config/",
|
|
920
|
+
"configs/"
|
|
921
|
+
].flatMap((prefix) => [`${prefix}.${MODULE_NAME}rc`, `${prefix}${MODULE_NAME}.config`]);
|
|
922
|
+
const SEARCH_EXTENSIONS = [
|
|
923
|
+
"ts",
|
|
924
|
+
"mts",
|
|
925
|
+
"cts",
|
|
926
|
+
"js",
|
|
927
|
+
"mjs",
|
|
928
|
+
"cjs"
|
|
929
|
+
];
|
|
930
|
+
/**
|
|
931
|
+
* Discovers the Kubb config and resolves it into a normalized array of configs.
|
|
932
|
+
* Every config in the result is guaranteed to have a `plugins` array.
|
|
933
|
+
*/
|
|
934
|
+
async function getConfigs({ configPath, input, watch, logLevel }) {
|
|
935
|
+
const abs = configPath ? (0, node_path.resolve)(configPath) : void 0;
|
|
936
|
+
const sources = abs ? [{
|
|
937
|
+
files: [(0, node_path.basename)(abs)],
|
|
938
|
+
extensions: [],
|
|
939
|
+
parser: tsLoader
|
|
940
|
+
}] : [{
|
|
941
|
+
files: SEARCH_FILES,
|
|
942
|
+
extensions: SEARCH_EXTENSIONS,
|
|
943
|
+
parser: tsLoader
|
|
944
|
+
}];
|
|
945
|
+
let result;
|
|
946
|
+
try {
|
|
947
|
+
result = await (0, unconfig.loadConfig)({
|
|
948
|
+
cwd: abs ? (0, node_path.dirname)(abs) : node_process.default.cwd(),
|
|
949
|
+
sources,
|
|
950
|
+
merge: false
|
|
951
|
+
});
|
|
952
|
+
} catch (error) {
|
|
953
|
+
throw new Error("Config failed loading", { cause: error });
|
|
954
|
+
}
|
|
955
|
+
const [filepath] = result.sources;
|
|
956
|
+
if (!result.config || !filepath) throw new Error("Config not defined, create a kubb.config.js or pass through your config with the option --config");
|
|
957
|
+
const config = result.config;
|
|
958
|
+
const resolved = await (typeof config === "function" ? config({
|
|
959
|
+
config: configPath,
|
|
960
|
+
input,
|
|
961
|
+
watch,
|
|
962
|
+
logLevel
|
|
963
|
+
}) : config);
|
|
964
|
+
return {
|
|
965
|
+
configPath: filepath,
|
|
966
|
+
configs: (Array.isArray(resolved) ? resolved : [resolved]).map((item) => ({
|
|
967
|
+
...item,
|
|
968
|
+
plugins: item.plugins ?? []
|
|
969
|
+
}))
|
|
970
|
+
};
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* Tokenizes a shell command string, respecting single and double quotes.
|
|
974
|
+
*
|
|
975
|
+
* @example
|
|
976
|
+
* ```ts
|
|
977
|
+
* tokenize('git commit -m "initial commit"')
|
|
978
|
+
* // → ['git', 'commit', '-m', 'initial commit']
|
|
979
|
+
* ```
|
|
980
|
+
*/
|
|
981
|
+
function tokenize(command) {
|
|
982
|
+
return (command.match(/[^\s"']+|"([^"]*)"|'([^']*)'/g) ?? []).map((token) => token.replace(/^["']|["']$/g, ""));
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
* Runs the `done` hooks defined in a Kubb config in sequence.
|
|
986
|
+
*/
|
|
987
|
+
async function executeHooks({ configHooks, hooks }) {
|
|
988
|
+
const commands = Array.isArray(configHooks.done) ? configHooks.done : [configHooks.done].filter(Boolean);
|
|
989
|
+
for (const command of commands) {
|
|
990
|
+
const [cmd, ...args] = tokenize(command);
|
|
991
|
+
if (!cmd) continue;
|
|
992
|
+
const hookId = (0, node_crypto.hash)("sha256", command, "hex");
|
|
993
|
+
const commandWithArgs = [cmd, ...args].join(" ");
|
|
994
|
+
await hooks.emit("kubb:hook:start", {
|
|
995
|
+
id: hookId,
|
|
996
|
+
command: cmd,
|
|
997
|
+
args
|
|
998
|
+
});
|
|
999
|
+
await runHook({
|
|
1000
|
+
id: hookId,
|
|
1001
|
+
command: cmd,
|
|
1002
|
+
args,
|
|
1003
|
+
commandWithArgs,
|
|
1004
|
+
hooks
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
/**
|
|
1009
|
+
* Spawns a hook command and reports its outcome through `kubb:hook:end`.
|
|
1010
|
+
* A non-zero exit signals failure via `kubb:hook:end` rather than throwing, so the caller can turn
|
|
1011
|
+
* it into a diagnostic. Other spawn errors do the same. Output is streamed through `kubb:hook:line`
|
|
1012
|
+
* only while a listener is attached.
|
|
1013
|
+
*/
|
|
1014
|
+
async function runHook({ id, command, args, commandWithArgs, hooks }) {
|
|
1015
|
+
const emitEnd = (success, error, output) => hooks.emit("kubb:hook:end", {
|
|
1016
|
+
command,
|
|
1017
|
+
args,
|
|
1018
|
+
id,
|
|
1019
|
+
success,
|
|
1020
|
+
error,
|
|
1021
|
+
...output
|
|
1022
|
+
});
|
|
1023
|
+
const stream = hooks.listenerCount("kubb:hook:line") > 0;
|
|
1024
|
+
try {
|
|
1025
|
+
const proc = (0, tinyexec.x)(command, [...args ?? []], {
|
|
1026
|
+
nodeOptions: { detached: node_process.default.platform !== "win32" },
|
|
1027
|
+
throwOnError: true
|
|
1028
|
+
});
|
|
1029
|
+
if (stream) for await (const line of proc) await hooks.emit("kubb:hook:line", {
|
|
1030
|
+
id,
|
|
1031
|
+
line
|
|
1032
|
+
});
|
|
1033
|
+
await proc;
|
|
1034
|
+
await hooks.emit("kubb:success", { message: `${(0, node_util.styleText)("dim", commandWithArgs)} successfully executed` });
|
|
1035
|
+
await emitEnd(true, null);
|
|
1036
|
+
} catch (err) {
|
|
1037
|
+
if (!(err instanceof tinyexec.NonZeroExitError)) {
|
|
1038
|
+
await emitEnd(false, require_errors.toError(err));
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
1041
|
+
const stderr = err.output?.stderr ?? "";
|
|
1042
|
+
const stdout = err.output?.stdout ?? "";
|
|
1043
|
+
await emitEnd(false, /* @__PURE__ */ new Error(`Hook execute failed: ${commandWithArgs}`), {
|
|
1044
|
+
stdout,
|
|
1045
|
+
stderr
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* Starts a file watcher on the given paths and calls `cb` on any change.
|
|
1051
|
+
* Ignores `.git` and `node_modules` directories.
|
|
1052
|
+
*/
|
|
1053
|
+
async function startWatcher(path, cb, log = {
|
|
1054
|
+
info: console.log,
|
|
1055
|
+
error: console.log
|
|
1056
|
+
}) {
|
|
1057
|
+
const { watch } = await import("chokidar");
|
|
1058
|
+
const watcher = watch(path, {
|
|
1059
|
+
ignorePermissionErrors: true,
|
|
1060
|
+
ignored: require_Telemetry.WATCHER_IGNORED_PATHS
|
|
1061
|
+
});
|
|
1062
|
+
node_process.default.once("SIGINT", () => {
|
|
1063
|
+
watcher.close();
|
|
1064
|
+
});
|
|
1065
|
+
node_process.default.once("SIGTERM", () => {
|
|
1066
|
+
watcher.close();
|
|
1067
|
+
});
|
|
1068
|
+
watcher.on("all", async (type, file) => {
|
|
1069
|
+
log.info((0, node_util.styleText)("yellow", (0, node_util.styleText)("bold", `Change detected: ${type} ${file}`)));
|
|
1070
|
+
try {
|
|
1071
|
+
await cb(path);
|
|
1072
|
+
} catch (_e) {
|
|
1073
|
+
log.error((0, node_util.styleText)("red", "Watcher failed"));
|
|
1074
|
+
}
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
//#endregion
|
|
1078
|
+
//#region src/runners/generate/run.ts
|
|
1079
|
+
/**
|
|
1080
|
+
* Registers a one-shot `kubb:hook:end` listener for `hookId` before the caller emits `kubb:hook:start`,
|
|
1081
|
+
* so a synchronous emitter cannot fire end before the listener is attached.
|
|
1082
|
+
*/
|
|
1083
|
+
function waitForHookEnd(hooks, hookId, onSuccess, fallbackErrorMessage) {
|
|
1084
|
+
return new Promise((resolve, reject) => {
|
|
1085
|
+
const handler = (ctx) => {
|
|
1086
|
+
if (ctx.id !== hookId) return;
|
|
1087
|
+
hooks.off("kubb:hook:end", handler);
|
|
1088
|
+
if (!ctx.success) {
|
|
1089
|
+
reject(ctx.error ?? new Error(fallbackErrorMessage));
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
Promise.resolve(onSuccess()).then(resolve).catch(reject);
|
|
1093
|
+
};
|
|
1094
|
+
hooks.on("kubb:hook:end", handler);
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefix, noToolMessage, configName, outputPath, logLevel, hooks, onStart, onEnd }) {
|
|
1098
|
+
await onStart();
|
|
1099
|
+
let resolvedTool = toolValue;
|
|
1100
|
+
if (resolvedTool === "auto") {
|
|
1101
|
+
const detected = await detect();
|
|
1102
|
+
if (!detected) await hooks.emit("kubb:warn", { message: noToolMessage });
|
|
1103
|
+
else {
|
|
1104
|
+
resolvedTool = detected;
|
|
1105
|
+
await hooks.emit("kubb:info", { message: `Auto-detected ${toolLabel}: ${(0, node_util.styleText)("dim", resolvedTool)}` });
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
let toolError;
|
|
1109
|
+
if (resolvedTool && resolvedTool !== "auto" && resolvedTool in toolMap && (0, node_fs.existsSync)(outputPath)) {
|
|
1110
|
+
const toolConfig = toolMap[resolvedTool];
|
|
1111
|
+
const hookId = (0, node_crypto.hash)("sha256", [configName, resolvedTool].filter(Boolean).join("-"), "hex");
|
|
1112
|
+
const successMessage = [
|
|
1113
|
+
`${successPrefix} with ${(0, node_util.styleText)("dim", resolvedTool)}`,
|
|
1114
|
+
logLevel >= _kubb_core.logLevel.info ? `on ${(0, node_util.styleText)("dim", outputPath)}` : void 0,
|
|
1115
|
+
"successfully"
|
|
1116
|
+
].filter(Boolean).join(" ");
|
|
1117
|
+
try {
|
|
1118
|
+
const hookArgs = toolConfig.args(outputPath);
|
|
1119
|
+
const commandWithArgs = [toolConfig.command, ...hookArgs].join(" ");
|
|
1120
|
+
const hookEndPromise = waitForHookEnd(hooks, hookId, () => hooks.emit("kubb:success", { message: successMessage }), toolConfig.errorMessage);
|
|
1121
|
+
await hooks.emit("kubb:hook:start", {
|
|
1122
|
+
id: hookId,
|
|
1123
|
+
command: toolConfig.command,
|
|
1124
|
+
args: hookArgs
|
|
1125
|
+
});
|
|
1126
|
+
runHook({
|
|
1127
|
+
id: hookId,
|
|
1128
|
+
command: toolConfig.command,
|
|
1129
|
+
args: hookArgs,
|
|
1130
|
+
commandWithArgs,
|
|
1131
|
+
hooks
|
|
1132
|
+
}).catch(() => {});
|
|
1133
|
+
await hookEndPromise;
|
|
1134
|
+
} catch (caughtError) {
|
|
1135
|
+
toolError = require_errors.toError(caughtError);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
await onEnd();
|
|
1139
|
+
if (toolError) throw toolError;
|
|
1140
|
+
}
|
|
1141
|
+
async function generate(options) {
|
|
1142
|
+
const { input, hooks, logLevel } = options;
|
|
1143
|
+
const hrStart = node_process.default.hrtime();
|
|
1144
|
+
const inputPath = input ?? (options.config.input && "path" in options.config.input ? options.config.input.path : void 0);
|
|
1145
|
+
const config = {
|
|
1146
|
+
...options.config,
|
|
1147
|
+
input: inputPath ? {
|
|
1148
|
+
...options.config.input,
|
|
1149
|
+
path: inputPath
|
|
1150
|
+
} : options.config.input,
|
|
1151
|
+
...options.config.output
|
|
1152
|
+
};
|
|
1153
|
+
const kubb = (0, _kubb_core.createKubb)(config, { hooks });
|
|
1154
|
+
await hooks.emit("kubb:generation:start", { config });
|
|
1155
|
+
await hooks.emit("kubb:info", {
|
|
1156
|
+
message: config.name ? `Setup generation ${(0, node_util.styleText)("bold", config.name)}` : "Setup generation",
|
|
1157
|
+
info: inputPath
|
|
1158
|
+
});
|
|
1159
|
+
await kubb.setup();
|
|
1160
|
+
await hooks.emit("kubb:info", {
|
|
1161
|
+
message: config.name ? `Build generation ${(0, node_util.styleText)("bold", config.name)}` : "Build generation",
|
|
1162
|
+
info: inputPath
|
|
1163
|
+
});
|
|
1164
|
+
const { files, diagnostics, driver } = await kubb.safeBuild();
|
|
1165
|
+
await hooks.emit("kubb:info", { message: "Load summary" });
|
|
1166
|
+
const telemetryPlugins = Array.from(driver.plugins.values(), (p) => ({
|
|
1167
|
+
name: p.name,
|
|
1168
|
+
options: p.options
|
|
1169
|
+
}));
|
|
1170
|
+
const reportTelemetry = (status) => require_Telemetry.Telemetry.send(require_Telemetry.Telemetry.build({
|
|
1171
|
+
command: "generate",
|
|
1172
|
+
kubbVersion: require_package.version,
|
|
1173
|
+
plugins: telemetryPlugins,
|
|
1174
|
+
hrStart,
|
|
1175
|
+
filesCreated: files.length,
|
|
1176
|
+
status
|
|
1177
|
+
}));
|
|
1178
|
+
for (const diagnostic of diagnostics) {
|
|
1179
|
+
if (!_kubb_core.Diagnostics.isProblem(diagnostic)) continue;
|
|
1180
|
+
const unknown = _kubb_core.Diagnostics.narrow(diagnostic, _kubb_core.Diagnostics.code.unknown);
|
|
1181
|
+
if (unknown) await hooks.emit("kubb:error", { error: unknown.cause ?? new Error(unknown.message) });
|
|
1182
|
+
else await _kubb_core.Diagnostics.emit(hooks, diagnostic);
|
|
1183
|
+
}
|
|
1184
|
+
if (_kubb_core.Diagnostics.hasError(diagnostics)) {
|
|
1185
|
+
await hooks.emit("kubb:generation:end", {
|
|
1186
|
+
config,
|
|
1187
|
+
storage: kubb.storage,
|
|
1188
|
+
diagnostics,
|
|
1189
|
+
filesCreated: files.length,
|
|
1190
|
+
status: "failed",
|
|
1191
|
+
hrStart
|
|
1192
|
+
});
|
|
1193
|
+
await reportTelemetry("failed");
|
|
1194
|
+
return false;
|
|
1195
|
+
}
|
|
1196
|
+
const outputPath = node_path.default.resolve(config.root, config.output.path);
|
|
1197
|
+
const outputDiagnostics = [];
|
|
1198
|
+
const toolPasses = [config.output.format && {
|
|
1199
|
+
code: _kubb_core.Diagnostics.code.formatFailed,
|
|
1200
|
+
toolValue: config.output.format,
|
|
1201
|
+
detect: () => require_tools.detectTool([
|
|
1202
|
+
"oxfmt",
|
|
1203
|
+
"biome",
|
|
1204
|
+
"prettier"
|
|
1205
|
+
]),
|
|
1206
|
+
toolMap: require_tools.formatters,
|
|
1207
|
+
toolLabel: "formatter",
|
|
1208
|
+
successPrefix: "Formatting",
|
|
1209
|
+
noToolMessage: "No formatter found (oxfmt, biome, or prettier). Skipping formatting.",
|
|
1210
|
+
onStart: () => hooks.emit("kubb:format:start"),
|
|
1211
|
+
onEnd: () => hooks.emit("kubb:format:end")
|
|
1212
|
+
}, config.output.lint && {
|
|
1213
|
+
code: _kubb_core.Diagnostics.code.lintFailed,
|
|
1214
|
+
toolValue: config.output.lint,
|
|
1215
|
+
detect: () => require_tools.detectTool([
|
|
1216
|
+
"oxlint",
|
|
1217
|
+
"biome",
|
|
1218
|
+
"eslint"
|
|
1219
|
+
]),
|
|
1220
|
+
toolMap: require_tools.linters,
|
|
1221
|
+
toolLabel: "linter",
|
|
1222
|
+
successPrefix: "Linting",
|
|
1223
|
+
noToolMessage: "No linter found (oxlint, biome, or eslint). Skipping linting.",
|
|
1224
|
+
onStart: () => hooks.emit("kubb:lint:start"),
|
|
1225
|
+
onEnd: () => hooks.emit("kubb:lint:end")
|
|
1226
|
+
}].filter(Boolean);
|
|
1227
|
+
for (const { code, ...pass } of toolPasses) try {
|
|
1228
|
+
await runToolPass({
|
|
1229
|
+
...pass,
|
|
1230
|
+
configName: config.name,
|
|
1231
|
+
outputPath,
|
|
1232
|
+
logLevel,
|
|
1233
|
+
hooks
|
|
1234
|
+
});
|
|
1235
|
+
} catch (caughtError) {
|
|
1236
|
+
const diagnostic = outputDiagnostic(code, pass.toolLabel, caughtError);
|
|
1237
|
+
outputDiagnostics.push(diagnostic);
|
|
1238
|
+
await _kubb_core.Diagnostics.emit(hooks, diagnostic);
|
|
1239
|
+
}
|
|
1240
|
+
if (config.hooks) {
|
|
1241
|
+
await hooks.emit("kubb:hooks:start");
|
|
1242
|
+
const hookFailures = [];
|
|
1243
|
+
const onHookEnd = (ctx) => {
|
|
1244
|
+
if (!ctx.success) hookFailures.push(ctx.error ?? /* @__PURE__ */ new Error("Post-generate hook failed"));
|
|
1245
|
+
};
|
|
1246
|
+
hooks.on("kubb:hook:end", onHookEnd);
|
|
1247
|
+
try {
|
|
1248
|
+
await executeHooks({
|
|
1249
|
+
configHooks: config.hooks,
|
|
1250
|
+
hooks
|
|
1251
|
+
});
|
|
1252
|
+
} finally {
|
|
1253
|
+
hooks.off("kubb:hook:end", onHookEnd);
|
|
1254
|
+
}
|
|
1255
|
+
for (const error of hookFailures) {
|
|
1256
|
+
const diagnostic = outputDiagnostic(_kubb_core.Diagnostics.code.hookFailed, "Post-generate hook", error);
|
|
1257
|
+
outputDiagnostics.push(diagnostic);
|
|
1258
|
+
await _kubb_core.Diagnostics.emit(hooks, diagnostic);
|
|
1259
|
+
}
|
|
1260
|
+
await hooks.emit("kubb:hooks:end");
|
|
1261
|
+
}
|
|
1262
|
+
const finalDiagnostics = [...diagnostics, ...outputDiagnostics];
|
|
1263
|
+
const failed = _kubb_core.Diagnostics.hasError(outputDiagnostics);
|
|
1264
|
+
if (!failed) await hooks.emit("kubb:success", {
|
|
1265
|
+
message: "Generation succeeded",
|
|
1266
|
+
info: inputPath
|
|
1267
|
+
});
|
|
1268
|
+
await hooks.emit("kubb:generation:end", {
|
|
1269
|
+
config,
|
|
1270
|
+
storage: kubb.storage,
|
|
1271
|
+
diagnostics: finalDiagnostics,
|
|
1272
|
+
filesCreated: files.length,
|
|
1273
|
+
status: failed ? "failed" : "success",
|
|
1274
|
+
hrStart
|
|
1275
|
+
});
|
|
1276
|
+
await reportTelemetry(failed ? "failed" : "success");
|
|
1277
|
+
return !failed;
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
* Builds a coded diagnostic for an output-phase failure (formatter, linter, or `done` hook).
|
|
1281
|
+
*/
|
|
1282
|
+
function outputDiagnostic(code, label, caughtError) {
|
|
1283
|
+
const error = require_errors.toError(caughtError);
|
|
1284
|
+
return {
|
|
1285
|
+
code,
|
|
1286
|
+
severity: "error",
|
|
1287
|
+
message: `${label} failed: ${error.message}`,
|
|
1288
|
+
help: "Check that the tool is installed and that the command and its config are correct.",
|
|
1289
|
+
location: { kind: "config" },
|
|
1290
|
+
cause: error
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
async function checkForUpdate(hooks) {
|
|
1294
|
+
try {
|
|
1295
|
+
const data = await (await fetch(require_Telemetry.KUBB_NPM_PACKAGE_URL)).json();
|
|
1296
|
+
if (data.version && require_package.version < data.version) await _kubb_core.Diagnostics.emit(hooks, _kubb_core.Diagnostics.update({
|
|
1297
|
+
currentVersion: require_package.version,
|
|
1298
|
+
latestVersion: data.version
|
|
1299
|
+
}));
|
|
1300
|
+
} catch {}
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* Runs the full Kubb generation lifecycle for the given CLI options.
|
|
1304
|
+
* Loads configs, sets up the reporters (CLI `--reporter` picks which of `config.reporters` to trigger),
|
|
1305
|
+
* checks for a newer version, and calls `generate` for each config entry.
|
|
1306
|
+
*/
|
|
1307
|
+
async function run({ input, configPath, logLevel: logLevelKey, watch, reporters: cliReporters }) {
|
|
1308
|
+
const logLevel = _kubb_core.logLevel[logLevelKey] ?? _kubb_core.logLevel.info;
|
|
1309
|
+
const hooks = new AsyncEventEmitter();
|
|
1310
|
+
let configs;
|
|
1311
|
+
let resolvedConfigPath;
|
|
1312
|
+
try {
|
|
1313
|
+
const loaded = await getConfigs({
|
|
1314
|
+
configPath,
|
|
1315
|
+
input,
|
|
1316
|
+
watch,
|
|
1317
|
+
logLevel: logLevelKey
|
|
1318
|
+
});
|
|
1319
|
+
configs = loaded.configs;
|
|
1320
|
+
resolvedConfigPath = loaded.configPath;
|
|
1321
|
+
} catch (error) {
|
|
1322
|
+
await setupReporters(hooks, {
|
|
1323
|
+
logLevel,
|
|
1324
|
+
reporters: [_kubb_core.cliReporter]
|
|
1325
|
+
});
|
|
1326
|
+
await hooks.emit("kubb:error", { error: require_errors.toError(error) });
|
|
1327
|
+
node_process.default.exit(1);
|
|
1328
|
+
}
|
|
1329
|
+
const requestedNames = cliReporters?.length ? cliReporters : ["cli"];
|
|
1330
|
+
await setupReporters(hooks, {
|
|
1331
|
+
logLevel,
|
|
1332
|
+
reporters: selectReporters(configs[0]?.reporters ?? [], requestedNames)
|
|
1333
|
+
});
|
|
1334
|
+
await hooks.emit("kubb:lifecycle:start", { version: require_package.version });
|
|
1335
|
+
await checkForUpdate(hooks);
|
|
1336
|
+
try {
|
|
1337
|
+
const relativeConfigPath = node_path.default.relative(node_process.default.cwd(), resolvedConfigPath);
|
|
1338
|
+
await hooks.emit("kubb:info", {
|
|
1339
|
+
message: "Config loaded",
|
|
1340
|
+
info: relativeConfigPath
|
|
1341
|
+
});
|
|
1342
|
+
await hooks.emit("kubb:success", {
|
|
1343
|
+
message: "Config loaded successfully",
|
|
1344
|
+
info: relativeConfigPath
|
|
1345
|
+
});
|
|
1346
|
+
let anyFailed = false;
|
|
1347
|
+
for (const config of configs) if (config.input && "path" in config.input && watch) await startWatcher([input || config.input.path], async (paths) => {
|
|
1348
|
+
await generate({
|
|
1349
|
+
input,
|
|
1350
|
+
config,
|
|
1351
|
+
logLevel,
|
|
1352
|
+
hooks
|
|
1353
|
+
});
|
|
1354
|
+
_clack_prompts.log.step((0, node_util.styleText)("yellow", `Watching for changes in ${paths.join(" and ")}`));
|
|
1355
|
+
}, {
|
|
1356
|
+
info: (msg) => _clack_prompts.log.info(msg),
|
|
1357
|
+
error: (msg) => _clack_prompts.log.error(msg)
|
|
1358
|
+
});
|
|
1359
|
+
else try {
|
|
1360
|
+
if (!await generate({
|
|
1361
|
+
input,
|
|
1362
|
+
config,
|
|
1363
|
+
logLevel,
|
|
1364
|
+
hooks
|
|
1365
|
+
})) anyFailed = true;
|
|
1366
|
+
} catch (configError) {
|
|
1367
|
+
await hooks.emit("kubb:error", { error: require_errors.toError(configError) });
|
|
1368
|
+
anyFailed = true;
|
|
1369
|
+
}
|
|
1370
|
+
await hooks.emit("kubb:lifecycle:end");
|
|
1371
|
+
if (anyFailed) node_process.default.exit(1);
|
|
1372
|
+
} catch (error) {
|
|
1373
|
+
await hooks.emit("kubb:error", { error: require_errors.toError(error) });
|
|
1374
|
+
node_process.default.exit(1);
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
//#endregion
|
|
1378
|
+
exports.run = run;
|
|
1379
|
+
|
|
1380
|
+
//# sourceMappingURL=run-B9R0rCqJ.cjs.map
|