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