@kubb/cli 1.15.0-canary.20231112T135054 → 2.0.0-alpha.10
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/README.md +1 -1
- package/bin/kubb.js +2 -2
- package/dist/index.cjs +148 -140
- 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 +133 -128
- package/dist/index.js.map +1 -1
- package/package.json +16 -8
- package/src/generate.ts +137 -0
- package/src/index.ts +96 -0
- package/src/init.ts +94 -0
- package/src/utils/OraWritable.ts +27 -0
- package/src/utils/getConfig.ts +37 -0
- package/src/utils/getCosmiConfig.ts +82 -0
- package/src/utils/getPlugins.ts +41 -0
- package/src/utils/getSummary.ts +84 -0
- package/src/utils/parseHrtimeToSeconds.ts +4 -0
- package/src/utils/renderErrors.ts +55 -0
- package/src/utils/spinner.ts +5 -0
- package/src/utils/watcher.ts +27 -0
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
</p>
|
|
19
19
|
|
|
20
20
|
<h4>
|
|
21
|
-
<a href="https://codesandbox.io/s/github/kubb-project/kubb/tree/
|
|
21
|
+
<a href="https://codesandbox.io/s/github/kubb-project/kubb/tree/alpha/examples/typescript" target="_blank">View Demo</a>
|
|
22
22
|
<span> · </span>
|
|
23
23
|
<a href="https://kubb.dev/" target="_blank">Documentation</a>
|
|
24
24
|
<span> · </span>
|
package/bin/kubb.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var path = require('path');
|
|
4
6
|
var core = require('@kubb/core');
|
|
5
7
|
var cac = require('cac');
|
|
6
|
-
var
|
|
8
|
+
var pc2 = require('picocolors');
|
|
9
|
+
var utils = require('@kubb/core/utils');
|
|
7
10
|
var cosmiconfig = require('cosmiconfig');
|
|
8
11
|
var tsNode = require('ts-node');
|
|
9
|
-
var stream = require('stream');
|
|
10
12
|
var PrettyError = require('pretty-error');
|
|
11
13
|
var ora = require('ora');
|
|
12
14
|
var execa = require('execa');
|
|
13
15
|
var stringArgv = require('string-argv');
|
|
16
|
+
var stream = require('stream');
|
|
14
17
|
|
|
15
18
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
19
|
|
|
17
|
-
var
|
|
18
|
-
var
|
|
20
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
21
|
+
var pc2__default = /*#__PURE__*/_interopDefault(pc2);
|
|
19
22
|
var tsNode__default = /*#__PURE__*/_interopDefault(tsNode);
|
|
20
23
|
var PrettyError__default = /*#__PURE__*/_interopDefault(PrettyError);
|
|
21
24
|
var ora__default = /*#__PURE__*/_interopDefault(ora);
|
|
@@ -29,10 +32,10 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
29
32
|
});
|
|
30
33
|
|
|
31
34
|
// package.json
|
|
32
|
-
var version = "
|
|
35
|
+
var version = "2.0.0-alpha.10";
|
|
33
36
|
function isJSONPlugins(plugins) {
|
|
34
37
|
return !!plugins?.some((plugin) => {
|
|
35
|
-
return typeof plugin?.
|
|
38
|
+
return Array.isArray(plugin) && typeof plugin?.at(0) === "string";
|
|
36
39
|
});
|
|
37
40
|
}
|
|
38
41
|
function isObjectPlugins(plugins) {
|
|
@@ -40,18 +43,16 @@ function isObjectPlugins(plugins) {
|
|
|
40
43
|
}
|
|
41
44
|
async function importPlugin(name, options) {
|
|
42
45
|
const packageManager = new core.PackageManager(process.cwd());
|
|
43
|
-
const importedPlugin = process.env.NODE_ENV === "test" ? await import(name) : await packageManager.import(name
|
|
46
|
+
const importedPlugin = process.env.NODE_ENV === "test" ? await import(name) : await packageManager.import(name);
|
|
44
47
|
return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options);
|
|
45
48
|
}
|
|
46
49
|
function getPlugins(plugins) {
|
|
47
50
|
if (isObjectPlugins(plugins)) {
|
|
48
|
-
|
|
49
|
-
return importPlugin(name, plugins[name]);
|
|
50
|
-
});
|
|
51
|
-
return Promise.all(promises);
|
|
51
|
+
throw new Error("Object plugins are not supported anymore, best to use http://kubb.dev/guide/configure#json");
|
|
52
52
|
}
|
|
53
53
|
if (isJSONPlugins(plugins)) {
|
|
54
|
-
const
|
|
54
|
+
const jsonPlugins = plugins;
|
|
55
|
+
const promises = jsonPlugins.map((plugin) => {
|
|
55
56
|
const [name, options = {}] = plugin;
|
|
56
57
|
return importPlugin(name, options);
|
|
57
58
|
});
|
|
@@ -66,12 +67,18 @@ async function getConfig(result, CLIOptions) {
|
|
|
66
67
|
let kubbUserConfig = Promise.resolve(config);
|
|
67
68
|
if (typeof config === "function") {
|
|
68
69
|
const possiblePromise = config(CLIOptions);
|
|
69
|
-
if (
|
|
70
|
+
if (utils.isPromise(possiblePromise)) {
|
|
70
71
|
kubbUserConfig = possiblePromise;
|
|
71
72
|
}
|
|
72
73
|
kubbUserConfig = Promise.resolve(possiblePromise);
|
|
73
74
|
}
|
|
74
75
|
let JSONConfig = await kubbUserConfig;
|
|
76
|
+
if (Array.isArray(JSONConfig)) {
|
|
77
|
+
const promises = JSONConfig.map(async (item) => {
|
|
78
|
+
return { ...item, plugins: item.plugins ? await getPlugins(item.plugins) : void 0 };
|
|
79
|
+
});
|
|
80
|
+
return Promise.all(promises);
|
|
81
|
+
}
|
|
75
82
|
JSONConfig = {
|
|
76
83
|
...JSONConfig,
|
|
77
84
|
plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
|
|
@@ -136,27 +143,6 @@ async function getCosmiConfig(moduleName2, config) {
|
|
|
136
143
|
}
|
|
137
144
|
return result;
|
|
138
145
|
}
|
|
139
|
-
var OraWritable = class extends stream.Writable {
|
|
140
|
-
command;
|
|
141
|
-
spinner;
|
|
142
|
-
constructor(spinner2, command, opts) {
|
|
143
|
-
super(opts);
|
|
144
|
-
this.command = command;
|
|
145
|
-
this.spinner = spinner2;
|
|
146
|
-
}
|
|
147
|
-
_write(chunk, _encoding, callback2) {
|
|
148
|
-
this.spinner.suffixText = `
|
|
149
|
-
|
|
150
|
-
${pc3__default.default.bold(pc3__default.default.blue(this.command))}: ${chunk?.toString()}`;
|
|
151
|
-
callback2();
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
// src/utils/parseHrtimeToSeconds.ts
|
|
156
|
-
function parseHrtimeToSeconds(hrtime) {
|
|
157
|
-
const seconds = (hrtime[0] + hrtime[1] / 1e9).toFixed(3);
|
|
158
|
-
return seconds;
|
|
159
|
-
}
|
|
160
146
|
var prettyError = new PrettyError__default.default().skipPackage("commander").skip(function callback(traceLine) {
|
|
161
147
|
const pattern = new RegExp("renderErrors");
|
|
162
148
|
const hasMatch = traceLine?.file?.match(pattern);
|
|
@@ -174,84 +160,90 @@ function getErrorCauses(errors) {
|
|
|
174
160
|
return prev;
|
|
175
161
|
}, []).filter(Boolean);
|
|
176
162
|
}
|
|
177
|
-
function renderErrors(error, {
|
|
163
|
+
function renderErrors(error, { logLevel = utils.LogLevel.silent }) {
|
|
178
164
|
if (!error) {
|
|
179
165
|
return "";
|
|
180
166
|
}
|
|
181
|
-
if (
|
|
182
|
-
return [prefixText, ...error.errors.map((e) => renderErrors(e, { logLevel }))].filter(Boolean).join("\n");
|
|
183
|
-
}
|
|
184
|
-
if (logLevel === core.LogLevel.silent) {
|
|
167
|
+
if (logLevel === utils.LogLevel.silent) {
|
|
185
168
|
prettyError.skipNodeFiles();
|
|
186
169
|
prettyError.skip(function skip() {
|
|
187
170
|
return true;
|
|
188
171
|
});
|
|
189
|
-
return [
|
|
172
|
+
return [prettyError.render(error)].filter(Boolean).join("\n");
|
|
190
173
|
}
|
|
191
174
|
const errors = getErrorCauses([error]);
|
|
192
|
-
return
|
|
175
|
+
return errors.filter(Boolean).join("\n");
|
|
193
176
|
}
|
|
194
177
|
var spinner = ora__default.default({
|
|
195
178
|
spinner: "clock"
|
|
196
179
|
});
|
|
197
|
-
async function startWatcher(
|
|
180
|
+
async function startWatcher(path4, cb) {
|
|
198
181
|
const { watch } = await import('chokidar');
|
|
199
182
|
const ignored = ["**/{.git,node_modules}/**"];
|
|
200
|
-
const watcher = watch(
|
|
183
|
+
const watcher = watch(path4, {
|
|
201
184
|
ignorePermissionErrors: true,
|
|
202
185
|
ignored
|
|
203
186
|
});
|
|
204
187
|
watcher.on("all", (type, file) => {
|
|
205
|
-
spinner.succeed(
|
|
188
|
+
spinner.succeed(pc2__default.default.yellow(pc2__default.default.bold(`Change detected: ${type} ${file}`)));
|
|
206
189
|
spinner.spinner = "clock";
|
|
207
190
|
try {
|
|
208
|
-
cb(
|
|
191
|
+
cb(path4);
|
|
209
192
|
} catch (e) {
|
|
210
|
-
spinner.warn(
|
|
193
|
+
spinner.warn(pc2__default.default.red("Watcher failed"));
|
|
211
194
|
}
|
|
212
195
|
});
|
|
213
196
|
return;
|
|
214
197
|
}
|
|
198
|
+
|
|
199
|
+
// src/utils/parseHrtimeToSeconds.ts
|
|
200
|
+
function parseHrtimeToSeconds(hrtime) {
|
|
201
|
+
const seconds = (hrtime[0] + hrtime[1] / 1e9).toFixed(3);
|
|
202
|
+
return seconds;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// src/utils/getSummary.ts
|
|
215
206
|
function getSummary({ pluginManager, status, hrstart, config, logLevel }) {
|
|
216
207
|
const logs = [];
|
|
217
208
|
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrstart));
|
|
218
|
-
const buildStartPlugins =
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const failedPlugins = config.plugins?.filter((plugin) => !buildStartPlugins.includes(plugin.name))?.map((plugin) => plugin.name);
|
|
209
|
+
const buildStartPlugins = pluginManager.executed.filter((item) => item.hookName === "buildStart" && item.plugin.name !== "core").map((item) => item.plugin.name);
|
|
210
|
+
const buildEndPlugins = pluginManager.executed.filter((item) => item.hookName === "buildEnd" && item.plugin.name !== "core").map((item) => item.plugin.name);
|
|
211
|
+
const failedPlugins = config.plugins?.filter((plugin) => !buildEndPlugins.includes(plugin.name))?.map((plugin) => plugin.name);
|
|
222
212
|
const pluginsCount = config.plugins?.length || 0;
|
|
223
213
|
const files = pluginManager.fileManager.files.sort((a, b) => {
|
|
224
|
-
if (!a.meta?.
|
|
214
|
+
if (!a.meta?.pluginKey?.[1] || !b.meta?.pluginKey?.[1]) {
|
|
225
215
|
return 0;
|
|
226
216
|
}
|
|
227
|
-
if (a.meta?.
|
|
217
|
+
if (a.meta?.pluginKey?.[1]?.length < b.meta?.pluginKey?.[1]?.length) {
|
|
228
218
|
return 1;
|
|
229
219
|
}
|
|
230
|
-
if (a.meta?.
|
|
220
|
+
if (a.meta?.pluginKey?.[1]?.length > b.meta?.pluginKey?.[1]?.length) {
|
|
231
221
|
return -1;
|
|
232
222
|
}
|
|
233
223
|
return 0;
|
|
234
224
|
});
|
|
235
225
|
const meta = {
|
|
236
|
-
|
|
237
|
-
|
|
226
|
+
name: config.name,
|
|
227
|
+
plugins: status === "success" ? `${pc2__default.default.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total` : `${pc2__default.default.red(`${failedPlugins?.length ?? 1} failed`)}, ${pluginsCount} total`,
|
|
228
|
+
pluginsFailed: status === "failed" ? failedPlugins?.map((name) => utils.randomPicoColour(name))?.join(", ") : void 0,
|
|
238
229
|
filesCreated: files.length,
|
|
239
|
-
time:
|
|
240
|
-
output:
|
|
230
|
+
time: pc2__default.default.yellow(`${elapsedSeconds}s`),
|
|
231
|
+
output: path__default.default.resolve(config.root, config.output.path)
|
|
241
232
|
};
|
|
242
|
-
if (logLevel ===
|
|
243
|
-
logs.push(
|
|
244
|
-
logs.push(files.map((file) => `${
|
|
233
|
+
if (logLevel === utils.LogLevel.debug) {
|
|
234
|
+
logs.push(pc2__default.default.bold("\nGenerated files:\n"));
|
|
235
|
+
logs.push(files.map((file) => `${utils.randomPicoColour(JSON.stringify(file.meta?.pluginKey))} ${file.path}`).join("\n"));
|
|
245
236
|
}
|
|
246
237
|
logs.push(
|
|
247
238
|
[
|
|
248
239
|
[`
|
|
249
240
|
`, true],
|
|
250
|
-
[`
|
|
251
|
-
[`
|
|
252
|
-
[
|
|
253
|
-
[
|
|
254
|
-
[`
|
|
241
|
+
[` ${pc2__default.default.bold("Name:")} ${meta.name}`, !!meta.name],
|
|
242
|
+
[` ${pc2__default.default.bold("Plugins:")} ${meta.plugins}`, true],
|
|
243
|
+
[` ${pc2__default.default.dim("Failed:")} ${meta.pluginsFailed || "none"}`, !!meta.pluginsFailed],
|
|
244
|
+
[`${pc2__default.default.bold("Generated:")} ${meta.filesCreated} files`, true],
|
|
245
|
+
[` ${pc2__default.default.bold("Time:")} ${meta.time}`, true],
|
|
246
|
+
[` ${pc2__default.default.bold("Output:")} ${meta.output}`, true],
|
|
255
247
|
[`
|
|
256
248
|
`, true]
|
|
257
249
|
].map((item) => {
|
|
@@ -263,6 +255,19 @@ function getSummary({ pluginManager, status, hrstart, config, logLevel }) {
|
|
|
263
255
|
);
|
|
264
256
|
return logs;
|
|
265
257
|
}
|
|
258
|
+
var OraWritable = class extends stream.Writable {
|
|
259
|
+
constructor(spinner2, command, opts) {
|
|
260
|
+
super(opts);
|
|
261
|
+
this.command = command;
|
|
262
|
+
this.spinner = spinner2;
|
|
263
|
+
}
|
|
264
|
+
_write(chunk, _encoding, callback2) {
|
|
265
|
+
this.spinner.suffixText = `
|
|
266
|
+
|
|
267
|
+
${pc2__default.default.bold(pc2__default.default.blue(this.command))}: ${chunk?.toString()}`;
|
|
268
|
+
callback2();
|
|
269
|
+
}
|
|
270
|
+
};
|
|
266
271
|
|
|
267
272
|
// src/generate.ts
|
|
268
273
|
async function executeHooks({ hooks, logLevel }) {
|
|
@@ -270,7 +275,7 @@ async function executeHooks({ hooks, logLevel }) {
|
|
|
270
275
|
return;
|
|
271
276
|
}
|
|
272
277
|
const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done];
|
|
273
|
-
if (logLevel ===
|
|
278
|
+
if (logLevel === utils.LogLevel.silent) {
|
|
274
279
|
spinner.start(`Executing hooks`);
|
|
275
280
|
}
|
|
276
281
|
const executers = commands.map(async (command) => {
|
|
@@ -280,66 +285,66 @@ async function executeHooks({ hooks, logLevel }) {
|
|
|
280
285
|
if (!cmd) {
|
|
281
286
|
return null;
|
|
282
287
|
}
|
|
283
|
-
|
|
284
|
-
spinner.start(`Executing hook ${logLevel !== "silent" ? pc3__default.default.dim(command) : ""}`);
|
|
288
|
+
spinner.start(`Executing hook ${logLevel !== "silent" ? pc2__default.default.dim(command) : ""}`);
|
|
285
289
|
const subProcess = await execa.execa(cmd, _args, { detached: true, signal: abortController.signal }).pipeStdout(oraWritable);
|
|
286
290
|
spinner.suffixText = "";
|
|
287
|
-
if (logLevel ===
|
|
288
|
-
spinner.succeed(`Executing hook ${logLevel !== "silent" ?
|
|
291
|
+
if (logLevel === utils.LogLevel.silent) {
|
|
292
|
+
spinner.succeed(`Executing hook ${logLevel !== "silent" ? pc2__default.default.dim(command) : ""}`);
|
|
289
293
|
console.log(subProcess.stdout);
|
|
290
294
|
}
|
|
291
295
|
oraWritable.destroy();
|
|
292
296
|
return { subProcess, abort: abortController.abort.bind(abortController) };
|
|
293
297
|
}).filter(Boolean);
|
|
294
|
-
await core.timeout(100);
|
|
295
298
|
await Promise.all(executers);
|
|
296
|
-
if (logLevel ===
|
|
299
|
+
if (logLevel === utils.LogLevel.silent) {
|
|
297
300
|
spinner.succeed(`Executing hooks`);
|
|
298
301
|
}
|
|
299
302
|
}
|
|
300
|
-
async function generate({ input, config, CLIOptions
|
|
303
|
+
async function generate({ input, config, CLIOptions }) {
|
|
304
|
+
const logger = utils.createLogger({ logLevel: CLIOptions.logLevel || utils.LogLevel.silent, name: config.name, spinner });
|
|
305
|
+
if (logger.name) {
|
|
306
|
+
spinner.prefixText = utils.randomPicoColour(logger.name);
|
|
307
|
+
}
|
|
301
308
|
const hrstart = process.hrtime();
|
|
302
|
-
if (CLIOptions.logLevel ===
|
|
309
|
+
if (CLIOptions.logLevel === utils.LogLevel.debug) {
|
|
303
310
|
const { performance, PerformanceObserver } = await import('perf_hooks');
|
|
304
311
|
const performanceOpserver = new PerformanceObserver((items) => {
|
|
305
312
|
const message = `${items.getEntries()[0]?.duration.toFixed(0)}ms`;
|
|
306
|
-
spinner.suffixText =
|
|
313
|
+
spinner.suffixText = pc2__default.default.yellow(message);
|
|
307
314
|
performance.clearMarks();
|
|
308
315
|
});
|
|
309
316
|
performanceOpserver.observe({ type: "measure" });
|
|
310
317
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
input
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
318
|
+
const { root: _root, ...userConfig } = config;
|
|
319
|
+
const logLevel = logger.logLevel;
|
|
320
|
+
const inputPath = input ?? ("path" in userConfig.input ? userConfig.input.path : void 0);
|
|
321
|
+
spinner.start(`\u{1F680} Building ${logLevel !== "silent" ? pc2__default.default.dim(inputPath) : ""}`);
|
|
322
|
+
const { pluginManager, error } = await core.safeBuild({
|
|
323
|
+
config: {
|
|
324
|
+
root: process.cwd(),
|
|
325
|
+
...userConfig,
|
|
326
|
+
input: inputPath ? {
|
|
327
|
+
...userConfig.input,
|
|
328
|
+
path: inputPath
|
|
329
|
+
} : userConfig.input,
|
|
330
|
+
output: {
|
|
331
|
+
write: true,
|
|
332
|
+
...userConfig.output
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
logger
|
|
336
|
+
});
|
|
337
|
+
const summary = getSummary({ pluginManager, config, status: error ? "failed" : "success", hrstart, logLevel: CLIOptions.logLevel });
|
|
338
|
+
if (error) {
|
|
331
339
|
spinner.suffixText = "";
|
|
332
|
-
spinner.
|
|
333
|
-
await executeHooks({ hooks: config.hooks, logLevel });
|
|
334
|
-
const summary = getSummary({ pluginManager: output.pluginManager, config, status: "success", hrstart, logLevel: CLIOptions.logLevel });
|
|
340
|
+
spinner.fail(`\u{1F680} Build failed ${logLevel !== "silent" ? pc2__default.default.dim(inputPath) : ""}`);
|
|
335
341
|
console.log(summary.join(""));
|
|
336
|
-
|
|
337
|
-
let summary = [];
|
|
338
|
-
if (error instanceof core.PluginError || error instanceof core.ParallelPluginError) {
|
|
339
|
-
summary = getSummary({ pluginManager: error.pluginManager, config, status: "failed", hrstart, logLevel: CLIOptions.logLevel });
|
|
340
|
-
}
|
|
341
|
-
throw new core.SummaryError("Something went wrong\n", { cause: error, summary });
|
|
342
|
+
throw error;
|
|
342
343
|
}
|
|
344
|
+
await executeHooks({ hooks: config.hooks, logLevel });
|
|
345
|
+
spinner.suffixText = "";
|
|
346
|
+
spinner.succeed(`\u{1F680} Build completed ${logLevel !== "silent" ? pc2__default.default.dim(inputPath) : ""}`);
|
|
347
|
+
console.log(summary.join(""));
|
|
343
348
|
}
|
|
344
349
|
var presets = {
|
|
345
350
|
simple: {
|
|
@@ -359,7 +364,7 @@ export default defineConfig({
|
|
|
359
364
|
clean: true,
|
|
360
365
|
},
|
|
361
366
|
hooks: {
|
|
362
|
-
done: 'echo "\u{1F389} done"',
|
|
367
|
+
done: ['echo "\u{1F389} done"'],
|
|
363
368
|
},
|
|
364
369
|
plugins: [createSwagger({}), createSwaggerTS({ output: 'models', enumType: 'enum' }), createSwaggerTanstackQuery({ output: './hooks' })],
|
|
365
370
|
})
|
|
@@ -367,26 +372,26 @@ export default defineConfig({
|
|
|
367
372
|
packages: ["@kubb/core", "@kubb/cli", "@kubb/swagger", "@kubb/swagger-ts", "@kubb/swagger-tanstack-query"]
|
|
368
373
|
}
|
|
369
374
|
};
|
|
370
|
-
async function init({ preset = "simple", logLevel =
|
|
375
|
+
async function init({ preset = "simple", logLevel = utils.LogLevel.silent, packageManager = "pnpm" }) {
|
|
371
376
|
spinner.start("\u{1F4E6} Initializing Kubb");
|
|
372
377
|
const presetMeta = presets[preset];
|
|
373
|
-
const
|
|
378
|
+
const configPath = path__default.default.resolve(process.cwd(), "./kubb.config.js");
|
|
374
379
|
const installCommand = packageManager === "npm" ? "install" : "add";
|
|
375
|
-
spinner.start(`\u{1F4C0} Writing \`kubb.config.js\` ${
|
|
376
|
-
await
|
|
377
|
-
spinner.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${
|
|
380
|
+
spinner.start(`\u{1F4C0} Writing \`kubb.config.js\` ${pc2__default.default.dim(configPath)}`);
|
|
381
|
+
await utils.write(presetMeta["kubb.config"], configPath);
|
|
382
|
+
spinner.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${pc2__default.default.dim(configPath)}`);
|
|
378
383
|
const results = await Promise.allSettled([
|
|
379
384
|
execa.$`npm init es6 -y`,
|
|
380
385
|
...presetMeta.packages.map(async (pack) => {
|
|
381
|
-
spinner.start(`\u{1F4C0} Installing ${
|
|
386
|
+
spinner.start(`\u{1F4C0} Installing ${pc2__default.default.dim(pack)}`);
|
|
382
387
|
const { stdout } = await execa.$({ preferLocal: false })`${packageManager} ${installCommand} ${pack}`;
|
|
383
|
-
spinner.succeed(`\u{1F4C0} Installed ${
|
|
388
|
+
spinner.succeed(`\u{1F4C0} Installed ${pc2__default.default.dim(pack)}`);
|
|
384
389
|
return stdout;
|
|
385
390
|
})
|
|
386
391
|
]);
|
|
387
|
-
if (logLevel ===
|
|
392
|
+
if (logLevel === utils.LogLevel.info) {
|
|
388
393
|
results.forEach((result) => {
|
|
389
|
-
if (
|
|
394
|
+
if (utils.isPromiseFulfilledResult(result)) {
|
|
390
395
|
console.log(result.value);
|
|
391
396
|
}
|
|
392
397
|
});
|
|
@@ -397,41 +402,42 @@ async function init({ preset = "simple", logLevel = core.LogLevel.silent, packag
|
|
|
397
402
|
|
|
398
403
|
// src/index.ts
|
|
399
404
|
var moduleName = "kubb";
|
|
400
|
-
var logger = core.createLogger(spinner);
|
|
401
405
|
function programCatcher(e, CLIOptions) {
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
const summaryError = error instanceof core.SummaryError ? error : void 0;
|
|
405
|
-
if (summaryError) {
|
|
406
|
-
error = summaryError.cause;
|
|
407
|
-
}
|
|
408
|
-
const message = renderErrors(error, { logLevel: CLIOptions.logLevel, prefixText: pc3__default.default.red(originalError?.message) });
|
|
406
|
+
const error = e;
|
|
407
|
+
const message = renderErrors(error, { logLevel: CLIOptions.logLevel });
|
|
409
408
|
if (error instanceof core.Warning) {
|
|
410
|
-
spinner.warn(
|
|
409
|
+
spinner.warn(pc2__default.default.yellow(error.message));
|
|
411
410
|
process.exit(0);
|
|
412
411
|
}
|
|
413
|
-
|
|
414
|
-
spinner.fail(message);
|
|
415
|
-
process.exit(1);
|
|
416
|
-
}
|
|
417
|
-
spinner.fail([message, ...summaryError?.summary || []].join("\n"));
|
|
412
|
+
spinner.fail(message);
|
|
418
413
|
process.exit(1);
|
|
419
414
|
}
|
|
420
415
|
async function generateAction(input, CLIOptions) {
|
|
421
|
-
spinner.start("\u{
|
|
416
|
+
spinner.start("\u{1F50D} Loading config");
|
|
422
417
|
const result = await getCosmiConfig(moduleName, CLIOptions.config);
|
|
423
|
-
spinner.succeed(`\u{
|
|
418
|
+
spinner.succeed(`\u{1F50D} Config loaded(${pc2__default.default.dim(path__default.default.relative(process.cwd(), result.filepath))})`);
|
|
424
419
|
const config = await getConfig(result, CLIOptions);
|
|
425
|
-
if (CLIOptions.watch
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
420
|
+
if (CLIOptions.watch) {
|
|
421
|
+
if (Array.isArray(config)) {
|
|
422
|
+
throw new Error("Cannot use watcher with multiple KubbConfigs(array)");
|
|
423
|
+
}
|
|
424
|
+
if (core.isInputPath(config)) {
|
|
425
|
+
return startWatcher([input || config.input.path], async (paths) => {
|
|
426
|
+
await generate({ config, CLIOptions });
|
|
427
|
+
spinner.spinner = "simpleDotsScrolling";
|
|
428
|
+
spinner.start(pc2__default.default.yellow(pc2__default.default.bold(`Watching for changes in ${paths.join(" and ")}`)));
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (Array.isArray(config)) {
|
|
433
|
+
const promiseManager = new core.PromiseManager();
|
|
434
|
+
const promises = config.map((item) => () => generate({ input, config: item, CLIOptions }));
|
|
435
|
+
await promiseManager.run("seq", promises);
|
|
436
|
+
return;
|
|
431
437
|
}
|
|
432
|
-
await generate({ input, config, CLIOptions
|
|
438
|
+
await generate({ input, config, CLIOptions });
|
|
433
439
|
}
|
|
434
|
-
async function
|
|
440
|
+
async function run(argv) {
|
|
435
441
|
const program = cac.cac(moduleName);
|
|
436
442
|
program.command("[input]", "Path of the input file(overrides the one in `kubb.config.js`)").action(generateAction);
|
|
437
443
|
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);
|
|
@@ -448,7 +454,9 @@ async function runCLI(argv) {
|
|
|
448
454
|
programCatcher(e, program.options);
|
|
449
455
|
}
|
|
450
456
|
}
|
|
457
|
+
var src_default = run;
|
|
451
458
|
|
|
452
|
-
|
|
459
|
+
exports.default = src_default;
|
|
460
|
+
exports.run = run;
|
|
453
461
|
//# sourceMappingURL=out.js.map
|
|
454
462
|
//# sourceMappingURL=index.cjs.map
|