@kubb/cli 1.15.0-canary.20231027T201044 → 2.0.0-canary.20231027T203814
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 +2 -2
- package/dist/index.cjs +121 -100
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +104 -86
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare function
|
|
1
|
+
declare function run(argv?: string[]): Promise<void>;
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { run as default, run };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare function
|
|
1
|
+
declare function run(argv?: string[]): Promise<void>;
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { run as default, run };
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { Warning, isInputPath, PromiseManager, ParallelPluginError, build, PluginError, SummaryError, PackageManager } from '@kubb/core';
|
|
4
|
+
import { write, LogLevel, isPromiseFulfilledResult, isPromise, createLogger, randomPicoColour } from '@kubb/core/utils';
|
|
4
5
|
import { cac } from 'cac';
|
|
5
|
-
import
|
|
6
|
+
import pc2 from 'picocolors';
|
|
6
7
|
import { cosmiconfig } from 'cosmiconfig';
|
|
7
8
|
import tsNode from 'ts-node';
|
|
8
|
-
import { Writable } from 'stream';
|
|
9
9
|
import PrettyError from 'pretty-error';
|
|
10
10
|
import ora from 'ora';
|
|
11
11
|
import { $, execa } from 'execa';
|
|
12
12
|
import { parseArgsStringToArgv } from 'string-argv';
|
|
13
|
+
import { Writable } from 'stream';
|
|
13
14
|
|
|
14
15
|
const require = createRequire(import.meta.url);
|
|
15
16
|
|
|
@@ -22,10 +23,10 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
22
23
|
});
|
|
23
24
|
|
|
24
25
|
// package.json
|
|
25
|
-
var version = "
|
|
26
|
+
var version = "2.0.0-alpha.1";
|
|
26
27
|
function isJSONPlugins(plugins) {
|
|
27
28
|
return !!plugins?.some((plugin) => {
|
|
28
|
-
return typeof plugin?.
|
|
29
|
+
return Array.isArray(plugin) && typeof plugin?.at(0) === "string";
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
function isObjectPlugins(plugins) {
|
|
@@ -33,18 +34,16 @@ function isObjectPlugins(plugins) {
|
|
|
33
34
|
}
|
|
34
35
|
async function importPlugin(name, options) {
|
|
35
36
|
const packageManager = new PackageManager(process.cwd());
|
|
36
|
-
const importedPlugin = process.env.NODE_ENV === "test" ? await import(name) : await packageManager.import(name
|
|
37
|
+
const importedPlugin = process.env.NODE_ENV === "test" ? await import(name) : await packageManager.import(name);
|
|
37
38
|
return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options);
|
|
38
39
|
}
|
|
39
40
|
function getPlugins(plugins) {
|
|
40
41
|
if (isObjectPlugins(plugins)) {
|
|
41
|
-
|
|
42
|
-
return importPlugin(name, plugins[name]);
|
|
43
|
-
});
|
|
44
|
-
return Promise.all(promises);
|
|
42
|
+
throw new Error("Object plugins are not supported anymore, best to use http://kubb.dev/configuration/configure#json");
|
|
45
43
|
}
|
|
46
44
|
if (isJSONPlugins(plugins)) {
|
|
47
|
-
const
|
|
45
|
+
const jsonPlugins = plugins;
|
|
46
|
+
const promises = jsonPlugins.map((plugin) => {
|
|
48
47
|
const [name, options = {}] = plugin;
|
|
49
48
|
return importPlugin(name, options);
|
|
50
49
|
});
|
|
@@ -65,6 +64,12 @@ async function getConfig(result, CLIOptions) {
|
|
|
65
64
|
kubbUserConfig = Promise.resolve(possiblePromise);
|
|
66
65
|
}
|
|
67
66
|
let JSONConfig = await kubbUserConfig;
|
|
67
|
+
if (Array.isArray(JSONConfig)) {
|
|
68
|
+
const promises = JSONConfig.map(async (item) => {
|
|
69
|
+
return { ...item, plugins: item.plugins ? await getPlugins(item.plugins) : void 0 };
|
|
70
|
+
});
|
|
71
|
+
return Promise.all(promises);
|
|
72
|
+
}
|
|
68
73
|
JSONConfig = {
|
|
69
74
|
...JSONConfig,
|
|
70
75
|
plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
|
|
@@ -129,27 +134,6 @@ async function getCosmiConfig(moduleName2, config) {
|
|
|
129
134
|
}
|
|
130
135
|
return result;
|
|
131
136
|
}
|
|
132
|
-
var OraWritable = class extends Writable {
|
|
133
|
-
command;
|
|
134
|
-
spinner;
|
|
135
|
-
constructor(spinner2, command, opts) {
|
|
136
|
-
super(opts);
|
|
137
|
-
this.command = command;
|
|
138
|
-
this.spinner = spinner2;
|
|
139
|
-
}
|
|
140
|
-
_write(chunk, _encoding, callback2) {
|
|
141
|
-
this.spinner.suffixText = `
|
|
142
|
-
|
|
143
|
-
${pc3.bold(pc3.blue(this.command))}: ${chunk?.toString()}`;
|
|
144
|
-
callback2();
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// src/utils/parseHrtimeToSeconds.ts
|
|
149
|
-
function parseHrtimeToSeconds(hrtime) {
|
|
150
|
-
const seconds = (hrtime[0] + hrtime[1] / 1e9).toFixed(3);
|
|
151
|
-
return seconds;
|
|
152
|
-
}
|
|
153
137
|
var prettyError = new PrettyError().skipPackage("commander").skip(function callback(traceLine) {
|
|
154
138
|
const pattern = new RegExp("renderErrors");
|
|
155
139
|
const hasMatch = traceLine?.file?.match(pattern);
|
|
@@ -187,64 +171,72 @@ function renderErrors(error, { prefixText, logLevel = LogLevel.silent }) {
|
|
|
187
171
|
var spinner = ora({
|
|
188
172
|
spinner: "clock"
|
|
189
173
|
});
|
|
190
|
-
async function startWatcher(
|
|
174
|
+
async function startWatcher(path4, cb) {
|
|
191
175
|
const { watch } = await import('chokidar');
|
|
192
176
|
const ignored = ["**/{.git,node_modules}/**"];
|
|
193
|
-
const watcher = watch(
|
|
177
|
+
const watcher = watch(path4, {
|
|
194
178
|
ignorePermissionErrors: true,
|
|
195
179
|
ignored
|
|
196
180
|
});
|
|
197
181
|
watcher.on("all", (type, file) => {
|
|
198
|
-
spinner.succeed(
|
|
182
|
+
spinner.succeed(pc2.yellow(pc2.bold(`Change detected: ${type} ${file}`)));
|
|
199
183
|
spinner.spinner = "clock";
|
|
200
184
|
try {
|
|
201
|
-
cb(
|
|
185
|
+
cb(path4);
|
|
202
186
|
} catch (e) {
|
|
203
|
-
spinner.warn(
|
|
187
|
+
spinner.warn(pc2.red("Watcher failed"));
|
|
204
188
|
}
|
|
205
189
|
});
|
|
206
190
|
return;
|
|
207
191
|
}
|
|
192
|
+
|
|
193
|
+
// src/utils/parseHrtimeToSeconds.ts
|
|
194
|
+
function parseHrtimeToSeconds(hrtime) {
|
|
195
|
+
const seconds = (hrtime[0] + hrtime[1] / 1e9).toFixed(3);
|
|
196
|
+
return seconds;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// src/utils/getSummary.ts
|
|
208
200
|
function getSummary({ pluginManager, status, hrstart, config, logLevel }) {
|
|
209
201
|
const logs = [];
|
|
210
202
|
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrstart));
|
|
211
|
-
const buildStartPlugins =
|
|
212
|
-
...new Set(pluginManager.executed.filter((item) => item.hookName === "buildStart" && item.plugin.name !== "core").map((item) => item.plugin.name))
|
|
213
|
-
];
|
|
203
|
+
const buildStartPlugins = pluginManager.executed.filter((item) => item.hookName === "buildStart" && item.plugin.name !== "core").map((item) => item.plugin.name);
|
|
214
204
|
const failedPlugins = config.plugins?.filter((plugin) => !buildStartPlugins.includes(plugin.name))?.map((plugin) => plugin.name);
|
|
215
205
|
const pluginsCount = config.plugins?.length || 0;
|
|
216
206
|
const files = pluginManager.fileManager.files.sort((a, b) => {
|
|
217
|
-
if (!a.meta?.
|
|
207
|
+
if (!a.meta?.pluginKey?.[1] || !b.meta?.pluginKey?.[1]) {
|
|
218
208
|
return 0;
|
|
219
209
|
}
|
|
220
|
-
if (a.meta?.
|
|
210
|
+
if (a.meta?.pluginKey?.[1]?.length < b.meta?.pluginKey?.[1]?.length) {
|
|
221
211
|
return 1;
|
|
222
212
|
}
|
|
223
|
-
if (a.meta?.
|
|
213
|
+
if (a.meta?.pluginKey?.[1]?.length > b.meta?.pluginKey?.[1]?.length) {
|
|
224
214
|
return -1;
|
|
225
215
|
}
|
|
226
216
|
return 0;
|
|
227
217
|
});
|
|
228
218
|
const meta = {
|
|
229
|
-
|
|
219
|
+
name: config.name,
|
|
220
|
+
plugins: status === "success" ? `${pc2.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total` : `${pc2.red(`${failedPlugins?.length ?? 1} failed`)}, ${pluginsCount} total`,
|
|
230
221
|
pluginsFailed: status === "failed" ? failedPlugins?.map((name) => randomPicoColour(name))?.join(", ") : void 0,
|
|
231
222
|
filesCreated: files.length,
|
|
232
|
-
time:
|
|
233
|
-
output:
|
|
223
|
+
time: pc2.yellow(`${elapsedSeconds}s`),
|
|
224
|
+
output: path.resolve(config.root, config.output.path)
|
|
234
225
|
};
|
|
235
226
|
if (logLevel === LogLevel.debug) {
|
|
236
|
-
logs.push(
|
|
237
|
-
logs.push(files.map((file) => `${randomPicoColour(file.meta?.
|
|
227
|
+
logs.push(pc2.bold("\nGenerated files:\n"));
|
|
228
|
+
logs.push(files.map((file) => `${randomPicoColour(JSON.stringify(file.meta?.pluginKey))} ${file.path}`).join("\n"));
|
|
238
229
|
}
|
|
239
230
|
logs.push(
|
|
240
231
|
[
|
|
241
232
|
[`
|
|
242
233
|
`, true],
|
|
243
|
-
[`
|
|
244
|
-
[`
|
|
245
|
-
[
|
|
246
|
-
[
|
|
247
|
-
[`
|
|
234
|
+
[` ${pc2.bold("Name:")} ${meta.name}`, !!meta.name],
|
|
235
|
+
[` ${pc2.bold("Plugins:")} ${meta.plugins}`, true],
|
|
236
|
+
[` ${pc2.dim("Failed:")} ${meta.pluginsFailed || "none"}`, !!meta.pluginsFailed],
|
|
237
|
+
[`${pc2.bold("Generated:")} ${meta.filesCreated} files`, true],
|
|
238
|
+
[` ${pc2.bold("Time:")} ${meta.time}`, true],
|
|
239
|
+
[` ${pc2.bold("Output:")} ${meta.output}`, true],
|
|
248
240
|
[`
|
|
249
241
|
`, true]
|
|
250
242
|
].map((item) => {
|
|
@@ -256,6 +248,19 @@ function getSummary({ pluginManager, status, hrstart, config, logLevel }) {
|
|
|
256
248
|
);
|
|
257
249
|
return logs;
|
|
258
250
|
}
|
|
251
|
+
var OraWritable = class extends Writable {
|
|
252
|
+
constructor(spinner2, command, opts) {
|
|
253
|
+
super(opts);
|
|
254
|
+
this.command = command;
|
|
255
|
+
this.spinner = spinner2;
|
|
256
|
+
}
|
|
257
|
+
_write(chunk, _encoding, callback2) {
|
|
258
|
+
this.spinner.suffixText = `
|
|
259
|
+
|
|
260
|
+
${pc2.bold(pc2.blue(this.command))}: ${chunk?.toString()}`;
|
|
261
|
+
callback2();
|
|
262
|
+
}
|
|
263
|
+
};
|
|
259
264
|
|
|
260
265
|
// src/generate.ts
|
|
261
266
|
async function executeHooks({ hooks, logLevel }) {
|
|
@@ -273,39 +278,41 @@ async function executeHooks({ hooks, logLevel }) {
|
|
|
273
278
|
if (!cmd) {
|
|
274
279
|
return null;
|
|
275
280
|
}
|
|
276
|
-
|
|
277
|
-
spinner.start(`Executing hook ${logLevel !== "silent" ? pc3.dim(command) : ""}`);
|
|
281
|
+
spinner.start(`Executing hook ${logLevel !== "silent" ? pc2.dim(command) : ""}`);
|
|
278
282
|
const subProcess = await execa(cmd, _args, { detached: true, signal: abortController.signal }).pipeStdout(oraWritable);
|
|
279
283
|
spinner.suffixText = "";
|
|
280
284
|
if (logLevel === LogLevel.silent) {
|
|
281
|
-
spinner.succeed(`Executing hook ${logLevel !== "silent" ?
|
|
285
|
+
spinner.succeed(`Executing hook ${logLevel !== "silent" ? pc2.dim(command) : ""}`);
|
|
282
286
|
console.log(subProcess.stdout);
|
|
283
287
|
}
|
|
284
288
|
oraWritable.destroy();
|
|
285
289
|
return { subProcess, abort: abortController.abort.bind(abortController) };
|
|
286
290
|
}).filter(Boolean);
|
|
287
|
-
await timeout(100);
|
|
288
291
|
await Promise.all(executers);
|
|
289
292
|
if (logLevel === LogLevel.silent) {
|
|
290
293
|
spinner.succeed(`Executing hooks`);
|
|
291
294
|
}
|
|
292
295
|
}
|
|
293
|
-
async function generate({ input, config, CLIOptions
|
|
296
|
+
async function generate({ input, config, CLIOptions }) {
|
|
297
|
+
const logger = createLogger({ logLevel: CLIOptions.logLevel || LogLevel.silent, name: config.name, spinner });
|
|
298
|
+
if (logger.name) {
|
|
299
|
+
spinner.prefixText = randomPicoColour(logger.name);
|
|
300
|
+
}
|
|
294
301
|
const hrstart = process.hrtime();
|
|
295
302
|
if (CLIOptions.logLevel === LogLevel.debug) {
|
|
296
303
|
const { performance, PerformanceObserver } = await import('perf_hooks');
|
|
297
304
|
const performanceOpserver = new PerformanceObserver((items) => {
|
|
298
305
|
const message = `${items.getEntries()[0]?.duration.toFixed(0)}ms`;
|
|
299
|
-
spinner.suffixText =
|
|
306
|
+
spinner.suffixText = pc2.yellow(message);
|
|
300
307
|
performance.clearMarks();
|
|
301
308
|
});
|
|
302
309
|
performanceOpserver.observe({ type: "measure" });
|
|
303
310
|
}
|
|
304
311
|
try {
|
|
305
312
|
const { root: _root, ...userConfig } = config;
|
|
306
|
-
const logLevel =
|
|
313
|
+
const logLevel = logger.logLevel;
|
|
307
314
|
const inputPath = input ?? ("path" in userConfig.input ? userConfig.input.path : void 0);
|
|
308
|
-
spinner.start(`\u{1F680} Building ${logLevel !== "silent" ?
|
|
315
|
+
spinner.start(`\u{1F680} Building ${logLevel !== "silent" ? pc2.dim(inputPath) : ""}`);
|
|
309
316
|
const output = await build({
|
|
310
317
|
config: {
|
|
311
318
|
root: process.cwd(),
|
|
@@ -319,11 +326,11 @@ async function generate({ input, config, CLIOptions, logger: logger2 }) {
|
|
|
319
326
|
...userConfig.output
|
|
320
327
|
}
|
|
321
328
|
},
|
|
322
|
-
logger
|
|
329
|
+
logger
|
|
323
330
|
});
|
|
324
|
-
spinner.suffixText = "";
|
|
325
|
-
spinner.succeed(`\u{1F680} Build completed ${logLevel !== "silent" ? pc3.dim(inputPath) : ""}`);
|
|
326
331
|
await executeHooks({ hooks: config.hooks, logLevel });
|
|
332
|
+
spinner.suffixText = "";
|
|
333
|
+
spinner.succeed(`\u{1F680} Build completed ${logLevel !== "silent" ? pc2.dim(inputPath) : ""}`);
|
|
327
334
|
const summary = getSummary({ pluginManager: output.pluginManager, config, status: "success", hrstart, logLevel: CLIOptions.logLevel });
|
|
328
335
|
console.log(summary.join(""));
|
|
329
336
|
} catch (error) {
|
|
@@ -352,7 +359,7 @@ export default defineConfig({
|
|
|
352
359
|
clean: true,
|
|
353
360
|
},
|
|
354
361
|
hooks: {
|
|
355
|
-
done: 'echo "\u{1F389} done"',
|
|
362
|
+
done: ['echo "\u{1F389} done"'],
|
|
356
363
|
},
|
|
357
364
|
plugins: [createSwagger({}), createSwaggerTS({ output: 'models', enumType: 'enum' }), createSwaggerTanstackQuery({ output: './hooks' })],
|
|
358
365
|
})
|
|
@@ -363,17 +370,17 @@ export default defineConfig({
|
|
|
363
370
|
async function init({ preset = "simple", logLevel = LogLevel.silent, packageManager = "pnpm" }) {
|
|
364
371
|
spinner.start("\u{1F4E6} Initializing Kubb");
|
|
365
372
|
const presetMeta = presets[preset];
|
|
366
|
-
const
|
|
373
|
+
const configPath = path.resolve(process.cwd(), "./kubb.config.js");
|
|
367
374
|
const installCommand = packageManager === "npm" ? "install" : "add";
|
|
368
|
-
spinner.start(`\u{1F4C0} Writing \`kubb.config.js\` ${
|
|
369
|
-
await write(presetMeta["kubb.config"],
|
|
370
|
-
spinner.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${
|
|
375
|
+
spinner.start(`\u{1F4C0} Writing \`kubb.config.js\` ${pc2.dim(configPath)}`);
|
|
376
|
+
await write(presetMeta["kubb.config"], configPath);
|
|
377
|
+
spinner.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${pc2.dim(configPath)}`);
|
|
371
378
|
const results = await Promise.allSettled([
|
|
372
379
|
$`npm init es6 -y`,
|
|
373
380
|
...presetMeta.packages.map(async (pack) => {
|
|
374
|
-
spinner.start(`\u{1F4C0} Installing ${
|
|
381
|
+
spinner.start(`\u{1F4C0} Installing ${pc2.dim(pack)}`);
|
|
375
382
|
const { stdout } = await $({ preferLocal: false })`${packageManager} ${installCommand} ${pack}`;
|
|
376
|
-
spinner.succeed(`\u{1F4C0} Installed ${
|
|
383
|
+
spinner.succeed(`\u{1F4C0} Installed ${pc2.dim(pack)}`);
|
|
377
384
|
return stdout;
|
|
378
385
|
})
|
|
379
386
|
]);
|
|
@@ -390,7 +397,6 @@ async function init({ preset = "simple", logLevel = LogLevel.silent, packageMana
|
|
|
390
397
|
|
|
391
398
|
// src/index.ts
|
|
392
399
|
var moduleName = "kubb";
|
|
393
|
-
var logger = createLogger(spinner);
|
|
394
400
|
function programCatcher(e, CLIOptions) {
|
|
395
401
|
const originalError = e;
|
|
396
402
|
let error = originalError;
|
|
@@ -398,9 +404,9 @@ function programCatcher(e, CLIOptions) {
|
|
|
398
404
|
if (summaryError) {
|
|
399
405
|
error = summaryError.cause;
|
|
400
406
|
}
|
|
401
|
-
const message = renderErrors(error, { logLevel: CLIOptions.logLevel, prefixText:
|
|
407
|
+
const message = renderErrors(error, { logLevel: CLIOptions.logLevel, prefixText: pc2.red(originalError?.message) });
|
|
402
408
|
if (error instanceof Warning) {
|
|
403
|
-
spinner.warn(
|
|
409
|
+
spinner.warn(pc2.yellow(error.message));
|
|
404
410
|
process.exit(0);
|
|
405
411
|
}
|
|
406
412
|
if (CLIOptions.logLevel === LogLevel.silent) {
|
|
@@ -411,20 +417,31 @@ function programCatcher(e, CLIOptions) {
|
|
|
411
417
|
process.exit(1);
|
|
412
418
|
}
|
|
413
419
|
async function generateAction(input, CLIOptions) {
|
|
414
|
-
spinner.start("\u{
|
|
420
|
+
spinner.start("\u{1F50D} Loading config");
|
|
415
421
|
const result = await getCosmiConfig(moduleName, CLIOptions.config);
|
|
416
|
-
spinner.succeed(`\u{
|
|
422
|
+
spinner.succeed(`\u{1F50D} Config loaded(${pc2.dim(path.relative(process.cwd(), result.filepath))})`);
|
|
417
423
|
const config = await getConfig(result, CLIOptions);
|
|
418
|
-
if (CLIOptions.watch
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
+
if (CLIOptions.watch) {
|
|
425
|
+
if (Array.isArray(config)) {
|
|
426
|
+
throw new Error("Cannot use watcher with multiple KubbConfigs(array)");
|
|
427
|
+
}
|
|
428
|
+
if (isInputPath(config)) {
|
|
429
|
+
return startWatcher([input || config.input.path], async (paths) => {
|
|
430
|
+
await generate({ config, CLIOptions });
|
|
431
|
+
spinner.spinner = "simpleDotsScrolling";
|
|
432
|
+
spinner.start(pc2.yellow(pc2.bold(`Watching for changes in ${paths.join(" and ")}`)));
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
if (Array.isArray(config)) {
|
|
437
|
+
const promiseManager = new PromiseManager();
|
|
438
|
+
const promises = config.map((item) => () => generate({ input, config: item, CLIOptions }));
|
|
439
|
+
await promiseManager.run("seq", promises);
|
|
440
|
+
return;
|
|
424
441
|
}
|
|
425
|
-
await generate({ input, config, CLIOptions
|
|
442
|
+
await generate({ input, config, CLIOptions });
|
|
426
443
|
}
|
|
427
|
-
async function
|
|
444
|
+
async function run(argv) {
|
|
428
445
|
const program = cac(moduleName);
|
|
429
446
|
program.command("[input]", "Path of the input file(overrides the one in `kubb.config.js`)").action(generateAction);
|
|
430
447
|
program.command("generate [input]", "Path of the input file(overrides the one in `kubb.config.js`)").option("-c, --config <path>", "Path to the Kubb config").option("-l, --log-level <type>", "Info, silent or debug").option("-w, --watch", "Watch mode based on the input file").action(generateAction);
|
|
@@ -441,7 +458,8 @@ async function runCLI(argv) {
|
|
|
441
458
|
programCatcher(e, program.options);
|
|
442
459
|
}
|
|
443
460
|
}
|
|
461
|
+
var src_default = run;
|
|
444
462
|
|
|
445
|
-
export {
|
|
463
|
+
export { src_default as default, run };
|
|
446
464
|
//# sourceMappingURL=out.js.map
|
|
447
465
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../package.json","../src/utils/getConfig.ts","../src/utils/getPlugins.ts","../src/utils/getCosmiConfig.ts","../src/utils/OraWritable.ts","../src/utils/parseHrtimeToSeconds.ts","../src/utils/renderErrors.ts","../src/utils/spinner.ts","../src/utils/watcher.ts","../src/generate.ts","../src/utils/getSummary.ts","../src/init.ts"],"names":["pathParser","LogLevel","SummaryError","pc","moduleName","spinner","callback","ParallelPluginError","logger"],"mappings":";;;;;;;;;;;;;AAAA,OAAOA,iBAAgB;AAEvB,SAAS,cAAc,YAAAC,WAAU,gBAAAC,eAAc,eAAe;AAE9D,SAAS,WAAW;AACpB,OAAOC,SAAQ;;;ACHb,cAAW;;;ACFb,SAAS,iBAAiB;;;ACI1B,SAAS,sBAAsB;AAI/B,SAAS,cAAc,SAAsF;AAC3G,SAAO,CAAC,CAAE,SAA+B,KAAK,CAAC,WAAW;AACxD,WAAO,OAAO,SAAS,CAAC,MAAM;AAAA,EAChC,CAAC;AACH;AAEA,SAAS,gBAAgB,SAAqF;AAC5G,SAAO,mBAAmB,UAAU,CAAC,MAAM,QAAQ,OAAO;AAC5D;AAEA,eAAe,aAAa,MAAc,SAAqD;AAC7F,QAAM,iBAAiB,IAAI,eAAe,QAAQ,IAAI,CAAC;AAEvD,QAAM,iBAAsB,QAAQ,IAAI,aAAa,SAAS,MAAM,OAAO,QAAQ,MAAM,eAAe,OAAO,MAAM,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,OAAO,CAAC,EAAE,CAAC,CAAC;AAAA,IACpF,CAAC;AAAA,EACH;AAEA,QAAM,SAAS,EAAE,OAAO,QAAQ,YAAY,OAAO,CAAC;AACtD;AAEA,eAAO,OAA8B,MAAgC;AACnE,QAAM,UAAU,IAAI,UAAU;AAE9B,UAAQ,QAAQ,WAAW,+DAA+D,EAAE,OAAO,cAAc;AAEjH,UACG,QAAQ,oBAAoB,+DAA+D,EAC3F,OAAO,uBAAuB,yBAAyB,EACvD,OAAO,0BAA0B,uBAAuB,EACxD,OAAO,eAAe,oCAAoC,EAC1D,OAAO,cAAc;AAExB,UAAQ,QAAQ,QAAQ,WAAW,EAAE,OAAO,YAAY;AACtD,WAAO,KAAK,EAAE,UAAU,OAAO,CAAC;AAAA,EAClC,CAAC;AAED,UAAQ,KAAK;AACb,UAAQ,QAAQ,OAAO;AACvB,UAAQ,MAAM,MAAM,EAAE,KAAK,MAAM,CAAC;AAElC,MAAI;AACF,UAAM,QAAQ,kBAAkB;AAEhC,YAAQ,KAAK,CAAC;AAAA,EAChB,SAAS,GAAG;AACV,mBAAe,GAAG,QAAQ,OAAO;AAAA,EACnC;AACF","sourcesContent":["import pathParser from 'node:path'\n\nimport { createLogger, LogLevel, SummaryError, Warning } from '@kubb/core'\n\nimport { cac } from 'cac'\nimport pc from 'picocolors'\n\nimport { version } from '../package.json'\nimport { getConfig, getCosmiConfig, renderErrors, spinner, startWatcher } from './utils/index.ts'\nimport generate from './generate.ts'\nimport init from './init.ts'\n\nimport type { CLIOptions } from '@kubb/core'\n\nconst moduleName = 'kubb'\nconst logger = createLogger(spinner)\n\nfunction programCatcher(e: unknown, CLIOptions: CLIOptions): void {\n const originalError = e as Error\n let error = originalError\n\n // summaryError check\n const summaryError = error instanceof SummaryError ? error : undefined\n\n if (summaryError) {\n // use the real error from summaryError and use the case of SummaryError to display a summary of plugins that failed\n error = summaryError.cause as Error\n }\n\n const message = renderErrors(error, { logLevel: CLIOptions.logLevel, prefixText: pc.red(originalError?.message) })\n\n if (error instanceof Warning) {\n spinner.warn(pc.yellow(error.message))\n process.exit(0)\n }\n\n if (CLIOptions.logLevel === LogLevel.silent) {\n spinner.fail(message)\n process.exit(1)\n }\n\n spinner.fail([message, ...(summaryError?.summary || [])].join('\\n'))\n process.exit(1)\n}\n\nasync function generateAction(input: string, CLIOptions: CLIOptions) {\n spinner.start('💾 Loading config')\n const result = await getCosmiConfig(moduleName, CLIOptions.config)\n spinner.succeed(`💾 Config loaded(${pc.dim(pathParser.relative(process.cwd(), result.filepath))})`)\n\n const config = await getConfig(result, CLIOptions)\n\n if (CLIOptions.watch && 'path' in config.input) {\n return startWatcher([input || config.input.path], async (paths) => {\n await generate({ config, CLIOptions, logger })\n spinner.spinner = 'simpleDotsScrolling'\n spinner.start(pc.yellow(pc.bold(`Watching for changes in ${paths.join(' and ')}`)))\n })\n }\n\n await generate({ input, config, CLIOptions, logger })\n}\n\nexport default async function runCLI(argv?: string[]): Promise<void> {\n const program = cac(moduleName)\n\n program.command('[input]', 'Path of the input file(overrides the one in `kubb.config.js`)').action(generateAction)\n\n program\n .command('generate [input]', 'Path of the input file(overrides the one in `kubb.config.js`)')\n .option('-c, --config <path>', 'Path to the Kubb config')\n .option('-l, --log-level <type>', 'Info, silent or debug')\n .option('-w, --watch', 'Watch mode based on the input file')\n .action(generateAction)\n\n program.command('init', 'Init Kubb').action(async () => {\n return init({ logLevel: 'info' })\n })\n\n program.help()\n program.version(version)\n program.parse(argv, { run: false })\n\n try {\n await program.runMatchedCommand()\n\n process.exit(0)\n } catch (e) {\n programCatcher(e, program.options)\n }\n}\n","{\n \"name\": \"@kubb/cli\",\n \"version\": \"1.14.5\",\n \"description\": \"Generator cli\",\n \"keywords\": [\n \"typescript\",\n \"plugins\",\n \"kubb\",\n \"codegen\",\n \"cli\"\n ],\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git://github.com/kubb-project/kubb.git\",\n \"directory\": \"packages/cli\"\n },\n \"license\": \"MIT\",\n \"author\": \"Stijn Van Hulle <stijn@stijnvanhulle.be\",\n \"sideEffects\": false,\n \"type\": \"module\",\n \"main\": \"dist/index.cjs\",\n \"module\": \"dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"bin\": {\n \"kubb\": \"bin/kubb.js\"\n },\n \"files\": [\n \"dist\",\n \"bin\",\n \"!/**/**.test.**\",\n \"!/**/__tests__/**\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"clean\": \"npx rimraf ./dist\",\n \"lint\": \"ESLINT_USE_FLAT_CONFIG=true eslint --format pretty .\",\n \"lint-fix\": \"bun run lint --quiet --fix\",\n \"release\": \"pnpm publish --no-git-check\",\n \"release:canary\": \"bash ../../.github/canary.sh && pnpm publish --no-git-check -tag canary\",\n \"release:alpha\": \"bash ../../.github/canary.sh && pnpm publish --no-git-check -tag alpha\",\n \"start\": \"tsup --watch\",\n \"test\": \"vitest --passWithNoTests\",\n \"typecheck\": \"tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false\"\n },\n \"dependencies\": {\n \"@kubb/core\": \"workspace:*\",\n \"cac\": \"^6.7.14\",\n \"chokidar\": \"^3.5.3\",\n \"cosmiconfig\": \"^8.3.6\",\n \"execa\": \"^8.0.1\",\n \"ora\": \"^7.0.1\",\n \"picocolors\": \"^1.0.0\",\n \"pretty-error\": \"^4.0.0\",\n \"string-argv\": \"^0.3.2\",\n \"ts-node\": \"^10.9.1\"\n },\n \"devDependencies\": {\n \"@kubb/swagger\": \"workspace:*\",\n \"@kubb/ts-config\": \"workspace:*\",\n \"@kubb/tsup-config\": \"workspace:*\",\n \"@types/node\": \"^20.8.9\",\n \"source-map-support\": \"^0.5.21\",\n \"tsup\": \"^7.2.0\",\n \"typescript\": \"^5.2.2\"\n },\n \"packageManager\": \"pnpm@8.3.0\",\n \"engines\": {\n \"node\": \">=18\",\n \"pnpm\": \">=8.3.0\"\n },\n \"preferGlobal\": true,\n \"publishConfig\": {\n \"access\": \"public\",\n \"registry\": \"https://registry.npmjs.org/\"\n }\n}\n","import { isPromise } from '@kubb/core'\n\nimport { getPlugins } from './getPlugins.ts'\n\nimport type { CLIOptions, KubbConfig, KubbUserConfig } from '@kubb/core'\nimport type { CosmiconfigResult } from '../types.ts'\n\nexport async function getConfig(result: CosmiconfigResult, CLIOptions: CLIOptions): Promise<KubbConfig> {\n const config = result?.config\n let kubbUserConfig: Promise<KubbUserConfig> = Promise.resolve(config) as Promise<KubbUserConfig>\n\n // for ts or js files\n if (typeof config === 'function') {\n const possiblePromise = config(CLIOptions)\n if (isPromise(possiblePromise)) {\n kubbUserConfig = possiblePromise\n }\n kubbUserConfig = Promise.resolve(possiblePromise)\n }\n\n let JSONConfig = await kubbUserConfig\n JSONConfig = {\n ...JSONConfig,\n plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : undefined,\n }\n\n return JSONConfig as KubbConfig\n}\n","/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-nocheck\n\nimport { PackageManager } from '@kubb/core'\n\nimport type { KubbJSONPlugins, KubbObjectPlugin, KubbUserConfig } from '@kubb/core'\n\nfunction isJSONPlugins(plugins: KubbUserConfig['plugins'] | KubbJSONPlugins[]): plugins is KubbJSONPlugins[] {\n return !!(plugins as KubbJSONPlugins[])?.some((plugin) => {\n return typeof plugin?.[0] === 'string'\n })\n}\n\nfunction isObjectPlugins(plugins: KubbUserConfig['plugins'] | KubbJSONPlugins[]): plugins is KubbObjectPlugin {\n return plugins instanceof Object && !Array.isArray(plugins)\n}\n\nasync function importPlugin(name: string, options: object): Promise<KubbUserConfig['plugins']> {\n const packageManager = new PackageManager(process.cwd())\n\n const importedPlugin: any = process.env.NODE_ENV === 'test' ? await import(name) : await packageManager.import(name, process.cwd())\n\n // eslint-disable-next-line\n return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options)\n}\n\nexport function getPlugins(plugins: KubbUserConfig['plugins'] | KubbJSONPlugins[] | KubbObjectPlugin[]): Promise<KubbUserConfig['plugins']> {\n if (isObjectPlugins(plugins)) {\n const promises = Object.keys(plugins).map((name) => {\n return importPlugin(name, plugins[name as keyof typeof plugins])\n })\n return Promise.all(promises)\n }\n\n if (isJSONPlugins(plugins)) {\n const promises = plugins.map((plugin) => {\n const [name, options = {}] = plugin\n return importPlugin(name, options as object)\n })\n return Promise.all(promises)\n }\n\n return Promise.resolve(plugins)\n}\n","/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-return */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { cosmiconfig } from 'cosmiconfig'\nimport tsNode from 'ts-node'\n\nimport type { CosmiconfigResult } from '../types.ts'\n\n// TODO fix tsLoader for node 20 when using ESM only\n// https://github.com/TypeStrong/ts-node/issues/1997\nconst tsLoader = (configFile: string) => {\n let registerer = { enabled() {} }\n\n try {\n // Register TypeScript compiler instance\n registerer = tsNode.register({\n compilerOptions: { module: 'commonjs' },\n typeCheck: false,\n })\n\n const module = require(configFile)\n\n return module.default\n } catch (err) {\n const error = err as Error\n\n if (error.name === 'MODULE_NOT_FOUND') {\n throw new Error(`'ts-node' is required for the TypeScript configuration files. Make sure it is installed\\nError: ${error.message}`)\n }\n\n throw error\n } finally {\n registerer.enabled()\n }\n}\n\nexport async function getCosmiConfig(moduleName: string, config?: string): Promise<CosmiconfigResult> {\n const searchPlaces = [\n 'package.json',\n `.${moduleName}rc`,\n `.${moduleName}rc.json`,\n `.${moduleName}rc.yaml`,\n `.${moduleName}rc.yml`,\n\n `.${moduleName}rc.ts`,\n `.${moduleName}rc.js`,\n `.${moduleName}rc.cjs`,\n `.${moduleName}rc.mjs`,\n\n `${moduleName}.config.ts`,\n `${moduleName}.config.js`,\n `${moduleName}.config.cjs`,\n `${moduleName}.config.mjs`,\n ]\n const explorer = cosmiconfig(moduleName, {\n cache: false,\n searchPlaces: [\n ...searchPlaces.map((searchPlace) => {\n return `.config/${searchPlace}`\n }),\n ...searchPlaces.map((searchPlace) => {\n return `configs/${searchPlace}`\n }),\n ...searchPlaces,\n ],\n loaders: {\n '.ts': tsLoader,\n },\n })\n\n const result = config ? await explorer.load(config) : await explorer.search()\n\n if (result?.isEmpty || !result || !result.config) {\n throw new Error('Config not defined, create a kubb.config.js or pass through your config with the option --config')\n }\n\n return result as CosmiconfigResult\n}\n","/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\n\n/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n\nimport { Writable } from 'node:stream'\n\nimport pc from 'picocolors'\n\nimport type { WritableOptions } from 'node:stream'\nimport type { Ora } from 'ora'\n\nexport class OraWritable extends Writable {\n public command: string\n public spinner: Ora\n constructor(spinner: Ora, command: string, opts?: WritableOptions) {\n super(opts)\n\n this.command = command\n this.spinner = spinner\n }\n _write(chunk: any, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {\n this.spinner.suffixText = `\\n\\n${pc.bold(pc.blue(this.command))}: ${chunk?.toString()}`\n\n callback()\n }\n}\n","export function parseHrtimeToSeconds(hrtime: [number, number]): string {\n const seconds = (hrtime[0] + hrtime[1] / 1e9).toFixed(3)\n return seconds\n}\n","/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\nimport { LogLevel, ParallelPluginError } from '@kubb/core'\n\nimport PrettyError from 'pretty-error'\n\nexport const prettyError = new PrettyError()\n .skipPackage('commander')\n .skip(function callback(traceLine: any) {\n // exclude renderErrors.ts\n const pattern = new RegExp('renderErrors')\n\n const hasMatch = traceLine?.file?.match(pattern)\n\n if (typeof traceLine.packageName !== 'undefined' && hasMatch) {\n return true\n }\n } as PrettyError.Callback)\n .start()\n\nfunction getErrorCauses(errors: Error[]): string[] {\n return errors\n .reduce((prev, error) => {\n const causedError = error?.cause as Error\n if (causedError) {\n prev = [...prev, ...getErrorCauses([causedError])]\n }\n prev = [...prev, prettyError.render(error)]\n\n return prev\n }, [] as string[])\n .filter(Boolean)\n}\n\nexport function renderErrors(error: Error | undefined, { prefixText, logLevel = LogLevel.silent }: { prefixText?: string; logLevel?: LogLevel }): string {\n if (!error) {\n return ''\n }\n\n if (error instanceof ParallelPluginError) {\n return [prefixText, ...error.errors.map((e) => renderErrors(e, { logLevel }))].filter(Boolean).join('\\n')\n }\n\n if (logLevel === LogLevel.silent) {\n // skip when no debug is set\n prettyError.skipNodeFiles()\n prettyError.skip(function skip() {\n return true\n } as PrettyError.Callback)\n\n return [prefixText, prettyError.render(error)].filter(Boolean).join('\\n')\n }\n\n const errors = getErrorCauses([error])\n\n return [prefixText, ...errors].filter(Boolean).join('\\n')\n}\n","import ora from 'ora'\n\nexport const spinner = ora({\n spinner: 'clock',\n})\n","import pc from 'picocolors'\n\nimport { spinner } from './spinner.ts'\n\nexport async function startWatcher(path: string[], cb: (path: string[]) => Promise<void>): Promise<void> {\n const { watch } = await import('chokidar')\n\n const ignored = ['**/{.git,node_modules}/**']\n\n const watcher = watch(path, {\n ignorePermissionErrors: true,\n ignored,\n })\n watcher.on('all', (type, file) => {\n spinner.succeed(pc.yellow(pc.bold(`Change detected: ${type} ${file}`)))\n // revert back\n spinner.spinner = 'clock'\n\n try {\n cb(path)\n } catch (e) {\n spinner.warn(pc.red('Watcher failed'))\n }\n })\n\n return\n}\n","import { build, LogLevel, ParallelPluginError, PluginError, SummaryError, timeout } from '@kubb/core'\n\nimport { execa } from 'execa'\nimport pc from 'picocolors'\nimport { parseArgsStringToArgv } from 'string-argv'\n\nimport { getSummary } from './utils/getSummary.ts'\nimport { OraWritable } from './utils/OraWritable.ts'\nimport { spinner } from './utils/spinner.ts'\n\nimport type { Writable } from 'node:stream'\nimport type { CLIOptions, KubbConfig, Logger } from '@kubb/core'\nimport type { ExecaReturnValue } from 'execa'\n\ntype GenerateProps = {\n input?: string\n config: KubbConfig\n CLIOptions: CLIOptions\n logger: Logger\n}\n\ntype ExecutingHooksProps = {\n hooks: KubbConfig['hooks']\n logLevel: LogLevel\n}\n\ntype Executer = { subProcess: ExecaReturnValue<string>; abort: AbortController['abort'] }\n\nasync function executeHooks({ hooks, logLevel }: ExecutingHooksProps): Promise<void> {\n if (!hooks?.done) {\n return\n }\n\n const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done]\n\n if (logLevel === LogLevel.silent) {\n spinner.start(`Executing hooks`)\n }\n\n const executers: Promise<Executer | null>[] = commands\n .map(async (command) => {\n const oraWritable = new OraWritable(spinner, command)\n const abortController = new AbortController()\n const [cmd, ..._args] = [...parseArgsStringToArgv(command)]\n\n if (!cmd) {\n return null\n }\n\n // wait for 100ms to be sure that all open files are close(fs)\n await timeout(100)\n\n spinner.start(`Executing hook ${logLevel !== 'silent' ? pc.dim(command) : ''}`)\n\n const subProcess = await execa(cmd, _args, { detached: true, signal: abortController.signal }).pipeStdout!(oraWritable as Writable)\n spinner.suffixText = ''\n\n if (logLevel === LogLevel.silent) {\n spinner.succeed(`Executing hook ${logLevel !== 'silent' ? pc.dim(command) : ''}`)\n\n console.log(subProcess.stdout)\n }\n\n oraWritable.destroy()\n return { subProcess, abort: abortController.abort.bind(abortController) }\n })\n .filter(Boolean)\n\n // wait for 100ms to be sure that all open files are close(fs)\n await timeout(100)\n\n await Promise.all(executers)\n\n if (logLevel === LogLevel.silent) {\n spinner.succeed(`Executing hooks`)\n }\n}\n\nexport default async function generate({ input, config, CLIOptions, logger }: GenerateProps): Promise<void> {\n const hrstart = process.hrtime()\n\n if (CLIOptions.logLevel === LogLevel.debug) {\n const { performance, PerformanceObserver } = await import('node:perf_hooks')\n\n const performanceOpserver = new PerformanceObserver((items) => {\n const message = `${items.getEntries()[0]?.duration.toFixed(0)}ms`\n\n spinner.suffixText = pc.yellow(message)\n\n performance.clearMarks()\n })\n\n performanceOpserver.observe({ type: 'measure' })\n }\n\n try {\n const { root: _root, ...userConfig } = config\n const logLevel = CLIOptions.logLevel ?? LogLevel.silent\n const inputPath = input ?? ('path' in userConfig.input ? userConfig.input.path : undefined)\n\n spinner.start(`🚀 Building ${logLevel !== 'silent' ? pc.dim(inputPath) : ''}`)\n\n const output = await build({\n config: {\n root: process.cwd(),\n ...userConfig,\n input: inputPath\n ? {\n ...userConfig.input,\n path: inputPath,\n }\n : userConfig.input,\n output: {\n write: true,\n ...userConfig.output,\n },\n },\n logger,\n })\n\n spinner.suffixText = ''\n spinner.succeed(`🚀 Build completed ${logLevel !== 'silent' ? pc.dim(inputPath) : ''}`)\n\n await executeHooks({ hooks: config.hooks, logLevel })\n\n const summary = getSummary({ pluginManager: output.pluginManager, config, status: 'success', hrstart, logLevel: CLIOptions.logLevel })\n console.log(summary.join(''))\n } catch (error) {\n let summary: string[] = []\n\n if (error instanceof PluginError || error instanceof ParallelPluginError) {\n summary = getSummary({ pluginManager: error.pluginManager, config, status: 'failed', hrstart, logLevel: CLIOptions.logLevel })\n }\n\n throw new SummaryError('Something went wrong\\n', { cause: error as Error, summary })\n }\n}\n","import pathParser from 'node:path'\n\nimport { LogLevel, randomPicoColour } from '@kubb/core'\n\nimport pc from 'picocolors'\n\nimport { parseHrtimeToSeconds } from './parseHrtimeToSeconds.ts'\n\nimport type { BuildOutput, KubbConfig } from '@kubb/core'\n\ntype SummaryProps = {\n pluginManager: BuildOutput['pluginManager']\n status: 'success' | 'failed'\n hrstart: [number, number]\n config: KubbConfig\n logLevel?: LogLevel\n}\n\nexport function getSummary({ pluginManager, status, hrstart, config, logLevel }: SummaryProps): string[] {\n const logs: string[] = []\n const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrstart))\n\n const buildStartPlugins = [\n ...new Set(pluginManager.executed.filter((item) => item.hookName === 'buildStart' && item.plugin.name !== 'core').map((item) => item.plugin.name)),\n ]\n\n const failedPlugins = config.plugins?.filter((plugin) => !buildStartPlugins.includes(plugin.name))?.map((plugin) => plugin.name)\n const pluginsCount = config.plugins?.length || 0\n const files = pluginManager.fileManager.files.sort((a, b) => {\n if (!a.meta?.pluginName || !b.meta?.pluginName) {\n return 0\n }\n if (a.meta?.pluginName.length < b.meta?.pluginName.length) {\n return 1\n }\n if (a.meta?.pluginName.length > b.meta?.pluginName.length) {\n return -1\n }\n return 0\n })\n\n const meta = {\n plugins: status === 'success'\n ? `${pc.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total`\n : `${pc.red(`${failedPlugins?.length ?? 1} failed`)}, ${pluginsCount} total`,\n pluginsFailed: status === 'failed' ? failedPlugins?.map((name) => randomPicoColour(name))?.join(', ') : undefined,\n filesCreated: files.length,\n time: pc.yellow(`${elapsedSeconds}s`),\n output: pathParser.resolve(config.root, config.output.path),\n } as const\n\n if (logLevel === LogLevel.debug) {\n logs.push(pc.bold('\\nGenerated files:\\n'))\n logs.push(files.map((file) => `${randomPicoColour(file.meta?.pluginName)} ${file.path}`).join('\\n'))\n }\n\n logs.push(\n [\n [`\\n`, true],\n [` ${pc.bold('Plugins:')} ${meta.plugins}`, true],\n [` ${pc.dim('Failed:')} ${meta.pluginsFailed || 'none'}`, !!meta.pluginsFailed],\n [`${pc.bold('Generated:')} ${meta.filesCreated} files`, true],\n [` ${pc.bold('Time:')} ${meta.time}`, true],\n [` ${pc.bold('Output:')} ${meta.output}`, true],\n [`\\n`, true],\n ]\n .map((item) => {\n if (item.at(1)) {\n return item.at(0)\n }\n return undefined\n })\n .filter(Boolean)\n .join('\\n'),\n )\n\n return logs\n}\n","import pathParser from 'node:path'\n\nimport { isPromiseFulfilledResult, LogLevel, write } from '@kubb/core'\n\nimport { $ } from 'execa'\nimport pc from 'picocolors'\n\nimport { spinner } from './utils/spinner.ts'\n\nexport type Preset = 'simple'\n\nexport type PackageManager = 'pnpm' | 'npm' | 'yarn'\n\nexport type PresetMeta = {\n 'kubb.config': string\n packages: string[]\n}\n\ntype InitProps = {\n /**\n * @default `'silent'`\n */\n logLevel?: LogLevel\n /**\n * @default `'simple'`\n */\n preset?: Preset\n /**\n * @default `'pnpm'`\n */\n packageManager?: PackageManager\n}\n\nconst presets: Record<Preset, PresetMeta> = {\n simple: {\n 'kubb.config': `\nimport { defineConfig } from '@kubb/core'\nimport createSwagger from '@kubb/swagger'\nimport createSwaggerTS from '@kubb/swagger-ts'\nimport createSwaggerTanstackQuery from '@kubb/swagger-tanstack-query'\n\nexport default defineConfig({\n root: '.',\n input: {\n path: 'https://petstore3.swagger.io/api/v3/openapi.json',\n },\n output: {\n path: './src/gen',\n clean: true,\n },\n hooks: {\n done: 'echo \"🎉 done\"',\n },\n plugins: [createSwagger({}), createSwaggerTS({ output: 'models', enumType: 'enum' }), createSwaggerTanstackQuery({ output: './hooks' })],\n})\n `,\n packages: ['@kubb/core', '@kubb/cli', '@kubb/swagger', '@kubb/swagger-ts', '@kubb/swagger-tanstack-query'],\n },\n}\n\nexport default async function init({ preset = 'simple', logLevel = LogLevel.silent, packageManager = 'pnpm' }: InitProps): Promise<undefined> {\n spinner.start('📦 Initializing Kubb')\n\n const presetMeta = presets[preset]\n const path = pathParser.resolve(process.cwd(), './kubb.config.js')\n const installCommand = packageManager === 'npm' ? 'install' : 'add'\n\n spinner.start(`📀 Writing \\`kubb.config.js\\` ${pc.dim(path)}`)\n await write(presetMeta['kubb.config'], path)\n spinner.succeed(`📀 Wrote \\`kubb.config.js\\` ${pc.dim(path)}`)\n\n const results = await Promise.allSettled([\n $`npm init es6 -y`,\n ...presetMeta.packages.map(async (pack) => {\n spinner.start(`📀 Installing ${pc.dim(pack)}`)\n const { stdout } = await $({ preferLocal: false })`${packageManager} ${installCommand} ${pack}`\n spinner.succeed(`📀 Installed ${pc.dim(pack)}`)\n\n return stdout\n }),\n ])\n\n if (logLevel === LogLevel.info) {\n results.forEach((result) => {\n if (isPromiseFulfilledResult(result)) {\n console.log(result.value)\n }\n })\n }\n spinner.succeed(`📦 initialized Kubb`)\n\n return\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../package.json","../src/utils/getConfig.ts","../src/utils/getPlugins.ts","../src/utils/getCosmiConfig.ts","../src/utils/renderErrors.ts","../src/utils/spinner.ts","../src/utils/watcher.ts","../src/generate.ts","../src/utils/getSummary.ts","../src/utils/parseHrtimeToSeconds.ts","../src/utils/OraWritable.ts","../src/init.ts"],"names":["path","SummaryError","LogLevel","pc","moduleName","ParallelPluginError","randomPicoColour","spinner","callback"],"mappings":";;;;;;;;;;;;;AAAA,OAAOA,WAAU;AAEjB,SAAS,aAAa,gBAAgB,gBAAAC,eAAc,eAAe;AACnE,SAAS,YAAAC,iBAAgB;AAEzB,SAAS,WAAW;AACpB,OAAOC,SAAQ;;;ACJb,cAAW;;;ACFb,SAAS,iBAAiB;;;ACE1B,SAAS,sBAAsB;AAI/B,SAAS,cAAc,SAAuF;AAC5G,SAAO,CAAC,CAAE,SAAsD,KAAK,CAAC,WAAW;AAC/E,WAAO,MAAM,QAAQ,MAAM,KAAK,OAAO,QAAQ,GAAG,CAAC,MAAM;AAAA,EAC3D,CAAC;AACH;AAEA,SAAS,gBAAgB,SAAoD;AAC3E,SAAO,mBAAmB,UAAU,CAAC,MAAM,QAAQ,OAAO;AAC5D;AAEA,eAAe,aAAa,MAAc,SAAqD;AAC7F,QAAM,iBAAiB,IAAI,eAAe,QAAQ,IAAI,CAAC;AAEvD,QAAM,iBAAsB,QAAQ,IAAI,aAAa,SAAS,MAAM,OAAO,QAAQ,MAAM,eAAe,OAAO,IAAI;AAGnH,SAAO,gBAAgB,UAAU,eAAe,QAAQ,OAAO,IAAI,eAAe,OAAO;AAC3F;AAEO,SAAS,WAAW,SAAwE;AACjG,MAAI,gBAAgB,OAAO,GAAG;AAC5B,UAAM,IAAI,MAAM,oGAAoG;AAAA,EACtH;AAEA,MAAI,cAAc,OAAO,GAAG;AAC1B,UAAM,cAAc;AACpB,UAAM,WAAW,YAAY,IAAI,CAAC,WAAW;AAC3C,YAAM,CAAC,MAAM,UAAU,CAAC,CAAC,IAAI;AAC7B,aAAO,aAAa,MAAM,OAAO;AAAA,IACnC,CAAC;AACD,WAAO,QAAQ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ClB,gBAAQ,MAAMG,IAAG,OAAOA,IAAG,KAAK,2BAA2B,MAAM,KAAK,OAAO,CAAC,EAAE,CAAC,CAAC;AAAA,MACpF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,MAAI,MAAM,QAAQ,MAAM,GAAG;AACzB,UAAM,iBAAiB,IAAI,eAAe;AAC1C,UAAM,WAAW,OAAO,IAAI,CAAC,SAAS,MAAM,SAAS,EAAE,OAAO,QAAQ,MAAM,WAAW,CAAC,CAAC;AAEzF,UAAM,eAAe,IAAI,OAAO,QAAQ;AAExC;AAAA,EACF;AAEA,QAAM,SAAS,EAAE,OAAO,QAAQ,WAAW,CAAC;AAC9C;AAEA,eAAsB,IAAI,MAAgC;AACxD,QAAM,UAAU,IAAI,UAAU;AAE9B,UAAQ,QAAQ,WAAW,+DAA+D,EAAE,OAAO,cAAc;AAEjH,UACG,QAAQ,oBAAoB,+DAA+D,EAC3F,OAAO,uBAAuB,yBAAyB,EACvD,OAAO,0BAA0B,uBAAuB,EACxD,OAAO,eAAe,oCAAoC,EAC1D,OAAO,cAAc;AAExB,UAAQ,QAAQ,QAAQ,WAAW,EAAE,OAAO,YAAY;AACtD,WAAO,KAAK,EAAE,UAAU,OAAO,CAAC;AAAA,EAClC,CAAC;AAED,UAAQ,KAAK;AACb,UAAQ,QAAQ,OAAO;AACvB,UAAQ,MAAM,MAAM,EAAE,KAAK,MAAM,CAAC;AAElC,MAAI;AACF,UAAM,QAAQ,kBAAkB;AAEhC,YAAQ,KAAK,CAAC;AAAA,EAChB,SAAS,GAAG;AACV,mBAAe,GAAG,QAAQ,OAAO;AAAA,EACnC;AACF;AAEA,IAAO,cAAQ","sourcesContent":["import path from 'node:path'\n\nimport { isInputPath, PromiseManager, SummaryError, Warning } from '@kubb/core'\nimport { LogLevel } from '@kubb/core/utils'\n\nimport { cac } from 'cac'\nimport pc from 'picocolors'\n\nimport { version } from '../package.json'\nimport { getConfig } from './utils/getConfig.ts'\nimport { getCosmiConfig } from './utils/getCosmiConfig.ts'\nimport { renderErrors } from './utils/renderErrors.ts'\nimport { spinner } from './utils/spinner.ts'\nimport { startWatcher } from './utils/watcher.ts'\nimport { generate } from './generate.ts'\nimport { init } from './init.ts'\n\nimport type { CLIOptions } from '@kubb/core'\n\nconst moduleName = 'kubb'\n\nfunction programCatcher(e: unknown, CLIOptions: CLIOptions): void {\n const originalError = e as Error\n let error = originalError\n\n // summaryError check\n const summaryError = error instanceof SummaryError ? error : undefined\n\n if (summaryError) {\n // use the real error from summaryError and use the case of SummaryError to display a summary of plugins that failed\n error = summaryError.cause as Error\n }\n\n const message = renderErrors(error, { logLevel: CLIOptions.logLevel, prefixText: pc.red(originalError?.message) })\n\n if (error instanceof Warning) {\n spinner.warn(pc.yellow(error.message))\n process.exit(0)\n }\n\n if (CLIOptions.logLevel === LogLevel.silent) {\n spinner.fail(message)\n process.exit(1)\n }\n\n spinner.fail([message, ...(summaryError?.summary || [])].join('\\n'))\n process.exit(1)\n}\n\nasync function generateAction(input: string, CLIOptions: CLIOptions) {\n spinner.start('🔍 Loading config')\n const result = await getCosmiConfig(moduleName, CLIOptions.config)\n spinner.succeed(`🔍 Config loaded(${pc.dim(path.relative(process.cwd(), result.filepath))})`)\n\n const config = await getConfig(result, CLIOptions)\n\n if (CLIOptions.watch) {\n if (Array.isArray(config)) {\n throw new Error('Cannot use watcher with multiple KubbConfigs(array)')\n }\n\n if (isInputPath(config)) {\n return startWatcher([input || config.input.path], async (paths) => {\n await generate({ config, CLIOptions })\n spinner.spinner = 'simpleDotsScrolling'\n spinner.start(pc.yellow(pc.bold(`Watching for changes in ${paths.join(' and ')}`)))\n })\n }\n }\n\n if (Array.isArray(config)) {\n const promiseManager = new PromiseManager()\n const promises = config.map((item) => () => generate({ input, config: item, CLIOptions }))\n\n await promiseManager.run('seq', promises)\n\n return\n }\n\n await generate({ input, config, CLIOptions })\n}\n\nexport async function run(argv?: string[]): Promise<void> {\n const program = cac(moduleName)\n\n program.command('[input]', 'Path of the input file(overrides the one in `kubb.config.js`)').action(generateAction)\n\n program\n .command('generate [input]', 'Path of the input file(overrides the one in `kubb.config.js`)')\n .option('-c, --config <path>', 'Path to the Kubb config')\n .option('-l, --log-level <type>', 'Info, silent or debug')\n .option('-w, --watch', 'Watch mode based on the input file')\n .action(generateAction)\n\n program.command('init', 'Init Kubb').action(async () => {\n return init({ logLevel: 'info' })\n })\n\n program.help()\n program.version(version)\n program.parse(argv, { run: false })\n\n try {\n await program.runMatchedCommand()\n\n process.exit(0)\n } catch (e) {\n programCatcher(e, program.options)\n }\n}\n\nexport default run\n","{\n \"name\": \"@kubb/cli\",\n \"version\": \"2.0.0-alpha.1\",\n \"description\": \"Generator cli\",\n \"keywords\": [\n \"typescript\",\n \"plugins\",\n \"kubb\",\n \"codegen\",\n \"cli\"\n ],\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git://github.com/kubb-project/kubb.git\",\n \"directory\": \"packages/cli\"\n },\n \"license\": \"MIT\",\n \"author\": \"Stijn Van Hulle <stijn@stijnvanhulle.be\",\n \"sideEffects\": false,\n \"type\": \"module\",\n \"main\": \"dist/index.cjs\",\n \"module\": \"dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"bin\": {\n \"kubb\": \"bin/kubb.js\"\n },\n \"files\": [\n \"dist\",\n \"bin\",\n \"!/**/**.test.**\",\n \"!/**/__tests__/**\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"clean\": \"npx rimraf ./dist\",\n \"lint\": \"ESLINT_USE_FLAT_CONFIG=true eslint --format pretty .\",\n \"lint-fix\": \"bun run lint --quiet --fix\",\n \"release\": \"pnpm publish --no-git-check\",\n \"release:canary\": \"bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check -tag canary\",\n \"release:alpha\": \"bash ../../.github/canary.sh && node ../../scripts/build.js alpha && pnpm publish --no-git-check -tag alpha\",\n \"start\": \"tsup --watch\",\n \"test\": \"vitest --passWithNoTests\",\n \"typecheck\": \"tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false\"\n },\n \"dependencies\": {\n \"@kubb/core\": \"workspace:*\",\n \"cac\": \"^6.7.14\",\n \"chokidar\": \"^3.5.3\",\n \"cosmiconfig\": \"^8.3.6\",\n \"execa\": \"^8.0.1\",\n \"ora\": \"^7.0.1\",\n \"picocolors\": \"^1.0.0\",\n \"pretty-error\": \"^4.0.0\",\n \"string-argv\": \"^0.3.2\",\n \"ts-node\": \"^10.9.1\"\n },\n \"devDependencies\": {\n \"@kubb/swagger\": \"workspace:*\",\n \"@kubb/ts-config\": \"workspace:*\",\n \"@kubb/tsup-config\": \"workspace:*\",\n \"@types/node\": \"^20.8.9\",\n \"source-map-support\": \"^0.5.21\",\n \"tsup\": \"^7.2.0\",\n \"typescript\": \"^5.2.2\"\n },\n \"packageManager\": \"pnpm@8.3.0\",\n \"engines\": {\n \"node\": \">=18\",\n \"pnpm\": \">=8.3.0\"\n },\n \"preferGlobal\": true,\n \"publishConfig\": {\n \"access\": \"public\",\n \"registry\": \"https://registry.npmjs.org/\"\n }\n}\n","import { isPromise } from '@kubb/core/utils'\n\nimport { getPlugins } from './getPlugins.ts'\n\nimport type { CLIOptions, KubbConfig, KubbUserConfig } from '@kubb/core'\nimport type { CosmiconfigResult } from './getCosmiConfig.ts'\n\nexport async function getConfig(result: CosmiconfigResult, CLIOptions: CLIOptions): Promise<Array<KubbConfig> | KubbConfig> {\n const config = result?.config\n let kubbUserConfig = Promise.resolve(config) as Promise<KubbUserConfig | Array<KubbUserConfig>>\n\n // for ts or js files\n if (typeof config === 'function') {\n const possiblePromise = config(CLIOptions)\n if (isPromise(possiblePromise)) {\n kubbUserConfig = possiblePromise\n }\n kubbUserConfig = Promise.resolve(possiblePromise)\n }\n\n let JSONConfig = await kubbUserConfig\n\n if (Array.isArray(JSONConfig)) {\n const promises = JSONConfig.map(async (item) => {\n return { ...item, plugins: item.plugins ? await getPlugins(item.plugins) : undefined }\n }) as unknown as Array<Promise<KubbConfig>>\n\n return Promise.all(promises)\n }\n\n JSONConfig = {\n ...JSONConfig,\n plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : undefined,\n }\n\n return JSONConfig as KubbConfig\n}\n","/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\nimport { PackageManager } from '@kubb/core'\n\nimport type { KubbUserConfig } from '@kubb/core'\n\nfunction isJSONPlugins(plugins: KubbUserConfig['plugins']): plugins is Array<[name: string, options: object]> {\n return !!(plugins as Array<[name: string, options: object]>[])?.some((plugin) => {\n return Array.isArray(plugin) && typeof plugin?.at(0) === 'string'\n })\n}\n\nfunction isObjectPlugins(plugins: KubbUserConfig['plugins']): plugins is any {\n return plugins instanceof Object && !Array.isArray(plugins)\n}\n\nasync function importPlugin(name: string, options: object): Promise<KubbUserConfig['plugins']> {\n const packageManager = new PackageManager(process.cwd())\n\n const importedPlugin: any = process.env.NODE_ENV === 'test' ? await import(name) : await packageManager.import(name)\n\n // eslint-disable-next-line\n return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options)\n}\n\nexport function getPlugins(plugins: KubbUserConfig['plugins']): Promise<KubbUserConfig['plugins']> {\n if (isObjectPlugins(plugins)) {\n throw new Error('Object plugins are not supported anymore, best to use http://kubb.dev/configuration/configure#json')\n }\n\n if (isJSONPlugins(plugins)) {\n const jsonPlugins = plugins as Array<[name: string, options: object]>\n const promises = jsonPlugins.map((plugin) => {\n const [name, options = {}] = plugin\n return importPlugin(name, options)\n })\n return Promise.all(promises) as Promise<KubbUserConfig['plugins']>\n }\n\n return Promise.resolve(plugins)\n}\n","/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-return */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { cosmiconfig } from 'cosmiconfig'\nimport tsNode from 'ts-node'\n\nimport type { defineConfig, KubbUserConfig } from '@kubb/core'\n\nexport type CosmiconfigResult = {\n filepath: string\n isEmpty?: boolean\n config: ReturnType<typeof defineConfig> | KubbUserConfig\n}\n\nconst tsLoader = (configFile: string) => {\n let registerer = { enabled() {} }\n\n try {\n // Register TypeScript compiler instance\n registerer = tsNode.register({\n compilerOptions: { module: 'commonjs' },\n typeCheck: false,\n })\n\n const module = require(configFile)\n\n return module.default\n } catch (err) {\n const error = err as Error\n\n if (error.name === 'MODULE_NOT_FOUND') {\n throw new Error(`'ts-node' is required for the TypeScript configuration files. Make sure it is installed\\nError: ${error.message}`)\n }\n\n throw error\n } finally {\n registerer.enabled()\n }\n}\n\nexport async function getCosmiConfig(moduleName: string, config?: string): Promise<CosmiconfigResult> {\n const searchPlaces = [\n 'package.json',\n `.${moduleName}rc`,\n `.${moduleName}rc.json`,\n `.${moduleName}rc.yaml`,\n `.${moduleName}rc.yml`,\n\n `.${moduleName}rc.ts`,\n `.${moduleName}rc.js`,\n `.${moduleName}rc.cjs`,\n `.${moduleName}rc.mjs`,\n\n `${moduleName}.config.ts`,\n `${moduleName}.config.js`,\n `${moduleName}.config.cjs`,\n `${moduleName}.config.mjs`,\n ]\n const explorer = cosmiconfig(moduleName, {\n cache: false,\n searchPlaces: [\n ...searchPlaces.map((searchPlace) => {\n return `.config/${searchPlace}`\n }),\n ...searchPlaces.map((searchPlace) => {\n return `configs/${searchPlace}`\n }),\n ...searchPlaces,\n ],\n loaders: {\n '.ts': tsLoader,\n },\n })\n\n const result = config ? await explorer.load(config) : await explorer.search()\n\n if (result?.isEmpty || !result || !result.config) {\n throw new Error('Config not defined, create a kubb.config.js or pass through your config with the option --config')\n }\n\n return result as CosmiconfigResult\n}\n","/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\nimport { ParallelPluginError } from '@kubb/core'\nimport { LogLevel } from '@kubb/core/utils'\n\nimport PrettyError from 'pretty-error'\n\nexport const prettyError = new PrettyError()\n .skipPackage('commander')\n .skip(function callback(traceLine: any) {\n // exclude renderErrors.ts\n const pattern = new RegExp('renderErrors')\n\n const hasMatch = traceLine?.file?.match(pattern)\n\n if (typeof traceLine.packageName !== 'undefined' && hasMatch) {\n return true\n }\n } as PrettyError.Callback)\n .start()\n\nfunction getErrorCauses(errors: Error[]): string[] {\n return errors\n .reduce((prev, error) => {\n const causedError = error?.cause as Error\n if (causedError) {\n prev = [...prev, ...getErrorCauses([causedError])]\n }\n prev = [...prev, prettyError.render(error)]\n\n return prev\n }, [] as string[])\n .filter(Boolean)\n}\n\nexport function renderErrors(error: Error | undefined, { prefixText, logLevel = LogLevel.silent }: { prefixText?: string; logLevel?: LogLevel }): string {\n if (!error) {\n return ''\n }\n\n if (error instanceof ParallelPluginError) {\n return [prefixText, ...error.errors.map((e) => renderErrors(e, { logLevel }))].filter(Boolean).join('\\n')\n }\n\n if (logLevel === LogLevel.silent) {\n // skip when no debug is set\n prettyError.skipNodeFiles()\n prettyError.skip(function skip() {\n return true\n } as PrettyError.Callback)\n\n return [prefixText, prettyError.render(error)].filter(Boolean).join('\\n')\n }\n\n const errors = getErrorCauses([error])\n\n return [prefixText, ...errors].filter(Boolean).join('\\n')\n}\n","import ora from 'ora'\n\nexport const spinner = ora({\n spinner: 'clock',\n})\n","import pc from 'picocolors'\n\nimport { spinner } from './spinner.ts'\n\nexport async function startWatcher(path: string[], cb: (path: string[]) => Promise<void>): Promise<void> {\n const { watch } = await import('chokidar')\n\n const ignored = ['**/{.git,node_modules}/**']\n\n const watcher = watch(path, {\n ignorePermissionErrors: true,\n ignored,\n })\n watcher.on('all', (type, file) => {\n spinner.succeed(pc.yellow(pc.bold(`Change detected: ${type} ${file}`)))\n // revert back\n spinner.spinner = 'clock'\n\n try {\n cb(path)\n } catch (e) {\n spinner.warn(pc.red('Watcher failed'))\n }\n })\n\n return\n}\n","import { build, ParallelPluginError, PluginError, SummaryError } from '@kubb/core'\nimport { createLogger, LogLevel, randomPicoColour } from '@kubb/core/utils'\n\nimport { execa } from 'execa'\nimport pc from 'picocolors'\nimport { parseArgsStringToArgv } from 'string-argv'\n\nimport { getSummary } from './utils/getSummary.ts'\nimport { OraWritable } from './utils/OraWritable.ts'\nimport { spinner } from './utils/spinner.ts'\n\nimport type { Writable } from 'node:stream'\nimport type { CLIOptions, KubbConfig } from '@kubb/core'\nimport type { ExecaReturnValue } from 'execa'\n\ntype GenerateProps = {\n input?: string\n config: KubbConfig\n CLIOptions: CLIOptions\n}\n\ntype ExecutingHooksProps = {\n hooks: KubbConfig['hooks']\n logLevel: LogLevel\n}\n\ntype Executer = { subProcess: ExecaReturnValue<string>; abort: AbortController['abort'] }\n\nasync function executeHooks({ hooks, logLevel }: ExecutingHooksProps): Promise<void> {\n if (!hooks?.done) {\n return\n }\n\n const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done]\n\n if (logLevel === LogLevel.silent) {\n spinner.start(`Executing hooks`)\n }\n\n const executers: Promise<Executer | null>[] = commands\n .map(async (command) => {\n const oraWritable = new OraWritable(spinner, command)\n const abortController = new AbortController()\n const [cmd, ..._args] = [...parseArgsStringToArgv(command)]\n\n if (!cmd) {\n return null\n }\n\n spinner.start(`Executing hook ${logLevel !== 'silent' ? pc.dim(command) : ''}`)\n\n const subProcess = await execa(cmd, _args, { detached: true, signal: abortController.signal }).pipeStdout!(oraWritable as Writable)\n spinner.suffixText = ''\n\n if (logLevel === LogLevel.silent) {\n spinner.succeed(`Executing hook ${logLevel !== 'silent' ? pc.dim(command) : ''}`)\n\n console.log(subProcess.stdout)\n }\n\n oraWritable.destroy()\n return { subProcess, abort: abortController.abort.bind(abortController) }\n })\n .filter(Boolean)\n\n await Promise.all(executers)\n\n if (logLevel === LogLevel.silent) {\n spinner.succeed(`Executing hooks`)\n }\n}\n\nexport async function generate({ input, config, CLIOptions }: GenerateProps): Promise<void> {\n const logger = createLogger({ logLevel: CLIOptions.logLevel || LogLevel.silent, name: config.name, spinner })\n\n if (logger.name) {\n spinner.prefixText = randomPicoColour(logger.name)\n }\n\n const hrstart = process.hrtime()\n\n if (CLIOptions.logLevel === LogLevel.debug) {\n const { performance, PerformanceObserver } = await import('node:perf_hooks')\n\n const performanceOpserver = new PerformanceObserver((items) => {\n const message = `${items.getEntries()[0]?.duration.toFixed(0)}ms`\n\n spinner.suffixText = pc.yellow(message)\n\n performance.clearMarks()\n })\n\n performanceOpserver.observe({ type: 'measure' })\n }\n\n try {\n const { root: _root, ...userConfig } = config\n const logLevel = logger.logLevel\n const inputPath = input ?? ('path' in userConfig.input ? userConfig.input.path : undefined)\n\n spinner.start(`🚀 Building ${logLevel !== 'silent' ? pc.dim(inputPath) : ''}`)\n\n const output = await build({\n config: {\n root: process.cwd(),\n ...userConfig,\n input: inputPath\n ? {\n ...userConfig.input,\n path: inputPath,\n }\n : userConfig.input,\n output: {\n write: true,\n ...userConfig.output,\n },\n },\n logger,\n })\n\n await executeHooks({ hooks: config.hooks, logLevel })\n\n spinner.suffixText = ''\n spinner.succeed(`🚀 Build completed ${logLevel !== 'silent' ? pc.dim(inputPath) : ''}`)\n\n const summary = getSummary({ pluginManager: output.pluginManager, config, status: 'success', hrstart, logLevel: CLIOptions.logLevel })\n console.log(summary.join(''))\n } catch (error) {\n let summary: string[] = []\n\n if (error instanceof PluginError || error instanceof ParallelPluginError) {\n summary = getSummary({ pluginManager: error.pluginManager, config, status: 'failed', hrstart, logLevel: CLIOptions.logLevel })\n }\n\n throw new SummaryError('Something went wrong\\n', { cause: error as Error, summary })\n }\n}\n","import path from 'node:path'\n\nimport { LogLevel, randomPicoColour } from '@kubb/core/utils'\n\nimport pc from 'picocolors'\n\nimport { parseHrtimeToSeconds } from './parseHrtimeToSeconds.ts'\n\nimport type { BuildOutput, KubbConfig } from '@kubb/core'\n\ntype SummaryProps = {\n pluginManager: BuildOutput['pluginManager']\n status: 'success' | 'failed'\n hrstart: [number, number]\n config: KubbConfig\n logLevel?: LogLevel\n}\n\nexport function getSummary({ pluginManager, status, hrstart, config, logLevel }: SummaryProps): string[] {\n const logs: string[] = []\n const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrstart))\n\n const buildStartPlugins = pluginManager.executed\n .filter((item) => item.hookName === 'buildStart' && item.plugin.name !== 'core')\n .map((item) => item.plugin.name)\n\n const failedPlugins = config.plugins?.filter((plugin) => !buildStartPlugins.includes(plugin.name))?.map((plugin) => plugin.name)\n const pluginsCount = config.plugins?.length || 0\n const files = pluginManager.fileManager.files.sort((a, b) => {\n if (!a.meta?.pluginKey?.[1] || !b.meta?.pluginKey?.[1]) {\n return 0\n }\n if (a.meta?.pluginKey?.[1]?.length < b.meta?.pluginKey?.[1]?.length) {\n return 1\n }\n if (a.meta?.pluginKey?.[1]?.length > b.meta?.pluginKey?.[1]?.length) {\n return -1\n }\n return 0\n })\n\n const meta = {\n name: config.name,\n plugins: status === 'success'\n ? `${pc.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total`\n : `${pc.red(`${failedPlugins?.length ?? 1} failed`)}, ${pluginsCount} total`,\n pluginsFailed: status === 'failed' ? failedPlugins?.map((name) => randomPicoColour(name))?.join(', ') : undefined,\n filesCreated: files.length,\n time: pc.yellow(`${elapsedSeconds}s`),\n output: path.resolve(config.root, config.output.path),\n } as const\n\n if (logLevel === LogLevel.debug) {\n logs.push(pc.bold('\\nGenerated files:\\n'))\n logs.push(files.map((file) => `${randomPicoColour(JSON.stringify(file.meta?.pluginKey))} ${file.path}`).join('\\n'))\n }\n\n logs.push(\n [\n [`\\n`, true],\n [` ${pc.bold('Name:')} ${meta.name}`, !!meta.name],\n [` ${pc.bold('Plugins:')} ${meta.plugins}`, true],\n [` ${pc.dim('Failed:')} ${meta.pluginsFailed || 'none'}`, !!meta.pluginsFailed],\n [`${pc.bold('Generated:')} ${meta.filesCreated} files`, true],\n [` ${pc.bold('Time:')} ${meta.time}`, true],\n [` ${pc.bold('Output:')} ${meta.output}`, true],\n [`\\n`, true],\n ]\n .map((item) => {\n if (item.at(1)) {\n return item.at(0)\n }\n return undefined\n })\n .filter(Boolean)\n .join('\\n'),\n )\n\n return logs\n}\n","export function parseHrtimeToSeconds(hrtime: [number, number]): string {\n const seconds = (hrtime[0] + hrtime[1] / 1e9).toFixed(3)\n return seconds\n}\n","/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\n\n/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n\nimport { Writable } from 'node:stream'\n\nimport pc from 'picocolors'\n\nimport type { WritableOptions } from 'node:stream'\nimport type { Ora } from 'ora'\n\nexport class OraWritable extends Writable {\n public command: string\n public spinner: Ora\n constructor(spinner: Ora, command: string, opts?: WritableOptions) {\n super(opts)\n\n this.command = command\n this.spinner = spinner\n }\n _write(chunk: any, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {\n this.spinner.suffixText = `\\n\\n${pc.bold(pc.blue(this.command))}: ${chunk?.toString()}`\n\n callback()\n }\n}\n","import path from 'node:path'\n\nimport { isPromiseFulfilledResult } from '@kubb/core/utils'\nimport { LogLevel, write } from '@kubb/core/utils'\n\nimport { $ } from 'execa'\nimport pc from 'picocolors'\n\nimport { spinner } from './utils/spinner.ts'\n\ntype Preset = 'simple'\n\ntype PackageManager = 'pnpm' | 'npm' | 'yarn'\n\ntype PresetMeta = {\n 'kubb.config': string\n packages: string[]\n}\n\ntype InitProps = {\n /**\n * @default `'silent'`\n */\n logLevel?: LogLevel\n /**\n * @default `'simple'`\n */\n preset?: Preset\n /**\n * @default `'pnpm'`\n */\n packageManager?: PackageManager\n}\n\nconst presets: Record<Preset, PresetMeta> = {\n simple: {\n 'kubb.config': `\nimport { defineConfig } from '@kubb/core'\nimport createSwagger from '@kubb/swagger'\nimport createSwaggerTS from '@kubb/swagger-ts'\nimport createSwaggerTanstackQuery from '@kubb/swagger-tanstack-query'\n\nexport default defineConfig({\n root: '.',\n input: {\n path: 'https://petstore3.swagger.io/api/v3/openapi.json',\n },\n output: {\n path: './src/gen',\n clean: true,\n },\n hooks: {\n done: ['echo \"🎉 done\"'],\n },\n plugins: [createSwagger({}), createSwaggerTS({ output: 'models', enumType: 'enum' }), createSwaggerTanstackQuery({ output: './hooks' })],\n})\n `,\n packages: ['@kubb/core', '@kubb/cli', '@kubb/swagger', '@kubb/swagger-ts', '@kubb/swagger-tanstack-query'],\n },\n}\n\nexport async function init({ preset = 'simple', logLevel = LogLevel.silent, packageManager = 'pnpm' }: InitProps): Promise<undefined> {\n spinner.start('📦 Initializing Kubb')\n\n const presetMeta = presets[preset]\n const configPath = path.resolve(process.cwd(), './kubb.config.js')\n const installCommand = packageManager === 'npm' ? 'install' : 'add'\n\n spinner.start(`📀 Writing \\`kubb.config.js\\` ${pc.dim(configPath)}`)\n await write(presetMeta['kubb.config'], configPath)\n spinner.succeed(`📀 Wrote \\`kubb.config.js\\` ${pc.dim(configPath)}`)\n\n const results = await Promise.allSettled([\n $`npm init es6 -y`,\n ...presetMeta.packages.map(async (pack) => {\n spinner.start(`📀 Installing ${pc.dim(pack)}`)\n const { stdout } = await $({ preferLocal: false })`${packageManager} ${installCommand} ${pack}`\n spinner.succeed(`📀 Installed ${pc.dim(pack)}`)\n\n return stdout\n }),\n ])\n\n if (logLevel === LogLevel.info) {\n results.forEach((result) => {\n if (isPromiseFulfilledResult(result)) {\n console.log(result.value)\n }\n })\n }\n spinner.succeed(`📦 initialized Kubb`)\n\n return\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-canary.20231027T203814",
|
|
4
4
|
"description": "Generator cli",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"!/**/__tests__/**"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"@kubb/core": "alpha",
|
|
34
35
|
"cac": "^6.7.14",
|
|
35
36
|
"chokidar": "^3.5.3",
|
|
36
37
|
"cosmiconfig": "^8.3.6",
|
|
@@ -39,17 +40,16 @@
|
|
|
39
40
|
"picocolors": "^1.0.0",
|
|
40
41
|
"pretty-error": "^4.0.0",
|
|
41
42
|
"string-argv": "^0.3.2",
|
|
42
|
-
"ts-node": "^10.9.1"
|
|
43
|
-
"@kubb/core": "1.15.0-canary.20231027T200912"
|
|
43
|
+
"ts-node": "^10.9.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
+
"@kubb/swagger": "alpha",
|
|
47
|
+
"@kubb/ts-config": "alpha",
|
|
48
|
+
"@kubb/tsup-config": "alpha",
|
|
46
49
|
"@types/node": "^20.8.9",
|
|
47
50
|
"source-map-support": "^0.5.21",
|
|
48
51
|
"tsup": "^7.2.0",
|
|
49
|
-
"typescript": "^5.2.2"
|
|
50
|
-
"@kubb/swagger": "1.15.0-canary.20231027T200956",
|
|
51
|
-
"@kubb/ts-config": "0.1.0",
|
|
52
|
-
"@kubb/tsup-config": "1.1.8"
|
|
52
|
+
"typescript": "^5.2.2"
|
|
53
53
|
},
|
|
54
54
|
"packageManager": "pnpm@8.3.0",
|
|
55
55
|
"engines": {
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
"lint": "ESLINT_USE_FLAT_CONFIG=true eslint --format pretty .",
|
|
68
68
|
"lint-fix": "bun run lint --quiet --fix",
|
|
69
69
|
"release": "pnpm publish --no-git-check",
|
|
70
|
-
"release:canary": "bash ../../.github/canary.sh && pnpm publish --no-git-check -tag canary",
|
|
71
|
-
"release:alpha": "bash ../../.github/canary.sh && pnpm publish --no-git-check -tag alpha",
|
|
70
|
+
"release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check -tag canary",
|
|
71
|
+
"release:alpha": "bash ../../.github/canary.sh && node ../../scripts/build.js alpha && pnpm publish --no-git-check -tag alpha",
|
|
72
72
|
"start": "tsup --watch",
|
|
73
73
|
"test": "vitest --passWithNoTests",
|
|
74
74
|
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|