@kubb/cli 1.14.0 → 1.14.1
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 +16 -17
- package/dist/index.cjs +204 -206
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +203 -205
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
2
|
import pathParser from 'path';
|
|
3
|
-
import { createLogger, write, LogLevel, isPromiseFulfilledResult, Warning,
|
|
3
|
+
import { createLogger, write, LogLevel, isPromiseFulfilledResult, Warning, isPromise, ParallelPluginError, build, PluginError, SummaryError, randomPicoColour, timeout, importModule } from '@kubb/core';
|
|
4
4
|
import { cac } from 'cac';
|
|
5
|
-
import
|
|
6
|
-
import { $, execa } from 'execa';
|
|
7
|
-
import { parseArgsStringToArgv } from 'string-argv';
|
|
8
|
-
import { Writable } from 'stream';
|
|
9
|
-
import ora from 'ora';
|
|
5
|
+
import pc3 from 'picocolors';
|
|
10
6
|
import { cosmiconfig } from 'cosmiconfig';
|
|
11
7
|
import tsNode from 'ts-node';
|
|
8
|
+
import { Writable } from 'stream';
|
|
12
9
|
import PrettyError from 'pretty-error';
|
|
10
|
+
import ora from 'ora';
|
|
11
|
+
import { $, execa } from 'execa';
|
|
12
|
+
import { parseArgsStringToArgv } from 'string-argv';
|
|
13
13
|
|
|
14
14
|
const require = createRequire(import.meta.url);
|
|
15
15
|
|
|
@@ -22,15 +22,188 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
// package.json
|
|
25
|
-
var version = "1.14.
|
|
25
|
+
var version = "1.14.1";
|
|
26
|
+
function isJSONPlugins(plugins) {
|
|
27
|
+
return !!plugins?.some((plugin) => {
|
|
28
|
+
return typeof plugin?.[0] === "string";
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function isObjectPlugins(plugins) {
|
|
32
|
+
return plugins instanceof Object && !Array.isArray(plugins);
|
|
33
|
+
}
|
|
34
|
+
async function importPlugin(name, options) {
|
|
35
|
+
const importedPlugin = process.env.NODE_ENV === "test" ? await import(name) : await importModule(name, process.cwd());
|
|
36
|
+
return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options);
|
|
37
|
+
}
|
|
38
|
+
function getPlugins(plugins) {
|
|
39
|
+
if (isObjectPlugins(plugins)) {
|
|
40
|
+
const promises = Object.keys(plugins).map((name) => {
|
|
41
|
+
return importPlugin(name, plugins[name]);
|
|
42
|
+
});
|
|
43
|
+
return Promise.all(promises);
|
|
44
|
+
}
|
|
45
|
+
if (isJSONPlugins(plugins)) {
|
|
46
|
+
const promises = plugins.map((plugin) => {
|
|
47
|
+
const [name, options = {}] = plugin;
|
|
48
|
+
return importPlugin(name, options);
|
|
49
|
+
});
|
|
50
|
+
return Promise.all(promises);
|
|
51
|
+
}
|
|
52
|
+
return Promise.resolve(plugins);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/utils/getConfig.ts
|
|
56
|
+
async function getConfig(result, CLIOptions) {
|
|
57
|
+
const config = result?.config;
|
|
58
|
+
let kubbUserConfig = Promise.resolve(config);
|
|
59
|
+
if (typeof config === "function") {
|
|
60
|
+
const possiblePromise = config(CLIOptions);
|
|
61
|
+
if (isPromise(possiblePromise)) {
|
|
62
|
+
kubbUserConfig = possiblePromise;
|
|
63
|
+
}
|
|
64
|
+
kubbUserConfig = Promise.resolve(possiblePromise);
|
|
65
|
+
}
|
|
66
|
+
let JSONConfig = await kubbUserConfig;
|
|
67
|
+
JSONConfig = {
|
|
68
|
+
...JSONConfig,
|
|
69
|
+
plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
|
|
70
|
+
};
|
|
71
|
+
return JSONConfig;
|
|
72
|
+
}
|
|
73
|
+
var tsLoader = (configFile) => {
|
|
74
|
+
let registerer = { enabled() {
|
|
75
|
+
} };
|
|
76
|
+
try {
|
|
77
|
+
registerer = tsNode.register({
|
|
78
|
+
compilerOptions: { module: "commonjs" },
|
|
79
|
+
typeCheck: false
|
|
80
|
+
});
|
|
81
|
+
const module = __require(configFile);
|
|
82
|
+
return module.default;
|
|
83
|
+
} catch (err) {
|
|
84
|
+
const error = err;
|
|
85
|
+
if (error.name === "MODULE_NOT_FOUND") {
|
|
86
|
+
throw new Error(`'ts-node' is required for the TypeScript configuration files. Make sure it is installed
|
|
87
|
+
Error: ${error.message}`);
|
|
88
|
+
}
|
|
89
|
+
throw error;
|
|
90
|
+
} finally {
|
|
91
|
+
registerer.enabled();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
async function getCosmiConfig(moduleName2, config) {
|
|
95
|
+
const searchPlaces = [
|
|
96
|
+
"package.json",
|
|
97
|
+
`.${moduleName2}rc`,
|
|
98
|
+
`.${moduleName2}rc.json`,
|
|
99
|
+
`.${moduleName2}rc.yaml`,
|
|
100
|
+
`.${moduleName2}rc.yml`,
|
|
101
|
+
`.${moduleName2}rc.ts`,
|
|
102
|
+
`.${moduleName2}rc.js`,
|
|
103
|
+
`.${moduleName2}rc.cjs`,
|
|
104
|
+
`.${moduleName2}rc.mjs`,
|
|
105
|
+
`${moduleName2}.config.ts`,
|
|
106
|
+
`${moduleName2}.config.js`,
|
|
107
|
+
`${moduleName2}.config.cjs`,
|
|
108
|
+
`${moduleName2}.config.mjs`
|
|
109
|
+
];
|
|
110
|
+
const explorer = cosmiconfig(moduleName2, {
|
|
111
|
+
cache: false,
|
|
112
|
+
searchPlaces: [
|
|
113
|
+
...searchPlaces.map((searchPlace) => {
|
|
114
|
+
return `.config/${searchPlace}`;
|
|
115
|
+
}),
|
|
116
|
+
...searchPlaces.map((searchPlace) => {
|
|
117
|
+
return `configs/${searchPlace}`;
|
|
118
|
+
}),
|
|
119
|
+
...searchPlaces
|
|
120
|
+
],
|
|
121
|
+
loaders: {
|
|
122
|
+
".ts": tsLoader
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
const result = config ? await explorer.load(config) : await explorer.search();
|
|
126
|
+
if (result?.isEmpty || !result || !result.config) {
|
|
127
|
+
throw new Error("Config not defined, create a kubb.config.js or pass through your config with the option --config");
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
var OraWritable = class extends Writable {
|
|
132
|
+
command;
|
|
133
|
+
spinner;
|
|
134
|
+
constructor(spinner2, command, opts) {
|
|
135
|
+
super(opts);
|
|
136
|
+
this.command = command;
|
|
137
|
+
this.spinner = spinner2;
|
|
138
|
+
}
|
|
139
|
+
_write(chunk, _encoding, callback2) {
|
|
140
|
+
this.spinner.suffixText = `
|
|
141
|
+
|
|
142
|
+
${pc3.bold(pc3.blue(this.command))}: ${chunk?.toString()}`;
|
|
143
|
+
callback2();
|
|
144
|
+
}
|
|
145
|
+
};
|
|
26
146
|
|
|
27
147
|
// src/utils/parseHrtimeToSeconds.ts
|
|
28
148
|
function parseHrtimeToSeconds(hrtime) {
|
|
29
149
|
const seconds = (hrtime[0] + hrtime[1] / 1e9).toFixed(3);
|
|
30
150
|
return seconds;
|
|
31
151
|
}
|
|
32
|
-
|
|
33
|
-
|
|
152
|
+
var prettyError = new PrettyError().skipPackage("commander").skip(function callback(traceLine) {
|
|
153
|
+
const pattern = new RegExp("renderErrors");
|
|
154
|
+
const hasMatch = traceLine?.file?.match(pattern);
|
|
155
|
+
if (typeof traceLine.packageName !== "undefined" && hasMatch) {
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
}).start();
|
|
159
|
+
function getErrorCauses(errors) {
|
|
160
|
+
return errors.reduce((prev, error) => {
|
|
161
|
+
const causedError = error?.cause;
|
|
162
|
+
if (causedError) {
|
|
163
|
+
prev = [...prev, ...getErrorCauses([causedError])];
|
|
164
|
+
}
|
|
165
|
+
prev = [...prev, prettyError.render(error)];
|
|
166
|
+
return prev;
|
|
167
|
+
}, []).filter(Boolean);
|
|
168
|
+
}
|
|
169
|
+
function renderErrors(error, { prefixText, logLevel = LogLevel.silent }) {
|
|
170
|
+
if (!error) {
|
|
171
|
+
return "";
|
|
172
|
+
}
|
|
173
|
+
if (error instanceof ParallelPluginError) {
|
|
174
|
+
return [prefixText, ...error.errors.map((e) => renderErrors(e, { logLevel }))].filter(Boolean).join("\n");
|
|
175
|
+
}
|
|
176
|
+
if (logLevel === LogLevel.silent) {
|
|
177
|
+
prettyError.skipNodeFiles();
|
|
178
|
+
prettyError.skip(function skip() {
|
|
179
|
+
return true;
|
|
180
|
+
});
|
|
181
|
+
return [prefixText, prettyError.render(error)].filter(Boolean).join("\n");
|
|
182
|
+
}
|
|
183
|
+
const errors = getErrorCauses([error]);
|
|
184
|
+
return [prefixText, ...errors].filter(Boolean).join("\n");
|
|
185
|
+
}
|
|
186
|
+
var spinner = ora({
|
|
187
|
+
spinner: "clock"
|
|
188
|
+
});
|
|
189
|
+
async function startWatcher(path, cb) {
|
|
190
|
+
const { watch } = await import('chokidar');
|
|
191
|
+
const ignored = ["**/{.git,node_modules}/**"];
|
|
192
|
+
const watcher = watch(path, {
|
|
193
|
+
ignorePermissionErrors: true,
|
|
194
|
+
ignored
|
|
195
|
+
});
|
|
196
|
+
watcher.on("all", (type, file) => {
|
|
197
|
+
spinner.succeed(pc3.yellow(pc3.bold(`Change detected: ${type} ${file}`)));
|
|
198
|
+
spinner.spinner = "clock";
|
|
199
|
+
try {
|
|
200
|
+
cb(path);
|
|
201
|
+
} catch (e) {
|
|
202
|
+
spinner.warn(pc3.red("Watcher failed"));
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
34
207
|
function getSummary({ pluginManager, status, hrstart, config, logLevel }) {
|
|
35
208
|
const logs = [];
|
|
36
209
|
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrstart));
|
|
@@ -52,25 +225,25 @@ function getSummary({ pluginManager, status, hrstart, config, logLevel }) {
|
|
|
52
225
|
return 0;
|
|
53
226
|
});
|
|
54
227
|
const meta = {
|
|
55
|
-
plugins: status === "success" ? `${
|
|
228
|
+
plugins: status === "success" ? `${pc3.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total` : `${pc3.red(`${failedPlugins?.length ?? 1} failed`)}, ${pluginsCount} total`,
|
|
56
229
|
pluginsFailed: status === "failed" ? failedPlugins?.map((name) => randomPicoColour(name))?.join(", ") : void 0,
|
|
57
230
|
filesCreated: files.length,
|
|
58
|
-
time:
|
|
231
|
+
time: pc3.yellow(`${elapsedSeconds}s`),
|
|
59
232
|
output: pathParser.resolve(config.root, config.output.path)
|
|
60
233
|
};
|
|
61
234
|
if (logLevel === LogLevel.debug) {
|
|
62
|
-
logs.push(
|
|
235
|
+
logs.push(pc3.bold("\nGenerated files:\n"));
|
|
63
236
|
logs.push(files.map((file) => `${randomPicoColour(file.meta?.pluginName)} ${file.path}`).join("\n"));
|
|
64
237
|
}
|
|
65
238
|
logs.push(
|
|
66
239
|
[
|
|
67
240
|
[`
|
|
68
241
|
`, true],
|
|
69
|
-
[` ${
|
|
70
|
-
[` ${
|
|
71
|
-
[`${
|
|
72
|
-
[` ${
|
|
73
|
-
[` ${
|
|
242
|
+
[` ${pc3.bold("Plugins:")} ${meta.plugins}`, true],
|
|
243
|
+
[` ${pc3.dim("Failed:")} ${meta.pluginsFailed || "none"}`, !!meta.pluginsFailed],
|
|
244
|
+
[`${pc3.bold("Generated:")} ${meta.filesCreated} files`, true],
|
|
245
|
+
[` ${pc3.bold("Time:")} ${meta.time}`, true],
|
|
246
|
+
[` ${pc3.bold("Output:")} ${meta.output}`, true],
|
|
74
247
|
[`
|
|
75
248
|
`, true]
|
|
76
249
|
].map((item) => {
|
|
@@ -82,24 +255,6 @@ function getSummary({ pluginManager, status, hrstart, config, logLevel }) {
|
|
|
82
255
|
);
|
|
83
256
|
return logs;
|
|
84
257
|
}
|
|
85
|
-
var OraWritable = class extends Writable {
|
|
86
|
-
command;
|
|
87
|
-
spinner;
|
|
88
|
-
constructor(spinner2, command, opts) {
|
|
89
|
-
super(opts);
|
|
90
|
-
this.command = command;
|
|
91
|
-
this.spinner = spinner2;
|
|
92
|
-
}
|
|
93
|
-
_write(chunk, _encoding, callback) {
|
|
94
|
-
this.spinner.suffixText = `
|
|
95
|
-
|
|
96
|
-
${pc.bold(pc.blue(this.command))}: ${chunk?.toString()}`;
|
|
97
|
-
callback();
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
var spinner = ora({
|
|
101
|
-
spinner: "clock"
|
|
102
|
-
});
|
|
103
258
|
|
|
104
259
|
// src/generate.ts
|
|
105
260
|
async function executeHooks({ hooks, logLevel }) {
|
|
@@ -118,11 +273,11 @@ async function executeHooks({ hooks, logLevel }) {
|
|
|
118
273
|
return null;
|
|
119
274
|
}
|
|
120
275
|
await timeout(100);
|
|
121
|
-
spinner.start(`Executing hook ${logLevel !== "silent" ?
|
|
276
|
+
spinner.start(`Executing hook ${logLevel !== "silent" ? pc3.dim(command) : ""}`);
|
|
122
277
|
const subProcess = await execa(cmd, _args, { detached: true, signal: abortController.signal }).pipeStdout(oraWritable);
|
|
123
278
|
spinner.suffixText = "";
|
|
124
279
|
if (logLevel === LogLevel.silent) {
|
|
125
|
-
spinner.succeed(`Executing hook ${logLevel !== "silent" ?
|
|
280
|
+
spinner.succeed(`Executing hook ${logLevel !== "silent" ? pc3.dim(command) : ""}`);
|
|
126
281
|
console.log(subProcess.stdout);
|
|
127
282
|
}
|
|
128
283
|
oraWritable.destroy();
|
|
@@ -140,7 +295,7 @@ async function generate({ input, config, CLIOptions, logger: logger2 }) {
|
|
|
140
295
|
const { performance, PerformanceObserver } = await import('perf_hooks');
|
|
141
296
|
const performanceOpserver = new PerformanceObserver((items) => {
|
|
142
297
|
const message = `${items.getEntries()[0]?.duration.toFixed(0)}ms`;
|
|
143
|
-
spinner.suffixText =
|
|
298
|
+
spinner.suffixText = pc3.yellow(message);
|
|
144
299
|
performance.clearMarks();
|
|
145
300
|
});
|
|
146
301
|
performanceOpserver.observe({ type: "measure" });
|
|
@@ -149,7 +304,7 @@ async function generate({ input, config, CLIOptions, logger: logger2 }) {
|
|
|
149
304
|
const { root: _root, ...userConfig } = config;
|
|
150
305
|
const logLevel = CLIOptions.logLevel ?? LogLevel.silent;
|
|
151
306
|
const inputPath = input ?? ("path" in userConfig.input ? userConfig.input.path : void 0);
|
|
152
|
-
spinner.start(`\u{1F680} Building ${logLevel !== "silent" ?
|
|
307
|
+
spinner.start(`\u{1F680} Building ${logLevel !== "silent" ? pc3.dim(inputPath) : ""}`);
|
|
153
308
|
const output = await build({
|
|
154
309
|
config: {
|
|
155
310
|
root: process.cwd(),
|
|
@@ -166,7 +321,7 @@ async function generate({ input, config, CLIOptions, logger: logger2 }) {
|
|
|
166
321
|
logger: logger2
|
|
167
322
|
});
|
|
168
323
|
spinner.suffixText = "";
|
|
169
|
-
spinner.succeed(`\u{1F680} Build completed ${logLevel !== "silent" ?
|
|
324
|
+
spinner.succeed(`\u{1F680} Build completed ${logLevel !== "silent" ? pc3.dim(inputPath) : ""}`);
|
|
170
325
|
await executeHooks({ hooks: config.hooks, logLevel });
|
|
171
326
|
const summary = getSummary({ pluginManager: output.pluginManager, config, status: "success", hrstart, logLevel: CLIOptions.logLevel });
|
|
172
327
|
console.log(summary.join(""));
|
|
@@ -209,15 +364,15 @@ async function init({ preset = "simple", logLevel = LogLevel.silent, packageMana
|
|
|
209
364
|
const presetMeta = presets[preset];
|
|
210
365
|
const path = pathParser.resolve(process.cwd(), "./kubb.config.js");
|
|
211
366
|
const installCommand = packageManager === "npm" ? "install" : "add";
|
|
212
|
-
spinner.start(`\u{1F4C0} Writing \`kubb.config.js\` ${
|
|
367
|
+
spinner.start(`\u{1F4C0} Writing \`kubb.config.js\` ${pc3.dim(path)}`);
|
|
213
368
|
await write(presetMeta["kubb.config"], path);
|
|
214
|
-
spinner.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${
|
|
369
|
+
spinner.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${pc3.dim(path)}`);
|
|
215
370
|
const results = await Promise.allSettled([
|
|
216
371
|
$`npm init es6 -y`,
|
|
217
372
|
...presetMeta.packages.map(async (pack) => {
|
|
218
|
-
spinner.start(`\u{1F4C0} Installing ${
|
|
373
|
+
spinner.start(`\u{1F4C0} Installing ${pc3.dim(pack)}`);
|
|
219
374
|
const { stdout } = await $({ preferLocal: false })`${packageManager} ${installCommand} ${pack}`;
|
|
220
|
-
spinner.succeed(`\u{1F4C0} Installed ${
|
|
375
|
+
spinner.succeed(`\u{1F4C0} Installed ${pc3.dim(pack)}`);
|
|
221
376
|
return stdout;
|
|
222
377
|
})
|
|
223
378
|
]);
|
|
@@ -231,163 +386,6 @@ async function init({ preset = "simple", logLevel = LogLevel.silent, packageMana
|
|
|
231
386
|
spinner.succeed(`\u{1F4E6} initialized Kubb`);
|
|
232
387
|
return;
|
|
233
388
|
}
|
|
234
|
-
function isJSONPlugins(plugins) {
|
|
235
|
-
return !!plugins?.some((plugin) => {
|
|
236
|
-
return typeof plugin?.[0] === "string";
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
function isObjectPlugins(plugins) {
|
|
240
|
-
return plugins instanceof Object && !Array.isArray(plugins);
|
|
241
|
-
}
|
|
242
|
-
async function importPlugin(name, options) {
|
|
243
|
-
const importedPlugin = process.env.NODE_ENV === "test" ? await import(name) : await importModule(name, process.cwd());
|
|
244
|
-
return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options);
|
|
245
|
-
}
|
|
246
|
-
function getPlugins(plugins) {
|
|
247
|
-
if (isObjectPlugins(plugins)) {
|
|
248
|
-
const promises = Object.keys(plugins).map((name) => {
|
|
249
|
-
return importPlugin(name, plugins[name]);
|
|
250
|
-
});
|
|
251
|
-
return Promise.all(promises);
|
|
252
|
-
}
|
|
253
|
-
if (isJSONPlugins(plugins)) {
|
|
254
|
-
const promises = plugins.map((plugin) => {
|
|
255
|
-
const [name, options = {}] = plugin;
|
|
256
|
-
return importPlugin(name, options);
|
|
257
|
-
});
|
|
258
|
-
return Promise.all(promises);
|
|
259
|
-
}
|
|
260
|
-
return Promise.resolve(plugins);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// src/utils/getConfig.ts
|
|
264
|
-
async function getConfig(result, CLIOptions) {
|
|
265
|
-
const config = result?.config;
|
|
266
|
-
let kubbUserConfig = Promise.resolve(config);
|
|
267
|
-
if (typeof config === "function") {
|
|
268
|
-
const possiblePromise = config(CLIOptions);
|
|
269
|
-
if (isPromise(possiblePromise)) {
|
|
270
|
-
kubbUserConfig = possiblePromise;
|
|
271
|
-
}
|
|
272
|
-
kubbUserConfig = Promise.resolve(possiblePromise);
|
|
273
|
-
}
|
|
274
|
-
let JSONConfig = await kubbUserConfig;
|
|
275
|
-
JSONConfig = {
|
|
276
|
-
...JSONConfig,
|
|
277
|
-
plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
|
|
278
|
-
};
|
|
279
|
-
return JSONConfig;
|
|
280
|
-
}
|
|
281
|
-
async function startWatcher(path, cb) {
|
|
282
|
-
const { watch } = await import('chokidar');
|
|
283
|
-
const ignored = ["**/{.git,node_modules}/**"];
|
|
284
|
-
const watcher = watch(path, {
|
|
285
|
-
ignorePermissionErrors: true,
|
|
286
|
-
ignored
|
|
287
|
-
});
|
|
288
|
-
watcher.on("all", (type, file) => {
|
|
289
|
-
spinner.succeed(pc.yellow(pc.bold(`Change detected: ${type} ${file}`)));
|
|
290
|
-
spinner.spinner = "clock";
|
|
291
|
-
try {
|
|
292
|
-
cb(path);
|
|
293
|
-
} catch (e) {
|
|
294
|
-
spinner.warn(pc.red("Watcher failed"));
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
var tsLoader = (configFile) => {
|
|
300
|
-
let registerer = { enabled() {
|
|
301
|
-
} };
|
|
302
|
-
try {
|
|
303
|
-
registerer = tsNode.register({
|
|
304
|
-
compilerOptions: { module: "commonjs" },
|
|
305
|
-
typeCheck: false
|
|
306
|
-
});
|
|
307
|
-
const module = __require(configFile);
|
|
308
|
-
return module.default;
|
|
309
|
-
} catch (err) {
|
|
310
|
-
const error = err;
|
|
311
|
-
if (error.name === "MODULE_NOT_FOUND") {
|
|
312
|
-
throw new Error(`'ts-node' is required for the TypeScript configuration files. Make sure it is installed
|
|
313
|
-
Error: ${error.message}`);
|
|
314
|
-
}
|
|
315
|
-
throw error;
|
|
316
|
-
} finally {
|
|
317
|
-
registerer.enabled();
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
async function getCosmiConfig(moduleName2, config) {
|
|
321
|
-
const searchPlaces = [
|
|
322
|
-
"package.json",
|
|
323
|
-
`.${moduleName2}rc`,
|
|
324
|
-
`.${moduleName2}rc.json`,
|
|
325
|
-
`.${moduleName2}rc.yaml`,
|
|
326
|
-
`.${moduleName2}rc.yml`,
|
|
327
|
-
`.${moduleName2}rc.ts`,
|
|
328
|
-
`.${moduleName2}rc.js`,
|
|
329
|
-
`.${moduleName2}rc.cjs`,
|
|
330
|
-
`.${moduleName2}rc.mjs`,
|
|
331
|
-
`${moduleName2}.config.ts`,
|
|
332
|
-
`${moduleName2}.config.js`,
|
|
333
|
-
`${moduleName2}.config.cjs`,
|
|
334
|
-
`${moduleName2}.config.mjs`
|
|
335
|
-
];
|
|
336
|
-
const explorer = cosmiconfig(moduleName2, {
|
|
337
|
-
cache: false,
|
|
338
|
-
searchPlaces: [
|
|
339
|
-
...searchPlaces.map((searchPlace) => {
|
|
340
|
-
return `.config/${searchPlace}`;
|
|
341
|
-
}),
|
|
342
|
-
...searchPlaces.map((searchPlace) => {
|
|
343
|
-
return `configs/${searchPlace}`;
|
|
344
|
-
}),
|
|
345
|
-
...searchPlaces
|
|
346
|
-
],
|
|
347
|
-
loaders: {
|
|
348
|
-
".ts": tsLoader
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
const result = config ? await explorer.load(config) : await explorer.search();
|
|
352
|
-
if (result?.isEmpty || !result || !result.config) {
|
|
353
|
-
throw new Error("Config not defined, create a kubb.config.js or pass through your config with the option --config");
|
|
354
|
-
}
|
|
355
|
-
return result;
|
|
356
|
-
}
|
|
357
|
-
var prettyError = new PrettyError().skipPackage("commander").skip(function(traceLine) {
|
|
358
|
-
const pattern = new RegExp("renderErrors");
|
|
359
|
-
const hasMatch = traceLine?.file?.match(pattern);
|
|
360
|
-
if (typeof traceLine.packageName !== "undefined" && hasMatch) {
|
|
361
|
-
return true;
|
|
362
|
-
}
|
|
363
|
-
}).start();
|
|
364
|
-
function getErrorCauses(errors) {
|
|
365
|
-
return errors.reduce((prev, error) => {
|
|
366
|
-
const causedError = error?.cause;
|
|
367
|
-
if (causedError) {
|
|
368
|
-
prev = [...prev, ...getErrorCauses([causedError])];
|
|
369
|
-
}
|
|
370
|
-
prev = [...prev, prettyError.render(error)];
|
|
371
|
-
return prev;
|
|
372
|
-
}, []).filter(Boolean);
|
|
373
|
-
}
|
|
374
|
-
function renderErrors(error, { prefixText, logLevel = LogLevel.silent }) {
|
|
375
|
-
if (!error) {
|
|
376
|
-
return "";
|
|
377
|
-
}
|
|
378
|
-
if (error instanceof ParallelPluginError) {
|
|
379
|
-
return [prefixText, ...error.errors.map((e) => renderErrors(e, { logLevel }))].filter(Boolean).join("\n");
|
|
380
|
-
}
|
|
381
|
-
if (logLevel === LogLevel.silent) {
|
|
382
|
-
prettyError.skipNodeFiles();
|
|
383
|
-
prettyError.skip(function() {
|
|
384
|
-
return true;
|
|
385
|
-
});
|
|
386
|
-
return [prefixText, prettyError.render(error)].filter(Boolean).join("\n");
|
|
387
|
-
}
|
|
388
|
-
const errors = getErrorCauses([error]);
|
|
389
|
-
return [prefixText, ...errors].filter(Boolean).join("\n");
|
|
390
|
-
}
|
|
391
389
|
|
|
392
390
|
// src/index.ts
|
|
393
391
|
var moduleName = "kubb";
|
|
@@ -399,9 +397,9 @@ function programCatcher(e, CLIOptions) {
|
|
|
399
397
|
if (summaryError) {
|
|
400
398
|
error = summaryError.cause;
|
|
401
399
|
}
|
|
402
|
-
const message = renderErrors(error, { logLevel: CLIOptions.logLevel, prefixText:
|
|
400
|
+
const message = renderErrors(error, { logLevel: CLIOptions.logLevel, prefixText: pc3.red(originalError?.message) });
|
|
403
401
|
if (error instanceof Warning) {
|
|
404
|
-
spinner.warn(
|
|
402
|
+
spinner.warn(pc3.yellow(error.message));
|
|
405
403
|
process.exit(0);
|
|
406
404
|
}
|
|
407
405
|
if (CLIOptions.logLevel === LogLevel.silent) {
|
|
@@ -414,13 +412,13 @@ function programCatcher(e, CLIOptions) {
|
|
|
414
412
|
async function generateAction(input, CLIOptions) {
|
|
415
413
|
spinner.start("\u{1F4BE} Loading config");
|
|
416
414
|
const result = await getCosmiConfig(moduleName, CLIOptions.config);
|
|
417
|
-
spinner.succeed(`\u{1F4BE} Config loaded(${
|
|
415
|
+
spinner.succeed(`\u{1F4BE} Config loaded(${pc3.dim(pathParser.relative(process.cwd(), result.filepath))})`);
|
|
418
416
|
const config = await getConfig(result, CLIOptions);
|
|
419
417
|
if (CLIOptions.watch && "path" in config.input) {
|
|
420
418
|
return startWatcher([input || config.input.path], async (paths) => {
|
|
421
419
|
await generate({ config, CLIOptions, logger });
|
|
422
420
|
spinner.spinner = "simpleDotsScrolling";
|
|
423
|
-
spinner.start(
|
|
421
|
+
spinner.start(pc3.yellow(pc3.bold(`Watching for changes in ${paths.join(" and ")}`)));
|
|
424
422
|
});
|
|
425
423
|
}
|
|
426
424
|
await generate({ input, config, CLIOptions, logger });
|