@kubb/cli 5.1.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -0
- package/dist/{Telemetry-Fiymfxez.js → Telemetry-BCTY-Nzq.js} +3 -49
- package/dist/Telemetry-BCTY-Nzq.js.map +1 -0
- package/dist/{Telemetry-D-Jpt27O.cjs → Telemetry-DKfJQxnC.cjs} +8 -60
- package/dist/Telemetry-DKfJQxnC.cjs.map +1 -0
- package/dist/constants-CdxpgX3_.cjs +115 -0
- package/dist/constants-CdxpgX3_.cjs.map +1 -0
- package/dist/constants-DHRspBTo.js +92 -0
- package/dist/constants-DHRspBTo.js.map +1 -0
- package/dist/env-DHaFBZTX.cjs +82 -0
- package/dist/env-DHaFBZTX.cjs.map +1 -0
- package/dist/env-DqPKEL59.js +59 -0
- package/dist/env-DqPKEL59.js.map +1 -0
- package/dist/{errors-CZtH2dKk.cjs → errors-C-wEou02.cjs} +2 -19
- package/dist/errors-C-wEou02.cjs.map +1 -0
- package/dist/errors-C8yNfV7w.js +20 -0
- package/dist/errors-C8yNfV7w.js.map +1 -0
- package/dist/{generate-BO_Gv-vi.cjs → generate-Btnbf2_0.cjs} +9 -6
- package/dist/generate-Btnbf2_0.cjs.map +1 -0
- package/dist/{generate-HzSh9v2l.js → generate-PT8_WDJZ.js} +9 -6
- package/dist/generate-PT8_WDJZ.js.map +1 -0
- package/dist/index.cjs +14 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +15 -10
- package/dist/index.js.map +1 -1
- package/dist/{init-EJOY4K6y.cjs → init-BwuaIvJr.cjs} +3 -3
- package/dist/{init-EJOY4K6y.cjs.map → init-BwuaIvJr.cjs.map} +1 -1
- package/dist/{init-BslRoYhh.js → init-dkS7T-wO.js} +3 -3
- package/dist/{init-BslRoYhh.js.map → init-dkS7T-wO.js.map} +1 -1
- package/dist/{mcp-CtV0d0Dc.js → mcp-B-GxGgVr.js} +8 -10
- package/dist/mcp-B-GxGgVr.js.map +1 -0
- package/dist/{mcp-BIcX2H1u.cjs → mcp-B3B-rE7W.cjs} +8 -10
- package/dist/mcp-B3B-rE7W.cjs.map +1 -0
- package/dist/output-B2V2MN_C.cjs +137 -0
- package/dist/output-B2V2MN_C.cjs.map +1 -0
- package/dist/output-LZvrgF3z.js +89 -0
- package/dist/output-LZvrgF3z.js.map +1 -0
- package/dist/package-CrOAfe1h.js +6 -0
- package/dist/package-CrOAfe1h.js.map +1 -0
- package/dist/{package-CnUMuss9.cjs → package-Dzjrfs0O.cjs} +2 -2
- package/dist/package-Dzjrfs0O.cjs.map +1 -0
- package/dist/{run-DSgLksGj.js → run-BzvsJ0Ek.js} +80 -112
- package/dist/run-BzvsJ0Ek.js.map +1 -0
- package/dist/run-CHfPmjaA.cjs +283 -0
- package/dist/run-CHfPmjaA.cjs.map +1 -0
- package/dist/{run-FPqeAEF4.cjs → run-DRBqVXX0.cjs} +93 -125
- package/dist/run-DRBqVXX0.cjs.map +1 -0
- package/dist/{run-ChKPZlIB.js → run-DReizVV9.js} +15 -4
- package/dist/run-DReizVV9.js.map +1 -0
- package/dist/run-DUY0lV8l.js +499 -0
- package/dist/run-DUY0lV8l.js.map +1 -0
- package/dist/run-DXPXPj4B.js +281 -0
- package/dist/run-DXPXPj4B.js.map +1 -0
- package/dist/{run-DCfdTu52.js → run-DvRhuqUM.js} +11 -4
- package/dist/run-DvRhuqUM.js.map +1 -0
- package/dist/run-Wkl7oK6Q.cjs +502 -0
- package/dist/run-Wkl7oK6Q.cjs.map +1 -0
- package/dist/{run-BV2tMjuz.cjs → run-aIkuYiQ6.cjs} +15 -4
- package/dist/run-aIkuYiQ6.cjs.map +1 -0
- package/dist/{run-Cs5FunVC.cjs → run-y7oTgJI3.cjs} +11 -4
- package/dist/run-y7oTgJI3.cjs.map +1 -0
- package/dist/studio-DKv2YLJZ.js +77 -0
- package/dist/studio-DKv2YLJZ.js.map +1 -0
- package/dist/studio-PDMxqFN0.cjs +76 -0
- package/dist/studio-PDMxqFN0.cjs.map +1 -0
- package/dist/{run-DAGbErY0.cjs → utils-B0SrWoNh.cjs} +303 -323
- package/dist/utils-B0SrWoNh.cjs.map +1 -0
- package/dist/{run-CLGgnrjg.js → utils-CzoNURwq.js} +274 -364
- package/dist/utils-CzoNURwq.js.map +1 -0
- package/dist/{validate-BxCwQou-.cjs → validate-BcB0tFQ6.cjs} +8 -13
- package/dist/validate-BcB0tFQ6.cjs.map +1 -0
- package/dist/{validate-DD2S9ffV.js → validate-QpkCbIFJ.js} +8 -13
- package/dist/validate-QpkCbIFJ.js.map +1 -0
- package/package.json +14 -9
- package/dist/Telemetry-D-Jpt27O.cjs.map +0 -1
- package/dist/Telemetry-Fiymfxez.js.map +0 -1
- package/dist/errors-CMvLO2NE.js +0 -31
- package/dist/errors-CMvLO2NE.js.map +0 -1
- package/dist/errors-CZtH2dKk.cjs.map +0 -1
- package/dist/generate-BO_Gv-vi.cjs.map +0 -1
- package/dist/generate-HzSh9v2l.js.map +0 -1
- package/dist/mcp-BIcX2H1u.cjs.map +0 -1
- package/dist/mcp-CtV0d0Dc.js.map +0 -1
- package/dist/package-CnUMuss9.cjs.map +0 -1
- package/dist/package-DiBDd6nT.js +0 -6
- package/dist/package-DiBDd6nT.js.map +0 -1
- package/dist/run-BV2tMjuz.cjs.map +0 -1
- package/dist/run-CLGgnrjg.js.map +0 -1
- package/dist/run-ChKPZlIB.js.map +0 -1
- package/dist/run-Cs5FunVC.cjs.map +0 -1
- package/dist/run-DAGbErY0.cjs.map +0 -1
- package/dist/run-DCfdTu52.js.map +0 -1
- package/dist/run-DSgLksGj.js.map +0 -1
- package/dist/run-FPqeAEF4.cjs.map +0 -1
- package/dist/tools-DH1a7ZJH.js +0 -152
- package/dist/tools-DH1a7ZJH.js.map +0 -1
- package/dist/tools-bwKAf_r-.cjs +0 -175
- package/dist/tools-bwKAf_r-.cjs.map +0 -1
- package/dist/validate-BxCwQou-.cjs.map +0 -1
- package/dist/validate-DD2S9ffV.js.map +0 -1
|
@@ -1,19 +1,125 @@
|
|
|
1
1
|
import "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as
|
|
5
|
-
import { i as linters, n as detectTool, r as formatters } from "./tools-DH1a7ZJH.js";
|
|
2
|
+
import { t as toError } from "./errors-C8yNfV7w.js";
|
|
3
|
+
import { s as WATCHER_IGNORED_PATHS } from "./Telemetry-BCTY-Nzq.js";
|
|
4
|
+
import { i as getAgentName, t as canUseTTY } from "./env-DqPKEL59.js";
|
|
6
5
|
import { styleText } from "node:util";
|
|
7
6
|
import { randomUUID } from "node:crypto";
|
|
8
7
|
import process$1 from "node:process";
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
8
|
+
import { basename, dirname, relative, resolve } from "node:path";
|
|
9
|
+
import { spawn } from "node:child_process";
|
|
10
|
+
import { Diagnostics, logLevel } from "@kubb/core";
|
|
11
11
|
import * as clack from "@clack/prompts";
|
|
12
|
-
import { Diagnostics, Hookable, cliReporter, createKubb, getInputKind, logLevel, memoryStorage } from "@kubb/core";
|
|
13
12
|
import { createJiti } from "jiti";
|
|
14
13
|
import { NonZeroExitError, x } from "tinyexec";
|
|
15
14
|
import { loadConfig } from "unconfig";
|
|
16
15
|
import { isGreater, isValid, truncate } from "verkit";
|
|
16
|
+
//#region ../../internals/utils/src/tools.ts
|
|
17
|
+
/**
|
|
18
|
+
* CLI command descriptors for each supported code formatter.
|
|
19
|
+
*/
|
|
20
|
+
const formatters = {
|
|
21
|
+
prettier: {
|
|
22
|
+
command: "prettier",
|
|
23
|
+
args: (outputPath) => [
|
|
24
|
+
"--ignore-unknown",
|
|
25
|
+
"--write",
|
|
26
|
+
outputPath
|
|
27
|
+
],
|
|
28
|
+
errorMessage: "Prettier not found"
|
|
29
|
+
},
|
|
30
|
+
biome: {
|
|
31
|
+
command: "biome",
|
|
32
|
+
args: (outputPath) => [
|
|
33
|
+
"format",
|
|
34
|
+
"--write",
|
|
35
|
+
outputPath
|
|
36
|
+
],
|
|
37
|
+
errorMessage: "Biome not found"
|
|
38
|
+
},
|
|
39
|
+
oxfmt: {
|
|
40
|
+
command: "oxfmt",
|
|
41
|
+
args: (outputPath) => [outputPath],
|
|
42
|
+
errorMessage: "Oxfmt not found"
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* CLI command descriptors for each supported linter.
|
|
47
|
+
*/
|
|
48
|
+
const linters = {
|
|
49
|
+
eslint: {
|
|
50
|
+
command: "eslint",
|
|
51
|
+
args: (outputPath) => [outputPath, "--fix"],
|
|
52
|
+
errorMessage: "Eslint not found"
|
|
53
|
+
},
|
|
54
|
+
biome: {
|
|
55
|
+
command: "biome",
|
|
56
|
+
args: (outputPath) => [
|
|
57
|
+
"lint",
|
|
58
|
+
"--fix",
|
|
59
|
+
outputPath
|
|
60
|
+
],
|
|
61
|
+
errorMessage: "Biome not found"
|
|
62
|
+
},
|
|
63
|
+
oxlint: {
|
|
64
|
+
command: "oxlint",
|
|
65
|
+
args: (outputPath) => [
|
|
66
|
+
"--fix",
|
|
67
|
+
"--no-ignore",
|
|
68
|
+
outputPath
|
|
69
|
+
],
|
|
70
|
+
errorMessage: "Oxlint not found"
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Preference order for `format: 'auto'`, most-preferred first. Spelled out rather than taken from
|
|
75
|
+
* the table's key order, which is arbitrary and would silently change what `auto` picks.
|
|
76
|
+
*/
|
|
77
|
+
const FORMATTER_PREFERENCE = [
|
|
78
|
+
"oxfmt",
|
|
79
|
+
"biome",
|
|
80
|
+
"prettier"
|
|
81
|
+
];
|
|
82
|
+
/**
|
|
83
|
+
* Preference order for `lint: 'auto'`, most-preferred first.
|
|
84
|
+
*/
|
|
85
|
+
const LINTER_PREFERENCE = [
|
|
86
|
+
"oxlint",
|
|
87
|
+
"biome",
|
|
88
|
+
"eslint"
|
|
89
|
+
];
|
|
90
|
+
/**
|
|
91
|
+
* Whether `name` is on PATH and answers `--version` with a zero exit.
|
|
92
|
+
*/
|
|
93
|
+
function isToolAvailable(name) {
|
|
94
|
+
return new Promise((resolve) => {
|
|
95
|
+
const child = spawn(name, ["--version"], { stdio: "ignore" });
|
|
96
|
+
child.on("close", (code) => resolve(code === 0));
|
|
97
|
+
child.on("error", () => resolve(false));
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns the first installed executable from `candidates`, or `null` when none are found.
|
|
102
|
+
*
|
|
103
|
+
* Not memoized: a long-running host that probes repeatedly should cache the result itself, and a
|
|
104
|
+
* `--watch` build should keep noticing a tool installed mid-session.
|
|
105
|
+
*/
|
|
106
|
+
async function detectTool(candidates) {
|
|
107
|
+
for (const candidate of candidates) if (await isToolAvailable(candidate)) return candidate;
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Tokenizes a shell command string, respecting single and double quotes.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* tokenize('git commit -m "initial commit"')
|
|
116
|
+
* // → ['git', 'commit', '-m', 'initial commit']
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
function tokenize(command) {
|
|
120
|
+
return (command.match(/[^\s"']+|"([^"]*)"|'([^']*)'/g) ?? []).map((token) => token.replace(/^["']|["']$/g, ""));
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
17
123
|
//#region ../../internals/utils/src/time.ts
|
|
18
124
|
/**
|
|
19
125
|
* Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.
|
|
@@ -47,7 +153,7 @@ function formatMs(ms) {
|
|
|
47
153
|
return `${Math.round(ms)}ms`;
|
|
48
154
|
}
|
|
49
155
|
//#endregion
|
|
50
|
-
//#region
|
|
156
|
+
//#region src/loggers/banner.ts
|
|
51
157
|
/**
|
|
52
158
|
* Parses a CSS hex color string (`#RGB`) into its RGB channels.
|
|
53
159
|
* Falls back to `255` for any channel that cannot be parsed.
|
|
@@ -158,43 +264,6 @@ function formatMsWithColor(ms) {
|
|
|
158
264
|
return styleText("red", formatted);
|
|
159
265
|
}
|
|
160
266
|
//#endregion
|
|
161
|
-
//#region ../../internals/utils/src/promise.ts
|
|
162
|
-
/**
|
|
163
|
-
* Wraps `run` so invocations never overlap: a trigger that lands while a run is in flight
|
|
164
|
-
* marks it dirty and runs once more after it finishes, no matter how many triggers arrived.
|
|
165
|
-
* Useful for event-driven reruns (a file watcher, a queue drain) where bursts should
|
|
166
|
-
* coalesce into a single trailing run.
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* ```ts
|
|
170
|
-
* const rebuild = createSerialRunner({
|
|
171
|
-
* run: () => build(),
|
|
172
|
-
* onError: (error) => log.error(error.message),
|
|
173
|
-
* })
|
|
174
|
-
* watcher.on('change', () => void rebuild())
|
|
175
|
-
* ```
|
|
176
|
-
*/
|
|
177
|
-
function createSerialRunner({ run, onError }) {
|
|
178
|
-
let running = false;
|
|
179
|
-
let dirty = false;
|
|
180
|
-
return async () => {
|
|
181
|
-
if (running) {
|
|
182
|
-
dirty = true;
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
running = true;
|
|
186
|
-
do {
|
|
187
|
-
dirty = false;
|
|
188
|
-
try {
|
|
189
|
-
await run();
|
|
190
|
-
} catch (error) {
|
|
191
|
-
onError(toError(error));
|
|
192
|
-
}
|
|
193
|
-
} while (dirty);
|
|
194
|
-
running = false;
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
//#endregion
|
|
198
267
|
//#region src/loggers/clackLogger.ts
|
|
199
268
|
/**
|
|
200
269
|
* TTY logger for local development, with spinners and progress bars.
|
|
@@ -202,7 +271,7 @@ function createSerialRunner({ run, onError }) {
|
|
|
202
271
|
const clackLogger = {
|
|
203
272
|
name: "clack",
|
|
204
273
|
install(context, options) {
|
|
205
|
-
const logLevel$
|
|
274
|
+
const logLevel$3 = options?.logLevel ?? logLevel.info;
|
|
206
275
|
const state = {
|
|
207
276
|
...createProgressCounters(),
|
|
208
277
|
spinner: clack.spinner(),
|
|
@@ -231,16 +300,16 @@ const clackLogger = {
|
|
|
231
300
|
return getMessage(running.length > 0 ? `Generating ${running.join(", ")}` : "Generating plugins");
|
|
232
301
|
}
|
|
233
302
|
function showProgressStep() {
|
|
234
|
-
if (logLevel$
|
|
303
|
+
if (logLevel$3 <= logLevel.silent) return;
|
|
235
304
|
const line = buildProgressLine(state);
|
|
236
305
|
if (line) clack.log.step(getMessage(line));
|
|
237
306
|
}
|
|
238
307
|
function getMessage(message) {
|
|
239
|
-
return formatMessage(message, logLevel$
|
|
308
|
+
return formatMessage(message, logLevel$3);
|
|
240
309
|
}
|
|
241
310
|
function onStep(hook, message) {
|
|
242
311
|
context.hook(hook, () => {
|
|
243
|
-
if (logLevel$
|
|
312
|
+
if (logLevel$3 <= logLevel.silent) return;
|
|
244
313
|
clack.log.step(getMessage(message));
|
|
245
314
|
});
|
|
246
315
|
}
|
|
@@ -250,7 +319,7 @@ const clackLogger = {
|
|
|
250
319
|
state.isSpinning = false;
|
|
251
320
|
}
|
|
252
321
|
context.hook("kubb:info", ({ message, info = "" }) => {
|
|
253
|
-
if (logLevel$
|
|
322
|
+
if (logLevel$3 <= logLevel.silent) return;
|
|
254
323
|
const text = getMessage([
|
|
255
324
|
styleText("blue", "ℹ"),
|
|
256
325
|
message,
|
|
@@ -263,11 +332,11 @@ const clackLogger = {
|
|
|
263
332
|
clack.log.info(text);
|
|
264
333
|
});
|
|
265
334
|
context.hook("kubb:success", ({ message, info = "" }) => {
|
|
266
|
-
if (logLevel$
|
|
335
|
+
if (logLevel$3 <= logLevel.silent) return;
|
|
267
336
|
const text = getMessage([
|
|
268
337
|
styleText("blue", "✓"),
|
|
269
338
|
message,
|
|
270
|
-
logLevel$
|
|
339
|
+
logLevel$3 >= logLevel.info ? styleText("dim", info) : void 0
|
|
271
340
|
].filter(Boolean).join(" "));
|
|
272
341
|
if (state.isSpinning) {
|
|
273
342
|
stopSpinner(text);
|
|
@@ -276,11 +345,11 @@ const clackLogger = {
|
|
|
276
345
|
clack.log.success(text);
|
|
277
346
|
});
|
|
278
347
|
context.hook("kubb:warn", ({ message, info }) => {
|
|
279
|
-
if (logLevel$
|
|
348
|
+
if (logLevel$3 < logLevel.warn) return;
|
|
280
349
|
const text = getMessage([
|
|
281
350
|
styleText("yellow", "⚠"),
|
|
282
351
|
message,
|
|
283
|
-
logLevel$
|
|
352
|
+
logLevel$3 >= logLevel.info && info ? styleText("dim", info) : void 0
|
|
284
353
|
].filter(Boolean).join(" "));
|
|
285
354
|
clack.log.warn(text);
|
|
286
355
|
});
|
|
@@ -291,7 +360,7 @@ const clackLogger = {
|
|
|
291
360
|
return;
|
|
292
361
|
}
|
|
293
362
|
clack.log.error(getMessage(text));
|
|
294
|
-
const frames = logLevel$
|
|
363
|
+
const frames = logLevel$3 >= logLevel.verbose ? formatErrorFrames(error) : null;
|
|
295
364
|
if (frames) {
|
|
296
365
|
for (const frame of frames.frames) clack.log.message(getMessage(styleText("dim", frame)));
|
|
297
366
|
if (frames.cause) {
|
|
@@ -301,7 +370,7 @@ const clackLogger = {
|
|
|
301
370
|
}
|
|
302
371
|
});
|
|
303
372
|
context.hook("kubb:diagnostic", ({ diagnostic }) => {
|
|
304
|
-
if (logLevel$
|
|
373
|
+
if (logLevel$3 <= logLevel.silent && diagnostic.severity !== "error") return;
|
|
305
374
|
stopSpinner();
|
|
306
375
|
stopActiveProgress();
|
|
307
376
|
if (Diagnostics.isUpdate(diagnostic)) {
|
|
@@ -322,6 +391,46 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
322
391
|
secondarySymbol: ""
|
|
323
392
|
});
|
|
324
393
|
});
|
|
394
|
+
context.hook("studio:connecting", ({ url }) => {
|
|
395
|
+
if (logLevel$3 <= logLevel.silent) return;
|
|
396
|
+
state.spinner = clack.spinner();
|
|
397
|
+
state.spinner.start(getMessage(`Connecting to ${styleText("cyan", url)}`));
|
|
398
|
+
state.isSpinning = true;
|
|
399
|
+
});
|
|
400
|
+
context.hook("studio:connected", ({ url, versions }) => {
|
|
401
|
+
if (logLevel$3 <= logLevel.silent) return;
|
|
402
|
+
const text = getMessage(`Connected to ${styleText("cyan", url)} ${styleText("dim", `(${formatVersions(versions)})`)}`);
|
|
403
|
+
if (state.isSpinning) {
|
|
404
|
+
stopSpinner(text);
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
clack.log.success(text);
|
|
408
|
+
});
|
|
409
|
+
context.hook("studio:disconnected", ({ reason }) => {
|
|
410
|
+
if (logLevel$3 < logLevel.warn) return;
|
|
411
|
+
stopSpinner();
|
|
412
|
+
clack.log.warn(getMessage(`Kubb Studio ended the session (${reason})`));
|
|
413
|
+
});
|
|
414
|
+
context.hook("studio:command:start", ({ command }) => {
|
|
415
|
+
if (logLevel$3 <= logLevel.silent) return;
|
|
416
|
+
clack.log.info(getMessage(`Kubb Studio asked to ${styleText("bold", command)}`));
|
|
417
|
+
});
|
|
418
|
+
context.hook("studio:command:end", ({ command, info }) => {
|
|
419
|
+
if (logLevel$3 <= logLevel.silent) return;
|
|
420
|
+
clack.log.success(getMessage(`Finished ${command}${info ? ` ${styleText("dim", `(${info})`)}` : ""}`));
|
|
421
|
+
});
|
|
422
|
+
context.hook("studio:warn", ({ message }) => {
|
|
423
|
+
if (logLevel$3 < logLevel.warn) return;
|
|
424
|
+
clack.log.warn(getMessage(message));
|
|
425
|
+
});
|
|
426
|
+
context.hook("studio:error", ({ error }) => {
|
|
427
|
+
const text = getMessage([styleText("red", "✗"), error.message].join(" "));
|
|
428
|
+
if (state.isSpinning) {
|
|
429
|
+
stopSpinner(text);
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
clack.log.error(text);
|
|
433
|
+
});
|
|
325
434
|
context.hook("kubb:lifecycle:start", async ({ version }) => {
|
|
326
435
|
console.log(`\n${getIntro({
|
|
327
436
|
title: "The meta framework for code generation",
|
|
@@ -334,7 +443,7 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
334
443
|
context.hook("kubb:generation:start", ({ config }) => {
|
|
335
444
|
reset();
|
|
336
445
|
state.totalPlugins = config.plugins?.length ?? 0;
|
|
337
|
-
if (logLevel$
|
|
446
|
+
if (logLevel$3 <= logLevel.silent) return;
|
|
338
447
|
const text = getMessage([
|
|
339
448
|
"Generation started",
|
|
340
449
|
config.name ? `for ${styleText("dim", config.name)}` : void 0,
|
|
@@ -343,7 +452,7 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
343
452
|
clack.intro(text);
|
|
344
453
|
});
|
|
345
454
|
context.hook("kubb:plugin:start", ({ plugin }) => {
|
|
346
|
-
if (logLevel$
|
|
455
|
+
if (logLevel$3 <= logLevel.silent) return;
|
|
347
456
|
stopSpinner();
|
|
348
457
|
state.runningPlugins.add(plugin.name);
|
|
349
458
|
const active = state.activeProgress.get("plugins");
|
|
@@ -363,7 +472,7 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
363
472
|
context.hook("kubb:plugin:end", ({ plugin, success }) => {
|
|
364
473
|
stopSpinner();
|
|
365
474
|
const active = state.activeProgress.get("plugins");
|
|
366
|
-
if (!active || logLevel$
|
|
475
|
+
if (!active || logLevel$3 <= logLevel.silent) return;
|
|
367
476
|
state.runningPlugins.delete(plugin.name);
|
|
368
477
|
recordPluginResult(state, success);
|
|
369
478
|
active.progressBar.advance(1, pluginProgressText());
|
|
@@ -374,7 +483,7 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
374
483
|
}
|
|
375
484
|
});
|
|
376
485
|
context.hook("kubb:files:processing:start", ({ files }) => {
|
|
377
|
-
if (logLevel$
|
|
486
|
+
if (logLevel$3 <= logLevel.silent) return;
|
|
378
487
|
stopSpinner();
|
|
379
488
|
state.totalFiles = files.length;
|
|
380
489
|
state.processedFiles = 0;
|
|
@@ -389,7 +498,7 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
389
498
|
state.activeProgress.set("files", { progressBar });
|
|
390
499
|
});
|
|
391
500
|
context.hook("kubb:files:processing:update", ({ files }) => {
|
|
392
|
-
if (logLevel$
|
|
501
|
+
if (logLevel$3 <= logLevel.silent) return;
|
|
393
502
|
stopSpinner();
|
|
394
503
|
const active = state.activeProgress.get("files");
|
|
395
504
|
for (const { file, config } of files) {
|
|
@@ -398,7 +507,7 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
398
507
|
}
|
|
399
508
|
});
|
|
400
509
|
context.hook("kubb:files:processing:end", () => {
|
|
401
|
-
if (logLevel$
|
|
510
|
+
if (logLevel$3 <= logLevel.silent) return;
|
|
402
511
|
stopSpinner();
|
|
403
512
|
const text = getMessage("Files written successfully");
|
|
404
513
|
const active = state.activeProgress.get("files");
|
|
@@ -416,7 +525,7 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
416
525
|
onStep("kubb:lint:start", "Linting");
|
|
417
526
|
onStep("kubb:hooks:start", "Running hooks");
|
|
418
527
|
context.hook("kubb:hook:start", ({ id, command, name, args }) => {
|
|
419
|
-
if (logLevel$
|
|
528
|
+
if (logLevel$3 <= logLevel.silent || !id) return;
|
|
420
529
|
stopSpinner();
|
|
421
530
|
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
422
531
|
const title = getMessage(`Running ${styleText("dim", name ?? commandWithArgs)}`);
|
|
@@ -426,12 +535,12 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
426
535
|
hrStart: process$1.hrtime()
|
|
427
536
|
});
|
|
428
537
|
});
|
|
429
|
-
if (logLevel$
|
|
538
|
+
if (logLevel$3 > logLevel.silent) context.hook("kubb:hook:line", ({ id, line }) => {
|
|
430
539
|
state.activeHookLogs.get(id)?.taskLog.message(styleText("dim", line));
|
|
431
540
|
});
|
|
432
541
|
context.hook("kubb:hook:end", ({ id, command, name, args, success, error, stdout, stderr }) => {
|
|
433
542
|
if (!id) return;
|
|
434
|
-
if (logLevel$
|
|
543
|
+
if (logLevel$3 <= logLevel.silent) {
|
|
435
544
|
if (!success) {
|
|
436
545
|
if (stdout) console.log(stdout);
|
|
437
546
|
if (stderr) console.error(stderr);
|
|
@@ -462,19 +571,19 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
462
571
|
const plainLogger = {
|
|
463
572
|
name: "plain",
|
|
464
573
|
install(context, options) {
|
|
465
|
-
const logLevel$
|
|
574
|
+
const logLevel$2 = options?.logLevel ?? logLevel.info;
|
|
466
575
|
const hookTimer = createHookTimer();
|
|
467
576
|
function getMessage(message) {
|
|
468
|
-
return formatMessage(message, logLevel$
|
|
577
|
+
return formatMessage(message, logLevel$2);
|
|
469
578
|
}
|
|
470
579
|
function onStep(hook, message) {
|
|
471
580
|
context.hook(hook, () => {
|
|
472
|
-
if (logLevel$
|
|
581
|
+
if (logLevel$2 <= logLevel.silent) return;
|
|
473
582
|
console.log(getMessage(message));
|
|
474
583
|
});
|
|
475
584
|
}
|
|
476
585
|
context.hook("kubb:info", ({ message, info }) => {
|
|
477
|
-
if (logLevel$
|
|
586
|
+
if (logLevel$2 <= logLevel.silent) return;
|
|
478
587
|
const text = getMessage([
|
|
479
588
|
"ℹ",
|
|
480
589
|
message,
|
|
@@ -483,27 +592,27 @@ const plainLogger = {
|
|
|
483
592
|
console.log(text);
|
|
484
593
|
});
|
|
485
594
|
context.hook("kubb:success", ({ message, info = "" }) => {
|
|
486
|
-
if (logLevel$
|
|
595
|
+
if (logLevel$2 <= logLevel.silent) return;
|
|
487
596
|
const text = getMessage([
|
|
488
597
|
"✓",
|
|
489
598
|
message,
|
|
490
|
-
logLevel$
|
|
599
|
+
logLevel$2 >= logLevel.info ? info : void 0
|
|
491
600
|
].filter(Boolean).join(" "));
|
|
492
601
|
console.log(text);
|
|
493
602
|
});
|
|
494
603
|
context.hook("kubb:warn", ({ message, info }) => {
|
|
495
|
-
if (logLevel$
|
|
604
|
+
if (logLevel$2 < logLevel.warn) return;
|
|
496
605
|
const text = getMessage([
|
|
497
606
|
"⚠",
|
|
498
607
|
message,
|
|
499
|
-
logLevel$
|
|
608
|
+
logLevel$2 >= logLevel.info ? info : void 0
|
|
500
609
|
].filter(Boolean).join(" "));
|
|
501
610
|
console.log(text);
|
|
502
611
|
});
|
|
503
612
|
context.hook("kubb:error", ({ error }) => {
|
|
504
613
|
const text = getMessage(["✗", error.message].join(" "));
|
|
505
614
|
console.log(text);
|
|
506
|
-
const frames = logLevel$
|
|
615
|
+
const frames = logLevel$2 >= logLevel.verbose ? formatErrorFrames(error) : null;
|
|
507
616
|
if (frames) {
|
|
508
617
|
for (const frame of frames.frames) console.log(getMessage(frame));
|
|
509
618
|
if (frames.cause) {
|
|
@@ -513,9 +622,36 @@ const plainLogger = {
|
|
|
513
622
|
}
|
|
514
623
|
});
|
|
515
624
|
context.hook("kubb:diagnostic", ({ diagnostic }) => {
|
|
516
|
-
if (logLevel$
|
|
625
|
+
if (logLevel$2 <= logLevel.silent && diagnostic.severity !== "error") return;
|
|
517
626
|
console.log(getMessage(Diagnostics.formatLines(diagnostic).join("\n")));
|
|
518
627
|
});
|
|
628
|
+
context.hook("studio:connecting", ({ url }) => {
|
|
629
|
+
if (logLevel$2 <= logLevel.silent) return;
|
|
630
|
+
console.log(getMessage(`Connecting to ${url}`));
|
|
631
|
+
});
|
|
632
|
+
context.hook("studio:connected", ({ url, versions }) => {
|
|
633
|
+
if (logLevel$2 <= logLevel.silent) return;
|
|
634
|
+
console.log(getMessage(`✓ Connected to ${url} (${formatVersions(versions)})`));
|
|
635
|
+
});
|
|
636
|
+
context.hook("studio:disconnected", ({ reason }) => {
|
|
637
|
+
if (logLevel$2 < logLevel.warn) return;
|
|
638
|
+
console.log(getMessage(`⚠ Kubb Studio ended the session (${reason})`));
|
|
639
|
+
});
|
|
640
|
+
context.hook("studio:command:start", ({ command }) => {
|
|
641
|
+
if (logLevel$2 <= logLevel.silent) return;
|
|
642
|
+
console.log(getMessage(`Kubb Studio asked to ${command}`));
|
|
643
|
+
});
|
|
644
|
+
context.hook("studio:command:end", ({ command, info }) => {
|
|
645
|
+
if (logLevel$2 <= logLevel.silent) return;
|
|
646
|
+
console.log(getMessage(`✓ Finished ${command}${info ? ` (${info})` : ""}`));
|
|
647
|
+
});
|
|
648
|
+
context.hook("studio:warn", ({ message }) => {
|
|
649
|
+
if (logLevel$2 < logLevel.warn) return;
|
|
650
|
+
console.log(getMessage(`⚠ ${message}`));
|
|
651
|
+
});
|
|
652
|
+
context.hook("studio:error", ({ error }) => {
|
|
653
|
+
console.log(getMessage(`✗ ${error.message}`));
|
|
654
|
+
});
|
|
519
655
|
context.hook("kubb:lifecycle:start", ({ version }) => {
|
|
520
656
|
console.log(`Kubb CLI v${version}`);
|
|
521
657
|
});
|
|
@@ -524,27 +660,27 @@ const plainLogger = {
|
|
|
524
660
|
console.log(text);
|
|
525
661
|
});
|
|
526
662
|
context.hook("kubb:plugin:start", ({ plugin }) => {
|
|
527
|
-
if (logLevel$
|
|
663
|
+
if (logLevel$2 <= logLevel.silent) return;
|
|
528
664
|
const text = getMessage(`Generating ${plugin.name}`);
|
|
529
665
|
console.log(text);
|
|
530
666
|
});
|
|
531
667
|
context.hook("kubb:plugin:end", ({ plugin, duration, success }) => {
|
|
532
|
-
if (logLevel$
|
|
668
|
+
if (logLevel$2 <= logLevel.silent) return;
|
|
533
669
|
const durationStr = formatMs(duration);
|
|
534
670
|
const text = getMessage(success ? `${plugin.name} completed in ${durationStr}` : `${plugin.name} failed in ${durationStr}`);
|
|
535
671
|
console.log(text);
|
|
536
672
|
});
|
|
537
673
|
context.hook("kubb:files:processing:start", ({ files }) => {
|
|
538
|
-
if (logLevel$
|
|
674
|
+
if (logLevel$2 <= logLevel.silent) return;
|
|
539
675
|
const text = getMessage(`Writing ${files.length} files`);
|
|
540
676
|
console.log(text);
|
|
541
677
|
});
|
|
542
678
|
context.hook("kubb:files:processing:update", ({ files }) => {
|
|
543
|
-
if (logLevel$
|
|
679
|
+
if (logLevel$2 <= logLevel.silent) return;
|
|
544
680
|
for (const { file, config } of files) console.log(getMessage(`Writing ${relative(config.root, file.path)}`));
|
|
545
681
|
});
|
|
546
682
|
context.hook("kubb:files:processing:end", () => {
|
|
547
|
-
if (logLevel$
|
|
683
|
+
if (logLevel$2 <= logLevel.silent) return;
|
|
548
684
|
const text = getMessage("Files written successfully");
|
|
549
685
|
console.log(text);
|
|
550
686
|
});
|
|
@@ -559,13 +695,13 @@ const plainLogger = {
|
|
|
559
695
|
onStep("kubb:hooks:start", "Hooks started");
|
|
560
696
|
onStep("kubb:hooks:end", "Hooks completed");
|
|
561
697
|
context.hook("kubb:hook:start", ({ id, command, name, args }) => {
|
|
562
|
-
if (logLevel$
|
|
698
|
+
if (logLevel$2 <= logLevel.silent) return;
|
|
563
699
|
if (id) hookTimer.start(id);
|
|
564
700
|
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
565
701
|
console.log(getMessage(`Hook ${name ?? commandWithArgs} started`));
|
|
566
702
|
});
|
|
567
703
|
context.hook("kubb:hook:end", ({ id, command, name, args, success, error, stdout, stderr }) => {
|
|
568
|
-
if (logLevel$
|
|
704
|
+
if (logLevel$2 <= logLevel.silent) return;
|
|
569
705
|
const ms = id ? hookTimer.end(id) : void 0;
|
|
570
706
|
const durationStr = ms !== void 0 ? ` in ${formatMs(ms)}` : "";
|
|
571
707
|
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
@@ -594,8 +730,8 @@ function getInputPath(config) {
|
|
|
594
730
|
* Optionally prefix a message with a [HH:MM:SS] timestamp when logLevel >= verbose.
|
|
595
731
|
* Shared across all logger adapters to avoid duplication.
|
|
596
732
|
*/
|
|
597
|
-
function formatMessage(message, logLevel$
|
|
598
|
-
if (logLevel$
|
|
733
|
+
function formatMessage(message, logLevel$1) {
|
|
734
|
+
if (logLevel$1 >= logLevel.verbose) {
|
|
599
735
|
const timestamp = (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", {
|
|
600
736
|
hour12: false,
|
|
601
737
|
hour: "2-digit",
|
|
@@ -607,6 +743,23 @@ function formatMessage(message, logLevel$3) {
|
|
|
607
743
|
return message;
|
|
608
744
|
}
|
|
609
745
|
/**
|
|
746
|
+
* Renders the versions from a `studio:connected` event as one parenthetical. The runtime is listed
|
|
747
|
+
* only when it differs from the host, and Studio's only when it sent one.
|
|
748
|
+
*/
|
|
749
|
+
function formatVersions({ studio, kubb, agent }) {
|
|
750
|
+
return [
|
|
751
|
+
`v${agent}`,
|
|
752
|
+
kubb !== agent ? `runtime v${kubb}` : void 0,
|
|
753
|
+
studio ? `Studio v${studio}` : void 0
|
|
754
|
+
].filter(Boolean).join(", ");
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Extracts the `.cause` of an `Error` as an `Error`, or `undefined` when absent or not an `Error`.
|
|
758
|
+
*/
|
|
759
|
+
function toCause(error) {
|
|
760
|
+
return error.cause instanceof Error ? error.cause : void 0;
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
610
763
|
* First stack frames for verbose error output, including an optional `cause` chain.
|
|
611
764
|
*/
|
|
612
765
|
function formatErrorFrames(error) {
|
|
@@ -857,18 +1010,6 @@ function isNewerVersion(current, latest) {
|
|
|
857
1010
|
return isGreater(truncate(latest, "patch"), truncate(current, "patch"));
|
|
858
1011
|
}
|
|
859
1012
|
/**
|
|
860
|
-
* Tokenizes a shell command string, respecting single and double quotes.
|
|
861
|
-
*
|
|
862
|
-
* @example
|
|
863
|
-
* ```ts
|
|
864
|
-
* tokenize('git commit -m "initial commit"')
|
|
865
|
-
* // → ['git', 'commit', '-m', 'initial commit']
|
|
866
|
-
* ```
|
|
867
|
-
*/
|
|
868
|
-
function tokenize(command) {
|
|
869
|
-
return (command.match(/[^\s"']+|"([^"]*)"|'([^']*)'/g) ?? []).map((token) => token.replace(/^["']|["']$/g, ""));
|
|
870
|
-
}
|
|
871
|
-
/**
|
|
872
1013
|
* Runs the `output.postGenerate` commands of a Kubb config in sequence and returns each command's
|
|
873
1014
|
* outcome, so the caller can turn failures into diagnostics.
|
|
874
1015
|
*/
|
|
@@ -949,6 +1090,41 @@ async function runHook({ id, command, name, args, commandWithArgs, hooks }) {
|
|
|
949
1090
|
}
|
|
950
1091
|
}
|
|
951
1092
|
/**
|
|
1093
|
+
* Wraps `run` so invocations never overlap: a trigger that lands while a run is in flight
|
|
1094
|
+
* marks it dirty and runs once more after it finishes, no matter how many triggers arrived.
|
|
1095
|
+
* Useful for event-driven reruns (a file watcher, a queue drain) where bursts should
|
|
1096
|
+
* coalesce into a single trailing run.
|
|
1097
|
+
*
|
|
1098
|
+
* @example
|
|
1099
|
+
* ```ts
|
|
1100
|
+
* const rebuild = createSerialRunner({
|
|
1101
|
+
* run: () => build(),
|
|
1102
|
+
* onError: (error) => log.error(error.message),
|
|
1103
|
+
* })
|
|
1104
|
+
* watcher.on('change', () => void rebuild())
|
|
1105
|
+
* ```
|
|
1106
|
+
*/
|
|
1107
|
+
function createSerialRunner({ run, onError }) {
|
|
1108
|
+
let running = false;
|
|
1109
|
+
let dirty = false;
|
|
1110
|
+
return async () => {
|
|
1111
|
+
if (running) {
|
|
1112
|
+
dirty = true;
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
running = true;
|
|
1116
|
+
do {
|
|
1117
|
+
dirty = false;
|
|
1118
|
+
try {
|
|
1119
|
+
await run();
|
|
1120
|
+
} catch (error) {
|
|
1121
|
+
onError(toError(error));
|
|
1122
|
+
}
|
|
1123
|
+
} while (dirty);
|
|
1124
|
+
running = false;
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
952
1128
|
* Starts a file watcher on the given paths and calls `cb` on any change.
|
|
953
1129
|
* Ignores `.git` and `node_modules` directories. Event bursts (an editor save emits several)
|
|
954
1130
|
* are debounced into one build, and builds never overlap: changes during a build queue exactly
|
|
@@ -985,272 +1161,6 @@ async function startWatcher(path, cb, log = {
|
|
|
985
1161
|
});
|
|
986
1162
|
}
|
|
987
1163
|
//#endregion
|
|
988
|
-
|
|
989
|
-
/**
|
|
990
|
-
* Runs one formatter or linter pass over the output directory. Returns the failure instead of
|
|
991
|
-
* throwing, so the caller can turn it into a coded diagnostic. Failures never render here:
|
|
992
|
-
* the caller emits them through `Diagnostics.emit`, like every other diagnostic.
|
|
993
|
-
*/
|
|
994
|
-
async function runToolPass({ toolValue, tool, outputPath, logLevel: logLevel$1, hooks, onStart, onEnd }) {
|
|
995
|
-
await onStart();
|
|
996
|
-
let resolvedTool = toolValue;
|
|
997
|
-
if (resolvedTool === "auto") {
|
|
998
|
-
const detected = await tool.detect();
|
|
999
|
-
if (!detected) await hooks.callHook("kubb:warn", { message: tool.noToolMessage });
|
|
1000
|
-
else {
|
|
1001
|
-
resolvedTool = detected;
|
|
1002
|
-
await hooks.callHook("kubb:info", { message: `Auto-detected ${tool.label}: ${styleText("dim", resolvedTool)}` });
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
let toolError = null;
|
|
1006
|
-
if (resolvedTool && resolvedTool !== "auto" && resolvedTool in tool.map && existsSync(outputPath)) {
|
|
1007
|
-
const toolConfig = tool.map[resolvedTool];
|
|
1008
|
-
const successMessage = [
|
|
1009
|
-
`${tool.successPrefix} with ${styleText("dim", resolvedTool)}`,
|
|
1010
|
-
logLevel$1 >= logLevel.info ? `on ${styleText("dim", outputPath)}` : void 0,
|
|
1011
|
-
"successfully"
|
|
1012
|
-
].filter(Boolean).join(" ");
|
|
1013
|
-
try {
|
|
1014
|
-
const hookId = randomUUID();
|
|
1015
|
-
const hookArgs = toolConfig.args(outputPath);
|
|
1016
|
-
const commandWithArgs = [toolConfig.command, ...hookArgs].join(" ");
|
|
1017
|
-
await hooks.callHook("kubb:hook:start", {
|
|
1018
|
-
id: hookId,
|
|
1019
|
-
command: toolConfig.command,
|
|
1020
|
-
args: hookArgs
|
|
1021
|
-
});
|
|
1022
|
-
const result = await runHook({
|
|
1023
|
-
id: hookId,
|
|
1024
|
-
command: toolConfig.command,
|
|
1025
|
-
args: hookArgs,
|
|
1026
|
-
commandWithArgs,
|
|
1027
|
-
hooks
|
|
1028
|
-
});
|
|
1029
|
-
if (result.success) await hooks.callHook("kubb:success", { message: successMessage });
|
|
1030
|
-
else toolError = result.error ?? new Error(toolConfig.errorMessage);
|
|
1031
|
-
} catch (caughtError) {
|
|
1032
|
-
toolError = toError(caughtError);
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
await onEnd();
|
|
1036
|
-
return toolError;
|
|
1037
|
-
}
|
|
1038
|
-
async function generate(options) {
|
|
1039
|
-
const { input, hooks, logLevel, dryRun = false } = options;
|
|
1040
|
-
const hrStart = process$1.hrtime();
|
|
1041
|
-
const inputPath = input ?? (typeof options.config.input === "string" ? options.config.input : void 0);
|
|
1042
|
-
const config = {
|
|
1043
|
-
...options.config,
|
|
1044
|
-
input: input ?? options.config.input,
|
|
1045
|
-
storage: dryRun ? memoryStorage() : options.config.storage
|
|
1046
|
-
};
|
|
1047
|
-
const processOutput = async ({ config: resolvedConfig, outputPath }) => {
|
|
1048
|
-
if (dryRun) return [];
|
|
1049
|
-
const outputDiagnostics = [];
|
|
1050
|
-
const reportOutputFailure = async (code, label, error) => {
|
|
1051
|
-
const diagnostic = outputDiagnostic(code, label, error);
|
|
1052
|
-
outputDiagnostics.push(diagnostic);
|
|
1053
|
-
await Diagnostics.emit(hooks, diagnostic);
|
|
1054
|
-
};
|
|
1055
|
-
const toolPasses = [{
|
|
1056
|
-
value: resolvedConfig.output.format,
|
|
1057
|
-
code: Diagnostics.code.formatFailed,
|
|
1058
|
-
tool: {
|
|
1059
|
-
label: "formatter",
|
|
1060
|
-
map: formatters,
|
|
1061
|
-
detect: () => detectTool([
|
|
1062
|
-
"oxfmt",
|
|
1063
|
-
"biome",
|
|
1064
|
-
"prettier"
|
|
1065
|
-
]),
|
|
1066
|
-
successPrefix: "Formatting",
|
|
1067
|
-
noToolMessage: "No formatter found (oxfmt, biome, or prettier). Skipping formatting."
|
|
1068
|
-
},
|
|
1069
|
-
onStart: () => hooks.callHook("kubb:format:start"),
|
|
1070
|
-
onEnd: () => hooks.callHook("kubb:format:end")
|
|
1071
|
-
}, {
|
|
1072
|
-
value: resolvedConfig.output.lint,
|
|
1073
|
-
code: Diagnostics.code.lintFailed,
|
|
1074
|
-
tool: {
|
|
1075
|
-
label: "linter",
|
|
1076
|
-
map: linters,
|
|
1077
|
-
detect: () => detectTool([
|
|
1078
|
-
"oxlint",
|
|
1079
|
-
"biome",
|
|
1080
|
-
"eslint"
|
|
1081
|
-
]),
|
|
1082
|
-
successPrefix: "Linting",
|
|
1083
|
-
noToolMessage: "No linter found (oxlint, biome, or eslint). Skipping linting."
|
|
1084
|
-
},
|
|
1085
|
-
onStart: () => hooks.callHook("kubb:lint:start"),
|
|
1086
|
-
onEnd: () => hooks.callHook("kubb:lint:end")
|
|
1087
|
-
}];
|
|
1088
|
-
for (const pass of toolPasses) {
|
|
1089
|
-
if (!pass.value) continue;
|
|
1090
|
-
const error = await runToolPass({
|
|
1091
|
-
toolValue: pass.value,
|
|
1092
|
-
tool: pass.tool,
|
|
1093
|
-
onStart: pass.onStart,
|
|
1094
|
-
onEnd: pass.onEnd,
|
|
1095
|
-
outputPath,
|
|
1096
|
-
logLevel,
|
|
1097
|
-
hooks
|
|
1098
|
-
});
|
|
1099
|
-
if (error) await reportOutputFailure(pass.code, pass.tool.label, error);
|
|
1100
|
-
}
|
|
1101
|
-
if (resolvedConfig.output.postGenerate?.length) {
|
|
1102
|
-
await hooks.callHook("kubb:hooks:start");
|
|
1103
|
-
const hookResults = await runPostGenerate({
|
|
1104
|
-
commands: resolvedConfig.output.postGenerate,
|
|
1105
|
-
hooks
|
|
1106
|
-
});
|
|
1107
|
-
for (const hookResult of hookResults) {
|
|
1108
|
-
if (hookResult.success) continue;
|
|
1109
|
-
await reportOutputFailure(Diagnostics.code.postGenerateFailed, "Post-generate command", hookResult.error ?? /* @__PURE__ */ new Error("Post-generate command failed"));
|
|
1110
|
-
}
|
|
1111
|
-
await hooks.callHook("kubb:hooks:end");
|
|
1112
|
-
}
|
|
1113
|
-
return outputDiagnostics;
|
|
1114
|
-
};
|
|
1115
|
-
hooks.hook("kubb:generation:end", ({ status }) => {
|
|
1116
|
-
if (status === "success") return hooks.callHook("kubb:success", {
|
|
1117
|
-
message: "Generation succeeded",
|
|
1118
|
-
info: inputPath
|
|
1119
|
-
});
|
|
1120
|
-
});
|
|
1121
|
-
const kubb = createKubb(config, { hooks });
|
|
1122
|
-
const result = await kubb.generate({ processOutput });
|
|
1123
|
-
if (dryRun) await hooks.callHook("kubb:info", {
|
|
1124
|
-
message: "Dry run: no files were written",
|
|
1125
|
-
info: `${result.files.length} file(s) would be generated`
|
|
1126
|
-
});
|
|
1127
|
-
const telemetryPlugins = Array.from(kubb.driver.plugins.values(), (p) => ({
|
|
1128
|
-
name: p.name,
|
|
1129
|
-
options: p.options
|
|
1130
|
-
}));
|
|
1131
|
-
await sendTelemetry(buildTelemetryEvent({
|
|
1132
|
-
command: "generate",
|
|
1133
|
-
kubbVersion: version,
|
|
1134
|
-
plugins: telemetryPlugins,
|
|
1135
|
-
hrStart,
|
|
1136
|
-
filesCreated: result.files.length,
|
|
1137
|
-
status: result.success ? "success" : "failed"
|
|
1138
|
-
}));
|
|
1139
|
-
return result.success;
|
|
1140
|
-
}
|
|
1141
|
-
/**
|
|
1142
|
-
* Builds a coded diagnostic for an output-phase failure (formatter, linter, or `done` hook).
|
|
1143
|
-
*/
|
|
1144
|
-
function outputDiagnostic(code, label, caughtError) {
|
|
1145
|
-
const error = toError(caughtError);
|
|
1146
|
-
return {
|
|
1147
|
-
code,
|
|
1148
|
-
severity: "error",
|
|
1149
|
-
message: `${label} failed: ${error.message}`,
|
|
1150
|
-
help: "Check that the tool is installed and that the command and its config are correct.",
|
|
1151
|
-
location: { kind: "config" },
|
|
1152
|
-
cause: error
|
|
1153
|
-
};
|
|
1154
|
-
}
|
|
1155
|
-
async function checkForUpdate(hooks) {
|
|
1156
|
-
try {
|
|
1157
|
-
const data = await (await fetch(KUBB_NPM_PACKAGE_URL, { signal: AbortSignal.timeout(UPDATE_CHECK_TIMEOUT_MS) })).json();
|
|
1158
|
-
if (data.version && isNewerVersion(version, data.version)) await Diagnostics.emit(hooks, Diagnostics.update({
|
|
1159
|
-
currentVersion: version,
|
|
1160
|
-
latestVersion: data.version
|
|
1161
|
-
}));
|
|
1162
|
-
} catch {}
|
|
1163
|
-
}
|
|
1164
|
-
/**
|
|
1165
|
-
* Runs the full Kubb generation lifecycle for the given CLI options.
|
|
1166
|
-
* Loads configs, sets up the reporters (CLI `--reporter` picks which of `config.reporters` to trigger),
|
|
1167
|
-
* checks for a newer version, and calls `generate` for each config entry.
|
|
1168
|
-
*/
|
|
1169
|
-
async function run({ input, configPath, logLevel: logLevelKey, watch, reporters: cliReporters, dryRun }) {
|
|
1170
|
-
const logLevel$2 = logLevel[logLevelKey] ?? logLevel.info;
|
|
1171
|
-
const hooks = new Hookable();
|
|
1172
|
-
let configs;
|
|
1173
|
-
let resolvedConfigPath;
|
|
1174
|
-
try {
|
|
1175
|
-
const loaded = await getConfigs({
|
|
1176
|
-
configPath,
|
|
1177
|
-
input,
|
|
1178
|
-
watch,
|
|
1179
|
-
logLevel: logLevelKey
|
|
1180
|
-
});
|
|
1181
|
-
configs = loaded.configs;
|
|
1182
|
-
resolvedConfigPath = loaded.configPath;
|
|
1183
|
-
} catch (error) {
|
|
1184
|
-
await setupReporters(hooks, {
|
|
1185
|
-
logLevel: logLevel$2,
|
|
1186
|
-
reporters: [cliReporter]
|
|
1187
|
-
});
|
|
1188
|
-
await hooks.callHook("kubb:error", { error: toError(error) });
|
|
1189
|
-
process$1.exit(1);
|
|
1190
|
-
}
|
|
1191
|
-
const requestedNames = cliReporters?.length ? cliReporters : ["cli"];
|
|
1192
|
-
await setupReporters(hooks, {
|
|
1193
|
-
logLevel: logLevel$2,
|
|
1194
|
-
reporters: selectReporters(configs[0]?.reporters ?? [], requestedNames)
|
|
1195
|
-
});
|
|
1196
|
-
await hooks.callHook("kubb:lifecycle:start", { version });
|
|
1197
|
-
await checkForUpdate(hooks);
|
|
1198
|
-
try {
|
|
1199
|
-
const relativeConfigPath = path.relative(process$1.cwd(), resolvedConfigPath);
|
|
1200
|
-
await hooks.callHook("kubb:info", {
|
|
1201
|
-
message: "Config loaded",
|
|
1202
|
-
info: relativeConfigPath
|
|
1203
|
-
});
|
|
1204
|
-
await hooks.callHook("kubb:success", {
|
|
1205
|
-
message: "Config loaded successfully",
|
|
1206
|
-
info: relativeConfigPath
|
|
1207
|
-
});
|
|
1208
|
-
let anyFailed = false;
|
|
1209
|
-
for (const config of configs) {
|
|
1210
|
-
const effectiveInput = input ?? config.input;
|
|
1211
|
-
const watchPath = typeof effectiveInput === "string" && getInputKind(effectiveInput) === "file" ? effectiveInput : void 0;
|
|
1212
|
-
if (watchPath && watch) {
|
|
1213
|
-
const watchedPaths = [watchPath];
|
|
1214
|
-
const build = async (paths) => {
|
|
1215
|
-
await generate({
|
|
1216
|
-
input,
|
|
1217
|
-
config,
|
|
1218
|
-
logLevel: logLevel$2,
|
|
1219
|
-
hooks,
|
|
1220
|
-
dryRun
|
|
1221
|
-
});
|
|
1222
|
-
clack.log.step(styleText("yellow", `Watching for changes in ${paths.join(" and ")}`));
|
|
1223
|
-
};
|
|
1224
|
-
try {
|
|
1225
|
-
await build(watchedPaths);
|
|
1226
|
-
} catch (buildError) {
|
|
1227
|
-
await hooks.callHook("kubb:error", { error: toError(buildError) });
|
|
1228
|
-
}
|
|
1229
|
-
await startWatcher(watchedPaths, build, {
|
|
1230
|
-
info: (msg) => clack.log.info(msg),
|
|
1231
|
-
error: (msg) => clack.log.error(msg)
|
|
1232
|
-
});
|
|
1233
|
-
} else try {
|
|
1234
|
-
if (!await generate({
|
|
1235
|
-
input,
|
|
1236
|
-
config,
|
|
1237
|
-
logLevel: logLevel$2,
|
|
1238
|
-
hooks,
|
|
1239
|
-
dryRun
|
|
1240
|
-
})) anyFailed = true;
|
|
1241
|
-
} catch (configError) {
|
|
1242
|
-
await hooks.callHook("kubb:error", { error: toError(configError) });
|
|
1243
|
-
anyFailed = true;
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
await hooks.callHook("kubb:lifecycle:end");
|
|
1247
|
-
if (anyFailed) process$1.exit(1);
|
|
1248
|
-
} catch (error) {
|
|
1249
|
-
await hooks.callHook("kubb:error", { error: toError(error) });
|
|
1250
|
-
process$1.exit(1);
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
//#endregion
|
|
1254
|
-
export { run };
|
|
1164
|
+
export { startWatcher as a, FORMATTER_PREFERENCE as c, formatters as d, linters as f, runPostGenerate as i, LINTER_PREFERENCE as l, isNewerVersion as n, selectReporters as o, runHook as r, setupReporters as s, getConfigs as t, detectTool as u };
|
|
1255
1165
|
|
|
1256
|
-
//# sourceMappingURL=
|
|
1166
|
+
//# sourceMappingURL=utils-CzoNURwq.js.map
|