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