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