@kubb/cli 4.32.4 → 4.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-CJ69TqoO.js +87 -0
- package/dist/agent-CJ69TqoO.js.map +1 -0
- package/dist/agent-CduUX7Ye.cjs +91 -0
- package/dist/agent-CduUX7Ye.cjs.map +1 -0
- package/dist/agent-D0A3RQho.js +57 -0
- package/dist/agent-D0A3RQho.js.map +1 -0
- package/dist/agent-DrnwQBZf.cjs +60 -0
- package/dist/agent-DrnwQBZf.cjs.map +1 -0
- package/dist/constants-CEKRremI.js +79 -0
- package/dist/constants-CEKRremI.js.map +1 -0
- package/dist/constants-CnPOlsJq.cjs +126 -0
- package/dist/constants-CnPOlsJq.cjs.map +1 -0
- package/dist/errors-BUjJsNoe.cjs +44 -0
- package/dist/errors-BUjJsNoe.cjs.map +1 -0
- package/dist/errors-bSLTEh4e.js +27 -0
- package/dist/errors-bSLTEh4e.js.map +1 -0
- package/dist/{generate-COj0aMS6.cjs → generate-ByMgAV76.cjs} +423 -577
- package/dist/generate-ByMgAV76.cjs.map +1 -0
- package/dist/generate-CiUPO5ds.cjs +65 -0
- package/dist/generate-CiUPO5ds.cjs.map +1 -0
- package/dist/generate-DIIxtkWT.js +66 -0
- package/dist/generate-DIIxtkWT.js.map +1 -0
- package/dist/{generate-CpWtSc45.js → generate-HP5ySfjV.js} +422 -577
- package/dist/generate-HP5ySfjV.js.map +1 -0
- package/dist/index.cjs +226 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +226 -35
- package/dist/index.js.map +1 -1
- package/dist/init-Cd1hCb7q.cjs +296 -0
- package/dist/init-Cd1hCb7q.cjs.map +1 -0
- package/dist/init-DLNrkDF4.js +25 -0
- package/dist/init-DLNrkDF4.js.map +1 -0
- package/dist/init-Df_aXezV.cjs +24 -0
- package/dist/init-Df_aXezV.cjs.map +1 -0
- package/dist/init-DyKK2fTp.js +291 -0
- package/dist/init-DyKK2fTp.js.map +1 -0
- package/dist/jiti-BdskUHhD.cjs +16 -0
- package/dist/jiti-BdskUHhD.cjs.map +1 -0
- package/dist/jiti-Cl7t20dO.js +11 -0
- package/dist/jiti-Cl7t20dO.js.map +1 -0
- package/dist/mcp-B73FC8dF.cjs +42 -0
- package/dist/mcp-B73FC8dF.cjs.map +1 -0
- package/dist/mcp-Bd9LITaI.js +16 -0
- package/dist/mcp-Bd9LITaI.js.map +1 -0
- package/dist/mcp-Cf-1dsB-.js +41 -0
- package/dist/mcp-Cf-1dsB-.js.map +1 -0
- package/dist/mcp-Clg-Qnkr.cjs +15 -0
- package/dist/mcp-Clg-Qnkr.cjs.map +1 -0
- package/dist/package-681jTtCk.js +6 -0
- package/dist/package-681jTtCk.js.map +1 -0
- package/dist/{package-aNQWvWbS.cjs → package-aKgzEJtp.cjs} +2 -2
- package/dist/package-aKgzEJtp.cjs.map +1 -0
- package/dist/{telemetry-DYWvlxqs.js → telemetry-C4gOKX2x.js} +31 -10
- package/dist/telemetry-C4gOKX2x.js.map +1 -0
- package/dist/{telemetry-BDSSqUiG.cjs → telemetry-T5IA2dWA.cjs} +40 -7
- package/dist/telemetry-T5IA2dWA.cjs.map +1 -0
- package/dist/types-CLtz0jem.js +25 -0
- package/dist/types-CLtz0jem.js.map +1 -0
- package/dist/types-Ck2lzFON.cjs +36 -0
- package/dist/types-Ck2lzFON.cjs.map +1 -0
- package/dist/validate-Chjg23AE.js +41 -0
- package/dist/validate-Chjg23AE.js.map +1 -0
- package/dist/validate-Cr26q5xX.js +25 -0
- package/dist/validate-Cr26q5xX.js.map +1 -0
- package/dist/validate-DURmg-2Q.cjs +24 -0
- package/dist/validate-DURmg-2Q.cjs.map +1 -0
- package/dist/validate-Dqi9T_c4.cjs +42 -0
- package/dist/validate-Dqi9T_c4.cjs.map +1 -0
- package/package.json +5 -6
- package/src/cli/adapters/nodeAdapter.ts +159 -0
- package/src/cli/help.ts +36 -0
- package/src/cli/index.ts +16 -0
- package/src/cli/parse.ts +18 -0
- package/src/cli/schema.ts +38 -0
- package/src/cli/types.ts +95 -0
- package/src/commands/agent/start.ts +27 -136
- package/src/commands/agent.ts +6 -25
- package/src/commands/generate.ts +26 -158
- package/src/commands/init.ts +9 -360
- package/src/commands/mcp.ts +7 -52
- package/src/commands/validate.ts +9 -60
- package/src/constants.ts +77 -0
- package/src/index.ts +36 -42
- package/src/loggers/clackLogger.ts +42 -140
- package/src/loggers/fileSystemLogger.ts +1 -12
- package/src/loggers/githubActionsLogger.ts +36 -101
- package/src/loggers/plainLogger.ts +23 -70
- package/src/loggers/utils.ts +66 -2
- package/src/runners/agent.ts +100 -0
- package/src/runners/generate.ts +208 -100
- package/src/runners/init.ts +322 -0
- package/src/runners/mcp.ts +32 -0
- package/src/runners/validate.ts +35 -0
- package/src/utils/Writables.ts +2 -2
- package/src/utils/envDetection.ts +34 -0
- package/src/utils/errors.ts +23 -0
- package/src/utils/executeHooks.ts +18 -6
- package/src/utils/getCosmiConfig.ts +10 -11
- package/src/utils/getIntro.ts +17 -18
- package/src/utils/getSummary.ts +11 -15
- package/src/utils/jiti.ts +9 -0
- package/src/utils/packageManager.ts +3 -3
- package/src/utils/randomColor.ts +3 -12
- package/src/utils/runHook.ts +75 -0
- package/src/utils/spawnAsync.ts +47 -0
- package/src/utils/telemetry.ts +8 -25
- package/src/utils/watcher.ts +2 -4
- package/dist/agent-6COck3B9.cjs +0 -20
- package/dist/agent-6COck3B9.cjs.map +0 -1
- package/dist/agent-DMm6c5Vg.js +0 -20
- package/dist/agent-DMm6c5Vg.js.map +0 -1
- package/dist/generate-COj0aMS6.cjs.map +0 -1
- package/dist/generate-CpWtSc45.js.map +0 -1
- package/dist/init-Bdn3_qir.js +0 -304
- package/dist/init-Bdn3_qir.js.map +0 -1
- package/dist/init-CFW2kWY8.cjs +0 -308
- package/dist/init-CFW2kWY8.cjs.map +0 -1
- package/dist/mcp-DkwtARfo.cjs +0 -57
- package/dist/mcp-DkwtARfo.cjs.map +0 -1
- package/dist/mcp-DrH93Vq4.js +0 -57
- package/dist/mcp-DrH93Vq4.js.map +0 -1
- package/dist/package-BnJbGmLm.js +0 -6
- package/dist/package-BnJbGmLm.js.map +0 -1
- package/dist/package-aNQWvWbS.cjs.map +0 -1
- package/dist/start-CqTUu14n.js +0 -131
- package/dist/start-CqTUu14n.js.map +0 -1
- package/dist/start-D-rsIJGo.cjs +0 -134
- package/dist/start-D-rsIJGo.cjs.map +0 -1
- package/dist/telemetry-BDSSqUiG.cjs.map +0 -1
- package/dist/telemetry-DYWvlxqs.js.map +0 -1
- package/dist/validate-BlV8L8gC.js +0 -66
- package/dist/validate-BlV8L8gC.js.map +0 -1
- package/dist/validate-COhZUXF8.cjs +0 -66
- package/dist/validate-COhZUXF8.cjs.map +0 -1
- package/src/loggers/envDetection.ts +0 -28
- package/src/loggers/index.ts +0 -5
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-ByKO4r7w.cjs");
|
|
2
|
-
const require_package = require("./package-
|
|
3
|
-
const
|
|
2
|
+
const require_package = require("./package-aKgzEJtp.cjs");
|
|
3
|
+
const require_constants = require("./constants-CnPOlsJq.cjs");
|
|
4
|
+
const require_telemetry = require("./telemetry-T5IA2dWA.cjs");
|
|
5
|
+
const require_errors = require("./errors-BUjJsNoe.cjs");
|
|
4
6
|
let node_util = require("node:util");
|
|
5
|
-
let citty = require("citty");
|
|
6
7
|
let node_crypto = require("node:crypto");
|
|
7
8
|
let node_process = require("node:process");
|
|
8
9
|
node_process = require_chunk.__toESM(node_process);
|
|
@@ -36,28 +37,26 @@ function formatMsWithColor(ms) {
|
|
|
36
37
|
* ANSI True Color (24-bit) utilities for terminal output
|
|
37
38
|
* Supports hex color codes without external dependencies like chalk
|
|
38
39
|
*/
|
|
40
|
+
/** Parse a hex color string into RGB components, defaulting to 255 on invalid input. */
|
|
41
|
+
function parseHex(color) {
|
|
42
|
+
const c = color.replace("#", "");
|
|
43
|
+
const r = Number.parseInt(c.slice(0, 2), 16);
|
|
44
|
+
const g = Number.parseInt(c.slice(2, 4), 16);
|
|
45
|
+
const b = Number.parseInt(c.slice(4, 6), 16);
|
|
46
|
+
return {
|
|
47
|
+
r: Number.isNaN(r) ? 255 : r,
|
|
48
|
+
g: Number.isNaN(g) ? 255 : g,
|
|
49
|
+
b: Number.isNaN(b) ? 255 : b
|
|
50
|
+
};
|
|
51
|
+
}
|
|
39
52
|
/**
|
|
40
53
|
* Convert hex color to ANSI 24-bit true color escape sequence
|
|
41
54
|
* @param color - Hex color code (with or without #), e.g., '#FF5500' or 'FF5500'
|
|
42
55
|
* @returns Function that wraps text with the color
|
|
43
56
|
*/
|
|
44
57
|
function hex(color) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
const g = Number.parseInt(cleanHex.slice(2, 4), 16);
|
|
48
|
-
const b = Number.parseInt(cleanHex.slice(4, 6), 16);
|
|
49
|
-
const safeR = Number.isNaN(r) ? 255 : r;
|
|
50
|
-
const safeG = Number.isNaN(g) ? 255 : g;
|
|
51
|
-
const safeB = Number.isNaN(b) ? 255 : b;
|
|
52
|
-
return (text) => `\x1b[38;2;${safeR};${safeG};${safeB}m${text}\x1b[0m`;
|
|
53
|
-
}
|
|
54
|
-
function hexToRgb(color) {
|
|
55
|
-
const c = color.replace("#", "");
|
|
56
|
-
return {
|
|
57
|
-
r: Number.parseInt(c.slice(0, 2), 16),
|
|
58
|
-
g: Number.parseInt(c.slice(2, 4), 16),
|
|
59
|
-
b: Number.parseInt(c.slice(4, 6), 16)
|
|
60
|
-
};
|
|
58
|
+
const { r, g, b } = parseHex(color);
|
|
59
|
+
return (text) => `\x1b[38;2;${r};${g};${b}m${text}\x1b[0m`;
|
|
61
60
|
}
|
|
62
61
|
function gradient(colors) {
|
|
63
62
|
return (text) => {
|
|
@@ -66,8 +65,8 @@ function gradient(colors) {
|
|
|
66
65
|
const t = chars.length <= 1 ? 0 : i / (chars.length - 1);
|
|
67
66
|
const seg = Math.min(Math.floor(t * (colors.length - 1)), colors.length - 2);
|
|
68
67
|
const lt = t * (colors.length - 1) - seg;
|
|
69
|
-
const from =
|
|
70
|
-
const to =
|
|
68
|
+
const from = parseHex(colors[seg]);
|
|
69
|
+
const to = parseHex(colors[seg + 1]);
|
|
71
70
|
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`;
|
|
72
71
|
}).join("");
|
|
73
72
|
};
|
|
@@ -104,35 +103,19 @@ function getIntro({ title, description, version, areEyesOpen }) {
|
|
|
104
103
|
}
|
|
105
104
|
//#endregion
|
|
106
105
|
//#region src/utils/randomColor.ts
|
|
107
|
-
function randomColor(text) {
|
|
108
|
-
if (!text) return "white";
|
|
109
|
-
const defaultColors = [
|
|
110
|
-
"black",
|
|
111
|
-
"red",
|
|
112
|
-
"green",
|
|
113
|
-
"yellow",
|
|
114
|
-
"blue",
|
|
115
|
-
"red",
|
|
116
|
-
"green",
|
|
117
|
-
"magenta",
|
|
118
|
-
"cyan",
|
|
119
|
-
"gray"
|
|
120
|
-
];
|
|
121
|
-
return defaultColors[(0, node_crypto.createHash)("sha256").update(text).digest().readUInt32BE(0) % defaultColors.length] ?? "white";
|
|
122
|
-
}
|
|
123
106
|
function randomCliColor(text) {
|
|
124
107
|
if (!text) return "";
|
|
125
|
-
return (0, node_util.styleText)(
|
|
108
|
+
return (0, node_util.styleText)(require_constants.randomColors[(0, node_crypto.createHash)("sha256").update(text).digest().readUInt32BE(0) % require_constants.randomColors.length] ?? "white", text);
|
|
126
109
|
}
|
|
127
110
|
//#endregion
|
|
128
111
|
//#region src/utils/getSummary.ts
|
|
129
112
|
function getSummary({ failedPlugins, filesCreated, status, hrStart, config, pluginTimings }) {
|
|
130
113
|
const duration = (0, _kubb_core_utils.formatHrtime)(hrStart);
|
|
131
|
-
const pluginsCount = config.plugins?.length
|
|
114
|
+
const pluginsCount = config.plugins?.length ?? 0;
|
|
132
115
|
const successCount = pluginsCount - failedPlugins.size;
|
|
133
116
|
const meta = {
|
|
134
117
|
plugins: status === "success" ? `${(0, node_util.styleText)("green", `${successCount} successful`)}, ${pluginsCount} total` : `${(0, node_util.styleText)("green", `${successCount} successful`)}, ${(0, node_util.styleText)("red", `${failedPlugins.size} failed`)}, ${pluginsCount} total`,
|
|
135
|
-
pluginsFailed: status === "failed" ? [...failedPlugins]
|
|
118
|
+
pluginsFailed: status === "failed" ? [...failedPlugins].map(({ plugin }) => randomCliColor(plugin.name)).join(", ") : void 0,
|
|
136
119
|
filesCreated,
|
|
137
120
|
time: (0, node_util.styleText)("green", duration),
|
|
138
121
|
output: node_path.default.isAbsolute(config.root) ? node_path.default.resolve(config.root, config.output.path) : config.root
|
|
@@ -150,23 +133,76 @@ function getSummary({ failedPlugins, filesCreated, status, hrStart, config, plug
|
|
|
150
133
|
if (meta.pluginsFailed) summaryLines.push(`${labels.failed.padEnd(maxLength + 2)} ${meta.pluginsFailed}`);
|
|
151
134
|
summaryLines.push(`${labels.generated.padEnd(maxLength + 2)} ${meta.filesCreated} files in ${meta.time}`);
|
|
152
135
|
if (pluginTimings && pluginTimings.size > 0) {
|
|
153
|
-
const TIME_SCALE_DIVISOR = 100;
|
|
154
|
-
const MAX_BAR_LENGTH = 10;
|
|
155
136
|
const sortedTimings = Array.from(pluginTimings.entries()).sort((a, b) => b[1] - a[1]);
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
});
|
|
164
|
-
}
|
|
137
|
+
summaryLines.push(`${labels.pluginTimings}`);
|
|
138
|
+
sortedTimings.forEach(([name, time]) => {
|
|
139
|
+
const timeStr = time >= 1e3 ? `${(time / 1e3).toFixed(2)}s` : `${Math.round(time)}ms`;
|
|
140
|
+
const barLength = Math.min(Math.ceil(time / 100), 10);
|
|
141
|
+
const bar = (0, node_util.styleText)("dim", "█".repeat(barLength));
|
|
142
|
+
summaryLines.push(`${(0, node_util.styleText)("dim", "•")} ${name.padEnd(maxLength + 1)}${bar} ${timeStr}`);
|
|
143
|
+
});
|
|
165
144
|
}
|
|
166
145
|
summaryLines.push(`${labels.output.padEnd(maxLength + 2)} ${meta.output}`);
|
|
167
146
|
return summaryLines;
|
|
168
147
|
}
|
|
169
148
|
//#endregion
|
|
149
|
+
//#region src/utils/runHook.ts
|
|
150
|
+
/**
|
|
151
|
+
* Execute a hook command, emit debug/hook:end events, and forward output to
|
|
152
|
+
* an optional HookOutputSink. All three logger adapters share this function
|
|
153
|
+
* so the process-spawning logic lives in exactly one place.
|
|
154
|
+
*/
|
|
155
|
+
async function runHook({ id, command, args, commandWithArgs, context, stream = false, sink }) {
|
|
156
|
+
try {
|
|
157
|
+
const proc = (0, tinyexec.x)(command, [...args ?? []], {
|
|
158
|
+
nodeOptions: { detached: true },
|
|
159
|
+
throwOnError: true
|
|
160
|
+
});
|
|
161
|
+
if (stream && sink?.onLine) for await (const line of proc) sink.onLine(line);
|
|
162
|
+
const result = await proc;
|
|
163
|
+
await context.emit("debug", {
|
|
164
|
+
date: /* @__PURE__ */ new Date(),
|
|
165
|
+
logs: [result.stdout.trimEnd()]
|
|
166
|
+
});
|
|
167
|
+
await context.emit("hook:end", {
|
|
168
|
+
command,
|
|
169
|
+
args,
|
|
170
|
+
id,
|
|
171
|
+
success: true,
|
|
172
|
+
error: null
|
|
173
|
+
});
|
|
174
|
+
} catch (err) {
|
|
175
|
+
if (!(err instanceof tinyexec.NonZeroExitError)) {
|
|
176
|
+
await context.emit("hook:end", {
|
|
177
|
+
command,
|
|
178
|
+
args,
|
|
179
|
+
id,
|
|
180
|
+
success: false,
|
|
181
|
+
error: require_errors.toError(err)
|
|
182
|
+
});
|
|
183
|
+
await context.emit("error", require_errors.toError(err));
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const stderr = err.output?.stderr ?? "";
|
|
187
|
+
const stdout = err.output?.stdout ?? "";
|
|
188
|
+
await context.emit("debug", {
|
|
189
|
+
date: /* @__PURE__ */ new Date(),
|
|
190
|
+
logs: [stdout, stderr].filter(Boolean)
|
|
191
|
+
});
|
|
192
|
+
if (stderr) sink?.onStderr?.(stderr);
|
|
193
|
+
if (stdout) sink?.onStdout?.(stdout);
|
|
194
|
+
const errorMessage = /* @__PURE__ */ new Error(`Hook execute failed: ${commandWithArgs}`);
|
|
195
|
+
await context.emit("hook:end", {
|
|
196
|
+
command,
|
|
197
|
+
args,
|
|
198
|
+
id,
|
|
199
|
+
success: false,
|
|
200
|
+
error: errorMessage
|
|
201
|
+
});
|
|
202
|
+
await context.emit("error", errorMessage);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
170
206
|
//#region src/utils/Writables.ts
|
|
171
207
|
var ClackWritable = class extends node_stream.Writable {
|
|
172
208
|
taskLog;
|
|
@@ -175,7 +211,7 @@ var ClackWritable = class extends node_stream.Writable {
|
|
|
175
211
|
this.taskLog = taskLog;
|
|
176
212
|
}
|
|
177
213
|
_write(chunk, _encoding, callback) {
|
|
178
|
-
this.taskLog.message(`${(0, node_util.styleText)("dim", chunk
|
|
214
|
+
this.taskLog.message(`${(0, node_util.styleText)("dim", chunk.toString())}`);
|
|
179
215
|
callback();
|
|
180
216
|
}
|
|
181
217
|
};
|
|
@@ -188,7 +224,7 @@ var ClackWritable = class extends node_stream.Writable {
|
|
|
188
224
|
const clackLogger = (0, _kubb_core.defineLogger)({
|
|
189
225
|
name: "clack",
|
|
190
226
|
install(context, options) {
|
|
191
|
-
const logLevel = options?.logLevel
|
|
227
|
+
const logLevel = options?.logLevel ?? _kubb_core.LogLevel.info;
|
|
192
228
|
const state = {
|
|
193
229
|
totalPlugins: 0,
|
|
194
230
|
completedPlugins: 0,
|
|
@@ -217,26 +253,11 @@ const clackLogger = (0, _kubb_core.defineLogger)({
|
|
|
217
253
|
}
|
|
218
254
|
function showProgressStep() {
|
|
219
255
|
if (logLevel <= _kubb_core.LogLevel.silent) return;
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
if (state.totalPlugins > 0) {
|
|
223
|
-
const pluginStr = state.failedPlugins > 0 ? `Plugins ${(0, node_util.styleText)("green", state.completedPlugins.toString())}/${state.totalPlugins} ${(0, node_util.styleText)("red", `(${state.failedPlugins} failed)`)}` : `Plugins ${(0, node_util.styleText)("green", state.completedPlugins.toString())}/${state.totalPlugins}`;
|
|
224
|
-
parts.push(pluginStr);
|
|
225
|
-
}
|
|
226
|
-
if (state.totalFiles > 0) parts.push(`Files ${(0, node_util.styleText)("green", state.processedFiles.toString())}/${state.totalFiles}`);
|
|
227
|
-
if (parts.length > 0) {
|
|
228
|
-
parts.push(`${(0, node_util.styleText)("green", duration)} elapsed`);
|
|
229
|
-
_clack_prompts.log.step(getMessage(parts.join((0, node_util.styleText)("dim", " | "))));
|
|
230
|
-
}
|
|
256
|
+
const line = buildProgressLine(state);
|
|
257
|
+
if (line) _clack_prompts.log.step(getMessage(line));
|
|
231
258
|
}
|
|
232
259
|
function getMessage(message) {
|
|
233
|
-
|
|
234
|
-
hour12: false,
|
|
235
|
-
hour: "2-digit",
|
|
236
|
-
minute: "2-digit",
|
|
237
|
-
second: "2-digit"
|
|
238
|
-
})}]`), message].join(" ");
|
|
239
|
-
return message;
|
|
260
|
+
return formatMessage(message, logLevel);
|
|
240
261
|
}
|
|
241
262
|
function startSpinner(text) {
|
|
242
263
|
state.spinner.start(text);
|
|
@@ -276,7 +297,7 @@ const clackLogger = (0, _kubb_core.defineLogger)({
|
|
|
276
297
|
_clack_prompts.log.warn(text);
|
|
277
298
|
});
|
|
278
299
|
context.on("error", (error) => {
|
|
279
|
-
const caused = error
|
|
300
|
+
const caused = require_errors.toCause(error);
|
|
280
301
|
const text = [(0, node_util.styleText)("red", "✗"), error.message].join(" ");
|
|
281
302
|
if (state.isSpinning) stopSpinner(getMessage(text));
|
|
282
303
|
else _clack_prompts.log.error(getMessage(text));
|
|
@@ -323,10 +344,10 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
323
344
|
_clack_prompts.outro(text);
|
|
324
345
|
});
|
|
325
346
|
context.on("generation:start", (config) => {
|
|
326
|
-
|
|
347
|
+
reset();
|
|
348
|
+
state.totalPlugins = config.plugins?.length ?? 0;
|
|
327
349
|
const text = getMessage(["Generation started", config.name ? `for ${(0, node_util.styleText)("dim", config.name)}` : void 0].filter(Boolean).join(" "));
|
|
328
350
|
_clack_prompts.intro(text);
|
|
329
|
-
reset();
|
|
330
351
|
});
|
|
331
352
|
context.on("plugin:start", (plugin) => {
|
|
332
353
|
if (logLevel <= _kubb_core.LogLevel.silent) return;
|
|
@@ -418,93 +439,43 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
418
439
|
_clack_prompts.outro(text);
|
|
419
440
|
});
|
|
420
441
|
context.on("hook:start", async ({ id, command, args }) => {
|
|
421
|
-
const commandWithArgs =
|
|
442
|
+
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
422
443
|
const text = getMessage(`Hook ${(0, node_util.styleText)("dim", commandWithArgs)} started`);
|
|
423
444
|
if (!id) return;
|
|
424
445
|
if (logLevel <= _kubb_core.LogLevel.silent) {
|
|
425
|
-
|
|
426
|
-
const result = await (0, tinyexec.x)(command, [...args ?? []], {
|
|
427
|
-
nodeOptions: { detached: true },
|
|
428
|
-
throwOnError: true
|
|
429
|
-
});
|
|
430
|
-
await context.emit("debug", {
|
|
431
|
-
date: /* @__PURE__ */ new Date(),
|
|
432
|
-
logs: [result.stdout.trimEnd()]
|
|
433
|
-
});
|
|
434
|
-
await context.emit("hook:end", {
|
|
435
|
-
command,
|
|
436
|
-
args,
|
|
437
|
-
id,
|
|
438
|
-
success: true,
|
|
439
|
-
error: null
|
|
440
|
-
});
|
|
441
|
-
} catch (err) {
|
|
442
|
-
const error = err;
|
|
443
|
-
const stderr = error.output?.stderr ?? "";
|
|
444
|
-
const stdout = error.output?.stdout ?? "";
|
|
445
|
-
await context.emit("debug", {
|
|
446
|
-
date: /* @__PURE__ */ new Date(),
|
|
447
|
-
logs: [stdout, stderr].filter(Boolean)
|
|
448
|
-
});
|
|
449
|
-
if (stderr) console.error(stderr);
|
|
450
|
-
if (stdout) console.log(stdout);
|
|
451
|
-
const errorMessage = /* @__PURE__ */ new Error(`Hook execute failed: ${commandWithArgs}`);
|
|
452
|
-
await context.emit("hook:end", {
|
|
453
|
-
command,
|
|
454
|
-
args,
|
|
455
|
-
id,
|
|
456
|
-
success: false,
|
|
457
|
-
error: errorMessage
|
|
458
|
-
});
|
|
459
|
-
await context.emit("error", errorMessage);
|
|
460
|
-
}
|
|
461
|
-
return;
|
|
462
|
-
}
|
|
463
|
-
_clack_prompts.intro(text);
|
|
464
|
-
const logger = _clack_prompts.taskLog({ title: getMessage(["Executing hook", logLevel >= _kubb_core.LogLevel.info ? (0, node_util.styleText)("dim", commandWithArgs) : void 0].filter(Boolean).join(" ")) });
|
|
465
|
-
const writable = new ClackWritable(logger);
|
|
466
|
-
try {
|
|
467
|
-
const proc = (0, tinyexec.x)(command, [...args ?? []], {
|
|
468
|
-
nodeOptions: { detached: true },
|
|
469
|
-
throwOnError: true
|
|
470
|
-
});
|
|
471
|
-
for await (const line of proc) writable.write(line);
|
|
472
|
-
const result = await proc;
|
|
473
|
-
await context.emit("debug", {
|
|
474
|
-
date: /* @__PURE__ */ new Date(),
|
|
475
|
-
logs: [result.stdout.trimEnd()]
|
|
476
|
-
});
|
|
477
|
-
await context.emit("hook:end", {
|
|
478
|
-
command,
|
|
479
|
-
args,
|
|
446
|
+
await runHook({
|
|
480
447
|
id,
|
|
481
|
-
success: true,
|
|
482
|
-
error: null
|
|
483
|
-
});
|
|
484
|
-
} catch (err) {
|
|
485
|
-
const error = err;
|
|
486
|
-
const stderr = error.output?.stderr ?? "";
|
|
487
|
-
const stdout = error.output?.stdout ?? "";
|
|
488
|
-
await context.emit("debug", {
|
|
489
|
-
date: /* @__PURE__ */ new Date(),
|
|
490
|
-
logs: [stdout, stderr].filter(Boolean)
|
|
491
|
-
});
|
|
492
|
-
if (stderr) logger.error(stderr);
|
|
493
|
-
if (stdout) logger.message(stdout);
|
|
494
|
-
const errorMessage = /* @__PURE__ */ new Error(`Hook execute failed: ${commandWithArgs}`);
|
|
495
|
-
await context.emit("hook:end", {
|
|
496
448
|
command,
|
|
497
449
|
args,
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
450
|
+
commandWithArgs,
|
|
451
|
+
context,
|
|
452
|
+
sink: {
|
|
453
|
+
onStderr: (s) => console.error(s),
|
|
454
|
+
onStdout: (s) => console.log(s)
|
|
455
|
+
}
|
|
501
456
|
});
|
|
502
|
-
|
|
457
|
+
return;
|
|
503
458
|
}
|
|
459
|
+
_clack_prompts.intro(text);
|
|
460
|
+
const logger = _clack_prompts.taskLog({ title: getMessage(["Executing hook", logLevel >= _kubb_core.LogLevel.info ? (0, node_util.styleText)("dim", commandWithArgs) : void 0].filter(Boolean).join(" ")) });
|
|
461
|
+
const writable = new ClackWritable(logger);
|
|
462
|
+
await runHook({
|
|
463
|
+
id,
|
|
464
|
+
command,
|
|
465
|
+
args,
|
|
466
|
+
commandWithArgs,
|
|
467
|
+
context,
|
|
468
|
+
stream: true,
|
|
469
|
+
sink: {
|
|
470
|
+
onLine: (line) => writable.write(line),
|
|
471
|
+
onStderr: (s) => logger.error(s),
|
|
472
|
+
onStdout: (s) => logger.message(s)
|
|
473
|
+
}
|
|
474
|
+
});
|
|
504
475
|
});
|
|
505
476
|
context.on("hook:end", ({ command, args }) => {
|
|
506
477
|
if (logLevel <= _kubb_core.LogLevel.silent) return;
|
|
507
|
-
const text = getMessage(`Hook ${(0, node_util.styleText)("dim",
|
|
478
|
+
const text = getMessage(`Hook ${(0, node_util.styleText)("dim", formatCommandWithArgs(command, args))} successfully executed`);
|
|
508
479
|
_clack_prompts.outro(text);
|
|
509
480
|
});
|
|
510
481
|
context.on("generation:summary", (config, { pluginTimings, failedPlugins, filesCreated, status, hrStart }) => {
|
|
@@ -519,20 +490,10 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
519
490
|
const title = config.name || "";
|
|
520
491
|
summary.unshift("\n");
|
|
521
492
|
summary.push("\n");
|
|
522
|
-
|
|
523
|
-
_clack_prompts.box(summary.join("\n"), getMessage(title), {
|
|
524
|
-
width: "auto",
|
|
525
|
-
formatBorder: (s) => (0, node_util.styleText)("green", s),
|
|
526
|
-
rounded: true,
|
|
527
|
-
withGuide: false,
|
|
528
|
-
contentAlign: "left",
|
|
529
|
-
titleAlign: "center"
|
|
530
|
-
});
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
493
|
+
const borderColor = status === "success" ? "green" : "red";
|
|
533
494
|
_clack_prompts.box(summary.join("\n"), getMessage(title), {
|
|
534
495
|
width: "auto",
|
|
535
|
-
formatBorder: (s) => (0, node_util.styleText)(
|
|
496
|
+
formatBorder: (s) => (0, node_util.styleText)(borderColor, s),
|
|
536
497
|
rounded: true,
|
|
537
498
|
withGuide: false,
|
|
538
499
|
contentAlign: "left",
|
|
@@ -545,26 +506,6 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
545
506
|
}
|
|
546
507
|
});
|
|
547
508
|
//#endregion
|
|
548
|
-
//#region src/loggers/envDetection.ts
|
|
549
|
-
/**
|
|
550
|
-
* Check if running in GitHub Actions environment
|
|
551
|
-
*/
|
|
552
|
-
function isGitHubActions() {
|
|
553
|
-
return !!process.env.GITHUB_ACTIONS;
|
|
554
|
-
}
|
|
555
|
-
/**
|
|
556
|
-
* Check if running in any CI environment
|
|
557
|
-
*/
|
|
558
|
-
function isCIEnvironment() {
|
|
559
|
-
return !!(process.env.CI || process.env.GITHUB_ACTIONS || process.env.GITLAB_CI || process.env.CIRCLECI || process.env.TRAVIS || process.env.JENKINS_URL || process.env.BUILDKITE);
|
|
560
|
-
}
|
|
561
|
-
/**
|
|
562
|
-
* Check if TTY is available for interactive output
|
|
563
|
-
*/
|
|
564
|
-
function canUseTTY() {
|
|
565
|
-
return !!process.stdout.isTTY && !isCIEnvironment();
|
|
566
|
-
}
|
|
567
|
-
//#endregion
|
|
568
509
|
//#region src/loggers/fileSystemLogger.ts
|
|
569
510
|
/**
|
|
570
511
|
* FileSystem logger for debug log persistence
|
|
@@ -593,7 +534,7 @@ const fileSystemLogger = (0, _kubb_core.defineLogger)({
|
|
|
593
534
|
name,
|
|
594
535
|
state.startDate
|
|
595
536
|
].filter(Boolean).join("-")}.log`;
|
|
596
|
-
const pathName = (0, node_path.resolve)(
|
|
537
|
+
const pathName = (0, node_path.resolve)(node_process.default.cwd(), ".kubb", baseName);
|
|
597
538
|
if (!files[pathName]) files[pathName] = [];
|
|
598
539
|
if (log.logs.length > 0) {
|
|
599
540
|
const timestamp = log.date.toLocaleString();
|
|
@@ -608,75 +549,66 @@ const fileSystemLogger = (0, _kubb_core.defineLogger)({
|
|
|
608
549
|
context.on("info", (message, info) => {
|
|
609
550
|
state.cachedLogs.add({
|
|
610
551
|
date: /* @__PURE__ */ new Date(),
|
|
611
|
-
logs: [`ℹ ${message} ${info}`]
|
|
612
|
-
fileName: void 0
|
|
552
|
+
logs: [`ℹ ${message} ${info}`]
|
|
613
553
|
});
|
|
614
554
|
});
|
|
615
555
|
context.on("success", (message, info) => {
|
|
616
556
|
state.cachedLogs.add({
|
|
617
557
|
date: /* @__PURE__ */ new Date(),
|
|
618
|
-
logs: [`✓ ${message} ${info}`]
|
|
619
|
-
fileName: void 0
|
|
558
|
+
logs: [`✓ ${message} ${info}`]
|
|
620
559
|
});
|
|
621
560
|
});
|
|
622
561
|
context.on("warn", (message, info) => {
|
|
623
562
|
state.cachedLogs.add({
|
|
624
563
|
date: /* @__PURE__ */ new Date(),
|
|
625
|
-
logs: [`⚠ ${message} ${info}`]
|
|
626
|
-
fileName: void 0
|
|
564
|
+
logs: [`⚠ ${message} ${info}`]
|
|
627
565
|
});
|
|
628
566
|
});
|
|
629
567
|
context.on("error", (error) => {
|
|
630
568
|
state.cachedLogs.add({
|
|
631
569
|
date: /* @__PURE__ */ new Date(),
|
|
632
|
-
logs: [`✗ ${error.message}`, error.stack || "unknown stack"]
|
|
633
|
-
fileName: void 0
|
|
570
|
+
logs: [`✗ ${error.message}`, error.stack || "unknown stack"]
|
|
634
571
|
});
|
|
635
572
|
});
|
|
636
573
|
context.on("debug", (message) => {
|
|
637
574
|
state.cachedLogs.add({
|
|
638
575
|
date: /* @__PURE__ */ new Date(),
|
|
639
|
-
logs: message.logs
|
|
640
|
-
fileName: void 0
|
|
576
|
+
logs: message.logs
|
|
641
577
|
});
|
|
642
578
|
});
|
|
643
579
|
context.on("plugin:start", (plugin) => {
|
|
644
580
|
state.cachedLogs.add({
|
|
645
581
|
date: /* @__PURE__ */ new Date(),
|
|
646
|
-
logs: [`Generating ${plugin.name}`]
|
|
647
|
-
fileName: void 0
|
|
582
|
+
logs: [`Generating ${plugin.name}`]
|
|
648
583
|
});
|
|
649
584
|
});
|
|
650
585
|
context.on("plugin:end", (plugin, { duration, success }) => {
|
|
651
586
|
const durationStr = (0, _kubb_core_utils.formatMs)(duration);
|
|
652
587
|
state.cachedLogs.add({
|
|
653
588
|
date: /* @__PURE__ */ new Date(),
|
|
654
|
-
logs: [success ? `${plugin.name} completed in ${durationStr}` : `${plugin.name} failed in ${durationStr}`]
|
|
655
|
-
fileName: void 0
|
|
589
|
+
logs: [success ? `${plugin.name} completed in ${durationStr}` : `${plugin.name} failed in ${durationStr}`]
|
|
656
590
|
});
|
|
657
591
|
});
|
|
658
592
|
context.on("files:processing:start", (files) => {
|
|
659
593
|
state.cachedLogs.add({
|
|
660
594
|
date: /* @__PURE__ */ new Date(),
|
|
661
|
-
logs: [`Start ${files.length} writing:`, ...files.map((file) => file.path)]
|
|
662
|
-
fileName: void 0
|
|
595
|
+
logs: [`Start ${files.length} writing:`, ...files.map((file) => file.path)]
|
|
663
596
|
});
|
|
664
597
|
});
|
|
665
598
|
context.on("generation:end", async (config) => {
|
|
666
599
|
const writtenFilePaths = await writeLogs(config.name);
|
|
667
600
|
if (writtenFilePaths.length > 0) {
|
|
668
|
-
const files = writtenFilePaths.map((f) => (0, node_path.relative)(
|
|
601
|
+
const files = writtenFilePaths.map((f) => (0, node_path.relative)(node_process.default.cwd(), f));
|
|
669
602
|
await context.emit("info", "Debug files written to:", files.join(", "));
|
|
670
603
|
}
|
|
671
604
|
reset();
|
|
672
605
|
});
|
|
673
|
-
context.on("lifecycle:end", async () => {});
|
|
674
606
|
const exitHandler = () => {
|
|
675
607
|
if (state.cachedLogs.size > 0) writeLogs().catch(() => {});
|
|
676
608
|
};
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
609
|
+
node_process.default.once("exit", exitHandler);
|
|
610
|
+
node_process.default.once("SIGINT", exitHandler);
|
|
611
|
+
node_process.default.once("SIGTERM", exitHandler);
|
|
680
612
|
}
|
|
681
613
|
});
|
|
682
614
|
//#endregion
|
|
@@ -688,7 +620,7 @@ const fileSystemLogger = (0, _kubb_core.defineLogger)({
|
|
|
688
620
|
const githubActionsLogger = (0, _kubb_core.defineLogger)({
|
|
689
621
|
name: "github-actions",
|
|
690
622
|
install(context, options) {
|
|
691
|
-
const logLevel = options?.logLevel
|
|
623
|
+
const logLevel = options?.logLevel ?? _kubb_core.LogLevel.info;
|
|
692
624
|
const state = {
|
|
693
625
|
totalPlugins: 0,
|
|
694
626
|
completedPlugins: 0,
|
|
@@ -705,29 +637,15 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
|
|
|
705
637
|
state.totalFiles = 0;
|
|
706
638
|
state.processedFiles = 0;
|
|
707
639
|
state.hrStart = process.hrtime();
|
|
640
|
+
state.currentConfigs = [];
|
|
708
641
|
}
|
|
709
642
|
function showProgressStep() {
|
|
710
643
|
if (logLevel <= _kubb_core.LogLevel.silent) return;
|
|
711
|
-
const
|
|
712
|
-
|
|
713
|
-
if (state.totalPlugins > 0) {
|
|
714
|
-
const pluginStr = state.failedPlugins > 0 ? `Plugins ${(0, node_util.styleText)("green", state.completedPlugins.toString())}/${state.totalPlugins} ${(0, node_util.styleText)("red", `(${state.failedPlugins} failed)`)}` : `Plugins ${(0, node_util.styleText)("green", state.completedPlugins.toString())}/${state.totalPlugins}`;
|
|
715
|
-
parts.push(pluginStr);
|
|
716
|
-
}
|
|
717
|
-
if (state.totalFiles > 0) parts.push(`Files ${(0, node_util.styleText)("green", state.processedFiles.toString())}/${state.totalFiles}`);
|
|
718
|
-
if (parts.length > 0) {
|
|
719
|
-
parts.push(`${(0, node_util.styleText)("green", duration)} elapsed`);
|
|
720
|
-
console.log(getMessage(parts.join((0, node_util.styleText)("dim", " | "))));
|
|
721
|
-
}
|
|
644
|
+
const line = buildProgressLine(state);
|
|
645
|
+
if (line) console.log(getMessage(line));
|
|
722
646
|
}
|
|
723
647
|
function getMessage(message) {
|
|
724
|
-
|
|
725
|
-
hour12: false,
|
|
726
|
-
hour: "2-digit",
|
|
727
|
-
minute: "2-digit",
|
|
728
|
-
second: "2-digit"
|
|
729
|
-
})}]`), message].join(" ");
|
|
730
|
-
return message;
|
|
648
|
+
return formatMessage(message, logLevel);
|
|
731
649
|
}
|
|
732
650
|
function openGroup(name) {
|
|
733
651
|
console.log(`::group::${name}`);
|
|
@@ -763,7 +681,7 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
|
|
|
763
681
|
console.warn(`::warning::${text}`);
|
|
764
682
|
});
|
|
765
683
|
context.on("error", (error) => {
|
|
766
|
-
const caused = error
|
|
684
|
+
const caused = require_errors.toCause(error);
|
|
767
685
|
if (logLevel <= _kubb_core.LogLevel.silent) return;
|
|
768
686
|
const message = error.message || String(error);
|
|
769
687
|
console.error(`::error::${message}`);
|
|
@@ -795,11 +713,11 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
|
|
|
795
713
|
closeGroup("Configuration");
|
|
796
714
|
});
|
|
797
715
|
context.on("generation:start", (config) => {
|
|
798
|
-
|
|
716
|
+
reset();
|
|
717
|
+
state.totalPlugins = config.plugins?.length ?? 0;
|
|
799
718
|
const text = config.name ? `Generation for ${(0, node_util.styleText)("bold", config.name)}` : "Generation";
|
|
800
719
|
if (state.currentConfigs.length > 1) openGroup(text);
|
|
801
720
|
if (state.currentConfigs.length === 1) console.log(getMessage(text));
|
|
802
|
-
reset();
|
|
803
721
|
});
|
|
804
722
|
context.on("plugin:start", (plugin) => {
|
|
805
723
|
if (logLevel <= _kubb_core.LogLevel.silent) return;
|
|
@@ -831,15 +749,12 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
|
|
|
831
749
|
const text = getMessage("Files written successfully");
|
|
832
750
|
console.log(text);
|
|
833
751
|
if (state.currentConfigs.length === 1) closeGroup("File Generation");
|
|
752
|
+
showProgressStep();
|
|
834
753
|
});
|
|
835
754
|
context.on("file:processing:update", () => {
|
|
836
755
|
if (logLevel <= _kubb_core.LogLevel.silent) return;
|
|
837
756
|
state.processedFiles++;
|
|
838
757
|
});
|
|
839
|
-
context.on("files:processing:end", () => {
|
|
840
|
-
if (logLevel <= _kubb_core.LogLevel.silent) return;
|
|
841
|
-
showProgressStep();
|
|
842
|
-
});
|
|
843
758
|
context.on("generation:end", (config) => {
|
|
844
759
|
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`);
|
|
845
760
|
console.log(text);
|
|
@@ -869,66 +784,43 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
|
|
|
869
784
|
if (state.currentConfigs.length === 1) closeGroup("Linting");
|
|
870
785
|
});
|
|
871
786
|
context.on("hook:start", async ({ id, command, args }) => {
|
|
872
|
-
const commandWithArgs =
|
|
787
|
+
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
873
788
|
const text = getMessage(`Hook ${(0, node_util.styleText)("dim", commandWithArgs)} started`);
|
|
874
789
|
if (logLevel > _kubb_core.LogLevel.silent) {
|
|
875
790
|
if (state.currentConfigs.length === 1) openGroup(`Hook ${commandWithArgs}`);
|
|
876
791
|
console.log(text);
|
|
877
792
|
}
|
|
878
793
|
if (!id) return;
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
command,
|
|
891
|
-
args,
|
|
892
|
-
id,
|
|
893
|
-
success: true,
|
|
894
|
-
error: null
|
|
895
|
-
});
|
|
896
|
-
} catch (err) {
|
|
897
|
-
const error = err;
|
|
898
|
-
const stderr = error.output?.stderr ?? "";
|
|
899
|
-
const stdout = error.output?.stdout ?? "";
|
|
900
|
-
await context.emit("debug", {
|
|
901
|
-
date: /* @__PURE__ */ new Date(),
|
|
902
|
-
logs: [stdout, stderr].filter(Boolean)
|
|
903
|
-
});
|
|
904
|
-
if (stderr) console.error(`::error::${stderr}`);
|
|
905
|
-
if (stdout) console.log(stdout);
|
|
906
|
-
const errorMessage = /* @__PURE__ */ new Error(`Hook execute failed: ${commandWithArgs}`);
|
|
907
|
-
await context.emit("hook:end", {
|
|
908
|
-
command,
|
|
909
|
-
args,
|
|
910
|
-
id,
|
|
911
|
-
success: false,
|
|
912
|
-
error: errorMessage
|
|
913
|
-
});
|
|
914
|
-
await context.emit("error", errorMessage);
|
|
915
|
-
}
|
|
794
|
+
await runHook({
|
|
795
|
+
id,
|
|
796
|
+
command,
|
|
797
|
+
args,
|
|
798
|
+
commandWithArgs,
|
|
799
|
+
context,
|
|
800
|
+
sink: {
|
|
801
|
+
onStdout: logLevel > _kubb_core.LogLevel.silent ? (s) => console.log(s) : void 0,
|
|
802
|
+
onStderr: logLevel > _kubb_core.LogLevel.silent ? (s) => console.error(`::error::${s}`) : void 0
|
|
803
|
+
}
|
|
804
|
+
});
|
|
916
805
|
});
|
|
917
806
|
context.on("hook:end", ({ command, args }) => {
|
|
918
807
|
if (logLevel <= _kubb_core.LogLevel.silent) return;
|
|
919
|
-
const commandWithArgs =
|
|
808
|
+
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
920
809
|
const text = getMessage(`Hook ${(0, node_util.styleText)("dim", commandWithArgs)} completed`);
|
|
921
810
|
console.log(text);
|
|
922
811
|
if (state.currentConfigs.length === 1) closeGroup(`Hook ${commandWithArgs}`);
|
|
923
812
|
});
|
|
924
813
|
context.on("generation:summary", (config, { status, hrStart, failedPlugins }) => {
|
|
925
|
-
const pluginsCount = config.plugins?.length
|
|
814
|
+
const pluginsCount = config.plugins?.length ?? 0;
|
|
926
815
|
const successCount = pluginsCount - failedPlugins.size;
|
|
927
816
|
const duration = (0, _kubb_core_utils.formatHrtime)(hrStart);
|
|
928
817
|
if (state.currentConfigs.length > 1) console.log(" ");
|
|
929
818
|
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)}`);
|
|
930
819
|
if (state.currentConfigs.length > 1) closeGroup(config.name ? `Generation for ${(0, node_util.styleText)("bold", config.name)}` : "Generation");
|
|
931
820
|
});
|
|
821
|
+
context.on("lifecycle:end", () => {
|
|
822
|
+
reset();
|
|
823
|
+
});
|
|
932
824
|
}
|
|
933
825
|
});
|
|
934
826
|
//#endregion
|
|
@@ -940,15 +832,9 @@ const githubActionsLogger = (0, _kubb_core.defineLogger)({
|
|
|
940
832
|
const plainLogger = (0, _kubb_core.defineLogger)({
|
|
941
833
|
name: "plain",
|
|
942
834
|
install(context, options) {
|
|
943
|
-
const logLevel = options?.logLevel
|
|
835
|
+
const logLevel = options?.logLevel ?? _kubb_core.LogLevel.info;
|
|
944
836
|
function getMessage(message) {
|
|
945
|
-
|
|
946
|
-
hour12: false,
|
|
947
|
-
hour: "2-digit",
|
|
948
|
-
minute: "2-digit",
|
|
949
|
-
second: "2-digit"
|
|
950
|
-
})}]`, message].join(" ");
|
|
951
|
-
return message;
|
|
837
|
+
return formatMessage(message, logLevel);
|
|
952
838
|
}
|
|
953
839
|
context.on("info", (message, info) => {
|
|
954
840
|
if (logLevel <= _kubb_core.LogLevel.silent) return;
|
|
@@ -978,7 +864,7 @@ const plainLogger = (0, _kubb_core.defineLogger)({
|
|
|
978
864
|
console.log(text);
|
|
979
865
|
});
|
|
980
866
|
context.on("error", (error) => {
|
|
981
|
-
const caused = error
|
|
867
|
+
const caused = require_errors.toCause(error);
|
|
982
868
|
const text = getMessage(["✗", error.message].join(" "));
|
|
983
869
|
console.log(text);
|
|
984
870
|
if (logLevel >= _kubb_core.LogLevel.debug && error.stack) {
|
|
@@ -1005,7 +891,7 @@ const plainLogger = (0, _kubb_core.defineLogger)({
|
|
|
1005
891
|
console.log(text);
|
|
1006
892
|
});
|
|
1007
893
|
context.on("generation:start", () => {
|
|
1008
|
-
const text = getMessage("
|
|
894
|
+
const text = getMessage("Generation started");
|
|
1009
895
|
console.log(text);
|
|
1010
896
|
});
|
|
1011
897
|
context.on("plugin:start", (plugin) => {
|
|
@@ -1059,51 +945,25 @@ const plainLogger = (0, _kubb_core.defineLogger)({
|
|
|
1059
945
|
console.log(text);
|
|
1060
946
|
});
|
|
1061
947
|
context.on("hook:start", async ({ id, command, args }) => {
|
|
1062
|
-
const commandWithArgs =
|
|
948
|
+
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
1063
949
|
const text = getMessage(`Hook ${commandWithArgs} started`);
|
|
1064
950
|
if (logLevel > _kubb_core.LogLevel.silent) console.log(text);
|
|
1065
951
|
if (!id) return;
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
command,
|
|
1078
|
-
args,
|
|
1079
|
-
id,
|
|
1080
|
-
success: true,
|
|
1081
|
-
error: null
|
|
1082
|
-
});
|
|
1083
|
-
} catch (err) {
|
|
1084
|
-
const error = err;
|
|
1085
|
-
const stderr = error.output?.stderr ?? "";
|
|
1086
|
-
const stdout = error.output?.stdout ?? "";
|
|
1087
|
-
await context.emit("debug", {
|
|
1088
|
-
date: /* @__PURE__ */ new Date(),
|
|
1089
|
-
logs: [stdout, stderr].filter(Boolean)
|
|
1090
|
-
});
|
|
1091
|
-
if (stderr) console.error(stderr);
|
|
1092
|
-
if (stdout) console.log(stdout);
|
|
1093
|
-
const errorMessage = /* @__PURE__ */ new Error(`Hook execute failed: ${commandWithArgs}`);
|
|
1094
|
-
await context.emit("hook:end", {
|
|
1095
|
-
command,
|
|
1096
|
-
args,
|
|
1097
|
-
id,
|
|
1098
|
-
success: false,
|
|
1099
|
-
error: errorMessage
|
|
1100
|
-
});
|
|
1101
|
-
await context.emit("error", errorMessage);
|
|
1102
|
-
}
|
|
952
|
+
await runHook({
|
|
953
|
+
id,
|
|
954
|
+
command,
|
|
955
|
+
args,
|
|
956
|
+
commandWithArgs,
|
|
957
|
+
context,
|
|
958
|
+
sink: {
|
|
959
|
+
onStdout: logLevel > _kubb_core.LogLevel.silent ? (s) => console.log(s) : void 0,
|
|
960
|
+
onStderr: logLevel > _kubb_core.LogLevel.silent ? (s) => console.error(s) : void 0
|
|
961
|
+
}
|
|
962
|
+
});
|
|
1103
963
|
});
|
|
1104
964
|
context.on("hook:end", ({ command, args }) => {
|
|
1105
965
|
if (logLevel <= _kubb_core.LogLevel.silent) return;
|
|
1106
|
-
const text = getMessage(`Hook ${
|
|
966
|
+
const text = getMessage(`Hook ${formatCommandWithArgs(command, args)} completed`);
|
|
1107
967
|
console.log(text);
|
|
1108
968
|
});
|
|
1109
969
|
context.on("generation:summary", (config, { pluginTimings, status, hrStart, failedPlugins, filesCreated }) => {
|
|
@@ -1115,17 +975,53 @@ const plainLogger = (0, _kubb_core.defineLogger)({
|
|
|
1115
975
|
hrStart,
|
|
1116
976
|
pluginTimings: logLevel >= _kubb_core.LogLevel.verbose ? pluginTimings : void 0
|
|
1117
977
|
});
|
|
1118
|
-
console.log(
|
|
978
|
+
console.log(require_constants.SUMMARY_SEPARATOR);
|
|
1119
979
|
console.log(summary.join("\n"));
|
|
1120
|
-
console.log(
|
|
980
|
+
console.log(require_constants.SUMMARY_SEPARATOR);
|
|
1121
981
|
});
|
|
1122
982
|
}
|
|
1123
983
|
});
|
|
1124
984
|
//#endregion
|
|
1125
985
|
//#region src/loggers/utils.ts
|
|
986
|
+
/**
|
|
987
|
+
* Optionally prefix a message with a [HH:MM:SS] timestamp when logLevel >= verbose.
|
|
988
|
+
* Shared across all logger adapters to avoid duplication.
|
|
989
|
+
*/
|
|
990
|
+
function formatMessage(message, logLevel) {
|
|
991
|
+
if (logLevel >= _kubb_core.LogLevel.verbose) return `${(0, node_util.styleText)("dim", `[${(/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", {
|
|
992
|
+
hour12: false,
|
|
993
|
+
hour: "2-digit",
|
|
994
|
+
minute: "2-digit",
|
|
995
|
+
second: "2-digit"
|
|
996
|
+
})}]`)} ${message}`;
|
|
997
|
+
return message;
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* Build the progress summary line shared by clack and GitHub Actions loggers.
|
|
1001
|
+
* Returns null when there is nothing to display.
|
|
1002
|
+
*/
|
|
1003
|
+
function buildProgressLine(state) {
|
|
1004
|
+
const parts = [];
|
|
1005
|
+
const duration = (0, _kubb_core_utils.formatHrtime)(state.hrStart);
|
|
1006
|
+
if (state.totalPlugins > 0) {
|
|
1007
|
+
const pluginStr = state.failedPlugins > 0 ? `Plugins ${(0, node_util.styleText)("green", state.completedPlugins.toString())}/${state.totalPlugins} ${(0, node_util.styleText)("red", `(${state.failedPlugins} failed)`)}` : `Plugins ${(0, node_util.styleText)("green", state.completedPlugins.toString())}/${state.totalPlugins}`;
|
|
1008
|
+
parts.push(pluginStr);
|
|
1009
|
+
}
|
|
1010
|
+
if (state.totalFiles > 0) parts.push(`Files ${(0, node_util.styleText)("green", state.processedFiles.toString())}/${state.totalFiles}`);
|
|
1011
|
+
if (parts.length === 0) return null;
|
|
1012
|
+
parts.push(`${(0, node_util.styleText)("green", duration)} elapsed`);
|
|
1013
|
+
return parts.join((0, node_util.styleText)("dim", " | "));
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Join a command and its optional args into a single display string.
|
|
1017
|
+
* e.g. ("prettier", ["--write", "."]) → "prettier --write ."
|
|
1018
|
+
*/
|
|
1019
|
+
function formatCommandWithArgs(command, args) {
|
|
1020
|
+
return args?.length ? `${command} ${args.join(" ")}` : command;
|
|
1021
|
+
}
|
|
1126
1022
|
function detectLogger() {
|
|
1127
|
-
if (isGitHubActions()) return "github-actions";
|
|
1128
|
-
if (canUseTTY()) return "clack";
|
|
1023
|
+
if (require_telemetry.isGitHubActions()) return "github-actions";
|
|
1024
|
+
if (require_telemetry.canUseTTY()) return "clack";
|
|
1129
1025
|
return "plain";
|
|
1130
1026
|
}
|
|
1131
1027
|
const logMapper = {
|
|
@@ -1149,19 +1045,140 @@ async function executeHooks({ hooks, events }) {
|
|
|
1149
1045
|
const [cmd, ...args] = (0, _kubb_core_utils.tokenize)(command);
|
|
1150
1046
|
if (!cmd) continue;
|
|
1151
1047
|
const hookId = (0, node_crypto.createHash)("sha256").update(command).digest("hex");
|
|
1048
|
+
const hookEndPromise = new Promise((resolve, reject) => {
|
|
1049
|
+
const handler = ({ id, success, error }) => {
|
|
1050
|
+
if (id !== hookId) return;
|
|
1051
|
+
events.off("hook:end", handler);
|
|
1052
|
+
if (!success) {
|
|
1053
|
+
reject(error ?? /* @__PURE__ */ new Error(`Hook failed: ${command}`));
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
events.emit("success", `${(0, node_util.styleText)("dim", command)} successfully executed`).then(resolve).catch(reject);
|
|
1057
|
+
};
|
|
1058
|
+
events.on("hook:end", handler);
|
|
1059
|
+
});
|
|
1152
1060
|
await events.emit("hook:start", {
|
|
1153
1061
|
id: hookId,
|
|
1154
1062
|
command: cmd,
|
|
1155
1063
|
args
|
|
1156
1064
|
});
|
|
1157
|
-
await
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1065
|
+
await hookEndPromise;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
//#endregion
|
|
1069
|
+
//#region src/utils/getCosmiConfig.ts
|
|
1070
|
+
const jiti$1 = (0, jiti.createJiti)(require("url").pathToFileURL(__filename).href, {
|
|
1071
|
+
jsx: {
|
|
1072
|
+
runtime: "automatic",
|
|
1073
|
+
importSource: "@kubb/react-fabric"
|
|
1074
|
+
},
|
|
1075
|
+
sourceMaps: true,
|
|
1076
|
+
interopDefault: true
|
|
1077
|
+
});
|
|
1078
|
+
const tsLoader = async (configFile) => {
|
|
1079
|
+
return await jiti$1.import(configFile, { default: true });
|
|
1080
|
+
};
|
|
1081
|
+
async function getCosmiConfig(moduleName, config) {
|
|
1082
|
+
let result;
|
|
1083
|
+
const searchPlaces = [
|
|
1084
|
+
"package.json",
|
|
1085
|
+
`.${moduleName}rc`,
|
|
1086
|
+
`.${moduleName}rc.json`,
|
|
1087
|
+
`.${moduleName}rc.yaml`,
|
|
1088
|
+
`.${moduleName}rc.yml`,
|
|
1089
|
+
`.${moduleName}rc.ts`,
|
|
1090
|
+
`.${moduleName}rc.js`,
|
|
1091
|
+
`.${moduleName}rc.mjs`,
|
|
1092
|
+
`.${moduleName}rc.cjs`,
|
|
1093
|
+
`${moduleName}.config.ts`,
|
|
1094
|
+
`${moduleName}.config.js`,
|
|
1095
|
+
`${moduleName}.config.mjs`,
|
|
1096
|
+
`${moduleName}.config.cjs`
|
|
1097
|
+
];
|
|
1098
|
+
const explorer = (0, cosmiconfig.cosmiconfig)(moduleName, {
|
|
1099
|
+
cache: false,
|
|
1100
|
+
searchPlaces: [
|
|
1101
|
+
...searchPlaces.map((searchPlace) => {
|
|
1102
|
+
return `.config/${searchPlace}`;
|
|
1103
|
+
}),
|
|
1104
|
+
...searchPlaces.map((searchPlace) => {
|
|
1105
|
+
return `configs/${searchPlace}`;
|
|
1106
|
+
}),
|
|
1107
|
+
...searchPlaces
|
|
1108
|
+
],
|
|
1109
|
+
loaders: { ".ts": tsLoader }
|
|
1110
|
+
});
|
|
1111
|
+
try {
|
|
1112
|
+
result = config ? await explorer.load(config) : await explorer.search();
|
|
1113
|
+
} catch (error) {
|
|
1114
|
+
throw new Error("Config failed loading", { cause: error });
|
|
1161
1115
|
}
|
|
1116
|
+
if (result?.isEmpty || !result || !result.config) throw new Error("Config not defined, create a kubb.config.js or pass through your config with the option --config");
|
|
1117
|
+
return result;
|
|
1118
|
+
}
|
|
1119
|
+
//#endregion
|
|
1120
|
+
//#region src/utils/watcher.ts
|
|
1121
|
+
async function startWatcher(path, cb) {
|
|
1122
|
+
const { watch } = await import("chokidar");
|
|
1123
|
+
watch(path, {
|
|
1124
|
+
ignorePermissionErrors: true,
|
|
1125
|
+
ignored: require_constants.WATCHER_IGNORED_PATHS
|
|
1126
|
+
}).on("all", async (type, file) => {
|
|
1127
|
+
console.log((0, node_util.styleText)("yellow", (0, node_util.styleText)("bold", `Change detected: ${type} ${file}`)));
|
|
1128
|
+
try {
|
|
1129
|
+
await cb(path);
|
|
1130
|
+
} catch (_e) {
|
|
1131
|
+
console.log((0, node_util.styleText)("red", "Watcher failed"));
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1162
1134
|
}
|
|
1163
1135
|
//#endregion
|
|
1164
1136
|
//#region src/runners/generate.ts
|
|
1137
|
+
async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefix, noToolMessage, configName, outputPath, logLevel, events, onStart, onEnd }) {
|
|
1138
|
+
await onStart();
|
|
1139
|
+
let resolvedTool = toolValue;
|
|
1140
|
+
if (resolvedTool === "auto") {
|
|
1141
|
+
const detected = await detect();
|
|
1142
|
+
if (!detected) await events.emit("warn", noToolMessage);
|
|
1143
|
+
else {
|
|
1144
|
+
resolvedTool = detected;
|
|
1145
|
+
await events.emit("info", `Auto-detected ${toolLabel}: ${(0, node_util.styleText)("dim", resolvedTool)}`);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
if (resolvedTool && resolvedTool !== "auto" && resolvedTool in toolMap) {
|
|
1149
|
+
const toolConfig = toolMap[resolvedTool];
|
|
1150
|
+
try {
|
|
1151
|
+
const hookId = (0, node_crypto.createHash)("sha256").update([configName, resolvedTool].filter(Boolean).join("-")).digest("hex");
|
|
1152
|
+
const hookEndPromise = new Promise((resolve, reject) => {
|
|
1153
|
+
const handler = ({ id, success, error }) => {
|
|
1154
|
+
if (id !== hookId) return;
|
|
1155
|
+
events.off("hook:end", handler);
|
|
1156
|
+
if (!success) {
|
|
1157
|
+
reject(error ?? /* @__PURE__ */ new Error(`${toolConfig.errorMessage}`));
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
events.emit("success", [
|
|
1161
|
+
`${successPrefix} with ${(0, node_util.styleText)("dim", resolvedTool)}`,
|
|
1162
|
+
logLevel >= _kubb_core.LogLevel.info ? `on ${(0, node_util.styleText)("dim", outputPath)}` : void 0,
|
|
1163
|
+
"successfully"
|
|
1164
|
+
].filter(Boolean).join(" ")).then(resolve).catch(reject);
|
|
1165
|
+
};
|
|
1166
|
+
events.on("hook:end", handler);
|
|
1167
|
+
});
|
|
1168
|
+
await events.emit("hook:start", {
|
|
1169
|
+
id: hookId,
|
|
1170
|
+
command: toolConfig.command,
|
|
1171
|
+
args: toolConfig.args(outputPath)
|
|
1172
|
+
});
|
|
1173
|
+
await hookEndPromise;
|
|
1174
|
+
} catch (caughtError) {
|
|
1175
|
+
const err = new Error(toolConfig.errorMessage);
|
|
1176
|
+
err.cause = caughtError;
|
|
1177
|
+
await events.emit("error", err);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
await onEnd();
|
|
1181
|
+
}
|
|
1165
1182
|
async function generate({ input, config: userConfig, events, logLevel }) {
|
|
1166
1183
|
const inputPath = input ?? ("path" in userConfig.input ? userConfig.input.path : void 0);
|
|
1167
1184
|
const hrStart = node_process.default.hrtime();
|
|
@@ -1198,9 +1215,8 @@ async function generate({ input, config: userConfig, events, logLevel }) {
|
|
|
1198
1215
|
});
|
|
1199
1216
|
await events.emit("info", "Load summary");
|
|
1200
1217
|
if (failedPlugins.size > 0 || error) {
|
|
1201
|
-
[error, ...Array.from(failedPlugins).filter((it) => it.error).map((it) => it.error)].filter(Boolean)
|
|
1202
|
-
|
|
1203
|
-
});
|
|
1218
|
+
const allErrors = [error, ...Array.from(failedPlugins).filter((it) => it.error).map((it) => it.error)].filter(Boolean);
|
|
1219
|
+
for (const err of allErrors) await events.emit("error", err);
|
|
1204
1220
|
await events.emit("generation:end", config, files, sources);
|
|
1205
1221
|
await events.emit("generation:summary", config, {
|
|
1206
1222
|
failedPlugins,
|
|
@@ -1224,80 +1240,35 @@ async function generate({ input, config: userConfig, events, logLevel }) {
|
|
|
1224
1240
|
}
|
|
1225
1241
|
await events.emit("success", "Generation successfully", inputPath);
|
|
1226
1242
|
await events.emit("generation:end", config, files, sources);
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
} catch (caughtError) {
|
|
1257
|
-
const error = new Error(formatterConfig.errorMessage);
|
|
1258
|
-
error.cause = caughtError;
|
|
1259
|
-
await events.emit("error", error);
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
await events.emit("format:end");
|
|
1263
|
-
}
|
|
1264
|
-
if (config.output.lint) {
|
|
1265
|
-
await events.emit("lint:start");
|
|
1266
|
-
let linter = config.output.lint;
|
|
1267
|
-
if (linter === "auto") {
|
|
1268
|
-
const detectedLinter = await (0, _kubb_core_utils.detectLinter)();
|
|
1269
|
-
if (!detectedLinter) await events.emit("warn", "No linter found (biome, oxlint, or eslint). Skipping linting.");
|
|
1270
|
-
else {
|
|
1271
|
-
linter = detectedLinter;
|
|
1272
|
-
await events.emit("info", `Auto-detected linter: ${(0, node_util.styleText)("dim", linter)}`);
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
if (linter && linter !== "auto" && linter in _kubb_core_utils.linters) {
|
|
1276
|
-
const linterConfig = _kubb_core_utils.linters[linter];
|
|
1277
|
-
const outputPath = node_path.default.resolve(config.root, config.output.path);
|
|
1278
|
-
try {
|
|
1279
|
-
const hookId = (0, node_crypto.createHash)("sha256").update([config.name, linter].filter(Boolean).join("-")).digest("hex");
|
|
1280
|
-
await events.emit("hook:start", {
|
|
1281
|
-
id: hookId,
|
|
1282
|
-
command: linterConfig.command,
|
|
1283
|
-
args: linterConfig.args(outputPath)
|
|
1284
|
-
});
|
|
1285
|
-
await events.onOnce("hook:end", async ({ success, error }) => {
|
|
1286
|
-
if (!success) throw error;
|
|
1287
|
-
await events.emit("success", [
|
|
1288
|
-
`Linting with ${(0, node_util.styleText)("dim", linter)}`,
|
|
1289
|
-
logLevel >= _kubb_core.LogLevel.info ? `on ${(0, node_util.styleText)("dim", outputPath)}` : void 0,
|
|
1290
|
-
"successfully"
|
|
1291
|
-
].filter(Boolean).join(" "));
|
|
1292
|
-
});
|
|
1293
|
-
} catch (caughtError) {
|
|
1294
|
-
const error = new Error(linterConfig.errorMessage);
|
|
1295
|
-
error.cause = caughtError;
|
|
1296
|
-
await events.emit("error", error);
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
await events.emit("lint:end");
|
|
1300
|
-
}
|
|
1243
|
+
const outputPath = node_path.default.resolve(config.root, config.output.path);
|
|
1244
|
+
if (config.output.format) await runToolPass({
|
|
1245
|
+
toolValue: config.output.format,
|
|
1246
|
+
detect: _kubb_core_utils.detectFormatter,
|
|
1247
|
+
toolMap: _kubb_core_utils.formatters,
|
|
1248
|
+
toolLabel: "formatter",
|
|
1249
|
+
successPrefix: "Formatting",
|
|
1250
|
+
noToolMessage: "No formatter found (biome, prettier, or oxfmt). Skipping formatting.",
|
|
1251
|
+
configName: config.name,
|
|
1252
|
+
outputPath,
|
|
1253
|
+
logLevel,
|
|
1254
|
+
events,
|
|
1255
|
+
onStart: () => events.emit("format:start"),
|
|
1256
|
+
onEnd: () => events.emit("format:end")
|
|
1257
|
+
});
|
|
1258
|
+
if (config.output.lint) await runToolPass({
|
|
1259
|
+
toolValue: config.output.lint,
|
|
1260
|
+
detect: _kubb_core_utils.detectLinter,
|
|
1261
|
+
toolMap: _kubb_core_utils.linters,
|
|
1262
|
+
toolLabel: "linter",
|
|
1263
|
+
successPrefix: "Linting",
|
|
1264
|
+
noToolMessage: "No linter found (biome, oxlint, or eslint). Skipping linting.",
|
|
1265
|
+
configName: config.name,
|
|
1266
|
+
outputPath,
|
|
1267
|
+
logLevel,
|
|
1268
|
+
events,
|
|
1269
|
+
onStart: () => events.emit("lint:start"),
|
|
1270
|
+
onEnd: () => events.emit("lint:end")
|
|
1271
|
+
});
|
|
1301
1272
|
if (config.hooks) {
|
|
1302
1273
|
await events.emit("hooks:start");
|
|
1303
1274
|
await executeHooks({
|
|
@@ -1306,11 +1277,10 @@ async function generate({ input, config: userConfig, events, logLevel }) {
|
|
|
1306
1277
|
});
|
|
1307
1278
|
await events.emit("hooks:end");
|
|
1308
1279
|
}
|
|
1309
|
-
const generationStatus = failedPlugins.size > 0 || error ? "failed" : "success";
|
|
1310
1280
|
await events.emit("generation:summary", config, {
|
|
1311
1281
|
failedPlugins,
|
|
1312
1282
|
filesCreated: files.length,
|
|
1313
|
-
status:
|
|
1283
|
+
status: "success",
|
|
1314
1284
|
hrStart,
|
|
1315
1285
|
pluginTimings
|
|
1316
1286
|
});
|
|
@@ -1323,183 +1293,59 @@ async function generate({ input, config: userConfig, events, logLevel }) {
|
|
|
1323
1293
|
})),
|
|
1324
1294
|
hrStart,
|
|
1325
1295
|
filesCreated: files.length,
|
|
1326
|
-
status:
|
|
1296
|
+
status: "success"
|
|
1327
1297
|
}));
|
|
1328
1298
|
}
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
const
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
importSource: "@kubb/react-fabric"
|
|
1336
|
-
},
|
|
1337
|
-
sourceMaps: true,
|
|
1338
|
-
interopDefault: true
|
|
1339
|
-
}).import(configFile, { default: true });
|
|
1340
|
-
};
|
|
1341
|
-
async function getCosmiConfig(moduleName, config) {
|
|
1342
|
-
let result;
|
|
1343
|
-
const searchPlaces = [
|
|
1344
|
-
"package.json",
|
|
1345
|
-
`.${moduleName}rc`,
|
|
1346
|
-
`.${moduleName}rc.json`,
|
|
1347
|
-
`.${moduleName}rc.yaml`,
|
|
1348
|
-
`.${moduleName}rc.yml`,
|
|
1349
|
-
`.${moduleName}rc.ts`,
|
|
1350
|
-
`.${moduleName}rc.js`,
|
|
1351
|
-
`.${moduleName}rc.mjs`,
|
|
1352
|
-
`.${moduleName}rc.cjs`,
|
|
1353
|
-
`${moduleName}.config.ts`,
|
|
1354
|
-
`${moduleName}.config.js`,
|
|
1355
|
-
`${moduleName}.config.mjs`,
|
|
1356
|
-
`${moduleName}.config.cjs`
|
|
1357
|
-
];
|
|
1358
|
-
const explorer = (0, cosmiconfig.cosmiconfig)(moduleName, {
|
|
1359
|
-
cache: false,
|
|
1360
|
-
searchPlaces: [
|
|
1361
|
-
...searchPlaces.map((searchPlace) => {
|
|
1362
|
-
return `.config/${searchPlace}`;
|
|
1363
|
-
}),
|
|
1364
|
-
...searchPlaces.map((searchPlace) => {
|
|
1365
|
-
return `configs/${searchPlace}`;
|
|
1366
|
-
}),
|
|
1367
|
-
...searchPlaces
|
|
1368
|
-
],
|
|
1369
|
-
loaders: { ".ts": tsLoader }
|
|
1370
|
-
});
|
|
1371
|
-
try {
|
|
1372
|
-
result = config ? await explorer.load(config) : await explorer.search();
|
|
1373
|
-
} catch (error) {
|
|
1374
|
-
throw new Error("Config failed loading", { cause: error });
|
|
1375
|
-
}
|
|
1376
|
-
if (result?.isEmpty || !result || !result.config) throw new Error("Config not defined, create a kubb.config.js or pass through your config with the option --config");
|
|
1377
|
-
return result;
|
|
1378
|
-
}
|
|
1379
|
-
//#endregion
|
|
1380
|
-
//#region src/utils/watcher.ts
|
|
1381
|
-
async function startWatcher(path, cb) {
|
|
1382
|
-
const { watch } = await import("chokidar");
|
|
1383
|
-
watch(path, {
|
|
1384
|
-
ignorePermissionErrors: true,
|
|
1385
|
-
ignored: "**/{.git,node_modules}/**"
|
|
1386
|
-
}).on("all", async (type, file) => {
|
|
1387
|
-
console.log((0, node_util.styleText)("yellow", (0, node_util.styleText)("bold", `Change detected: ${type} ${file}`)));
|
|
1299
|
+
async function runGenerateCommand({ input, configPath, logLevel: logLevelKey, watch }) {
|
|
1300
|
+
const logLevel = _kubb_core.LogLevel[logLevelKey] ?? _kubb_core.LogLevel.info;
|
|
1301
|
+
const events = new _kubb_core_utils.AsyncEventEmitter();
|
|
1302
|
+
const promiseManager = new _kubb_core.PromiseManager();
|
|
1303
|
+
await setupLogger(events, { logLevel });
|
|
1304
|
+
await (0, _kubb_core_utils.executeIfOnline)(async () => {
|
|
1388
1305
|
try {
|
|
1389
|
-
await
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
}
|
|
1306
|
+
const latestVersion = (await (await fetch(require_constants.KUBB_NPM_PACKAGE_URL)).json()).version;
|
|
1307
|
+
if (latestVersion && require_package.version < latestVersion) await events.emit("version:new", require_package.version, latestVersion);
|
|
1308
|
+
} catch {}
|
|
1393
1309
|
});
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
default: "info",
|
|
1413
|
-
valueHint: "silent|info|verbose|debug"
|
|
1414
|
-
},
|
|
1415
|
-
watch: {
|
|
1416
|
-
type: "boolean",
|
|
1417
|
-
description: "Watch mode based on the input file",
|
|
1418
|
-
alias: "w",
|
|
1419
|
-
default: false
|
|
1420
|
-
},
|
|
1421
|
-
debug: {
|
|
1422
|
-
type: "boolean",
|
|
1423
|
-
description: "Override logLevel to debug",
|
|
1424
|
-
alias: "d",
|
|
1425
|
-
default: false
|
|
1426
|
-
},
|
|
1427
|
-
verbose: {
|
|
1428
|
-
type: "boolean",
|
|
1429
|
-
description: "Override logLevel to verbose",
|
|
1430
|
-
alias: "v",
|
|
1431
|
-
default: false
|
|
1432
|
-
},
|
|
1433
|
-
silent: {
|
|
1434
|
-
type: "boolean",
|
|
1435
|
-
description: "Override logLevel to silent",
|
|
1436
|
-
alias: "s",
|
|
1437
|
-
default: false
|
|
1438
|
-
},
|
|
1439
|
-
help: {
|
|
1440
|
-
type: "boolean",
|
|
1441
|
-
description: "Show help",
|
|
1442
|
-
alias: "h",
|
|
1443
|
-
default: false
|
|
1444
|
-
}
|
|
1445
|
-
},
|
|
1446
|
-
async run(commandContext) {
|
|
1447
|
-
const { args } = commandContext;
|
|
1448
|
-
const input = args._[0];
|
|
1449
|
-
const events = new _kubb_core_utils.AsyncEventEmitter();
|
|
1450
|
-
const promiseManager = new _kubb_core.PromiseManager();
|
|
1451
|
-
if (args.help) return (0, citty.showUsage)(command);
|
|
1452
|
-
if (args.debug) args.logLevel = "debug";
|
|
1453
|
-
if (args.verbose) args.logLevel = "verbose";
|
|
1454
|
-
if (args.silent) args.logLevel = "silent";
|
|
1455
|
-
const logLevel = _kubb_core.LogLevel[args.logLevel] || 3;
|
|
1456
|
-
await setupLogger(events, { logLevel });
|
|
1457
|
-
await (0, _kubb_core_utils.executeIfOnline)(async () => {
|
|
1458
|
-
try {
|
|
1459
|
-
const latestVersion = (await (await fetch("https://registry.npmjs.org/@kubb/cli/latest")).json()).version;
|
|
1460
|
-
if (latestVersion && require_package.version < latestVersion) await events.emit("version:new", require_package.version, latestVersion);
|
|
1461
|
-
} catch {}
|
|
1462
|
-
});
|
|
1463
|
-
try {
|
|
1464
|
-
const result = await getCosmiConfig("kubb", args.config);
|
|
1465
|
-
const configs = await (0, _kubb_core_utils.getConfigs)(result.config, args);
|
|
1466
|
-
await events.emit("config:start");
|
|
1467
|
-
await events.emit("info", "Config loaded", node_path.default.relative(node_process.cwd(), result.filepath));
|
|
1468
|
-
await events.emit("success", "Config loaded successfully", node_path.default.relative(node_process.cwd(), result.filepath));
|
|
1469
|
-
await events.emit("config:end", configs);
|
|
1470
|
-
await events.emit("lifecycle:start", require_package.version);
|
|
1471
|
-
const promises = configs.map((config) => {
|
|
1472
|
-
return async () => {
|
|
1473
|
-
if ((0, _kubb_core.isInputPath)(config) && args.watch) {
|
|
1474
|
-
await startWatcher([input || config.input.path], async (paths) => {
|
|
1475
|
-
events.removeAll();
|
|
1476
|
-
await generate({
|
|
1477
|
-
input,
|
|
1478
|
-
config,
|
|
1479
|
-
logLevel,
|
|
1480
|
-
events
|
|
1481
|
-
});
|
|
1482
|
-
_clack_prompts.log.step((0, node_util.styleText)("yellow", `Watching for changes in ${paths.join(" and ")}`));
|
|
1310
|
+
try {
|
|
1311
|
+
const result = await getCosmiConfig("kubb", configPath);
|
|
1312
|
+
const configs = await (0, _kubb_core_utils.getConfigs)(result.config, { input });
|
|
1313
|
+
await events.emit("config:start");
|
|
1314
|
+
await events.emit("info", "Config loaded", node_path.default.relative(node_process.default.cwd(), result.filepath));
|
|
1315
|
+
await events.emit("success", "Config loaded successfully", node_path.default.relative(node_process.default.cwd(), result.filepath));
|
|
1316
|
+
await events.emit("config:end", configs);
|
|
1317
|
+
await events.emit("lifecycle:start", require_package.version);
|
|
1318
|
+
const promises = configs.map((config) => {
|
|
1319
|
+
return async () => {
|
|
1320
|
+
if ((0, _kubb_core.isInputPath)(config) && watch) {
|
|
1321
|
+
await startWatcher([input || config.input.path], async (paths) => {
|
|
1322
|
+
events.removeAll();
|
|
1323
|
+
await generate({
|
|
1324
|
+
input,
|
|
1325
|
+
config,
|
|
1326
|
+
logLevel,
|
|
1327
|
+
events
|
|
1483
1328
|
});
|
|
1484
|
-
|
|
1485
|
-
}
|
|
1486
|
-
await generate({
|
|
1487
|
-
input,
|
|
1488
|
-
config,
|
|
1489
|
-
logLevel,
|
|
1490
|
-
events
|
|
1329
|
+
_clack_prompts.log.step((0, node_util.styleText)("yellow", `Watching for changes in ${paths.join(" and ")}`));
|
|
1491
1330
|
});
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1331
|
+
return;
|
|
1332
|
+
}
|
|
1333
|
+
await generate({
|
|
1334
|
+
input,
|
|
1335
|
+
config,
|
|
1336
|
+
logLevel,
|
|
1337
|
+
events
|
|
1338
|
+
});
|
|
1339
|
+
};
|
|
1340
|
+
});
|
|
1341
|
+
await promiseManager.run("seq", promises);
|
|
1342
|
+
await events.emit("lifecycle:end");
|
|
1343
|
+
} catch (error) {
|
|
1344
|
+
await events.emit("error", require_errors.toError(error));
|
|
1345
|
+
node_process.default.exit(1);
|
|
1500
1346
|
}
|
|
1501
|
-
}
|
|
1347
|
+
}
|
|
1502
1348
|
//#endregion
|
|
1503
|
-
exports.
|
|
1349
|
+
exports.runGenerateCommand = runGenerateCommand;
|
|
1504
1350
|
|
|
1505
|
-
//# sourceMappingURL=generate-
|
|
1351
|
+
//# sourceMappingURL=generate-ByMgAV76.cjs.map
|