@kubb/cli 1.1.12 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/kubb.js +8 -1
- package/dist/index.cjs +169 -160
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +168 -158
- package/dist/index.js.map +1 -0
- package/package.json +7 -7
package/bin/kubb.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
'use strict';
|
|
3
2
|
|
|
4
3
|
var pathParser = require('path');
|
|
@@ -7,24 +6,21 @@ var ora = require('ora');
|
|
|
7
6
|
var pc3 = require('picocolors');
|
|
8
7
|
var core = require('@kubb/core');
|
|
9
8
|
var execa = require('execa');
|
|
10
|
-
var PrettyError = require('pretty-error');
|
|
11
9
|
var stringArgv = require('string-argv');
|
|
12
10
|
var stream = require('stream');
|
|
13
|
-
var mod = require('module');
|
|
14
|
-
var url = require('url');
|
|
15
11
|
var cosmiconfig = require('cosmiconfig');
|
|
16
12
|
var tsNode = require('ts-node');
|
|
17
13
|
var yaml = require('yaml');
|
|
14
|
+
var PrettyError = require('pretty-error');
|
|
18
15
|
|
|
19
16
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
17
|
|
|
21
18
|
var pathParser__default = /*#__PURE__*/_interopDefault(pathParser);
|
|
22
19
|
var ora__default = /*#__PURE__*/_interopDefault(ora);
|
|
23
20
|
var pc3__default = /*#__PURE__*/_interopDefault(pc3);
|
|
24
|
-
var PrettyError__default = /*#__PURE__*/_interopDefault(PrettyError);
|
|
25
|
-
var mod__default = /*#__PURE__*/_interopDefault(mod);
|
|
26
21
|
var tsNode__default = /*#__PURE__*/_interopDefault(tsNode);
|
|
27
22
|
var yaml__default = /*#__PURE__*/_interopDefault(yaml);
|
|
23
|
+
var PrettyError__default = /*#__PURE__*/_interopDefault(PrettyError);
|
|
28
24
|
|
|
29
25
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
30
26
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
@@ -35,7 +31,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
35
31
|
});
|
|
36
32
|
|
|
37
33
|
// package.json
|
|
38
|
-
var version = "1.
|
|
34
|
+
var version = "1.2.0";
|
|
39
35
|
var presets = {
|
|
40
36
|
simple: {
|
|
41
37
|
"kubb.config": `
|
|
@@ -63,31 +59,32 @@ export default defineConfig({
|
|
|
63
59
|
packages: ["@kubb/core", "@kubb/cli", "@kubb/swagger", "@kubb/swagger-ts", "@kubb/swagger-tanstack-query"]
|
|
64
60
|
}
|
|
65
61
|
};
|
|
66
|
-
async function init({
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
${error?.message}`));
|
|
62
|
+
async function init({ preset = "simple", logLevel = "silent", packageManager = "pnpm" }) {
|
|
63
|
+
spinner.start("\u{1F4E6} Initializing Kubb");
|
|
64
|
+
const presetMeta = presets[preset];
|
|
65
|
+
const path = pathParser__default.default.resolve(process.cwd(), "./kubb.config.js");
|
|
66
|
+
const installCommand = packageManager === "npm" ? "install" : "add";
|
|
67
|
+
spinner.start(`\u{1F4C0} Writing \`kubb.config.js\` ${pc3__default.default.dim(path)}`);
|
|
68
|
+
await core.write(presetMeta["kubb.config"], path);
|
|
69
|
+
spinner.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${pc3__default.default.dim(path)}`);
|
|
70
|
+
const results = await Promise.allSettled([
|
|
71
|
+
execa.$`npm init es6 -y`,
|
|
72
|
+
...presetMeta.packages.map(async (pack) => {
|
|
73
|
+
spinner.start(`\u{1F4C0} Installing ${pc3__default.default.dim(pack)}`);
|
|
74
|
+
const { stdout } = await execa.$({ preferLocal: false })`${packageManager} ${installCommand} ${pack}`;
|
|
75
|
+
spinner.succeed(`\u{1F4C0} Installed ${pc3__default.default.dim(pack)}`);
|
|
76
|
+
return stdout;
|
|
77
|
+
})
|
|
78
|
+
]);
|
|
79
|
+
if (logLevel === "info") {
|
|
80
|
+
results.forEach((result) => {
|
|
81
|
+
if (core.isPromiseFulfilledResult(result)) {
|
|
82
|
+
console.log(result.value);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
90
85
|
}
|
|
86
|
+
spinner.succeed(`\u{1F4E6} initialized Kubb`);
|
|
87
|
+
return;
|
|
91
88
|
}
|
|
92
89
|
|
|
93
90
|
// src/utils/parseHrtimeToSeconds.ts
|
|
@@ -117,59 +114,44 @@ ${pc3__default.default.bold(pc3__default.default.blue(this.command))}: ${chunk?.
|
|
|
117
114
|
};
|
|
118
115
|
|
|
119
116
|
// src/run.ts
|
|
120
|
-
async function run({ config, options
|
|
117
|
+
async function run({ config, options }) {
|
|
121
118
|
const hrstart = process.hrtime();
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
spinner2.fail(pc3__default.default.red(`${message}
|
|
125
|
-
|
|
126
|
-
` || `Something went wrong
|
|
127
|
-
|
|
128
|
-
`));
|
|
129
|
-
} else if (logLevel === "info") {
|
|
130
|
-
if (message) {
|
|
131
|
-
spinner2.text = message;
|
|
132
|
-
} else {
|
|
133
|
-
spinner2.text = `\u{1FA82} Executing ${params?.hookName || "unknown"}(${pc3__default.default.yellow(params?.pluginName || "unknown")})`;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}, 100);
|
|
137
|
-
const logger = {
|
|
138
|
-
log,
|
|
139
|
-
spinner: spinner2
|
|
140
|
-
};
|
|
141
|
-
const onDone = async (hooks, logLevel) => {
|
|
119
|
+
const logger = core.createLogger(spinner);
|
|
120
|
+
const executeHooks = async (hooks, logLevel) => {
|
|
142
121
|
if (!hooks?.done) {
|
|
143
122
|
return;
|
|
144
123
|
}
|
|
145
|
-
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
} else {
|
|
149
|
-
commands = hooks.done;
|
|
124
|
+
const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done];
|
|
125
|
+
if (logLevel === "silent") {
|
|
126
|
+
spinner.start(`\u{1FA82} Executing hooks`);
|
|
150
127
|
}
|
|
151
|
-
const
|
|
152
|
-
const oraWritable = new OraWritable(
|
|
128
|
+
const executers = commands.map(async (command) => {
|
|
129
|
+
const oraWritable = new OraWritable(spinner, command);
|
|
130
|
+
const abortController = new AbortController();
|
|
153
131
|
const [cmd, ..._args] = [...stringArgv.parseArgsStringToArgv(command)];
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
oraWritable.destroy();
|
|
132
|
+
spinner.start(parseText(`\u{1FA82} Executing hook`, { info: ` ${pc3__default.default.dim(command)}` }, logLevel));
|
|
133
|
+
const subProcess = await execa.execa(cmd, _args, { detached: true, signal: abortController.signal }).pipeStdout(oraWritable);
|
|
134
|
+
spinner.suffixText = "";
|
|
158
135
|
if (logLevel === "info") {
|
|
159
|
-
|
|
160
|
-
console.log(stdout);
|
|
136
|
+
spinner.succeed(parseText(`\u{1FA82} Executing hook`, { info: ` ${pc3__default.default.dim(command)}` }, logLevel));
|
|
137
|
+
console.log(subProcess.stdout);
|
|
161
138
|
}
|
|
139
|
+
await core.timeout(50);
|
|
140
|
+
oraWritable.destroy();
|
|
141
|
+
return { subProcess, abort: abortController.abort.bind(abortController) };
|
|
162
142
|
});
|
|
163
|
-
await Promise.all(
|
|
143
|
+
await Promise.all(executers);
|
|
164
144
|
if (logLevel === "silent") {
|
|
165
|
-
|
|
145
|
+
spinner.succeed(`\u{1FA82} Executing hooks`);
|
|
166
146
|
}
|
|
167
147
|
};
|
|
168
|
-
const
|
|
148
|
+
const getSummary = (pluginManager, status) => {
|
|
149
|
+
const logs = [];
|
|
169
150
|
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrstart));
|
|
170
151
|
const buildStartPlugins = [
|
|
171
152
|
...new Set(pluginManager.executed.filter((item) => item.hookName === "buildStart" && item.plugin.name !== "core").map((item) => item.plugin.name))
|
|
172
153
|
];
|
|
154
|
+
const failedPlugins = config.plugins?.filter((plugin) => !buildStartPlugins.includes(plugin.name))?.map((plugin) => plugin.name);
|
|
173
155
|
const pluginsCount = config.plugins?.length || 0;
|
|
174
156
|
const files = pluginManager.fileManager.files.sort((a, b) => {
|
|
175
157
|
if (!a.meta?.pluginName || !b.meta?.pluginName) {
|
|
@@ -184,44 +166,39 @@ async function run({ config, options, spinner: spinner2 }) {
|
|
|
184
166
|
return 0;
|
|
185
167
|
});
|
|
186
168
|
const meta = {
|
|
187
|
-
plugins: status === "success" ? `${pc3__default.default.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total` : `${pc3__default.default.red(`${
|
|
169
|
+
plugins: status === "success" ? `${pc3__default.default.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total` : `${pc3__default.default.red(`${failedPlugins?.length || 0} failed`)}, ${pluginsCount} total`,
|
|
170
|
+
pluginsFailed: status === "failed" ? failedPlugins?.join(", ") : void 0,
|
|
188
171
|
filesCreated: files.length,
|
|
189
172
|
time: pc3__default.default.yellow(`${elapsedSeconds}s`),
|
|
190
173
|
output: pathParser__default.default.resolve(config.root, config.output.path)
|
|
191
174
|
};
|
|
192
|
-
console.log(`
|
|
193
|
-
${pc3__default.default.bold("Plugins:")} ${meta.plugins}
|
|
194
|
-
${pc3__default.default.bold("Generated:")} ${meta.filesCreated} files
|
|
195
|
-
${pc3__default.default.bold("Time:")} ${meta.time}
|
|
196
|
-
${pc3__default.default.bold("Output:")} ${meta.output}
|
|
197
|
-
`);
|
|
198
175
|
if (options.debug) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
const printErrors = (error) => {
|
|
204
|
-
const pe = new PrettyError__default.default();
|
|
205
|
-
if (options.debug) {
|
|
206
|
-
spinner2.fail(pc3__default.default.red(`Something went wrong
|
|
207
|
-
|
|
208
|
-
`));
|
|
209
|
-
const causedError = error?.cause;
|
|
210
|
-
console.log(pe.render(error));
|
|
211
|
-
if (causedError) {
|
|
212
|
-
console.log(pe.render(causedError));
|
|
213
|
-
}
|
|
214
|
-
} else {
|
|
215
|
-
spinner2.fail(pc3__default.default.red(`Something went wrong
|
|
216
|
-
|
|
217
|
-
${error?.message}`));
|
|
176
|
+
logs.push(pc3__default.default.bold("Generated files:\n"));
|
|
177
|
+
logs.push(files.map((file) => `${pc3__default.default.blue(file.meta?.pluginName)} ${file.path}`).join("\n"));
|
|
218
178
|
}
|
|
179
|
+
logs.push(
|
|
180
|
+
[
|
|
181
|
+
[` ${pc3__default.default.bold("Plugins:")} ${meta.plugins}`, true],
|
|
182
|
+
[` ${pc3__default.default.dim("Failed:")} ${meta.pluginsFailed || "none"}`, !!meta.pluginsFailed],
|
|
183
|
+
[`${pc3__default.default.bold("Generated:")} ${meta.filesCreated} files`, true],
|
|
184
|
+
[` ${pc3__default.default.bold("Time:")} ${meta.time}`, true],
|
|
185
|
+
[` ${pc3__default.default.bold("Output:")} ${meta.output}`, true],
|
|
186
|
+
[`
|
|
187
|
+
`, true]
|
|
188
|
+
].map((item) => {
|
|
189
|
+
if (item.at(1)) {
|
|
190
|
+
return item.at(0);
|
|
191
|
+
}
|
|
192
|
+
return void 0;
|
|
193
|
+
}).filter(Boolean).join("\n")
|
|
194
|
+
);
|
|
195
|
+
return logs;
|
|
219
196
|
};
|
|
220
197
|
try {
|
|
221
|
-
const { root, ...userConfig } = config;
|
|
198
|
+
const { root: _root, ...userConfig } = config;
|
|
222
199
|
const logLevel = options.logLevel ?? userConfig.logLevel ?? "silent";
|
|
223
200
|
const inputPath = options.input ?? userConfig.input.path;
|
|
224
|
-
|
|
201
|
+
spinner.start(parseText(`\u{1F680} Building`, { info: `(${pc3__default.default.dim(inputPath)})` }, logLevel));
|
|
225
202
|
const output = await core.build({
|
|
226
203
|
config: {
|
|
227
204
|
root: process.cwd(),
|
|
@@ -238,39 +215,18 @@ ${error?.message}`));
|
|
|
238
215
|
},
|
|
239
216
|
logger
|
|
240
217
|
});
|
|
241
|
-
|
|
242
|
-
await
|
|
243
|
-
|
|
218
|
+
spinner.succeed(parseText(`\u{1F680} Build completed`, { info: `(${pc3__default.default.dim(inputPath)})` }, logLevel));
|
|
219
|
+
await executeHooks(config.hooks, logLevel);
|
|
220
|
+
const summary = getSummary(output.pluginManager, "success");
|
|
221
|
+
console.log(summary.join(""));
|
|
244
222
|
} catch (error) {
|
|
245
|
-
if (error instanceof core.ParallelPluginError) {
|
|
246
|
-
error.errors.map((e) => printErrors(e));
|
|
247
|
-
} else {
|
|
248
|
-
printErrors(error);
|
|
249
|
-
}
|
|
250
223
|
if (error instanceof core.PluginError || error instanceof core.ParallelPluginError) {
|
|
251
|
-
|
|
224
|
+
const summary = getSummary(error.pluginManager, "failed");
|
|
225
|
+
throw new core.SummaryError("Something went wrong\n", { cause: error, summary });
|
|
252
226
|
}
|
|
253
|
-
throw error;
|
|
227
|
+
throw new core.SummaryError("Something went wrong\n", { cause: error });
|
|
254
228
|
}
|
|
255
229
|
}
|
|
256
|
-
var SLASHES = /* @__PURE__ */ new Set(["/", "\\"]);
|
|
257
|
-
function normalizeDirectory(directory) {
|
|
258
|
-
if (!SLASHES.has(directory[directory.length - 1])) {
|
|
259
|
-
return `${directory}/`;
|
|
260
|
-
}
|
|
261
|
-
return directory;
|
|
262
|
-
}
|
|
263
|
-
async function importModule(path, cwd) {
|
|
264
|
-
let location = path;
|
|
265
|
-
if (cwd) {
|
|
266
|
-
const require2 = mod__default.default.createRequire(normalizeDirectory(cwd));
|
|
267
|
-
location = require2.resolve(path);
|
|
268
|
-
}
|
|
269
|
-
const module = await import(url.pathToFileURL(location).href);
|
|
270
|
-
return module?.default ?? module;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// src/utils/getPlugins.ts
|
|
274
230
|
function isJSONPlugins(plugins) {
|
|
275
231
|
return !!plugins?.some((plugin) => {
|
|
276
232
|
return typeof plugin?.[0] === "string";
|
|
@@ -280,18 +236,18 @@ function isObjectPlugins(plugins) {
|
|
|
280
236
|
return plugins instanceof Object && !Array.isArray(plugins);
|
|
281
237
|
}
|
|
282
238
|
async function importPlugin(name, options) {
|
|
283
|
-
const importedPlugin = process.env.NODE_ENV === "test" ? await import(name) : await importModule(name, process.cwd());
|
|
239
|
+
const importedPlugin = process.env.NODE_ENV === "test" ? await import(name) : await core.importModule(name, process.cwd());
|
|
284
240
|
return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options);
|
|
285
241
|
}
|
|
286
242
|
function getPlugins(plugins) {
|
|
287
243
|
if (isObjectPlugins(plugins)) {
|
|
288
|
-
const promises = Object.keys(plugins).map(
|
|
244
|
+
const promises = Object.keys(plugins).map((name) => {
|
|
289
245
|
return importPlugin(name, plugins[name]);
|
|
290
246
|
});
|
|
291
247
|
return Promise.all(promises);
|
|
292
248
|
}
|
|
293
249
|
if (isJSONPlugins(plugins)) {
|
|
294
|
-
const promises = plugins.map(
|
|
250
|
+
const promises = plugins.map((plugin) => {
|
|
295
251
|
const [name, options = {}] = plugin;
|
|
296
252
|
return importPlugin(name, options);
|
|
297
253
|
});
|
|
@@ -318,8 +274,7 @@ async function getConfig(result, options) {
|
|
|
318
274
|
};
|
|
319
275
|
return JSONConfig;
|
|
320
276
|
}
|
|
321
|
-
async function startWatcher(
|
|
322
|
-
const { spinner: spinner2, path } = options;
|
|
277
|
+
async function startWatcher(path, cb) {
|
|
323
278
|
const { watch } = await import('chokidar');
|
|
324
279
|
const ignored = ["**/{.git,node_modules}/**"];
|
|
325
280
|
const watcher = watch(path, {
|
|
@@ -327,17 +282,18 @@ async function startWatcher(cb, options) {
|
|
|
327
282
|
ignored
|
|
328
283
|
});
|
|
329
284
|
watcher.on("all", (type, file) => {
|
|
330
|
-
|
|
331
|
-
|
|
285
|
+
spinner.succeed(pc3__default.default.yellow(pc3__default.default.bold(`Change detected: ${type} ${file}`)));
|
|
286
|
+
spinner.spinner = "clock";
|
|
332
287
|
try {
|
|
333
|
-
cb(
|
|
288
|
+
cb(path);
|
|
334
289
|
} catch (e) {
|
|
335
|
-
|
|
290
|
+
spinner.warn(pc3__default.default.red("Watcher failed"));
|
|
336
291
|
}
|
|
337
292
|
});
|
|
293
|
+
return;
|
|
338
294
|
}
|
|
339
295
|
var jsLoader = async (configFile) => {
|
|
340
|
-
return importModule(configFile);
|
|
296
|
+
return core.importModule(configFile);
|
|
341
297
|
};
|
|
342
298
|
var tsLoader = (configFile) => {
|
|
343
299
|
let registerer = { enabled() {
|
|
@@ -355,7 +311,6 @@ var tsLoader = (configFile) => {
|
|
|
355
311
|
throw new Error(`'ts-node' is required for the TypeScript configuration files. Make sure it is installed
|
|
356
312
|
Error: ${err.message}`);
|
|
357
313
|
}
|
|
358
|
-
console.log(err);
|
|
359
314
|
throw err;
|
|
360
315
|
} finally {
|
|
361
316
|
registerer.enabled();
|
|
@@ -395,42 +350,96 @@ async function getCosmiConfig(moduleName2, config) {
|
|
|
395
350
|
}
|
|
396
351
|
return result;
|
|
397
352
|
}
|
|
398
|
-
|
|
399
|
-
|
|
353
|
+
var prettyError = new PrettyError__default.default().skipPackage("commander").skip(function(traceLine, lineNumber) {
|
|
354
|
+
const pattern = new RegExp("renderErrors");
|
|
355
|
+
const hasMatch = traceLine?.file?.match(pattern);
|
|
356
|
+
if (typeof traceLine.packageName !== "undefined" && hasMatch) {
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
}).start();
|
|
360
|
+
function getErrorCauses(errors) {
|
|
361
|
+
return errors.reduce((prev, error) => {
|
|
362
|
+
const causedError = error?.cause;
|
|
363
|
+
if (causedError) {
|
|
364
|
+
prev = [...prev, ...getErrorCauses([causedError])];
|
|
365
|
+
}
|
|
366
|
+
prev = [...prev, prettyError.render(error)];
|
|
367
|
+
return prev;
|
|
368
|
+
}, []).filter(Boolean);
|
|
369
|
+
}
|
|
370
|
+
function renderErrors(error, { prefixText, debug = false }) {
|
|
371
|
+
if (!error) {
|
|
372
|
+
return "";
|
|
373
|
+
}
|
|
374
|
+
if (error instanceof core.ParallelPluginError) {
|
|
375
|
+
return [prefixText, ...error.errors.map((e) => renderErrors(e, { debug }))].filter(Boolean).join("\n");
|
|
376
|
+
}
|
|
377
|
+
if (debug) {
|
|
378
|
+
const errors = getErrorCauses([error]);
|
|
379
|
+
return [prefixText, ...errors].filter(Boolean).join("\n");
|
|
380
|
+
}
|
|
381
|
+
prettyError.skipNodeFiles();
|
|
382
|
+
prettyError.skip(function() {
|
|
383
|
+
return true;
|
|
384
|
+
});
|
|
385
|
+
return [prefixText, prettyError.render(error.message)].filter(Boolean).join("\n");
|
|
386
|
+
}
|
|
400
387
|
var moduleName = "kubb";
|
|
401
388
|
var spinner = ora__default.default({
|
|
402
389
|
spinner: "clock"
|
|
403
|
-
})
|
|
404
|
-
var program = new commander.Command(moduleName).description("Kubb").
|
|
390
|
+
});
|
|
391
|
+
var program = new commander.Command(moduleName).name(moduleName).description("Kubb").version(version, "-v").exitOverride((err) => {
|
|
392
|
+
if (err instanceof commander.CommanderError) {
|
|
393
|
+
process.exit(1);
|
|
394
|
+
}
|
|
395
|
+
}).configureOutput({
|
|
396
|
+
outputError: (message, write2) => {
|
|
397
|
+
const options = program.opts();
|
|
398
|
+
write2(
|
|
399
|
+
renderErrors(new Error(message, { cause: void 0 }), { debug: options.debug, prefixText: pc3__default.default.red("Something went wrong with processing the CLI\n") }) + "\n"
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
}).addOption(new commander.Option("-c, --config <path>", "Path to the Kubb config")).addOption(new commander.Option("-i, --input <path>", "Path of the input file(overrides the one in `kubb.config.js`)")).addOption(new commander.Option("-l, --logLevel <type>", "Type of the logging(overrides the one in `kubb.config.js`)").choices(["error", "info", "silent"])).addOption(new commander.Option("--init", "Init Kubb")).addOption(new commander.Option("-d, --debug", "Debug mode").default(false)).addOption(new commander.Option("-w, --watch", "Watch mode based on the input file")).action(async (options) => {
|
|
405
403
|
try {
|
|
404
|
+
spinner.start();
|
|
406
405
|
if (options.init) {
|
|
407
|
-
|
|
408
|
-
await init({ spinner, logLevel: options.logLevel });
|
|
409
|
-
spinner.succeed(`\u{1F4E6} initialized Kubb`);
|
|
410
|
-
return;
|
|
406
|
+
return init({ logLevel: options.logLevel });
|
|
411
407
|
}
|
|
412
408
|
spinner.start("\u{1F4BE} Loading config");
|
|
413
409
|
const result = await getCosmiConfig(moduleName, options.config);
|
|
414
410
|
spinner.succeed(`\u{1F4BE} Config loaded(${pc3__default.default.dim(pathParser__default.default.relative(process.cwd(), result.filepath))})`);
|
|
415
411
|
if (options.watch) {
|
|
416
|
-
const
|
|
417
|
-
startWatcher(
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
},
|
|
423
|
-
{
|
|
424
|
-
spinner,
|
|
425
|
-
path: [config.input.path]
|
|
426
|
-
}
|
|
427
|
-
);
|
|
428
|
-
} else {
|
|
429
|
-
const config = await getConfig(result, options);
|
|
430
|
-
await run({ config, spinner, options });
|
|
412
|
+
const config2 = await getConfig(result, options);
|
|
413
|
+
return startWatcher([config2.input.path], async (paths) => {
|
|
414
|
+
await run({ config: config2, options });
|
|
415
|
+
spinner.spinner = "simpleDotsScrolling";
|
|
416
|
+
spinner.start(pc3__default.default.yellow(pc3__default.default.bold(`Watching for changes in ${paths.join(" and ")}`)));
|
|
417
|
+
});
|
|
431
418
|
}
|
|
419
|
+
const config = await getConfig(result, options);
|
|
420
|
+
await run({ config, options });
|
|
432
421
|
} catch (e) {
|
|
422
|
+
const originalError = e;
|
|
423
|
+
let error = originalError;
|
|
424
|
+
const summaryError = error instanceof core.SummaryError ? error : void 0;
|
|
425
|
+
if (summaryError) {
|
|
426
|
+
error = summaryError.cause;
|
|
427
|
+
}
|
|
428
|
+
const message = renderErrors(error, { debug: options.debug, prefixText: pc3__default.default.red(originalError?.message) });
|
|
429
|
+
if (error instanceof core.Warning) {
|
|
430
|
+
spinner.warn(pc3__default.default.yellow(error.message));
|
|
431
|
+
process.exit(0);
|
|
432
|
+
}
|
|
433
|
+
spinner.fail([message, ...summaryError?.summary || []].join("\n"));
|
|
433
434
|
process.exit(1);
|
|
434
435
|
}
|
|
435
|
-
})
|
|
436
|
-
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
// src/index.ts
|
|
439
|
+
function runCLI(argv) {
|
|
440
|
+
return program.parse(argv);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
module.exports = runCLI;
|
|
444
|
+
//# sourceMappingURL=out.js.map
|
|
445
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/program.ts","../package.json","../src/init.ts","../src/run.ts","../src/utils/parseHrtimeToSeconds.ts","../src/utils/parseText.ts","../src/utils/OraWritable.ts","../src/utils/getConfig.ts","../src/utils/getPlugins.ts","../src/utils/watcher.ts","../src/utils/getCosmiConfig.ts","../src/utils/renderErrors.ts","../src/index.ts"],"names":["pathParser","pc","spinner","importModule","moduleName","ParallelPluginError","SummaryError","write","config"],"mappings":";;;;;;;;;AAAA,OAAOA,iBAAgB;AAEvB,SAAS,SAAS,gBAAgB,cAAc;AAChD,OAAO,SAAS;AAChB,OAAOC,SAAQ;;;ACFb,cAAW;;;ACFb,OAAO,gBAAgB;AAEvB,SAAS,0BAA0B,aAAa;AAEhD,SAAS,SAAS;AAClB,OAAO,QAAQ;AA6Bf,IAAM,UAAsC;AAAA,EAC1C,QAAQ;AAAA,IACN,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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YL,IAAG,IAAI,eAAe,OAAO,EAAE,CAAC;AAExG,QAAI,iBAAiB,SAAS;AAC5B,cAAQ,KAAKA,IAAG,OAAO,MAAM,OAAO,CAAC;AACrC,cAAQ,KAAK,CAAC;AAAA,IAChB;AAEA,YAAQ,KAAK,CAAC,SAAS,GAAI,cAAc,WAAW,CAAC,CAAE,EAAE,KAAK,IAAI,CAAC;AACnE,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF,CAAC;;;AY5FY,SAAR,OAAwB,MAAmC;AAChE,SAAO,QAAQ,MAAM,IAAI;AAC3B","sourcesContent":["import pathParser from 'node:path'\n\nimport { Command, CommanderError, Option } from 'commander'\nimport ora from 'ora'\nimport pc from 'picocolors'\n\nimport { version } from '../package.json'\nimport { init } from './init.ts'\nimport { run } from './run.ts'\nimport { getConfig, getCosmiConfig, renderErrors, startWatcher } from './utils/index.ts'\n\nimport { SummaryError } from '@kubb/core'\nimport type { CLIOptions } from '@kubb/core'\nimport { Warning } from '@kubb/core'\n\nconst moduleName = 'kubb'\n\nexport const spinner = ora({\n spinner: 'clock',\n})\n\nexport const program = new Command(moduleName)\n .name(moduleName)\n .description('Kubb')\n .version(version, '-v')\n .exitOverride((err) => {\n if (err instanceof CommanderError) {\n process.exit(1)\n }\n })\n .configureOutput({\n outputError: (message, write) => {\n const options: CLIOptions = program.opts()\n\n write(\n renderErrors(new Error(message, { cause: undefined }), { debug: options.debug, prefixText: pc.red('Something went wrong with processing the CLI\\n') }) +\n '\\n'\n )\n },\n })\n .addOption(new Option('-c, --config <path>', 'Path to the Kubb config'))\n .addOption(new Option('-i, --input <path>', 'Path of the input file(overrides the one in `kubb.config.js`)'))\n .addOption(new Option('-l, --logLevel <type>', 'Type of the logging(overrides the one in `kubb.config.js`)').choices(['error', 'info', 'silent']))\n .addOption(new Option('--init', 'Init Kubb'))\n .addOption(new Option('-d, --debug', 'Debug mode').default(false))\n .addOption(new Option('-w, --watch', 'Watch mode based on the input file'))\n .action(async (options: CLIOptions) => {\n try {\n spinner.start()\n\n if (options.init) {\n return init({ logLevel: options.logLevel })\n }\n\n // CONFIG\n // TODO use options.config to show path instead of relying on the `result`\n spinner.start('💾 Loading config')\n const result = await getCosmiConfig(moduleName, options.config)\n spinner.succeed(`💾 Config loaded(${pc.dim(pathParser.relative(process.cwd(), result.filepath))})`)\n // END CONFIG\n\n if (options.watch) {\n const config = await getConfig(result, options)\n\n return startWatcher([config.input.path], async (paths) => {\n await run({ config, options })\n spinner.spinner = 'simpleDotsScrolling'\n spinner.start(pc.yellow(pc.bold(`Watching for changes in ${paths.join(' and ')}`)))\n })\n }\n\n const config = await getConfig(result, options)\n\n await run({ config, options })\n } catch (e: any) {\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, { debug: options.debug, 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 spinner.fail([message, ...(summaryError?.summary || [])].join('\\n'))\n process.exit(1)\n }\n })\n","{\n \"name\": \"@kubb/cli\",\n \"version\": \"1.2.0\",\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.js\",\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\": \"rimraf ./dist\",\n \"lint\": \"eslint --format pretty ./src\",\n \"lint-fix\": \"bun run lint --quiet --fix\",\n \"release\": \"pnpm publish --no-git-check\",\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 \"@swc/core\": \"^1.3.64\",\n \"chokidar\": \"^3.5.3\",\n \"commander\": \"^10.0.1\",\n \"cosmiconfig\": \"^8.2.0\",\n \"execa\": \"^7.1.1\",\n \"ora\": \"^6.3.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 \"yaml\": \"^2.3.1\"\n },\n \"devDependencies\": {\n \"@kubb/swagger\": \"workspace:*\",\n \"@kubb/ts-config\": \"workspace:*\",\n \"@kubb/tsup-config\": \"workspace:*\",\n \"@types/node\": \"^20.3.1\",\n \"source-map-support\": \"^0.5.21\",\n \"tsup\": \"^6.7.0\",\n \"typescript\": \"^5.1.3\"\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 pathParser from 'node:path'\n\nimport { isPromiseFulfilledResult, write } from '@kubb/core'\n\nimport { $ } from 'execa'\nimport pc from 'picocolors'\n\nimport type { LogLevel } from '@kubb/core'\nimport { spinner } from './program.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 RunProps = {\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 logLevel: 'info',\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 = 'silent', packageManager = 'pnpm' }: RunProps): 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 === '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","import pathParser from 'node:path'\n\nimport { build, ParallelPluginError, PluginError, SummaryError, timeout, createLogger } from '@kubb/core'\n\nimport type { ExecaReturnValue } from 'execa'\nimport { execa } from 'execa'\nimport pc from 'picocolors'\n\nimport { parseArgsStringToArgv } from 'string-argv'\n\nimport { parseHrtimeToSeconds } from './utils/parseHrtimeToSeconds.ts'\nimport { parseText } from './utils/parseText.ts'\n\nimport type { BuildOutput, CLIOptions, KubbConfig, LogLevel } from '@kubb/core'\nimport { OraWritable } from './utils/OraWritable.ts'\nimport { spinner } from './program.ts'\n\ntype RunProps = {\n config: KubbConfig\n options: CLIOptions\n}\n\nexport async function run({ config, options }: RunProps): Promise<void> {\n const hrstart = process.hrtime()\n\n const logger = createLogger(spinner)\n\n const executeHooks = async (hooks: KubbConfig['hooks'], logLevel: LogLevel) => {\n if (!hooks?.done) {\n return\n }\n\n const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done]\n\n if (logLevel === 'silent') {\n spinner.start(`🪂 Executing hooks`)\n }\n type Executer = { subProcess: ExecaReturnValue<string>; abort: AbortController['abort'] }\n\n const executers: Promise<Executer>[] = commands.map(async (command) => {\n const oraWritable = new OraWritable(spinner, command)\n const abortController = new AbortController()\n const [cmd, ..._args] = [...parseArgsStringToArgv(command)]\n\n spinner.start(parseText(`🪂 Executing hook`, { info: ` ${pc.dim(command)}` }, logLevel))\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const subProcess = await execa(cmd, _args, { detached: true, signal: abortController.signal }).pipeStdout!(oraWritable)\n spinner.suffixText = ''\n\n if (logLevel === 'info') {\n spinner.succeed(parseText(`🪂 Executing hook`, { info: ` ${pc.dim(command)}` }, logLevel))\n\n console.log(subProcess.stdout)\n }\n\n // wait for 50ms to be sure that all open files are close(fs)\n await timeout(50)\n\n oraWritable.destroy()\n return { subProcess, abort: abortController.abort.bind(abortController) }\n })\n\n await Promise.all(executers)\n\n if (logLevel === 'silent') {\n spinner.succeed(`🪂 Executing hooks`)\n }\n }\n\n const getSummary = (pluginManager: BuildOutput['pluginManager'], status: 'success' | 'failed'): 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:\n status === 'success'\n ? `${pc.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total`\n : `${pc.red(`${failedPlugins?.length || 0} failed`)}, ${pluginsCount} total`,\n pluginsFailed: status === 'failed' ? failedPlugins?.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 (options.debug) {\n logs.push(pc.bold('Generated files:\\n'))\n logs.push(files.map((file) => `${pc.blue(file.meta?.pluginName)} ${file.path}`).join('\\n'))\n }\n\n logs.push(\n [\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\n try {\n const { root: _root, ...userConfig } = config\n const logLevel = options.logLevel ?? userConfig.logLevel ?? 'silent'\n const inputPath = options.input ?? userConfig.input.path\n\n spinner.start(parseText(`🚀 Building`, { info: `(${pc.dim(inputPath)})` }, logLevel))\n\n const output = await build({\n config: {\n root: process.cwd(),\n ...userConfig,\n logLevel,\n input: {\n ...userConfig.input,\n path: inputPath,\n },\n output: {\n write: true,\n ...userConfig.output,\n },\n },\n logger,\n })\n\n spinner.succeed(parseText(`🚀 Build completed`, { info: `(${pc.dim(inputPath)})` }, logLevel))\n\n await executeHooks(config.hooks, logLevel)\n\n const summary = getSummary(output.pluginManager, 'success')\n console.log(summary.join(''))\n } catch (error: any) {\n if (error instanceof PluginError || error instanceof ParallelPluginError) {\n const summary = getSummary(error.pluginManager, 'failed')\n\n throw new SummaryError('Something went wrong\\n', { cause: error, summary })\n }\n\n throw new SummaryError('Something went wrong\\n', { cause: error })\n }\n}\n","export function parseHrtimeToSeconds(hrtime: [number, number]) {\n const seconds = (hrtime[0] + hrtime[1] / 1e9).toFixed(3)\n return seconds\n}\n","import type { LogLevel } from '@kubb/core'\n\nexport function parseText(baseText: string, config: Partial<Record<LogLevel, string>>, logLevel: LogLevel = 'silent') {\n return `${baseText}${config[logLevel] || ''}`\n}\n","import type { WritableOptions } from 'node:stream'\nimport { Writable } from 'node:stream'\nimport type { Ora } from 'ora'\nimport pc from 'picocolors'\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: NodeJS.BufferEncoding, callback: (error?: Error | null) => void) {\n this.spinner.suffixText = `\\n\\n${pc.bold(pc.blue(this.command))}: ${chunk?.toString()}`\n\n callback()\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, options: 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(options)\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-next-line @typescript-eslint/ban-ts-comment\n// @ts-nocheck\n\nimport { importModule } 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 importedPlugin: any = process.env.NODE_ENV === 'test' ? await import(name) : await importModule(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)\n })\n return Promise.all(promises)\n }\n\n return Promise.resolve(plugins)\n}\n","import pc from 'picocolors'\n\nimport { spinner } from '../program'\n\nexport async function startWatcher(path: string[], cb: (path: string[]) => 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","/* eslint-disable @typescript-eslint/no-unsafe-return */\nimport { importModule } from '@kubb/core'\n\nimport { cosmiconfig } from 'cosmiconfig'\nimport tsNode from 'ts-node'\nimport yaml from 'yaml'\n\nimport type { CosmiconfigResult } from '../types.ts'\n\nconst jsLoader = async (configFile: string) => {\n return importModule(configFile)\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 // eslint-disable-next-line @typescript-eslint/no-empty-function\n let registerer = { enabled() {} }\n\n try {\n // Register TypeScript compiler instance\n registerer = tsNode.register({\n compilerOptions: { module: 'commonjs' },\n swc: true,\n typeCheck: false,\n })\n\n const module = require(configFile)\n\n return module.default\n } catch (err: any) {\n if (err.code === 'MODULE_NOT_FOUND') {\n throw new Error(`'ts-node' is required for the TypeScript configuration files. Make sure it is installed\\nError: ${err.message}`)\n }\n\n throw err\n } finally {\n registerer.enabled()\n }\n}\n\nexport async function getCosmiConfig(moduleName: string, config?: string) {\n const explorer = cosmiconfig(moduleName, {\n cache: false,\n 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 loaders: {\n '.yaml': (filepath, content) => yaml.parse(content),\n '.yml': (filepath, content) => yaml.parse(content),\n '.js': jsLoader,\n '.cjs': jsLoader,\n '.mjs': jsLoader,\n '.ts': tsLoader,\n noExt: jsLoader,\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","import { ParallelPluginError } from '@kubb/core'\nimport PrettyError from 'pretty-error'\n\nexport const prettyError = new PrettyError()\n .skipPackage('commander')\n .skip(function (traceLine, lineNumber) {\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, debug = false }: { prefixText?: string; debug?: boolean }): string {\n if (!error) {\n return ''\n }\n\n if (error instanceof ParallelPluginError) {\n return [prefixText, ...error.errors.map((e) => renderErrors(e, { debug }))].filter(Boolean).join('\\n')\n }\n\n if (debug) {\n const errors = getErrorCauses([error])\n\n return [prefixText, ...errors].filter(Boolean).join('\\n')\n }\n\n // skip when no debug is set\n prettyError.skipNodeFiles()\n prettyError.skip(function () {\n return true\n } as PrettyError.Callback)\n\n return [prefixText, prettyError.render(error.message)].filter(Boolean).join('\\n')\n}\n","import type { Command } from 'commander'\n\nimport { program } from './program.ts'\n\nexport default function runCLI(argv?: readonly string[]): Command {\n return program.parse(argv)\n}\n"]}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
import { createRequire } from 'module';
|
|
3
2
|
import pathParser from 'node:path';
|
|
4
|
-
import { Command, Option } from 'commander';
|
|
3
|
+
import { Command, CommanderError, Option } from 'commander';
|
|
5
4
|
import ora from 'ora';
|
|
6
5
|
import pc3 from 'picocolors';
|
|
7
|
-
import { write,
|
|
6
|
+
import { Warning, write, isPromiseFulfilledResult, createLogger, build, PluginError, ParallelPluginError, SummaryError, isPromise, timeout, importModule } from '@kubb/core';
|
|
8
7
|
import { $, execa } from 'execa';
|
|
9
|
-
import PrettyError from 'pretty-error';
|
|
10
8
|
import { parseArgsStringToArgv } from 'string-argv';
|
|
11
9
|
import { Writable } from 'node:stream';
|
|
12
|
-
import mod from 'node:module';
|
|
13
|
-
import { pathToFileURL } from 'node:url';
|
|
14
10
|
import { cosmiconfig } from 'cosmiconfig';
|
|
15
11
|
import tsNode from 'ts-node';
|
|
16
12
|
import yaml from 'yaml';
|
|
13
|
+
import PrettyError from 'pretty-error';
|
|
17
14
|
|
|
18
15
|
const require = createRequire(import.meta.url);
|
|
19
16
|
|
|
@@ -26,7 +23,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
26
23
|
});
|
|
27
24
|
|
|
28
25
|
// package.json
|
|
29
|
-
var version = "1.
|
|
26
|
+
var version = "1.2.0";
|
|
30
27
|
var presets = {
|
|
31
28
|
simple: {
|
|
32
29
|
"kubb.config": `
|
|
@@ -54,31 +51,32 @@ export default defineConfig({
|
|
|
54
51
|
packages: ["@kubb/core", "@kubb/cli", "@kubb/swagger", "@kubb/swagger-ts", "@kubb/swagger-tanstack-query"]
|
|
55
52
|
}
|
|
56
53
|
};
|
|
57
|
-
async function init({
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
${error?.message}`));
|
|
54
|
+
async function init({ preset = "simple", logLevel = "silent", packageManager = "pnpm" }) {
|
|
55
|
+
spinner.start("\u{1F4E6} Initializing Kubb");
|
|
56
|
+
const presetMeta = presets[preset];
|
|
57
|
+
const path = pathParser.resolve(process.cwd(), "./kubb.config.js");
|
|
58
|
+
const installCommand = packageManager === "npm" ? "install" : "add";
|
|
59
|
+
spinner.start(`\u{1F4C0} Writing \`kubb.config.js\` ${pc3.dim(path)}`);
|
|
60
|
+
await write(presetMeta["kubb.config"], path);
|
|
61
|
+
spinner.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${pc3.dim(path)}`);
|
|
62
|
+
const results = await Promise.allSettled([
|
|
63
|
+
$`npm init es6 -y`,
|
|
64
|
+
...presetMeta.packages.map(async (pack) => {
|
|
65
|
+
spinner.start(`\u{1F4C0} Installing ${pc3.dim(pack)}`);
|
|
66
|
+
const { stdout } = await $({ preferLocal: false })`${packageManager} ${installCommand} ${pack}`;
|
|
67
|
+
spinner.succeed(`\u{1F4C0} Installed ${pc3.dim(pack)}`);
|
|
68
|
+
return stdout;
|
|
69
|
+
})
|
|
70
|
+
]);
|
|
71
|
+
if (logLevel === "info") {
|
|
72
|
+
results.forEach((result) => {
|
|
73
|
+
if (isPromiseFulfilledResult(result)) {
|
|
74
|
+
console.log(result.value);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
81
77
|
}
|
|
78
|
+
spinner.succeed(`\u{1F4E6} initialized Kubb`);
|
|
79
|
+
return;
|
|
82
80
|
}
|
|
83
81
|
|
|
84
82
|
// src/utils/parseHrtimeToSeconds.ts
|
|
@@ -108,59 +106,44 @@ ${pc3.bold(pc3.blue(this.command))}: ${chunk?.toString()}`;
|
|
|
108
106
|
};
|
|
109
107
|
|
|
110
108
|
// src/run.ts
|
|
111
|
-
async function run({ config, options
|
|
109
|
+
async function run({ config, options }) {
|
|
112
110
|
const hrstart = process.hrtime();
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
spinner2.fail(pc3.red(`${message}
|
|
116
|
-
|
|
117
|
-
` || `Something went wrong
|
|
118
|
-
|
|
119
|
-
`));
|
|
120
|
-
} else if (logLevel === "info") {
|
|
121
|
-
if (message) {
|
|
122
|
-
spinner2.text = message;
|
|
123
|
-
} else {
|
|
124
|
-
spinner2.text = `\u{1FA82} Executing ${params?.hookName || "unknown"}(${pc3.yellow(params?.pluginName || "unknown")})`;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}, 100);
|
|
128
|
-
const logger = {
|
|
129
|
-
log,
|
|
130
|
-
spinner: spinner2
|
|
131
|
-
};
|
|
132
|
-
const onDone = async (hooks, logLevel) => {
|
|
111
|
+
const logger = createLogger(spinner);
|
|
112
|
+
const executeHooks = async (hooks, logLevel) => {
|
|
133
113
|
if (!hooks?.done) {
|
|
134
114
|
return;
|
|
135
115
|
}
|
|
136
|
-
|
|
137
|
-
if (
|
|
138
|
-
|
|
139
|
-
} else {
|
|
140
|
-
commands = hooks.done;
|
|
116
|
+
const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done];
|
|
117
|
+
if (logLevel === "silent") {
|
|
118
|
+
spinner.start(`\u{1FA82} Executing hooks`);
|
|
141
119
|
}
|
|
142
|
-
const
|
|
143
|
-
const oraWritable = new OraWritable(
|
|
120
|
+
const executers = commands.map(async (command) => {
|
|
121
|
+
const oraWritable = new OraWritable(spinner, command);
|
|
122
|
+
const abortController = new AbortController();
|
|
144
123
|
const [cmd, ..._args] = [...parseArgsStringToArgv(command)];
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
oraWritable.destroy();
|
|
124
|
+
spinner.start(parseText(`\u{1FA82} Executing hook`, { info: ` ${pc3.dim(command)}` }, logLevel));
|
|
125
|
+
const subProcess = await execa(cmd, _args, { detached: true, signal: abortController.signal }).pipeStdout(oraWritable);
|
|
126
|
+
spinner.suffixText = "";
|
|
149
127
|
if (logLevel === "info") {
|
|
150
|
-
|
|
151
|
-
console.log(stdout);
|
|
128
|
+
spinner.succeed(parseText(`\u{1FA82} Executing hook`, { info: ` ${pc3.dim(command)}` }, logLevel));
|
|
129
|
+
console.log(subProcess.stdout);
|
|
152
130
|
}
|
|
131
|
+
await timeout(50);
|
|
132
|
+
oraWritable.destroy();
|
|
133
|
+
return { subProcess, abort: abortController.abort.bind(abortController) };
|
|
153
134
|
});
|
|
154
|
-
await Promise.all(
|
|
135
|
+
await Promise.all(executers);
|
|
155
136
|
if (logLevel === "silent") {
|
|
156
|
-
|
|
137
|
+
spinner.succeed(`\u{1FA82} Executing hooks`);
|
|
157
138
|
}
|
|
158
139
|
};
|
|
159
|
-
const
|
|
140
|
+
const getSummary = (pluginManager, status) => {
|
|
141
|
+
const logs = [];
|
|
160
142
|
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrstart));
|
|
161
143
|
const buildStartPlugins = [
|
|
162
144
|
...new Set(pluginManager.executed.filter((item) => item.hookName === "buildStart" && item.plugin.name !== "core").map((item) => item.plugin.name))
|
|
163
145
|
];
|
|
146
|
+
const failedPlugins = config.plugins?.filter((plugin) => !buildStartPlugins.includes(plugin.name))?.map((plugin) => plugin.name);
|
|
164
147
|
const pluginsCount = config.plugins?.length || 0;
|
|
165
148
|
const files = pluginManager.fileManager.files.sort((a, b) => {
|
|
166
149
|
if (!a.meta?.pluginName || !b.meta?.pluginName) {
|
|
@@ -175,44 +158,39 @@ async function run({ config, options, spinner: spinner2 }) {
|
|
|
175
158
|
return 0;
|
|
176
159
|
});
|
|
177
160
|
const meta = {
|
|
178
|
-
plugins: status === "success" ? `${pc3.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total` : `${pc3.red(`${
|
|
161
|
+
plugins: status === "success" ? `${pc3.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total` : `${pc3.red(`${failedPlugins?.length || 0} failed`)}, ${pluginsCount} total`,
|
|
162
|
+
pluginsFailed: status === "failed" ? failedPlugins?.join(", ") : void 0,
|
|
179
163
|
filesCreated: files.length,
|
|
180
164
|
time: pc3.yellow(`${elapsedSeconds}s`),
|
|
181
165
|
output: pathParser.resolve(config.root, config.output.path)
|
|
182
166
|
};
|
|
183
|
-
console.log(`
|
|
184
|
-
${pc3.bold("Plugins:")} ${meta.plugins}
|
|
185
|
-
${pc3.bold("Generated:")} ${meta.filesCreated} files
|
|
186
|
-
${pc3.bold("Time:")} ${meta.time}
|
|
187
|
-
${pc3.bold("Output:")} ${meta.output}
|
|
188
|
-
`);
|
|
189
167
|
if (options.debug) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
const printErrors = (error) => {
|
|
195
|
-
const pe = new PrettyError();
|
|
196
|
-
if (options.debug) {
|
|
197
|
-
spinner2.fail(pc3.red(`Something went wrong
|
|
198
|
-
|
|
199
|
-
`));
|
|
200
|
-
const causedError = error?.cause;
|
|
201
|
-
console.log(pe.render(error));
|
|
202
|
-
if (causedError) {
|
|
203
|
-
console.log(pe.render(causedError));
|
|
204
|
-
}
|
|
205
|
-
} else {
|
|
206
|
-
spinner2.fail(pc3.red(`Something went wrong
|
|
207
|
-
|
|
208
|
-
${error?.message}`));
|
|
168
|
+
logs.push(pc3.bold("Generated files:\n"));
|
|
169
|
+
logs.push(files.map((file) => `${pc3.blue(file.meta?.pluginName)} ${file.path}`).join("\n"));
|
|
209
170
|
}
|
|
171
|
+
logs.push(
|
|
172
|
+
[
|
|
173
|
+
[` ${pc3.bold("Plugins:")} ${meta.plugins}`, true],
|
|
174
|
+
[` ${pc3.dim("Failed:")} ${meta.pluginsFailed || "none"}`, !!meta.pluginsFailed],
|
|
175
|
+
[`${pc3.bold("Generated:")} ${meta.filesCreated} files`, true],
|
|
176
|
+
[` ${pc3.bold("Time:")} ${meta.time}`, true],
|
|
177
|
+
[` ${pc3.bold("Output:")} ${meta.output}`, true],
|
|
178
|
+
[`
|
|
179
|
+
`, true]
|
|
180
|
+
].map((item) => {
|
|
181
|
+
if (item.at(1)) {
|
|
182
|
+
return item.at(0);
|
|
183
|
+
}
|
|
184
|
+
return void 0;
|
|
185
|
+
}).filter(Boolean).join("\n")
|
|
186
|
+
);
|
|
187
|
+
return logs;
|
|
210
188
|
};
|
|
211
189
|
try {
|
|
212
|
-
const { root, ...userConfig } = config;
|
|
190
|
+
const { root: _root, ...userConfig } = config;
|
|
213
191
|
const logLevel = options.logLevel ?? userConfig.logLevel ?? "silent";
|
|
214
192
|
const inputPath = options.input ?? userConfig.input.path;
|
|
215
|
-
|
|
193
|
+
spinner.start(parseText(`\u{1F680} Building`, { info: `(${pc3.dim(inputPath)})` }, logLevel));
|
|
216
194
|
const output = await build({
|
|
217
195
|
config: {
|
|
218
196
|
root: process.cwd(),
|
|
@@ -229,39 +207,18 @@ ${error?.message}`));
|
|
|
229
207
|
},
|
|
230
208
|
logger
|
|
231
209
|
});
|
|
232
|
-
|
|
233
|
-
await
|
|
234
|
-
|
|
210
|
+
spinner.succeed(parseText(`\u{1F680} Build completed`, { info: `(${pc3.dim(inputPath)})` }, logLevel));
|
|
211
|
+
await executeHooks(config.hooks, logLevel);
|
|
212
|
+
const summary = getSummary(output.pluginManager, "success");
|
|
213
|
+
console.log(summary.join(""));
|
|
235
214
|
} catch (error) {
|
|
236
|
-
if (error instanceof ParallelPluginError) {
|
|
237
|
-
error.errors.map((e) => printErrors(e));
|
|
238
|
-
} else {
|
|
239
|
-
printErrors(error);
|
|
240
|
-
}
|
|
241
215
|
if (error instanceof PluginError || error instanceof ParallelPluginError) {
|
|
242
|
-
|
|
216
|
+
const summary = getSummary(error.pluginManager, "failed");
|
|
217
|
+
throw new SummaryError("Something went wrong\n", { cause: error, summary });
|
|
243
218
|
}
|
|
244
|
-
throw error;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
var SLASHES = /* @__PURE__ */ new Set(["/", "\\"]);
|
|
248
|
-
function normalizeDirectory(directory) {
|
|
249
|
-
if (!SLASHES.has(directory[directory.length - 1])) {
|
|
250
|
-
return `${directory}/`;
|
|
251
|
-
}
|
|
252
|
-
return directory;
|
|
253
|
-
}
|
|
254
|
-
async function importModule(path, cwd) {
|
|
255
|
-
let location = path;
|
|
256
|
-
if (cwd) {
|
|
257
|
-
const require2 = mod.createRequire(normalizeDirectory(cwd));
|
|
258
|
-
location = require2.resolve(path);
|
|
219
|
+
throw new SummaryError("Something went wrong\n", { cause: error });
|
|
259
220
|
}
|
|
260
|
-
const module = await import(pathToFileURL(location).href);
|
|
261
|
-
return module?.default ?? module;
|
|
262
221
|
}
|
|
263
|
-
|
|
264
|
-
// src/utils/getPlugins.ts
|
|
265
222
|
function isJSONPlugins(plugins) {
|
|
266
223
|
return !!plugins?.some((plugin) => {
|
|
267
224
|
return typeof plugin?.[0] === "string";
|
|
@@ -276,13 +233,13 @@ async function importPlugin(name, options) {
|
|
|
276
233
|
}
|
|
277
234
|
function getPlugins(plugins) {
|
|
278
235
|
if (isObjectPlugins(plugins)) {
|
|
279
|
-
const promises = Object.keys(plugins).map(
|
|
236
|
+
const promises = Object.keys(plugins).map((name) => {
|
|
280
237
|
return importPlugin(name, plugins[name]);
|
|
281
238
|
});
|
|
282
239
|
return Promise.all(promises);
|
|
283
240
|
}
|
|
284
241
|
if (isJSONPlugins(plugins)) {
|
|
285
|
-
const promises = plugins.map(
|
|
242
|
+
const promises = plugins.map((plugin) => {
|
|
286
243
|
const [name, options = {}] = plugin;
|
|
287
244
|
return importPlugin(name, options);
|
|
288
245
|
});
|
|
@@ -309,8 +266,7 @@ async function getConfig(result, options) {
|
|
|
309
266
|
};
|
|
310
267
|
return JSONConfig;
|
|
311
268
|
}
|
|
312
|
-
async function startWatcher(
|
|
313
|
-
const { spinner: spinner2, path } = options;
|
|
269
|
+
async function startWatcher(path, cb) {
|
|
314
270
|
const { watch } = await import('chokidar');
|
|
315
271
|
const ignored = ["**/{.git,node_modules}/**"];
|
|
316
272
|
const watcher = watch(path, {
|
|
@@ -318,14 +274,15 @@ async function startWatcher(cb, options) {
|
|
|
318
274
|
ignored
|
|
319
275
|
});
|
|
320
276
|
watcher.on("all", (type, file) => {
|
|
321
|
-
|
|
322
|
-
|
|
277
|
+
spinner.succeed(pc3.yellow(pc3.bold(`Change detected: ${type} ${file}`)));
|
|
278
|
+
spinner.spinner = "clock";
|
|
323
279
|
try {
|
|
324
|
-
cb(
|
|
280
|
+
cb(path);
|
|
325
281
|
} catch (e) {
|
|
326
|
-
|
|
282
|
+
spinner.warn(pc3.red("Watcher failed"));
|
|
327
283
|
}
|
|
328
284
|
});
|
|
285
|
+
return;
|
|
329
286
|
}
|
|
330
287
|
var jsLoader = async (configFile) => {
|
|
331
288
|
return importModule(configFile);
|
|
@@ -346,7 +303,6 @@ var tsLoader = (configFile) => {
|
|
|
346
303
|
throw new Error(`'ts-node' is required for the TypeScript configuration files. Make sure it is installed
|
|
347
304
|
Error: ${err.message}`);
|
|
348
305
|
}
|
|
349
|
-
console.log(err);
|
|
350
306
|
throw err;
|
|
351
307
|
} finally {
|
|
352
308
|
registerer.enabled();
|
|
@@ -386,42 +342,96 @@ async function getCosmiConfig(moduleName2, config) {
|
|
|
386
342
|
}
|
|
387
343
|
return result;
|
|
388
344
|
}
|
|
389
|
-
|
|
390
|
-
|
|
345
|
+
var prettyError = new PrettyError().skipPackage("commander").skip(function(traceLine, lineNumber) {
|
|
346
|
+
const pattern = new RegExp("renderErrors");
|
|
347
|
+
const hasMatch = traceLine?.file?.match(pattern);
|
|
348
|
+
if (typeof traceLine.packageName !== "undefined" && hasMatch) {
|
|
349
|
+
return true;
|
|
350
|
+
}
|
|
351
|
+
}).start();
|
|
352
|
+
function getErrorCauses(errors) {
|
|
353
|
+
return errors.reduce((prev, error) => {
|
|
354
|
+
const causedError = error?.cause;
|
|
355
|
+
if (causedError) {
|
|
356
|
+
prev = [...prev, ...getErrorCauses([causedError])];
|
|
357
|
+
}
|
|
358
|
+
prev = [...prev, prettyError.render(error)];
|
|
359
|
+
return prev;
|
|
360
|
+
}, []).filter(Boolean);
|
|
361
|
+
}
|
|
362
|
+
function renderErrors(error, { prefixText, debug = false }) {
|
|
363
|
+
if (!error) {
|
|
364
|
+
return "";
|
|
365
|
+
}
|
|
366
|
+
if (error instanceof ParallelPluginError) {
|
|
367
|
+
return [prefixText, ...error.errors.map((e) => renderErrors(e, { debug }))].filter(Boolean).join("\n");
|
|
368
|
+
}
|
|
369
|
+
if (debug) {
|
|
370
|
+
const errors = getErrorCauses([error]);
|
|
371
|
+
return [prefixText, ...errors].filter(Boolean).join("\n");
|
|
372
|
+
}
|
|
373
|
+
prettyError.skipNodeFiles();
|
|
374
|
+
prettyError.skip(function() {
|
|
375
|
+
return true;
|
|
376
|
+
});
|
|
377
|
+
return [prefixText, prettyError.render(error.message)].filter(Boolean).join("\n");
|
|
378
|
+
}
|
|
391
379
|
var moduleName = "kubb";
|
|
392
380
|
var spinner = ora({
|
|
393
381
|
spinner: "clock"
|
|
394
|
-
})
|
|
395
|
-
var program = new Command(moduleName).description("Kubb").
|
|
382
|
+
});
|
|
383
|
+
var program = new Command(moduleName).name(moduleName).description("Kubb").version(version, "-v").exitOverride((err) => {
|
|
384
|
+
if (err instanceof CommanderError) {
|
|
385
|
+
process.exit(1);
|
|
386
|
+
}
|
|
387
|
+
}).configureOutput({
|
|
388
|
+
outputError: (message, write2) => {
|
|
389
|
+
const options = program.opts();
|
|
390
|
+
write2(
|
|
391
|
+
renderErrors(new Error(message, { cause: void 0 }), { debug: options.debug, prefixText: pc3.red("Something went wrong with processing the CLI\n") }) + "\n"
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
}).addOption(new Option("-c, --config <path>", "Path to the Kubb config")).addOption(new Option("-i, --input <path>", "Path of the input file(overrides the one in `kubb.config.js`)")).addOption(new Option("-l, --logLevel <type>", "Type of the logging(overrides the one in `kubb.config.js`)").choices(["error", "info", "silent"])).addOption(new Option("--init", "Init Kubb")).addOption(new Option("-d, --debug", "Debug mode").default(false)).addOption(new Option("-w, --watch", "Watch mode based on the input file")).action(async (options) => {
|
|
396
395
|
try {
|
|
396
|
+
spinner.start();
|
|
397
397
|
if (options.init) {
|
|
398
|
-
|
|
399
|
-
await init({ spinner, logLevel: options.logLevel });
|
|
400
|
-
spinner.succeed(`\u{1F4E6} initialized Kubb`);
|
|
401
|
-
return;
|
|
398
|
+
return init({ logLevel: options.logLevel });
|
|
402
399
|
}
|
|
403
400
|
spinner.start("\u{1F4BE} Loading config");
|
|
404
401
|
const result = await getCosmiConfig(moduleName, options.config);
|
|
405
402
|
spinner.succeed(`\u{1F4BE} Config loaded(${pc3.dim(pathParser.relative(process.cwd(), result.filepath))})`);
|
|
406
403
|
if (options.watch) {
|
|
407
|
-
const
|
|
408
|
-
startWatcher(
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
},
|
|
414
|
-
{
|
|
415
|
-
spinner,
|
|
416
|
-
path: [config.input.path]
|
|
417
|
-
}
|
|
418
|
-
);
|
|
419
|
-
} else {
|
|
420
|
-
const config = await getConfig(result, options);
|
|
421
|
-
await run({ config, spinner, options });
|
|
404
|
+
const config2 = await getConfig(result, options);
|
|
405
|
+
return startWatcher([config2.input.path], async (paths) => {
|
|
406
|
+
await run({ config: config2, options });
|
|
407
|
+
spinner.spinner = "simpleDotsScrolling";
|
|
408
|
+
spinner.start(pc3.yellow(pc3.bold(`Watching for changes in ${paths.join(" and ")}`)));
|
|
409
|
+
});
|
|
422
410
|
}
|
|
411
|
+
const config = await getConfig(result, options);
|
|
412
|
+
await run({ config, options });
|
|
423
413
|
} catch (e) {
|
|
414
|
+
const originalError = e;
|
|
415
|
+
let error = originalError;
|
|
416
|
+
const summaryError = error instanceof SummaryError ? error : void 0;
|
|
417
|
+
if (summaryError) {
|
|
418
|
+
error = summaryError.cause;
|
|
419
|
+
}
|
|
420
|
+
const message = renderErrors(error, { debug: options.debug, prefixText: pc3.red(originalError?.message) });
|
|
421
|
+
if (error instanceof Warning) {
|
|
422
|
+
spinner.warn(pc3.yellow(error.message));
|
|
423
|
+
process.exit(0);
|
|
424
|
+
}
|
|
425
|
+
spinner.fail([message, ...summaryError?.summary || []].join("\n"));
|
|
424
426
|
process.exit(1);
|
|
425
427
|
}
|
|
426
|
-
})
|
|
427
|
-
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
// src/index.ts
|
|
431
|
+
function runCLI(argv) {
|
|
432
|
+
return program.parse(argv);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export { runCLI as default };
|
|
436
|
+
//# sourceMappingURL=out.js.map
|
|
437
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/program.ts","../package.json","../src/init.ts","../src/run.ts","../src/utils/parseHrtimeToSeconds.ts","../src/utils/parseText.ts","../src/utils/OraWritable.ts","../src/utils/getConfig.ts","../src/utils/getPlugins.ts","../src/utils/watcher.ts","../src/utils/getCosmiConfig.ts","../src/utils/renderErrors.ts","../src/index.ts"],"names":["pathParser","pc","spinner","importModule","moduleName","ParallelPluginError","SummaryError","write","config"],"mappings":";;;;;;;;;;;;;AAAA,OAAOA,iBAAgB;AAEvB,SAAS,SAAS,gBAAgB,cAAc;AAChD,OAAO,SAAS;AAChB,OAAOC,SAAQ;;;ACFb,cAAW;;;ACFb,OAAO,gBAAgB;AAEvB,SAAS,0BAA0B,aAAa;AAEhD,SAAS,SAAS;AAClB,OAAO,QAAQ;AA6Bf,IAAM,UAAsC;AAAA,EAC1C,QAAQ;AAAA,IACN,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAsBf,UAAU,CAAC,cAAc,aAAa,iBAAiB,oBAAoB,8BAA8B;AAAA,EAC3G;AACF;AAEA,eAAsB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AA,IAChB;AAEA,YAAQ,KAAK,CAAC,SAAS,GAAI,cAAc,WAAW,CAAC,CAAE,EAAE,KAAK,IAAI,CAAC;AACnE,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF,CAAC;;;AY5FY,SAAR,OAAwB,MAAmC;AAChE,SAAO,QAAQ,MAAM,IAAI;AAC3B","sourcesContent":["import pathParser from 'node:path'\n\nimport { Command, CommanderError, Option } from 'commander'\nimport ora from 'ora'\nimport pc from 'picocolors'\n\nimport { version } from '../package.json'\nimport { init } from './init.ts'\nimport { run } from './run.ts'\nimport { getConfig, getCosmiConfig, renderErrors, startWatcher } from './utils/index.ts'\n\nimport { SummaryError } from '@kubb/core'\nimport type { CLIOptions } from '@kubb/core'\nimport { Warning } from '@kubb/core'\n\nconst moduleName = 'kubb'\n\nexport const spinner = ora({\n spinner: 'clock',\n})\n\nexport const program = new Command(moduleName)\n .name(moduleName)\n .description('Kubb')\n .version(version, '-v')\n .exitOverride((err) => {\n if (err instanceof CommanderError) {\n process.exit(1)\n }\n })\n .configureOutput({\n outputError: (message, write) => {\n const options: CLIOptions = program.opts()\n\n write(\n renderErrors(new Error(message, { cause: undefined }), { debug: options.debug, prefixText: pc.red('Something went wrong with processing the CLI\\n') }) +\n '\\n'\n )\n },\n })\n .addOption(new Option('-c, --config <path>', 'Path to the Kubb config'))\n .addOption(new Option('-i, --input <path>', 'Path of the input file(overrides the one in `kubb.config.js`)'))\n .addOption(new Option('-l, --logLevel <type>', 'Type of the logging(overrides the one in `kubb.config.js`)').choices(['error', 'info', 'silent']))\n .addOption(new Option('--init', 'Init Kubb'))\n .addOption(new Option('-d, --debug', 'Debug mode').default(false))\n .addOption(new Option('-w, --watch', 'Watch mode based on the input file'))\n .action(async (options: CLIOptions) => {\n try {\n spinner.start()\n\n if (options.init) {\n return init({ logLevel: options.logLevel })\n }\n\n // CONFIG\n // TODO use options.config to show path instead of relying on the `result`\n spinner.start('💾 Loading config')\n const result = await getCosmiConfig(moduleName, options.config)\n spinner.succeed(`💾 Config loaded(${pc.dim(pathParser.relative(process.cwd(), result.filepath))})`)\n // END CONFIG\n\n if (options.watch) {\n const config = await getConfig(result, options)\n\n return startWatcher([config.input.path], async (paths) => {\n await run({ config, options })\n spinner.spinner = 'simpleDotsScrolling'\n spinner.start(pc.yellow(pc.bold(`Watching for changes in ${paths.join(' and ')}`)))\n })\n }\n\n const config = await getConfig(result, options)\n\n await run({ config, options })\n } catch (e: any) {\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, { debug: options.debug, 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 spinner.fail([message, ...(summaryError?.summary || [])].join('\\n'))\n process.exit(1)\n }\n })\n","{\n \"name\": \"@kubb/cli\",\n \"version\": \"1.2.0\",\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.js\",\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\": \"rimraf ./dist\",\n \"lint\": \"eslint --format pretty ./src\",\n \"lint-fix\": \"bun run lint --quiet --fix\",\n \"release\": \"pnpm publish --no-git-check\",\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 \"@swc/core\": \"^1.3.64\",\n \"chokidar\": \"^3.5.3\",\n \"commander\": \"^10.0.1\",\n \"cosmiconfig\": \"^8.2.0\",\n \"execa\": \"^7.1.1\",\n \"ora\": \"^6.3.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 \"yaml\": \"^2.3.1\"\n },\n \"devDependencies\": {\n \"@kubb/swagger\": \"workspace:*\",\n \"@kubb/ts-config\": \"workspace:*\",\n \"@kubb/tsup-config\": \"workspace:*\",\n \"@types/node\": \"^20.3.1\",\n \"source-map-support\": \"^0.5.21\",\n \"tsup\": \"^6.7.0\",\n \"typescript\": \"^5.1.3\"\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 pathParser from 'node:path'\n\nimport { isPromiseFulfilledResult, write } from '@kubb/core'\n\nimport { $ } from 'execa'\nimport pc from 'picocolors'\n\nimport type { LogLevel } from '@kubb/core'\nimport { spinner } from './program.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 RunProps = {\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 logLevel: 'info',\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 = 'silent', packageManager = 'pnpm' }: RunProps): 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 === '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","import pathParser from 'node:path'\n\nimport { build, ParallelPluginError, PluginError, SummaryError, timeout, createLogger } from '@kubb/core'\n\nimport type { ExecaReturnValue } from 'execa'\nimport { execa } from 'execa'\nimport pc from 'picocolors'\n\nimport { parseArgsStringToArgv } from 'string-argv'\n\nimport { parseHrtimeToSeconds } from './utils/parseHrtimeToSeconds.ts'\nimport { parseText } from './utils/parseText.ts'\n\nimport type { BuildOutput, CLIOptions, KubbConfig, LogLevel } from '@kubb/core'\nimport { OraWritable } from './utils/OraWritable.ts'\nimport { spinner } from './program.ts'\n\ntype RunProps = {\n config: KubbConfig\n options: CLIOptions\n}\n\nexport async function run({ config, options }: RunProps): Promise<void> {\n const hrstart = process.hrtime()\n\n const logger = createLogger(spinner)\n\n const executeHooks = async (hooks: KubbConfig['hooks'], logLevel: LogLevel) => {\n if (!hooks?.done) {\n return\n }\n\n const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done]\n\n if (logLevel === 'silent') {\n spinner.start(`🪂 Executing hooks`)\n }\n type Executer = { subProcess: ExecaReturnValue<string>; abort: AbortController['abort'] }\n\n const executers: Promise<Executer>[] = commands.map(async (command) => {\n const oraWritable = new OraWritable(spinner, command)\n const abortController = new AbortController()\n const [cmd, ..._args] = [...parseArgsStringToArgv(command)]\n\n spinner.start(parseText(`🪂 Executing hook`, { info: ` ${pc.dim(command)}` }, logLevel))\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const subProcess = await execa(cmd, _args, { detached: true, signal: abortController.signal }).pipeStdout!(oraWritable)\n spinner.suffixText = ''\n\n if (logLevel === 'info') {\n spinner.succeed(parseText(`🪂 Executing hook`, { info: ` ${pc.dim(command)}` }, logLevel))\n\n console.log(subProcess.stdout)\n }\n\n // wait for 50ms to be sure that all open files are close(fs)\n await timeout(50)\n\n oraWritable.destroy()\n return { subProcess, abort: abortController.abort.bind(abortController) }\n })\n\n await Promise.all(executers)\n\n if (logLevel === 'silent') {\n spinner.succeed(`🪂 Executing hooks`)\n }\n }\n\n const getSummary = (pluginManager: BuildOutput['pluginManager'], status: 'success' | 'failed'): 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:\n status === 'success'\n ? `${pc.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total`\n : `${pc.red(`${failedPlugins?.length || 0} failed`)}, ${pluginsCount} total`,\n pluginsFailed: status === 'failed' ? failedPlugins?.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 (options.debug) {\n logs.push(pc.bold('Generated files:\\n'))\n logs.push(files.map((file) => `${pc.blue(file.meta?.pluginName)} ${file.path}`).join('\\n'))\n }\n\n logs.push(\n [\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\n try {\n const { root: _root, ...userConfig } = config\n const logLevel = options.logLevel ?? userConfig.logLevel ?? 'silent'\n const inputPath = options.input ?? userConfig.input.path\n\n spinner.start(parseText(`🚀 Building`, { info: `(${pc.dim(inputPath)})` }, logLevel))\n\n const output = await build({\n config: {\n root: process.cwd(),\n ...userConfig,\n logLevel,\n input: {\n ...userConfig.input,\n path: inputPath,\n },\n output: {\n write: true,\n ...userConfig.output,\n },\n },\n logger,\n })\n\n spinner.succeed(parseText(`🚀 Build completed`, { info: `(${pc.dim(inputPath)})` }, logLevel))\n\n await executeHooks(config.hooks, logLevel)\n\n const summary = getSummary(output.pluginManager, 'success')\n console.log(summary.join(''))\n } catch (error: any) {\n if (error instanceof PluginError || error instanceof ParallelPluginError) {\n const summary = getSummary(error.pluginManager, 'failed')\n\n throw new SummaryError('Something went wrong\\n', { cause: error, summary })\n }\n\n throw new SummaryError('Something went wrong\\n', { cause: error })\n }\n}\n","export function parseHrtimeToSeconds(hrtime: [number, number]) {\n const seconds = (hrtime[0] + hrtime[1] / 1e9).toFixed(3)\n return seconds\n}\n","import type { LogLevel } from '@kubb/core'\n\nexport function parseText(baseText: string, config: Partial<Record<LogLevel, string>>, logLevel: LogLevel = 'silent') {\n return `${baseText}${config[logLevel] || ''}`\n}\n","import type { WritableOptions } from 'node:stream'\nimport { Writable } from 'node:stream'\nimport type { Ora } from 'ora'\nimport pc from 'picocolors'\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: NodeJS.BufferEncoding, callback: (error?: Error | null) => void) {\n this.spinner.suffixText = `\\n\\n${pc.bold(pc.blue(this.command))}: ${chunk?.toString()}`\n\n callback()\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, options: 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(options)\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-next-line @typescript-eslint/ban-ts-comment\n// @ts-nocheck\n\nimport { importModule } 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 importedPlugin: any = process.env.NODE_ENV === 'test' ? await import(name) : await importModule(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)\n })\n return Promise.all(promises)\n }\n\n return Promise.resolve(plugins)\n}\n","import pc from 'picocolors'\n\nimport { spinner } from '../program'\n\nexport async function startWatcher(path: string[], cb: (path: string[]) => 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","/* eslint-disable @typescript-eslint/no-unsafe-return */\nimport { importModule } from '@kubb/core'\n\nimport { cosmiconfig } from 'cosmiconfig'\nimport tsNode from 'ts-node'\nimport yaml from 'yaml'\n\nimport type { CosmiconfigResult } from '../types.ts'\n\nconst jsLoader = async (configFile: string) => {\n return importModule(configFile)\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 // eslint-disable-next-line @typescript-eslint/no-empty-function\n let registerer = { enabled() {} }\n\n try {\n // Register TypeScript compiler instance\n registerer = tsNode.register({\n compilerOptions: { module: 'commonjs' },\n swc: true,\n typeCheck: false,\n })\n\n const module = require(configFile)\n\n return module.default\n } catch (err: any) {\n if (err.code === 'MODULE_NOT_FOUND') {\n throw new Error(`'ts-node' is required for the TypeScript configuration files. Make sure it is installed\\nError: ${err.message}`)\n }\n\n throw err\n } finally {\n registerer.enabled()\n }\n}\n\nexport async function getCosmiConfig(moduleName: string, config?: string) {\n const explorer = cosmiconfig(moduleName, {\n cache: false,\n 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 loaders: {\n '.yaml': (filepath, content) => yaml.parse(content),\n '.yml': (filepath, content) => yaml.parse(content),\n '.js': jsLoader,\n '.cjs': jsLoader,\n '.mjs': jsLoader,\n '.ts': tsLoader,\n noExt: jsLoader,\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","import { ParallelPluginError } from '@kubb/core'\nimport PrettyError from 'pretty-error'\n\nexport const prettyError = new PrettyError()\n .skipPackage('commander')\n .skip(function (traceLine, lineNumber) {\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, debug = false }: { prefixText?: string; debug?: boolean }): string {\n if (!error) {\n return ''\n }\n\n if (error instanceof ParallelPluginError) {\n return [prefixText, ...error.errors.map((e) => renderErrors(e, { debug }))].filter(Boolean).join('\\n')\n }\n\n if (debug) {\n const errors = getErrorCauses([error])\n\n return [prefixText, ...errors].filter(Boolean).join('\\n')\n }\n\n // skip when no debug is set\n prettyError.skipNodeFiles()\n prettyError.skip(function () {\n return true\n } as PrettyError.Callback)\n\n return [prefixText, prettyError.render(error.message)].filter(Boolean).join('\\n')\n}\n","import type { Command } from 'commander'\n\nimport { program } from './program.ts'\n\nexport default function runCLI(argv?: readonly string[]): Command {\n return program.parse(argv)\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Generator cli",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"!/**/__tests__/**"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@swc/core": "^1.3.
|
|
34
|
+
"@swc/core": "^1.3.64",
|
|
35
35
|
"chokidar": "^3.5.3",
|
|
36
36
|
"commander": "^10.0.1",
|
|
37
37
|
"cosmiconfig": "^8.2.0",
|
|
@@ -42,13 +42,14 @@
|
|
|
42
42
|
"string-argv": "^0.3.2",
|
|
43
43
|
"ts-node": "^10.9.1",
|
|
44
44
|
"yaml": "^2.3.1",
|
|
45
|
-
"@kubb/core": "1.
|
|
45
|
+
"@kubb/core": "1.2.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/node": "^20.3.1",
|
|
49
|
+
"source-map-support": "^0.5.21",
|
|
49
50
|
"tsup": "^6.7.0",
|
|
50
51
|
"typescript": "^5.1.3",
|
|
51
|
-
"@kubb/swagger": "1.
|
|
52
|
+
"@kubb/swagger": "1.2.0",
|
|
52
53
|
"@kubb/ts-config": "0.1.0",
|
|
53
54
|
"@kubb/tsup-config": "1.1.8"
|
|
54
55
|
},
|
|
@@ -65,12 +66,11 @@
|
|
|
65
66
|
"scripts": {
|
|
66
67
|
"build": "tsup",
|
|
67
68
|
"clean": "rimraf ./dist",
|
|
68
|
-
"lint": "eslint
|
|
69
|
+
"lint": "eslint --format pretty ./src",
|
|
69
70
|
"lint-fix": "bun run lint --quiet --fix",
|
|
70
71
|
"release": "pnpm publish --no-git-check",
|
|
71
72
|
"start": "tsup --watch",
|
|
72
73
|
"test": "vitest --passWithNoTests",
|
|
73
|
-
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
|
74
|
-
"upgrade": "pnpm update"
|
|
74
|
+
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
|
75
75
|
}
|
|
76
76
|
}
|