@kubb/cli 1.1.10 → 1.1.12
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/dist/index.cjs +64 -35
- package/dist/index.js +64 -35
- package/package.json +5 -6
- package/src/index.ts +0 -69
- package/src/init.ts +0 -91
- package/src/run.ts +0 -163
- package/src/types.ts +0 -7
- package/src/utils/getConfig.ts +0 -28
- package/src/utils/getCosmiConfig.ts +0 -80
- package/src/utils/getPlugins.ts +0 -40
- package/src/utils/importModule.ts +0 -36
- package/src/utils/index.ts +0 -7
- package/src/utils/mocks/noop.cjs +0 -3
- package/src/utils/mocks/noop.js +0 -3
- package/src/utils/parseHrtimeToSeconds.ts +0 -4
- package/src/utils/parseText.ts +0 -5
- package/src/utils/watcher.ts +0 -30
package/dist/index.cjs
CHANGED
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
var pathParser = require('path');
|
|
5
5
|
var commander = require('commander');
|
|
6
6
|
var ora = require('ora');
|
|
7
|
-
var
|
|
7
|
+
var pc3 = require('picocolors');
|
|
8
8
|
var core = require('@kubb/core');
|
|
9
9
|
var execa = require('execa');
|
|
10
10
|
var PrettyError = require('pretty-error');
|
|
11
11
|
var stringArgv = require('string-argv');
|
|
12
|
+
var stream = require('stream');
|
|
12
13
|
var mod = require('module');
|
|
13
14
|
var url = require('url');
|
|
14
15
|
var cosmiconfig = require('cosmiconfig');
|
|
@@ -19,7 +20,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
19
20
|
|
|
20
21
|
var pathParser__default = /*#__PURE__*/_interopDefault(pathParser);
|
|
21
22
|
var ora__default = /*#__PURE__*/_interopDefault(ora);
|
|
22
|
-
var
|
|
23
|
+
var pc3__default = /*#__PURE__*/_interopDefault(pc3);
|
|
23
24
|
var PrettyError__default = /*#__PURE__*/_interopDefault(PrettyError);
|
|
24
25
|
var mod__default = /*#__PURE__*/_interopDefault(mod);
|
|
25
26
|
var tsNode__default = /*#__PURE__*/_interopDefault(tsNode);
|
|
@@ -34,7 +35,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
// package.json
|
|
37
|
-
var version = "1.1.
|
|
38
|
+
var version = "1.1.12";
|
|
38
39
|
var presets = {
|
|
39
40
|
simple: {
|
|
40
41
|
"kubb.config": `
|
|
@@ -67,15 +68,15 @@ async function init({ spinner: spinner2, preset = "simple", logLevel = "silent",
|
|
|
67
68
|
const presetMeta = presets[preset];
|
|
68
69
|
const path = pathParser__default.default.resolve(process.cwd(), "./kubb.config.js");
|
|
69
70
|
const installCommand = packageManager === "npm" ? "install" : "add";
|
|
70
|
-
spinner2.start(`\u{1F4C0} Writing \`kubb.config.js\` ${
|
|
71
|
+
spinner2.start(`\u{1F4C0} Writing \`kubb.config.js\` ${pc3__default.default.dim(path)}`);
|
|
71
72
|
await core.write(presetMeta["kubb.config"], path);
|
|
72
|
-
spinner2.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${
|
|
73
|
+
spinner2.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${pc3__default.default.dim(path)}`);
|
|
73
74
|
const data = await Promise.all([
|
|
74
75
|
execa.$`npm init es6 -y`,
|
|
75
76
|
...presetMeta.packages.map(async (pack) => {
|
|
76
|
-
spinner2.start(`\u{1F4C0} Installing ${
|
|
77
|
+
spinner2.start(`\u{1F4C0} Installing ${pc3__default.default.dim(pack)}`);
|
|
77
78
|
const { stdout } = await execa.$({ preferLocal: false })`${packageManager} ${installCommand} ${pack}`;
|
|
78
|
-
spinner2.succeed(`\u{1F4C0} Installed ${
|
|
79
|
+
spinner2.succeed(`\u{1F4C0} Installed ${pc3__default.default.dim(pack)}`);
|
|
79
80
|
return stdout;
|
|
80
81
|
})
|
|
81
82
|
]);
|
|
@@ -83,7 +84,7 @@ async function init({ spinner: spinner2, preset = "simple", logLevel = "silent",
|
|
|
83
84
|
data.forEach((text) => console.log(text));
|
|
84
85
|
}
|
|
85
86
|
} catch (error) {
|
|
86
|
-
spinner2.fail(
|
|
87
|
+
spinner2.fail(pc3__default.default.red(`Something went wrong
|
|
87
88
|
|
|
88
89
|
${error?.message}`));
|
|
89
90
|
}
|
|
@@ -99,18 +100,42 @@ function parseHrtimeToSeconds(hrtime) {
|
|
|
99
100
|
function parseText(baseText, config, logLevel = "silent") {
|
|
100
101
|
return `${baseText}${config[logLevel] || ""}`;
|
|
101
102
|
}
|
|
103
|
+
var OraWritable = class extends stream.Writable {
|
|
104
|
+
command;
|
|
105
|
+
spinner;
|
|
106
|
+
constructor(spinner2, command, opts) {
|
|
107
|
+
super(opts);
|
|
108
|
+
this.command = command;
|
|
109
|
+
this.spinner = spinner2;
|
|
110
|
+
}
|
|
111
|
+
_write(chunk, _encoding, callback) {
|
|
112
|
+
this.spinner.suffixText = `
|
|
113
|
+
|
|
114
|
+
${pc3__default.default.bold(pc3__default.default.blue(this.command))}: ${chunk?.toString()}`;
|
|
115
|
+
callback();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
102
118
|
|
|
103
119
|
// src/run.ts
|
|
104
120
|
async function run({ config, options, spinner: spinner2 }) {
|
|
105
121
|
const hrstart = process.hrtime();
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
122
|
+
const [log] = core.throttle((message, { logLevel, params }) => {
|
|
123
|
+
if (logLevel === "error") {
|
|
124
|
+
spinner2.fail(pc3__default.default.red(`${message}
|
|
125
|
+
|
|
126
|
+
` || `Something went wrong
|
|
127
|
+
|
|
128
|
+
`));
|
|
129
|
+
} else if (logLevel === "info") {
|
|
130
|
+
if (message) {
|
|
131
|
+
spinner2.text = message;
|
|
110
132
|
} else {
|
|
111
|
-
spinner2.
|
|
133
|
+
spinner2.text = `\u{1FA82} Executing ${params?.hookName || "unknown"}(${pc3__default.default.yellow(params?.pluginName || "unknown")})`;
|
|
112
134
|
}
|
|
113
|
-
}
|
|
135
|
+
}
|
|
136
|
+
}, 100);
|
|
137
|
+
const logger = {
|
|
138
|
+
log,
|
|
114
139
|
spinner: spinner2
|
|
115
140
|
};
|
|
116
141
|
const onDone = async (hooks, logLevel) => {
|
|
@@ -124,15 +149,21 @@ async function run({ config, options, spinner: spinner2 }) {
|
|
|
124
149
|
commands = hooks.done;
|
|
125
150
|
}
|
|
126
151
|
const promises = commands.map(async (command) => {
|
|
152
|
+
const oraWritable = new OraWritable(spinner2, command);
|
|
127
153
|
const [cmd, ..._args] = [...stringArgv.parseArgsStringToArgv(command)];
|
|
128
|
-
spinner2.start(parseText(`\u{1FA82} Executing hooks(${
|
|
129
|
-
const { stdout } = await execa.execa(cmd, _args);
|
|
130
|
-
spinner2.
|
|
154
|
+
spinner2.start(parseText(`\u{1FA82} Executing hooks(${pc3__default.default.yellow("done")})`, { info: ` ${pc3__default.default.dim(command)}` }, logLevel));
|
|
155
|
+
const { stdout } = await execa.execa(cmd, _args, {}).pipeStdout(oraWritable);
|
|
156
|
+
spinner2.suffixText = "";
|
|
157
|
+
oraWritable.destroy();
|
|
131
158
|
if (logLevel === "info") {
|
|
159
|
+
spinner2.succeed(parseText(`\u{1FA82} Executing hooks(${pc3__default.default.yellow("done")})`, { info: ` ${pc3__default.default.dim(command)}` }, logLevel));
|
|
132
160
|
console.log(stdout);
|
|
133
161
|
}
|
|
134
162
|
});
|
|
135
163
|
await Promise.all(promises);
|
|
164
|
+
if (logLevel === "silent") {
|
|
165
|
+
spinner2.succeed(parseText(`\u{1FA82} Executing hooks(${pc3__default.default.yellow("done")})`, {}, logLevel));
|
|
166
|
+
}
|
|
136
167
|
};
|
|
137
168
|
const printSummary = (pluginManager, status) => {
|
|
138
169
|
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrstart));
|
|
@@ -153,26 +184,26 @@ async function run({ config, options, spinner: spinner2 }) {
|
|
|
153
184
|
return 0;
|
|
154
185
|
});
|
|
155
186
|
const meta = {
|
|
156
|
-
plugins: status === "success" ? `${
|
|
187
|
+
plugins: status === "success" ? `${pc3__default.default.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total` : `${pc3__default.default.red(`${pluginsCount - buildStartPlugins.length} failed`)}, ${pluginsCount} total`,
|
|
157
188
|
filesCreated: files.length,
|
|
158
|
-
time:
|
|
189
|
+
time: pc3__default.default.yellow(`${elapsedSeconds}s`),
|
|
159
190
|
output: pathParser__default.default.resolve(config.root, config.output.path)
|
|
160
191
|
};
|
|
161
192
|
console.log(`
|
|
162
|
-
${
|
|
163
|
-
${
|
|
164
|
-
${
|
|
165
|
-
${
|
|
193
|
+
${pc3__default.default.bold("Plugins:")} ${meta.plugins}
|
|
194
|
+
${pc3__default.default.bold("Generated:")} ${meta.filesCreated} files
|
|
195
|
+
${pc3__default.default.bold("Time:")} ${meta.time}
|
|
196
|
+
${pc3__default.default.bold("Output:")} ${meta.output}
|
|
166
197
|
`);
|
|
167
198
|
if (options.debug) {
|
|
168
|
-
console.log(`${
|
|
169
|
-
console.log(`${files.map((file) => `${
|
|
199
|
+
console.log(`${pc3__default.default.bold("Generated files:")}`);
|
|
200
|
+
console.log(`${files.map((file) => `${pc3__default.default.blue(file.meta?.pluginName)} ${file.path}`).join("\n")}`);
|
|
170
201
|
}
|
|
171
202
|
};
|
|
172
203
|
const printErrors = (error) => {
|
|
173
204
|
const pe = new PrettyError__default.default();
|
|
174
205
|
if (options.debug) {
|
|
175
|
-
spinner2.fail(
|
|
206
|
+
spinner2.fail(pc3__default.default.red(`Something went wrong
|
|
176
207
|
|
|
177
208
|
`));
|
|
178
209
|
const causedError = error?.cause;
|
|
@@ -181,7 +212,7 @@ ${pc2__default.default.bold("Generated:")} ${meta.filesCreated} files
|
|
|
181
212
|
console.log(pe.render(causedError));
|
|
182
213
|
}
|
|
183
214
|
} else {
|
|
184
|
-
spinner2.fail(
|
|
215
|
+
spinner2.fail(pc3__default.default.red(`Something went wrong
|
|
185
216
|
|
|
186
217
|
${error?.message}`));
|
|
187
218
|
}
|
|
@@ -190,7 +221,7 @@ ${error?.message}`));
|
|
|
190
221
|
const { root, ...userConfig } = config;
|
|
191
222
|
const logLevel = options.logLevel ?? userConfig.logLevel ?? "silent";
|
|
192
223
|
const inputPath = options.input ?? userConfig.input.path;
|
|
193
|
-
spinner2.start(parseText(`\u{1F680} Building`, { info: `(${
|
|
224
|
+
spinner2.start(parseText(`\u{1F680} Building`, { info: `(${pc3__default.default.dim(inputPath)})` }, logLevel));
|
|
194
225
|
const output = await core.build({
|
|
195
226
|
config: {
|
|
196
227
|
root: process.cwd(),
|
|
@@ -207,7 +238,7 @@ ${error?.message}`));
|
|
|
207
238
|
},
|
|
208
239
|
logger
|
|
209
240
|
});
|
|
210
|
-
spinner2.succeed(parseText(`\u{1F680} Build completed`, { info: `(${
|
|
241
|
+
spinner2.succeed(parseText(`\u{1F680} Build completed`, { info: `(${pc3__default.default.dim(inputPath)})` }, logLevel));
|
|
211
242
|
await onDone(config.hooks, logLevel);
|
|
212
243
|
printSummary(output.pluginManager, "success");
|
|
213
244
|
} catch (error) {
|
|
@@ -296,12 +327,12 @@ async function startWatcher(cb, options) {
|
|
|
296
327
|
ignored
|
|
297
328
|
});
|
|
298
329
|
watcher.on("all", (type, file) => {
|
|
299
|
-
spinner2.succeed(
|
|
330
|
+
spinner2.succeed(pc3__default.default.yellow(pc3__default.default.bold(`Change detected: ${type} ${file}`)));
|
|
300
331
|
spinner2.spinner = "clock";
|
|
301
332
|
try {
|
|
302
333
|
cb(options.path);
|
|
303
334
|
} catch (e) {
|
|
304
|
-
spinner2.warn(
|
|
335
|
+
spinner2.warn(pc3__default.default.red("Watcher failed"));
|
|
305
336
|
}
|
|
306
337
|
});
|
|
307
338
|
}
|
|
@@ -339,12 +370,10 @@ async function getCosmiConfig(moduleName2, config) {
|
|
|
339
370
|
`.${moduleName2}rc.json`,
|
|
340
371
|
`.${moduleName2}rc.yaml`,
|
|
341
372
|
`.${moduleName2}rc.yml`,
|
|
342
|
-
// TODO fix tsLoader
|
|
343
373
|
`.${moduleName2}rc.ts`,
|
|
344
374
|
`.${moduleName2}rc.js`,
|
|
345
375
|
`.${moduleName2}rc.cjs`,
|
|
346
376
|
`.${moduleName2}rc.mjs`,
|
|
347
|
-
// TODO fix tsLoader
|
|
348
377
|
`${moduleName2}.config.ts`,
|
|
349
378
|
`${moduleName2}.config.js`,
|
|
350
379
|
`${moduleName2}.config.cjs`,
|
|
@@ -382,14 +411,14 @@ var program = new commander.Command(moduleName).description("Kubb").action(async
|
|
|
382
411
|
}
|
|
383
412
|
spinner.start("\u{1F4BE} Loading config");
|
|
384
413
|
const result = await getCosmiConfig(moduleName, options.config);
|
|
385
|
-
spinner.succeed(`\u{1F4BE} Config loaded(${
|
|
414
|
+
spinner.succeed(`\u{1F4BE} Config loaded(${pc3__default.default.dim(pathParser__default.default.relative(process.cwd(), result.filepath))})`);
|
|
386
415
|
if (options.watch) {
|
|
387
416
|
const config = await getConfig(result, options);
|
|
388
417
|
startWatcher(
|
|
389
418
|
async (paths) => {
|
|
390
419
|
await run({ config, spinner, options });
|
|
391
420
|
spinner.spinner = "simpleDotsScrolling";
|
|
392
|
-
spinner.start(
|
|
421
|
+
spinner.start(pc3__default.default.yellow(pc3__default.default.bold(`Watching for changes in ${paths.join(" and ")}`)));
|
|
393
422
|
},
|
|
394
423
|
{
|
|
395
424
|
spinner,
|
package/dist/index.js
CHANGED
|
@@ -3,11 +3,12 @@ import { createRequire } from 'module';
|
|
|
3
3
|
import pathParser from 'node:path';
|
|
4
4
|
import { Command, Option } from 'commander';
|
|
5
5
|
import ora from 'ora';
|
|
6
|
-
import
|
|
7
|
-
import { write, build, ParallelPluginError, PluginError, isPromise } from '@kubb/core';
|
|
6
|
+
import pc3 from 'picocolors';
|
|
7
|
+
import { write, throttle, build, ParallelPluginError, PluginError, isPromise } from '@kubb/core';
|
|
8
8
|
import { $, execa } from 'execa';
|
|
9
9
|
import PrettyError from 'pretty-error';
|
|
10
10
|
import { parseArgsStringToArgv } from 'string-argv';
|
|
11
|
+
import { Writable } from 'node:stream';
|
|
11
12
|
import mod from 'node:module';
|
|
12
13
|
import { pathToFileURL } from 'node:url';
|
|
13
14
|
import { cosmiconfig } from 'cosmiconfig';
|
|
@@ -25,7 +26,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
25
26
|
});
|
|
26
27
|
|
|
27
28
|
// package.json
|
|
28
|
-
var version = "1.1.
|
|
29
|
+
var version = "1.1.12";
|
|
29
30
|
var presets = {
|
|
30
31
|
simple: {
|
|
31
32
|
"kubb.config": `
|
|
@@ -58,15 +59,15 @@ async function init({ spinner: spinner2, preset = "simple", logLevel = "silent",
|
|
|
58
59
|
const presetMeta = presets[preset];
|
|
59
60
|
const path = pathParser.resolve(process.cwd(), "./kubb.config.js");
|
|
60
61
|
const installCommand = packageManager === "npm" ? "install" : "add";
|
|
61
|
-
spinner2.start(`\u{1F4C0} Writing \`kubb.config.js\` ${
|
|
62
|
+
spinner2.start(`\u{1F4C0} Writing \`kubb.config.js\` ${pc3.dim(path)}`);
|
|
62
63
|
await write(presetMeta["kubb.config"], path);
|
|
63
|
-
spinner2.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${
|
|
64
|
+
spinner2.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${pc3.dim(path)}`);
|
|
64
65
|
const data = await Promise.all([
|
|
65
66
|
$`npm init es6 -y`,
|
|
66
67
|
...presetMeta.packages.map(async (pack) => {
|
|
67
|
-
spinner2.start(`\u{1F4C0} Installing ${
|
|
68
|
+
spinner2.start(`\u{1F4C0} Installing ${pc3.dim(pack)}`);
|
|
68
69
|
const { stdout } = await $({ preferLocal: false })`${packageManager} ${installCommand} ${pack}`;
|
|
69
|
-
spinner2.succeed(`\u{1F4C0} Installed ${
|
|
70
|
+
spinner2.succeed(`\u{1F4C0} Installed ${pc3.dim(pack)}`);
|
|
70
71
|
return stdout;
|
|
71
72
|
})
|
|
72
73
|
]);
|
|
@@ -74,7 +75,7 @@ async function init({ spinner: spinner2, preset = "simple", logLevel = "silent",
|
|
|
74
75
|
data.forEach((text) => console.log(text));
|
|
75
76
|
}
|
|
76
77
|
} catch (error) {
|
|
77
|
-
spinner2.fail(
|
|
78
|
+
spinner2.fail(pc3.red(`Something went wrong
|
|
78
79
|
|
|
79
80
|
${error?.message}`));
|
|
80
81
|
}
|
|
@@ -90,18 +91,42 @@ function parseHrtimeToSeconds(hrtime) {
|
|
|
90
91
|
function parseText(baseText, config, logLevel = "silent") {
|
|
91
92
|
return `${baseText}${config[logLevel] || ""}`;
|
|
92
93
|
}
|
|
94
|
+
var OraWritable = class extends Writable {
|
|
95
|
+
command;
|
|
96
|
+
spinner;
|
|
97
|
+
constructor(spinner2, command, opts) {
|
|
98
|
+
super(opts);
|
|
99
|
+
this.command = command;
|
|
100
|
+
this.spinner = spinner2;
|
|
101
|
+
}
|
|
102
|
+
_write(chunk, _encoding, callback) {
|
|
103
|
+
this.spinner.suffixText = `
|
|
104
|
+
|
|
105
|
+
${pc3.bold(pc3.blue(this.command))}: ${chunk?.toString()}`;
|
|
106
|
+
callback();
|
|
107
|
+
}
|
|
108
|
+
};
|
|
93
109
|
|
|
94
110
|
// src/run.ts
|
|
95
111
|
async function run({ config, options, spinner: spinner2 }) {
|
|
96
112
|
const hrstart = process.hrtime();
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
113
|
+
const [log] = throttle((message, { logLevel, params }) => {
|
|
114
|
+
if (logLevel === "error") {
|
|
115
|
+
spinner2.fail(pc3.red(`${message}
|
|
116
|
+
|
|
117
|
+
` || `Something went wrong
|
|
118
|
+
|
|
119
|
+
`));
|
|
120
|
+
} else if (logLevel === "info") {
|
|
121
|
+
if (message) {
|
|
122
|
+
spinner2.text = message;
|
|
101
123
|
} else {
|
|
102
|
-
spinner2.
|
|
124
|
+
spinner2.text = `\u{1FA82} Executing ${params?.hookName || "unknown"}(${pc3.yellow(params?.pluginName || "unknown")})`;
|
|
103
125
|
}
|
|
104
|
-
}
|
|
126
|
+
}
|
|
127
|
+
}, 100);
|
|
128
|
+
const logger = {
|
|
129
|
+
log,
|
|
105
130
|
spinner: spinner2
|
|
106
131
|
};
|
|
107
132
|
const onDone = async (hooks, logLevel) => {
|
|
@@ -115,15 +140,21 @@ async function run({ config, options, spinner: spinner2 }) {
|
|
|
115
140
|
commands = hooks.done;
|
|
116
141
|
}
|
|
117
142
|
const promises = commands.map(async (command) => {
|
|
143
|
+
const oraWritable = new OraWritable(spinner2, command);
|
|
118
144
|
const [cmd, ..._args] = [...parseArgsStringToArgv(command)];
|
|
119
|
-
spinner2.start(parseText(`\u{1FA82} Executing hooks(${
|
|
120
|
-
const { stdout } = await execa(cmd, _args);
|
|
121
|
-
spinner2.
|
|
145
|
+
spinner2.start(parseText(`\u{1FA82} Executing hooks(${pc3.yellow("done")})`, { info: ` ${pc3.dim(command)}` }, logLevel));
|
|
146
|
+
const { stdout } = await execa(cmd, _args, {}).pipeStdout(oraWritable);
|
|
147
|
+
spinner2.suffixText = "";
|
|
148
|
+
oraWritable.destroy();
|
|
122
149
|
if (logLevel === "info") {
|
|
150
|
+
spinner2.succeed(parseText(`\u{1FA82} Executing hooks(${pc3.yellow("done")})`, { info: ` ${pc3.dim(command)}` }, logLevel));
|
|
123
151
|
console.log(stdout);
|
|
124
152
|
}
|
|
125
153
|
});
|
|
126
154
|
await Promise.all(promises);
|
|
155
|
+
if (logLevel === "silent") {
|
|
156
|
+
spinner2.succeed(parseText(`\u{1FA82} Executing hooks(${pc3.yellow("done")})`, {}, logLevel));
|
|
157
|
+
}
|
|
127
158
|
};
|
|
128
159
|
const printSummary = (pluginManager, status) => {
|
|
129
160
|
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrstart));
|
|
@@ -144,26 +175,26 @@ async function run({ config, options, spinner: spinner2 }) {
|
|
|
144
175
|
return 0;
|
|
145
176
|
});
|
|
146
177
|
const meta = {
|
|
147
|
-
plugins: status === "success" ? `${
|
|
178
|
+
plugins: status === "success" ? `${pc3.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total` : `${pc3.red(`${pluginsCount - buildStartPlugins.length} failed`)}, ${pluginsCount} total`,
|
|
148
179
|
filesCreated: files.length,
|
|
149
|
-
time:
|
|
180
|
+
time: pc3.yellow(`${elapsedSeconds}s`),
|
|
150
181
|
output: pathParser.resolve(config.root, config.output.path)
|
|
151
182
|
};
|
|
152
183
|
console.log(`
|
|
153
|
-
${
|
|
154
|
-
${
|
|
155
|
-
${
|
|
156
|
-
${
|
|
184
|
+
${pc3.bold("Plugins:")} ${meta.plugins}
|
|
185
|
+
${pc3.bold("Generated:")} ${meta.filesCreated} files
|
|
186
|
+
${pc3.bold("Time:")} ${meta.time}
|
|
187
|
+
${pc3.bold("Output:")} ${meta.output}
|
|
157
188
|
`);
|
|
158
189
|
if (options.debug) {
|
|
159
|
-
console.log(`${
|
|
160
|
-
console.log(`${files.map((file) => `${
|
|
190
|
+
console.log(`${pc3.bold("Generated files:")}`);
|
|
191
|
+
console.log(`${files.map((file) => `${pc3.blue(file.meta?.pluginName)} ${file.path}`).join("\n")}`);
|
|
161
192
|
}
|
|
162
193
|
};
|
|
163
194
|
const printErrors = (error) => {
|
|
164
195
|
const pe = new PrettyError();
|
|
165
196
|
if (options.debug) {
|
|
166
|
-
spinner2.fail(
|
|
197
|
+
spinner2.fail(pc3.red(`Something went wrong
|
|
167
198
|
|
|
168
199
|
`));
|
|
169
200
|
const causedError = error?.cause;
|
|
@@ -172,7 +203,7 @@ ${pc2.bold("Generated:")} ${meta.filesCreated} files
|
|
|
172
203
|
console.log(pe.render(causedError));
|
|
173
204
|
}
|
|
174
205
|
} else {
|
|
175
|
-
spinner2.fail(
|
|
206
|
+
spinner2.fail(pc3.red(`Something went wrong
|
|
176
207
|
|
|
177
208
|
${error?.message}`));
|
|
178
209
|
}
|
|
@@ -181,7 +212,7 @@ ${error?.message}`));
|
|
|
181
212
|
const { root, ...userConfig } = config;
|
|
182
213
|
const logLevel = options.logLevel ?? userConfig.logLevel ?? "silent";
|
|
183
214
|
const inputPath = options.input ?? userConfig.input.path;
|
|
184
|
-
spinner2.start(parseText(`\u{1F680} Building`, { info: `(${
|
|
215
|
+
spinner2.start(parseText(`\u{1F680} Building`, { info: `(${pc3.dim(inputPath)})` }, logLevel));
|
|
185
216
|
const output = await build({
|
|
186
217
|
config: {
|
|
187
218
|
root: process.cwd(),
|
|
@@ -198,7 +229,7 @@ ${error?.message}`));
|
|
|
198
229
|
},
|
|
199
230
|
logger
|
|
200
231
|
});
|
|
201
|
-
spinner2.succeed(parseText(`\u{1F680} Build completed`, { info: `(${
|
|
232
|
+
spinner2.succeed(parseText(`\u{1F680} Build completed`, { info: `(${pc3.dim(inputPath)})` }, logLevel));
|
|
202
233
|
await onDone(config.hooks, logLevel);
|
|
203
234
|
printSummary(output.pluginManager, "success");
|
|
204
235
|
} catch (error) {
|
|
@@ -287,12 +318,12 @@ async function startWatcher(cb, options) {
|
|
|
287
318
|
ignored
|
|
288
319
|
});
|
|
289
320
|
watcher.on("all", (type, file) => {
|
|
290
|
-
spinner2.succeed(
|
|
321
|
+
spinner2.succeed(pc3.yellow(pc3.bold(`Change detected: ${type} ${file}`)));
|
|
291
322
|
spinner2.spinner = "clock";
|
|
292
323
|
try {
|
|
293
324
|
cb(options.path);
|
|
294
325
|
} catch (e) {
|
|
295
|
-
spinner2.warn(
|
|
326
|
+
spinner2.warn(pc3.red("Watcher failed"));
|
|
296
327
|
}
|
|
297
328
|
});
|
|
298
329
|
}
|
|
@@ -330,12 +361,10 @@ async function getCosmiConfig(moduleName2, config) {
|
|
|
330
361
|
`.${moduleName2}rc.json`,
|
|
331
362
|
`.${moduleName2}rc.yaml`,
|
|
332
363
|
`.${moduleName2}rc.yml`,
|
|
333
|
-
// TODO fix tsLoader
|
|
334
364
|
`.${moduleName2}rc.ts`,
|
|
335
365
|
`.${moduleName2}rc.js`,
|
|
336
366
|
`.${moduleName2}rc.cjs`,
|
|
337
367
|
`.${moduleName2}rc.mjs`,
|
|
338
|
-
// TODO fix tsLoader
|
|
339
368
|
`${moduleName2}.config.ts`,
|
|
340
369
|
`${moduleName2}.config.js`,
|
|
341
370
|
`${moduleName2}.config.cjs`,
|
|
@@ -373,14 +402,14 @@ var program = new Command(moduleName).description("Kubb").action(async (options)
|
|
|
373
402
|
}
|
|
374
403
|
spinner.start("\u{1F4BE} Loading config");
|
|
375
404
|
const result = await getCosmiConfig(moduleName, options.config);
|
|
376
|
-
spinner.succeed(`\u{1F4BE} Config loaded(${
|
|
405
|
+
spinner.succeed(`\u{1F4BE} Config loaded(${pc3.dim(pathParser.relative(process.cwd(), result.filepath))})`);
|
|
377
406
|
if (options.watch) {
|
|
378
407
|
const config = await getConfig(result, options);
|
|
379
408
|
startWatcher(
|
|
380
409
|
async (paths) => {
|
|
381
410
|
await run({ config, spinner, options });
|
|
382
411
|
spinner.spinner = "simpleDotsScrolling";
|
|
383
|
-
spinner.start(
|
|
412
|
+
spinner.start(pc3.yellow(pc3.bold(`Watching for changes in ${paths.join(" and ")}`)));
|
|
384
413
|
},
|
|
385
414
|
{
|
|
386
415
|
spinner,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.12",
|
|
4
4
|
"description": "Generator cli",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -27,12 +27,11 @@
|
|
|
27
27
|
"files": [
|
|
28
28
|
"dist",
|
|
29
29
|
"bin",
|
|
30
|
-
"src",
|
|
31
30
|
"!/**/**.test.**",
|
|
32
31
|
"!/**/__tests__/**"
|
|
33
32
|
],
|
|
34
33
|
"dependencies": {
|
|
35
|
-
"@swc/core": "^1.3.
|
|
34
|
+
"@swc/core": "^1.3.63",
|
|
36
35
|
"chokidar": "^3.5.3",
|
|
37
36
|
"commander": "^10.0.1",
|
|
38
37
|
"cosmiconfig": "^8.2.0",
|
|
@@ -43,13 +42,13 @@
|
|
|
43
42
|
"string-argv": "^0.3.2",
|
|
44
43
|
"ts-node": "^10.9.1",
|
|
45
44
|
"yaml": "^2.3.1",
|
|
46
|
-
"@kubb/core": "1.1.
|
|
45
|
+
"@kubb/core": "1.1.12"
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
|
-
"@types/node": "^20.
|
|
48
|
+
"@types/node": "^20.3.1",
|
|
50
49
|
"tsup": "^6.7.0",
|
|
51
50
|
"typescript": "^5.1.3",
|
|
52
|
-
"@kubb/swagger": "1.1.
|
|
51
|
+
"@kubb/swagger": "1.1.12",
|
|
53
52
|
"@kubb/ts-config": "0.1.0",
|
|
54
53
|
"@kubb/tsup-config": "1.1.8"
|
|
55
54
|
},
|
package/src/index.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import pathParser from 'node:path'
|
|
3
|
-
|
|
4
|
-
import { Command, Option } from 'commander'
|
|
5
|
-
import ora from 'ora'
|
|
6
|
-
import pc from 'picocolors'
|
|
7
|
-
|
|
8
|
-
import { version } from '../package.json'
|
|
9
|
-
import { init } from './init.ts'
|
|
10
|
-
import { run } from './run.ts'
|
|
11
|
-
import { getConfig, getCosmiConfig, startWatcher } from './utils/index.ts'
|
|
12
|
-
|
|
13
|
-
import type { CLIOptions } from '@kubb/core'
|
|
14
|
-
|
|
15
|
-
const moduleName = 'kubb'
|
|
16
|
-
|
|
17
|
-
const spinner = ora({
|
|
18
|
-
spinner: 'clock',
|
|
19
|
-
}).start()
|
|
20
|
-
|
|
21
|
-
const program = new Command(moduleName)
|
|
22
|
-
.description('Kubb')
|
|
23
|
-
.action(async (options: CLIOptions) => {
|
|
24
|
-
try {
|
|
25
|
-
if (options.init) {
|
|
26
|
-
spinner.start('📦 Initializing Kubb')
|
|
27
|
-
await init({ spinner, logLevel: options.logLevel })
|
|
28
|
-
spinner.succeed(`📦 initialized Kubb`)
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// CONFIG
|
|
33
|
-
spinner.start('💾 Loading config')
|
|
34
|
-
const result = await getCosmiConfig(moduleName, options.config)
|
|
35
|
-
spinner.succeed(`💾 Config loaded(${pc.dim(pathParser.relative(process.cwd(), result.filepath))})`)
|
|
36
|
-
|
|
37
|
-
// END CONFIG
|
|
38
|
-
|
|
39
|
-
if (options.watch) {
|
|
40
|
-
const config = await getConfig(result, options)
|
|
41
|
-
|
|
42
|
-
startWatcher(
|
|
43
|
-
async (paths) => {
|
|
44
|
-
await run({ config, spinner, options })
|
|
45
|
-
spinner.spinner = 'simpleDotsScrolling'
|
|
46
|
-
spinner.start(pc.yellow(pc.bold(`Watching for changes in ${paths.join(' and ')}`)))
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
spinner,
|
|
50
|
-
path: [config.input.path],
|
|
51
|
-
}
|
|
52
|
-
)
|
|
53
|
-
} else {
|
|
54
|
-
const config = await getConfig(result, options)
|
|
55
|
-
|
|
56
|
-
await run({ config, spinner, options })
|
|
57
|
-
}
|
|
58
|
-
} catch (e) {
|
|
59
|
-
process.exit(1)
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
.addOption(new Option('-c, --config <path>', 'Path to the Kubb config'))
|
|
63
|
-
.addOption(new Option('-i, --input <path>', 'Path of the input file(overrides the one in `kubb.config.js`)'))
|
|
64
|
-
.addOption(new Option('-l, --logLevel <type>', 'Type of the logging(overrides the one in `kubb.config.js`)').choices(['error', 'info', 'silent']))
|
|
65
|
-
.addOption(new Option('--init', 'Init Kubb'))
|
|
66
|
-
.addOption(new Option('-d, --debug', 'Debug mode').default(false))
|
|
67
|
-
.addOption(new Option('-w, --watch', 'Watch mode based on the input file'))
|
|
68
|
-
|
|
69
|
-
program.name(moduleName).description('Generate').version(version, '-v').parse()
|
package/src/init.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import pathParser from 'node:path'
|
|
2
|
-
|
|
3
|
-
import { write } from '@kubb/core'
|
|
4
|
-
|
|
5
|
-
import { $ } from 'execa'
|
|
6
|
-
import pc from 'picocolors'
|
|
7
|
-
|
|
8
|
-
import type { LogLevel } from '@kubb/core'
|
|
9
|
-
import type { Ora } from 'ora'
|
|
10
|
-
|
|
11
|
-
export type Preset = 'simple'
|
|
12
|
-
|
|
13
|
-
export type PackageManager = 'pnpm' | 'npm' | 'yarn'
|
|
14
|
-
|
|
15
|
-
export type PresetMeta = {
|
|
16
|
-
'kubb.config': string
|
|
17
|
-
packages: string[]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
type RunProps = {
|
|
21
|
-
spinner: Ora
|
|
22
|
-
/**
|
|
23
|
-
* @default `'silent'`
|
|
24
|
-
*/
|
|
25
|
-
logLevel?: LogLevel
|
|
26
|
-
/**
|
|
27
|
-
* @default `'simple'`
|
|
28
|
-
*/
|
|
29
|
-
preset?: Preset
|
|
30
|
-
/**
|
|
31
|
-
* @default `'pnpm'`
|
|
32
|
-
*/
|
|
33
|
-
packageManager?: PackageManager
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const presets: Record<Preset, PresetMeta> = {
|
|
37
|
-
simple: {
|
|
38
|
-
'kubb.config': `
|
|
39
|
-
import { defineConfig } from '@kubb/core'
|
|
40
|
-
import createSwagger from '@kubb/swagger'
|
|
41
|
-
import createSwaggerTS from '@kubb/swagger-ts'
|
|
42
|
-
import createSwaggerTanstackQuery from '@kubb/swagger-tanstack-query'
|
|
43
|
-
|
|
44
|
-
export default defineConfig({
|
|
45
|
-
root: '.',
|
|
46
|
-
input: {
|
|
47
|
-
path: 'https://petstore3.swagger.io/api/v3/openapi.json',
|
|
48
|
-
},
|
|
49
|
-
output: {
|
|
50
|
-
path: './src/gen',
|
|
51
|
-
clean: true,
|
|
52
|
-
},
|
|
53
|
-
hooks: {
|
|
54
|
-
done: 'echo "🎉 done"',
|
|
55
|
-
},
|
|
56
|
-
logLevel: 'info',
|
|
57
|
-
plugins: [createSwagger({}), createSwaggerTS({ output: 'models', enumType: 'enum' }), createSwaggerTanstackQuery({ output: './hooks' })],
|
|
58
|
-
})
|
|
59
|
-
`,
|
|
60
|
-
packages: ['@kubb/core', '@kubb/cli', '@kubb/swagger', '@kubb/swagger-ts', '@kubb/swagger-tanstack-query'],
|
|
61
|
-
},
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export async function init({ spinner, preset = 'simple', logLevel = 'silent', packageManager = 'pnpm' }: RunProps): Promise<void> {
|
|
65
|
-
try {
|
|
66
|
-
const presetMeta = presets[preset]
|
|
67
|
-
const path = pathParser.resolve(process.cwd(), './kubb.config.js')
|
|
68
|
-
const installCommand = packageManager === 'npm' ? 'install' : 'add'
|
|
69
|
-
|
|
70
|
-
spinner.start(`📀 Writing \`kubb.config.js\` ${pc.dim(path)}`)
|
|
71
|
-
await write(presetMeta['kubb.config'], path)
|
|
72
|
-
spinner.succeed(`📀 Wrote \`kubb.config.js\` ${pc.dim(path)}`)
|
|
73
|
-
|
|
74
|
-
const data = await Promise.all([
|
|
75
|
-
$`npm init es6 -y`,
|
|
76
|
-
...presetMeta.packages.map(async (pack) => {
|
|
77
|
-
spinner.start(`📀 Installing ${pc.dim(pack)}`)
|
|
78
|
-
const { stdout } = await $({ preferLocal: false })`${packageManager} ${installCommand} ${pack}`
|
|
79
|
-
spinner.succeed(`📀 Installed ${pc.dim(pack)}`)
|
|
80
|
-
|
|
81
|
-
return stdout
|
|
82
|
-
}),
|
|
83
|
-
])
|
|
84
|
-
|
|
85
|
-
if (logLevel === 'info') {
|
|
86
|
-
data.forEach((text) => console.log(text))
|
|
87
|
-
}
|
|
88
|
-
} catch (error) {
|
|
89
|
-
spinner.fail(pc.red(`Something went wrong\n\n${(error as Error)?.message}`))
|
|
90
|
-
}
|
|
91
|
-
}
|
package/src/run.ts
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import pathParser from 'node:path'
|
|
2
|
-
|
|
3
|
-
import { build, ParallelPluginError, PluginError } from '@kubb/core'
|
|
4
|
-
|
|
5
|
-
import { execa } from 'execa'
|
|
6
|
-
import pc from 'picocolors'
|
|
7
|
-
import PrettyError from 'pretty-error'
|
|
8
|
-
import { parseArgsStringToArgv } from 'string-argv'
|
|
9
|
-
|
|
10
|
-
import { parseHrtimeToSeconds } from './utils/parseHrtimeToSeconds.ts'
|
|
11
|
-
import { parseText } from './utils/parseText.ts'
|
|
12
|
-
|
|
13
|
-
import type { BuildOutput, CLIOptions, KubbConfig, Logger, LogLevel } from '@kubb/core'
|
|
14
|
-
import type { Ora } from 'ora'
|
|
15
|
-
|
|
16
|
-
type RunProps = {
|
|
17
|
-
config: KubbConfig
|
|
18
|
-
spinner: Ora
|
|
19
|
-
options: CLIOptions
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export async function run({ config, options, spinner }: RunProps): Promise<void> {
|
|
23
|
-
const hrstart = process.hrtime()
|
|
24
|
-
const logger: Logger = {
|
|
25
|
-
log(message, logLevel) {
|
|
26
|
-
if (logLevel === 'error') {
|
|
27
|
-
spinner.fail(message)
|
|
28
|
-
} else {
|
|
29
|
-
spinner.info(message)
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
spinner,
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const onDone = async (hooks: KubbConfig['hooks'], logLevel: LogLevel) => {
|
|
36
|
-
if (!hooks?.done) {
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
let commands: string[] = []
|
|
41
|
-
if (typeof hooks?.done === 'string') {
|
|
42
|
-
commands = [hooks.done]
|
|
43
|
-
} else {
|
|
44
|
-
commands = hooks.done
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const promises = commands.map(async (command) => {
|
|
48
|
-
const [cmd, ..._args] = [...parseArgsStringToArgv(command)]
|
|
49
|
-
spinner.start(parseText(`🪂 Executing hooks(${pc.yellow('done')})`, { info: ` ${pc.dim(command)}` }, logLevel))
|
|
50
|
-
const { stdout } = await execa(cmd, _args)
|
|
51
|
-
spinner.succeed(parseText(`🪂 Executing hooks(${pc.yellow('done')})`, { info: ` ${pc.dim(command)}` }, logLevel))
|
|
52
|
-
|
|
53
|
-
if (logLevel === 'info') {
|
|
54
|
-
console.log(stdout)
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
await Promise.all(promises)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const printSummary = (pluginManager: BuildOutput['pluginManager'], status: 'success' | 'failed') => {
|
|
62
|
-
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrstart))
|
|
63
|
-
|
|
64
|
-
const buildStartPlugins = [
|
|
65
|
-
...new Set(pluginManager.executed.filter((item) => item.hookName === 'buildStart' && item.plugin.name !== 'core').map((item) => item.plugin.name)),
|
|
66
|
-
]
|
|
67
|
-
const pluginsCount = config.plugins?.length || 0
|
|
68
|
-
const files = pluginManager.fileManager.files.sort((a, b) => {
|
|
69
|
-
if (!a.meta?.pluginName || !b.meta?.pluginName) {
|
|
70
|
-
return 0
|
|
71
|
-
}
|
|
72
|
-
if (a.meta?.pluginName.length < b.meta?.pluginName.length) {
|
|
73
|
-
return 1
|
|
74
|
-
}
|
|
75
|
-
if (a.meta?.pluginName.length > b.meta?.pluginName.length) {
|
|
76
|
-
return -1
|
|
77
|
-
}
|
|
78
|
-
return 0
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
const meta = {
|
|
82
|
-
plugins:
|
|
83
|
-
status === 'success'
|
|
84
|
-
? `${pc.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total`
|
|
85
|
-
: `${pc.red(`${pluginsCount - buildStartPlugins.length} failed`)}, ${pluginsCount} total`,
|
|
86
|
-
filesCreated: files.length,
|
|
87
|
-
time: pc.yellow(`${elapsedSeconds}s`),
|
|
88
|
-
output: pathParser.resolve(config.root, config.output.path),
|
|
89
|
-
} as const
|
|
90
|
-
|
|
91
|
-
console.log(`
|
|
92
|
-
${pc.bold('Plugins:')} ${meta.plugins}
|
|
93
|
-
${pc.bold('Generated:')} ${meta.filesCreated} files
|
|
94
|
-
${pc.bold('Time:')} ${meta.time}
|
|
95
|
-
${pc.bold('Output:')} ${meta.output}
|
|
96
|
-
`)
|
|
97
|
-
|
|
98
|
-
if (options.debug) {
|
|
99
|
-
console.log(`${pc.bold('Generated files:')}`)
|
|
100
|
-
console.log(`${files.map((file) => `${pc.blue(file.meta?.pluginName)} ${file.path}`).join('\n')}`)
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const printErrors = (error: Error) => {
|
|
105
|
-
const pe = new PrettyError()
|
|
106
|
-
|
|
107
|
-
if (options.debug) {
|
|
108
|
-
spinner.fail(pc.red(`Something went wrong\n\n`))
|
|
109
|
-
const causedError = error?.cause as Error
|
|
110
|
-
|
|
111
|
-
console.log(pe.render(error))
|
|
112
|
-
|
|
113
|
-
if (causedError) {
|
|
114
|
-
console.log(pe.render(causedError))
|
|
115
|
-
}
|
|
116
|
-
} else {
|
|
117
|
-
spinner.fail(pc.red(`Something went wrong\n\n${error?.message}`))
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
try {
|
|
122
|
-
const { root, ...userConfig } = config
|
|
123
|
-
const logLevel = options.logLevel ?? userConfig.logLevel ?? 'silent'
|
|
124
|
-
const inputPath = options.input ?? userConfig.input.path
|
|
125
|
-
|
|
126
|
-
spinner.start(parseText(`🚀 Building`, { info: `(${pc.dim(inputPath)})` }, logLevel))
|
|
127
|
-
|
|
128
|
-
const output = await build({
|
|
129
|
-
config: {
|
|
130
|
-
root: process.cwd(),
|
|
131
|
-
...userConfig,
|
|
132
|
-
logLevel,
|
|
133
|
-
input: {
|
|
134
|
-
...userConfig.input,
|
|
135
|
-
path: inputPath,
|
|
136
|
-
},
|
|
137
|
-
output: {
|
|
138
|
-
write: true,
|
|
139
|
-
...userConfig.output,
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
logger,
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
spinner.succeed(parseText(`🚀 Build completed`, { info: `(${pc.dim(inputPath)})` }, logLevel))
|
|
146
|
-
|
|
147
|
-
await onDone(config.hooks, logLevel)
|
|
148
|
-
|
|
149
|
-
printSummary(output.pluginManager, 'success')
|
|
150
|
-
} catch (error: any) {
|
|
151
|
-
if (error instanceof ParallelPluginError) {
|
|
152
|
-
error.errors.map((e) => printErrors(e))
|
|
153
|
-
} else {
|
|
154
|
-
printErrors(error as Error)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (error instanceof PluginError || error instanceof ParallelPluginError) {
|
|
158
|
-
printSummary(error.pluginManager, 'failed')
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
throw error
|
|
162
|
-
}
|
|
163
|
-
}
|
package/src/types.ts
DELETED
package/src/utils/getConfig.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { isPromise } from '@kubb/core'
|
|
2
|
-
|
|
3
|
-
import { getPlugins } from './getPlugins.ts'
|
|
4
|
-
|
|
5
|
-
import type { CLIOptions, KubbConfig, KubbUserConfig } from '@kubb/core'
|
|
6
|
-
import type { CosmiconfigResult } from '../types.ts'
|
|
7
|
-
|
|
8
|
-
export async function getConfig(result: CosmiconfigResult, options: CLIOptions): Promise<KubbConfig> {
|
|
9
|
-
const config = result?.config
|
|
10
|
-
let kubbUserConfig: Promise<KubbUserConfig> = Promise.resolve(config) as Promise<KubbUserConfig>
|
|
11
|
-
|
|
12
|
-
// for ts or js files
|
|
13
|
-
if (typeof config === 'function') {
|
|
14
|
-
const possiblePromise = config(options)
|
|
15
|
-
if (isPromise(possiblePromise)) {
|
|
16
|
-
kubbUserConfig = possiblePromise
|
|
17
|
-
}
|
|
18
|
-
kubbUserConfig = Promise.resolve(possiblePromise)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
let JSONConfig = await kubbUserConfig
|
|
22
|
-
JSONConfig = {
|
|
23
|
-
...JSONConfig,
|
|
24
|
-
plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : undefined,
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return JSONConfig as KubbConfig
|
|
28
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
2
|
-
import { cosmiconfig } from 'cosmiconfig'
|
|
3
|
-
import tsNode from 'ts-node'
|
|
4
|
-
import yaml from 'yaml'
|
|
5
|
-
|
|
6
|
-
import { importModule } from './importModule.ts'
|
|
7
|
-
|
|
8
|
-
import type { CosmiconfigResult } from '../types.ts'
|
|
9
|
-
|
|
10
|
-
const jsLoader = async (configFile: string) => {
|
|
11
|
-
return importModule(configFile)
|
|
12
|
-
}
|
|
13
|
-
// TODO fix tsLoader for node 20
|
|
14
|
-
// https://github.com/TypeStrong/ts-node/issues/1997
|
|
15
|
-
const tsLoader = (configFile: string) => {
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
17
|
-
let registerer = { enabled() {} }
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
// Register TypeScript compiler instance
|
|
21
|
-
registerer = tsNode.register({
|
|
22
|
-
compilerOptions: { module: 'commonjs' },
|
|
23
|
-
swc: true,
|
|
24
|
-
typeCheck: false,
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
const module = require(configFile)
|
|
28
|
-
|
|
29
|
-
return module.default
|
|
30
|
-
} catch (err: any) {
|
|
31
|
-
if (err.code === 'MODULE_NOT_FOUND') {
|
|
32
|
-
throw new Error(`'ts-node' is required for the TypeScript configuration files. Make sure it is installed\nError: ${err.message}`)
|
|
33
|
-
}
|
|
34
|
-
console.log(err)
|
|
35
|
-
|
|
36
|
-
throw err
|
|
37
|
-
} finally {
|
|
38
|
-
registerer.enabled()
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export async function getCosmiConfig(moduleName: string, config?: string) {
|
|
43
|
-
const explorer = cosmiconfig(moduleName, {
|
|
44
|
-
cache: false,
|
|
45
|
-
searchPlaces: [
|
|
46
|
-
'package.json',
|
|
47
|
-
`.${moduleName}rc`,
|
|
48
|
-
`.${moduleName}rc.json`,
|
|
49
|
-
`.${moduleName}rc.yaml`,
|
|
50
|
-
`.${moduleName}rc.yml`,
|
|
51
|
-
// TODO fix tsLoader
|
|
52
|
-
`.${moduleName}rc.ts`,
|
|
53
|
-
`.${moduleName}rc.js`,
|
|
54
|
-
`.${moduleName}rc.cjs`,
|
|
55
|
-
`.${moduleName}rc.mjs`,
|
|
56
|
-
// TODO fix tsLoader
|
|
57
|
-
`${moduleName}.config.ts`,
|
|
58
|
-
`${moduleName}.config.js`,
|
|
59
|
-
`${moduleName}.config.cjs`,
|
|
60
|
-
`${moduleName}.config.mjs`,
|
|
61
|
-
],
|
|
62
|
-
loaders: {
|
|
63
|
-
'.yaml': (filepath, content) => yaml.parse(content),
|
|
64
|
-
'.yml': (filepath, content) => yaml.parse(content),
|
|
65
|
-
'.js': jsLoader,
|
|
66
|
-
'.cjs': jsLoader,
|
|
67
|
-
'.mjs': jsLoader,
|
|
68
|
-
'.ts': tsLoader,
|
|
69
|
-
noExt: jsLoader,
|
|
70
|
-
},
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
const result = config ? await explorer.load(config) : await explorer.search()
|
|
74
|
-
|
|
75
|
-
if (result?.isEmpty || !result || !result.config) {
|
|
76
|
-
throw new Error('Config not defined, create a kubb.config.js or pass through your config with the option --config')
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return result as CosmiconfigResult
|
|
80
|
-
}
|
package/src/utils/getPlugins.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
|
|
4
|
-
import { importModule } from './importModule.ts'
|
|
5
|
-
|
|
6
|
-
import type { KubbJSONPlugin, KubbObjectPlugin, KubbUserConfig } from '@kubb/core'
|
|
7
|
-
|
|
8
|
-
function isJSONPlugins(plugins: KubbUserConfig['plugins'] | KubbJSONPlugin[]): plugins is KubbJSONPlugin[] {
|
|
9
|
-
return !!(plugins as KubbJSONPlugin[])?.some((plugin) => {
|
|
10
|
-
return typeof plugin?.[0] === 'string'
|
|
11
|
-
})
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function isObjectPlugins(plugins: KubbUserConfig['plugins'] | KubbJSONPlugin[]): plugins is KubbObjectPlugin {
|
|
15
|
-
return plugins instanceof Object && !Array.isArray(plugins)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async function importPlugin(name: string, options: object) {
|
|
19
|
-
const importedPlugin = process.env.NODE_ENV === 'test' ? await import(name) : await importModule(name, process.cwd())
|
|
20
|
-
|
|
21
|
-
return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function getPlugins(plugins: KubbUserConfig['plugins'] | KubbJSONPlugin[]): Promise<KubbUserConfig['plugins']> {
|
|
25
|
-
if (isObjectPlugins(plugins)) {
|
|
26
|
-
const promises = Object.keys(plugins).map(async (name) => {
|
|
27
|
-
return importPlugin(name, plugins[name as keyof typeof plugins])
|
|
28
|
-
})
|
|
29
|
-
return Promise.all(promises)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (isJSONPlugins(plugins)) {
|
|
33
|
-
const promises = plugins.map(async (plugin) => {
|
|
34
|
-
const [name, options = {}] = plugin
|
|
35
|
-
return importPlugin(name, options)
|
|
36
|
-
})
|
|
37
|
-
return Promise.all(promises)
|
|
38
|
-
}
|
|
39
|
-
return Promise.resolve(plugins)
|
|
40
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
2
|
-
import mod from 'node:module'
|
|
3
|
-
import { pathToFileURL } from 'node:url'
|
|
4
|
-
|
|
5
|
-
const SLASHES = new Set(['/', '\\'])
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Normalizes directories to have a trailing slash.
|
|
9
|
-
* Resolve is pretty finicky -- if the directory name doesn't have
|
|
10
|
-
* a trailing slash then it tries to look in the parent directory.
|
|
11
|
-
* i.e., if the directory is "/usr/nzakas/foo" it will start the
|
|
12
|
-
* search in /usr/nzakas. However, if the directory is "/user/nzakas/foo/",
|
|
13
|
-
* then it will start the search in /user/nzakas/foo.
|
|
14
|
-
* @param {string} directory The directory to check.
|
|
15
|
-
* @returns {string} The normalized directory.
|
|
16
|
-
*/
|
|
17
|
-
export function normalizeDirectory(directory: string) {
|
|
18
|
-
if (!SLASHES.has(directory[directory.length - 1])) {
|
|
19
|
-
return `${directory}/`
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return directory
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export async function importModule(path: string, cwd?: string): Promise<any> {
|
|
26
|
-
let location = path
|
|
27
|
-
|
|
28
|
-
if (cwd) {
|
|
29
|
-
const require = mod.createRequire(normalizeDirectory(cwd))
|
|
30
|
-
location = require.resolve(path)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const module = await import(pathToFileURL(location).href)
|
|
34
|
-
|
|
35
|
-
return module?.default ?? module
|
|
36
|
-
}
|
package/src/utils/index.ts
DELETED
package/src/utils/mocks/noop.cjs
DELETED
package/src/utils/mocks/noop.js
DELETED
package/src/utils/parseText.ts
DELETED
package/src/utils/watcher.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import pc from 'picocolors'
|
|
2
|
-
|
|
3
|
-
import type { Ora } from 'ora'
|
|
4
|
-
|
|
5
|
-
type Options = {
|
|
6
|
-
path: string[]
|
|
7
|
-
spinner: Ora
|
|
8
|
-
}
|
|
9
|
-
export async function startWatcher(cb: (path: string[]) => Promise<void>, options: Options) {
|
|
10
|
-
const { spinner, path } = options
|
|
11
|
-
const { watch } = await import('chokidar')
|
|
12
|
-
|
|
13
|
-
const ignored = ['**/{.git,node_modules}/**']
|
|
14
|
-
|
|
15
|
-
const watcher = watch(path, {
|
|
16
|
-
ignorePermissionErrors: true,
|
|
17
|
-
ignored,
|
|
18
|
-
})
|
|
19
|
-
watcher.on('all', (type, file) => {
|
|
20
|
-
spinner.succeed(pc.yellow(pc.bold(`Change detected: ${type} ${file}`)))
|
|
21
|
-
// revert back
|
|
22
|
-
spinner.spinner = 'clock'
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
cb(options.path)
|
|
26
|
-
} catch (e) {
|
|
27
|
-
spinner.warn(pc.red('Watcher failed'))
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
}
|