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