@kubb/cli 1.1.13 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +157 -153
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +156 -151
- package/dist/index.js.map +1 -1
- package/package.json +7 -8
package/dist/index.cjs
CHANGED
|
@@ -6,10 +6,9 @@ var ora = require('ora');
|
|
|
6
6
|
var pc3 = require('picocolors');
|
|
7
7
|
var core = require('@kubb/core');
|
|
8
8
|
var execa = require('execa');
|
|
9
|
+
var perf_hooks = require('perf_hooks');
|
|
9
10
|
var stringArgv = require('string-argv');
|
|
10
11
|
var stream = require('stream');
|
|
11
|
-
var mod = require('module');
|
|
12
|
-
var url = require('url');
|
|
13
12
|
var cosmiconfig = require('cosmiconfig');
|
|
14
13
|
var tsNode = require('ts-node');
|
|
15
14
|
var yaml = require('yaml');
|
|
@@ -20,7 +19,6 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
20
19
|
var pathParser__default = /*#__PURE__*/_interopDefault(pathParser);
|
|
21
20
|
var ora__default = /*#__PURE__*/_interopDefault(ora);
|
|
22
21
|
var pc3__default = /*#__PURE__*/_interopDefault(pc3);
|
|
23
|
-
var mod__default = /*#__PURE__*/_interopDefault(mod);
|
|
24
22
|
var tsNode__default = /*#__PURE__*/_interopDefault(tsNode);
|
|
25
23
|
var yaml__default = /*#__PURE__*/_interopDefault(yaml);
|
|
26
24
|
var PrettyError__default = /*#__PURE__*/_interopDefault(PrettyError);
|
|
@@ -34,7 +32,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
34
32
|
});
|
|
35
33
|
|
|
36
34
|
// package.json
|
|
37
|
-
var version = "1.1
|
|
35
|
+
var version = "1.2.1";
|
|
38
36
|
var presets = {
|
|
39
37
|
simple: {
|
|
40
38
|
"kubb.config": `
|
|
@@ -62,25 +60,32 @@ export default defineConfig({
|
|
|
62
60
|
packages: ["@kubb/core", "@kubb/cli", "@kubb/swagger", "@kubb/swagger-ts", "@kubb/swagger-tanstack-query"]
|
|
63
61
|
}
|
|
64
62
|
};
|
|
65
|
-
async function init({
|
|
63
|
+
async function init({ preset = "simple", logLevel = core.LogLevel.silent, packageManager = "pnpm" }) {
|
|
64
|
+
spinner.start("\u{1F4E6} Initializing Kubb");
|
|
66
65
|
const presetMeta = presets[preset];
|
|
67
66
|
const path = pathParser__default.default.resolve(process.cwd(), "./kubb.config.js");
|
|
68
67
|
const installCommand = packageManager === "npm" ? "install" : "add";
|
|
69
|
-
|
|
68
|
+
spinner.start(`\u{1F4C0} Writing \`kubb.config.js\` ${pc3__default.default.dim(path)}`);
|
|
70
69
|
await core.write(presetMeta["kubb.config"], path);
|
|
71
|
-
|
|
72
|
-
const
|
|
70
|
+
spinner.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${pc3__default.default.dim(path)}`);
|
|
71
|
+
const results = await Promise.allSettled([
|
|
73
72
|
execa.$`npm init es6 -y`,
|
|
74
73
|
...presetMeta.packages.map(async (pack) => {
|
|
75
|
-
|
|
74
|
+
spinner.start(`\u{1F4C0} Installing ${pc3__default.default.dim(pack)}`);
|
|
76
75
|
const { stdout } = await execa.$({ preferLocal: false })`${packageManager} ${installCommand} ${pack}`;
|
|
77
|
-
|
|
76
|
+
spinner.succeed(`\u{1F4C0} Installed ${pc3__default.default.dim(pack)}`);
|
|
78
77
|
return stdout;
|
|
79
78
|
})
|
|
80
79
|
]);
|
|
81
|
-
if (logLevel
|
|
82
|
-
|
|
80
|
+
if (core.canLogHierarchy(logLevel, core.LogLevel.info)) {
|
|
81
|
+
results.forEach((result) => {
|
|
82
|
+
if (core.isPromiseFulfilledResult(result)) {
|
|
83
|
+
console.log(result.value);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
83
86
|
}
|
|
87
|
+
spinner.succeed(`\u{1F4E6} initialized Kubb`);
|
|
88
|
+
return;
|
|
84
89
|
}
|
|
85
90
|
|
|
86
91
|
// src/utils/parseHrtimeToSeconds.ts
|
|
@@ -88,9 +93,7 @@ function parseHrtimeToSeconds(hrtime) {
|
|
|
88
93
|
const seconds = (hrtime[0] + hrtime[1] / 1e9).toFixed(3);
|
|
89
94
|
return seconds;
|
|
90
95
|
}
|
|
91
|
-
|
|
92
|
-
// src/utils/parseText.ts
|
|
93
|
-
function parseText(baseText, config, logLevel = "silent") {
|
|
96
|
+
function parseText(baseText, config, logLevel = core.LogLevel.silent) {
|
|
94
97
|
return `${baseText}${config[logLevel] || ""}`;
|
|
95
98
|
}
|
|
96
99
|
var OraWritable = class extends stream.Writable {
|
|
@@ -110,94 +113,100 @@ ${pc3__default.default.bold(pc3__default.default.blue(this.command))}: ${chunk?.
|
|
|
110
113
|
};
|
|
111
114
|
|
|
112
115
|
// src/run.ts
|
|
113
|
-
async function
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
116
|
+
async function executeHooks({ hooks, logLevel }) {
|
|
117
|
+
if (!hooks?.done) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done];
|
|
121
|
+
if (core.canLogHierarchy(logLevel, core.LogLevel.silent)) {
|
|
122
|
+
spinner.start(`Executing hooks`);
|
|
123
|
+
}
|
|
124
|
+
const executers = commands.map(async (command) => {
|
|
125
|
+
const oraWritable = new OraWritable(spinner, command);
|
|
126
|
+
const abortController = new AbortController();
|
|
127
|
+
const [cmd, ..._args] = [...stringArgv.parseArgsStringToArgv(command)];
|
|
128
|
+
spinner.start(parseText(`Executing hook`, { info: ` ${pc3__default.default.dim(command)}` }, logLevel));
|
|
129
|
+
const subProcess = await execa.execa(cmd, _args, { detached: true, signal: abortController.signal }).pipeStdout(oraWritable);
|
|
130
|
+
spinner.suffixText = "";
|
|
131
|
+
if (core.canLogHierarchy(logLevel, core.LogLevel.info)) {
|
|
132
|
+
spinner.succeed(parseText(`Executing hook`, { info: ` ${pc3__default.default.dim(command)}` }, logLevel));
|
|
133
|
+
console.log(subProcess.stdout);
|
|
124
134
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
135
|
+
await core.timeout(100);
|
|
136
|
+
oraWritable.destroy();
|
|
137
|
+
return { subProcess, abort: abortController.abort.bind(abortController) };
|
|
138
|
+
});
|
|
139
|
+
await Promise.all(executers);
|
|
140
|
+
if (core.canLogHierarchy(logLevel, core.LogLevel.silent)) {
|
|
141
|
+
spinner.succeed(`Executing hooks`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function getSummary({ pluginManager, status, hrstart, config, logLevel }) {
|
|
145
|
+
const logs = [];
|
|
146
|
+
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrstart));
|
|
147
|
+
const buildStartPlugins = [
|
|
148
|
+
...new Set(pluginManager.executed.filter((item) => item.hookName === "buildStart" && item.plugin.name !== "core").map((item) => item.plugin.name))
|
|
149
|
+
];
|
|
150
|
+
const failedPlugins = config.plugins?.filter((plugin) => !buildStartPlugins.includes(plugin.name))?.map((plugin) => plugin.name);
|
|
151
|
+
const pluginsCount = config.plugins?.length || 0;
|
|
152
|
+
const files = pluginManager.fileManager.files.sort((a, b) => {
|
|
153
|
+
if (!a.meta?.pluginName || !b.meta?.pluginName) {
|
|
154
|
+
return 0;
|
|
133
155
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
commands = [hooks.done];
|
|
137
|
-
} else {
|
|
138
|
-
commands = hooks.done;
|
|
156
|
+
if (a.meta?.pluginName.length < b.meta?.pluginName.length) {
|
|
157
|
+
return 1;
|
|
139
158
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const [cmd, ..._args] = [...stringArgv.parseArgsStringToArgv(command)];
|
|
143
|
-
spinner.start(parseText(`\u{1FA82} Executing hooks(${pc3__default.default.yellow("done")})`, { info: ` ${pc3__default.default.dim(command)}` }, logLevel));
|
|
144
|
-
const { stdout } = await execa.execa(cmd, _args, {}).pipeStdout(oraWritable);
|
|
145
|
-
spinner.suffixText = "";
|
|
146
|
-
oraWritable.destroy();
|
|
147
|
-
await core.timeout(50);
|
|
148
|
-
if (logLevel === "info") {
|
|
149
|
-
spinner.succeed(parseText(`\u{1FA82} Executing hooks(${pc3__default.default.yellow("done")})`, { info: ` ${pc3__default.default.dim(command)}` }, logLevel));
|
|
150
|
-
console.log(stdout);
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
await Promise.all(promises);
|
|
154
|
-
if (logLevel === "silent") {
|
|
155
|
-
spinner.succeed(parseText(`\u{1FA82} Executing hooks(${pc3__default.default.yellow("done")})`, {}, logLevel));
|
|
159
|
+
if (a.meta?.pluginName.length > b.meta?.pluginName.length) {
|
|
160
|
+
return -1;
|
|
156
161
|
}
|
|
162
|
+
return 0;
|
|
163
|
+
});
|
|
164
|
+
const meta = {
|
|
165
|
+
plugins: status === "success" ? `${pc3__default.default.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total` : `${pc3__default.default.red(`${failedPlugins?.length || 0} failed`)}, ${pluginsCount} total`,
|
|
166
|
+
pluginsFailed: status === "failed" ? failedPlugins?.map((name) => core.randomPicoColour(name))?.join(", ") : void 0,
|
|
167
|
+
filesCreated: files.length,
|
|
168
|
+
time: pc3__default.default.yellow(`${elapsedSeconds}s`),
|
|
169
|
+
output: pathParser__default.default.resolve(config.root, config.output.path)
|
|
157
170
|
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
if (core.canLogHierarchy(logLevel, "stacktrace")) {
|
|
172
|
+
logs.push(pc3__default.default.bold("Generated files:\n"));
|
|
173
|
+
logs.push(files.map((file) => `${core.randomPicoColour(file.meta?.pluginName)} ${file.path}`).join("\n"));
|
|
174
|
+
}
|
|
175
|
+
logs.push(
|
|
176
|
+
[
|
|
177
|
+
[`
|
|
178
|
+
`, true],
|
|
179
|
+
[` ${pc3__default.default.bold("Plugins:")} ${meta.plugins}`, true],
|
|
180
|
+
[` ${pc3__default.default.dim("Failed:")} ${meta.pluginsFailed || "none"}`, !!meta.pluginsFailed],
|
|
181
|
+
[`${pc3__default.default.bold("Generated:")} ${meta.filesCreated} files`, true],
|
|
182
|
+
[` ${pc3__default.default.bold("Time:")} ${meta.time}`, true],
|
|
183
|
+
[` ${pc3__default.default.bold("Output:")} ${meta.output}`, true],
|
|
184
|
+
[`
|
|
185
|
+
`, true]
|
|
186
|
+
].map((item) => {
|
|
187
|
+
if (item.at(1)) {
|
|
188
|
+
return item.at(0);
|
|
174
189
|
}
|
|
175
|
-
return 0;
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
${pc3__default.default.bold("Time:")} ${meta.time}
|
|
192
|
-
${pc3__default.default.bold("Output:")} ${meta.output}
|
|
193
|
-
|
|
194
|
-
`);
|
|
195
|
-
return logs;
|
|
196
|
-
};
|
|
190
|
+
return void 0;
|
|
191
|
+
}).filter(Boolean).join("\n")
|
|
192
|
+
);
|
|
193
|
+
return logs;
|
|
194
|
+
}
|
|
195
|
+
async function run({ config, CLIOptions }) {
|
|
196
|
+
const hrstart = process.hrtime();
|
|
197
|
+
const logger = core.createLogger(spinner);
|
|
198
|
+
const performanceOpserver = new perf_hooks.PerformanceObserver((items) => {
|
|
199
|
+
const message = `${items.getEntries()[0].duration.toFixed(0)}ms`;
|
|
200
|
+
spinner.suffixText = pc3__default.default.yellow(message);
|
|
201
|
+
perf_hooks.performance.clearMarks();
|
|
202
|
+
});
|
|
203
|
+
if (CLIOptions.debug) {
|
|
204
|
+
performanceOpserver.observe({ type: "measure" });
|
|
205
|
+
}
|
|
197
206
|
try {
|
|
198
|
-
const { root, ...userConfig } = config;
|
|
199
|
-
const logLevel =
|
|
200
|
-
const inputPath =
|
|
207
|
+
const { root: _root, ...userConfig } = config;
|
|
208
|
+
const logLevel = CLIOptions.logLevel ?? userConfig.logLevel ?? core.LogLevel.silent;
|
|
209
|
+
const inputPath = CLIOptions.input ?? userConfig.input.path;
|
|
201
210
|
spinner.start(parseText(`\u{1F680} Building`, { info: `(${pc3__default.default.dim(inputPath)})` }, logLevel));
|
|
202
211
|
const output = await core.build({
|
|
203
212
|
config: {
|
|
@@ -213,38 +222,23 @@ ${pc3__default.default.bold("Generated:")} ${meta.filesCreated} files
|
|
|
213
222
|
...userConfig.output
|
|
214
223
|
}
|
|
215
224
|
},
|
|
216
|
-
logger
|
|
225
|
+
logger,
|
|
226
|
+
debug: CLIOptions.debug
|
|
217
227
|
});
|
|
228
|
+
spinner.suffixText = "";
|
|
218
229
|
spinner.succeed(parseText(`\u{1F680} Build completed`, { info: `(${pc3__default.default.dim(inputPath)})` }, logLevel));
|
|
219
|
-
await
|
|
220
|
-
|
|
230
|
+
await core.timeout(100);
|
|
231
|
+
await executeHooks({ hooks: config.hooks, logLevel, debug: CLIOptions.debug });
|
|
232
|
+
const summary = getSummary({ pluginManager: output.pluginManager, config, status: "success", hrstart, logLevel: CLIOptions.logLevel });
|
|
221
233
|
console.log(summary.join(""));
|
|
222
234
|
} catch (error) {
|
|
235
|
+
let summary = [];
|
|
223
236
|
if (error instanceof core.PluginError || error instanceof core.ParallelPluginError) {
|
|
224
|
-
|
|
225
|
-
throw new core.SummaryError("Something went wrong\n", { cause: error, summary });
|
|
237
|
+
summary = getSummary({ pluginManager: error.pluginManager, config, status: "failed", hrstart, logLevel: CLIOptions.logLevel });
|
|
226
238
|
}
|
|
227
|
-
throw new core.SummaryError("Something went wrong\n", { cause: error });
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
var SLASHES = /* @__PURE__ */ new Set(["/", "\\"]);
|
|
231
|
-
function normalizeDirectory(directory) {
|
|
232
|
-
if (!SLASHES.has(directory[directory.length - 1])) {
|
|
233
|
-
return `${directory}/`;
|
|
234
|
-
}
|
|
235
|
-
return directory;
|
|
236
|
-
}
|
|
237
|
-
async function importModule(path, cwd) {
|
|
238
|
-
let location = path;
|
|
239
|
-
if (cwd) {
|
|
240
|
-
const require2 = mod__default.default.createRequire(normalizeDirectory(cwd));
|
|
241
|
-
location = require2.resolve(path);
|
|
239
|
+
throw new core.SummaryError("Something went wrong\n", { cause: error, summary });
|
|
242
240
|
}
|
|
243
|
-
const module = await import(url.pathToFileURL(location).href);
|
|
244
|
-
return module?.default ?? module;
|
|
245
241
|
}
|
|
246
|
-
|
|
247
|
-
// src/utils/getPlugins.ts
|
|
248
242
|
function isJSONPlugins(plugins) {
|
|
249
243
|
return !!plugins?.some((plugin) => {
|
|
250
244
|
return typeof plugin?.[0] === "string";
|
|
@@ -254,18 +248,18 @@ function isObjectPlugins(plugins) {
|
|
|
254
248
|
return plugins instanceof Object && !Array.isArray(plugins);
|
|
255
249
|
}
|
|
256
250
|
async function importPlugin(name, options) {
|
|
257
|
-
const importedPlugin = process.env.NODE_ENV === "test" ? await import(name) : await importModule(name, process.cwd());
|
|
251
|
+
const importedPlugin = process.env.NODE_ENV === "test" ? await import(name) : await core.importModule(name, process.cwd());
|
|
258
252
|
return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options);
|
|
259
253
|
}
|
|
260
254
|
function getPlugins(plugins) {
|
|
261
255
|
if (isObjectPlugins(plugins)) {
|
|
262
|
-
const promises = Object.keys(plugins).map(
|
|
256
|
+
const promises = Object.keys(plugins).map((name) => {
|
|
263
257
|
return importPlugin(name, plugins[name]);
|
|
264
258
|
});
|
|
265
259
|
return Promise.all(promises);
|
|
266
260
|
}
|
|
267
261
|
if (isJSONPlugins(plugins)) {
|
|
268
|
-
const promises = plugins.map(
|
|
262
|
+
const promises = plugins.map((plugin) => {
|
|
269
263
|
const [name, options = {}] = plugin;
|
|
270
264
|
return importPlugin(name, options);
|
|
271
265
|
});
|
|
@@ -275,11 +269,11 @@ function getPlugins(plugins) {
|
|
|
275
269
|
}
|
|
276
270
|
|
|
277
271
|
// src/utils/getConfig.ts
|
|
278
|
-
async function getConfig(result,
|
|
272
|
+
async function getConfig(result, CLIOptions) {
|
|
279
273
|
const config = result?.config;
|
|
280
274
|
let kubbUserConfig = Promise.resolve(config);
|
|
281
275
|
if (typeof config === "function") {
|
|
282
|
-
const possiblePromise = config(
|
|
276
|
+
const possiblePromise = config(CLIOptions);
|
|
283
277
|
if (core.isPromise(possiblePromise)) {
|
|
284
278
|
kubbUserConfig = possiblePromise;
|
|
285
279
|
}
|
|
@@ -308,9 +302,10 @@ async function startWatcher(path, cb) {
|
|
|
308
302
|
spinner.warn(pc3__default.default.red("Watcher failed"));
|
|
309
303
|
}
|
|
310
304
|
});
|
|
305
|
+
return;
|
|
311
306
|
}
|
|
312
307
|
var jsLoader = async (configFile) => {
|
|
313
|
-
return importModule(configFile);
|
|
308
|
+
return core.importModule(configFile);
|
|
314
309
|
};
|
|
315
310
|
var tsLoader = (configFile) => {
|
|
316
311
|
let registerer = { enabled() {
|
|
@@ -384,14 +379,14 @@ function getErrorCauses(errors) {
|
|
|
384
379
|
return prev;
|
|
385
380
|
}, []).filter(Boolean);
|
|
386
381
|
}
|
|
387
|
-
function renderErrors(error, { prefixText,
|
|
382
|
+
function renderErrors(error, { prefixText, logLevel = core.LogLevel.silent }) {
|
|
388
383
|
if (!error) {
|
|
389
384
|
return "";
|
|
390
385
|
}
|
|
391
386
|
if (error instanceof core.ParallelPluginError) {
|
|
392
|
-
return [prefixText, ...error.errors.map((e) => renderErrors(e, {
|
|
387
|
+
return [prefixText, ...error.errors.map((e) => renderErrors(e, { logLevel }))].filter(Boolean).join("\n");
|
|
393
388
|
}
|
|
394
|
-
if (
|
|
389
|
+
if (core.canLogHierarchy(logLevel, "stacktrace")) {
|
|
395
390
|
const errors = getErrorCauses([error]);
|
|
396
391
|
return [prefixText, ...errors].filter(Boolean).join("\n");
|
|
397
392
|
}
|
|
@@ -405,52 +400,61 @@ var moduleName = "kubb";
|
|
|
405
400
|
var spinner = ora__default.default({
|
|
406
401
|
spinner: "clock"
|
|
407
402
|
});
|
|
403
|
+
function programCatcher(e, CLIOptions) {
|
|
404
|
+
const originalError = e;
|
|
405
|
+
let error = originalError;
|
|
406
|
+
const summaryError = error instanceof core.SummaryError ? error : void 0;
|
|
407
|
+
if (summaryError) {
|
|
408
|
+
error = summaryError.cause;
|
|
409
|
+
}
|
|
410
|
+
const message = renderErrors(error, { logLevel: CLIOptions.logLevel, prefixText: pc3__default.default.red(originalError?.message) });
|
|
411
|
+
if (error instanceof core.Warning) {
|
|
412
|
+
spinner.warn(pc3__default.default.yellow(error.message));
|
|
413
|
+
process.exit(0);
|
|
414
|
+
}
|
|
415
|
+
if (core.canLogHierarchy(CLIOptions.logLevel, core.LogLevel.silent)) {
|
|
416
|
+
spinner.fail(message);
|
|
417
|
+
process.exit(1);
|
|
418
|
+
}
|
|
419
|
+
spinner.fail([message, ...summaryError?.summary || []].join("\n"));
|
|
420
|
+
process.exit(1);
|
|
421
|
+
}
|
|
408
422
|
var program = new commander.Command(moduleName).name(moduleName).description("Kubb").version(version, "-v").exitOverride((err) => {
|
|
409
423
|
if (err instanceof commander.CommanderError) {
|
|
410
424
|
process.exit(1);
|
|
411
425
|
}
|
|
412
426
|
}).configureOutput({
|
|
413
427
|
outputError: (message, write2) => {
|
|
414
|
-
const
|
|
428
|
+
const CLIOptions = program.opts();
|
|
415
429
|
write2(
|
|
416
|
-
renderErrors(new Error(message, { cause: void 0 }), {
|
|
430
|
+
renderErrors(new Error(message, { cause: void 0 }), {
|
|
431
|
+
logLevel: CLIOptions.logLevel,
|
|
432
|
+
prefixText: pc3__default.default.red("Something went wrong with processing the CLI\n")
|
|
433
|
+
}) + "\n"
|
|
417
434
|
);
|
|
418
435
|
}
|
|
419
|
-
}).action(async (options) => {
|
|
436
|
+
}).addOption(new commander.Option("-c, --config <path>", "Path to the Kubb config")).addOption(new commander.Option("-i, --input <path>", "Path of the input file(overrides the one in `kubb.config.js`)")).addOption(new commander.Option("-l, --logLevel <type>", "Type of the logging(overrides the one in `kubb.config.js`)").choices(["info", "silent", "stacktrace"])).addOption(new commander.Option("--init", "Init Kubb")).addOption(new commander.Option("-d, --debug", "Debug mode").default(false)).addOption(new commander.Option("-w, --watch", "Watch mode based on the input file")).action(async (options) => {
|
|
420
437
|
try {
|
|
421
|
-
spinner.start();
|
|
422
438
|
if (options.init) {
|
|
423
|
-
|
|
424
|
-
await init({ spinner, logLevel: options.logLevel });
|
|
425
|
-
spinner.succeed(`\u{1F4E6} initialized Kubb`);
|
|
426
|
-
return;
|
|
439
|
+
return init({ logLevel: options.logLevel });
|
|
427
440
|
}
|
|
428
441
|
spinner.start("\u{1F4BE} Loading config");
|
|
429
442
|
const result = await getCosmiConfig(moduleName, options.config);
|
|
430
443
|
spinner.succeed(`\u{1F4BE} Config loaded(${pc3__default.default.dim(pathParser__default.default.relative(process.cwd(), result.filepath))})`);
|
|
431
444
|
if (options.watch) {
|
|
432
|
-
const
|
|
433
|
-
startWatcher([
|
|
434
|
-
await run({ config, options });
|
|
445
|
+
const config2 = await getConfig(result, options);
|
|
446
|
+
return startWatcher([config2.input.path], async (paths) => {
|
|
447
|
+
await run({ config: config2, CLIOptions: options });
|
|
435
448
|
spinner.spinner = "simpleDotsScrolling";
|
|
436
449
|
spinner.start(pc3__default.default.yellow(pc3__default.default.bold(`Watching for changes in ${paths.join(" and ")}`)));
|
|
437
450
|
});
|
|
438
|
-
} else {
|
|
439
|
-
const config = await getConfig(result, options);
|
|
440
|
-
await run({ config, options });
|
|
441
451
|
}
|
|
452
|
+
const config = await getConfig(result, options);
|
|
453
|
+
await run({ config, CLIOptions: options });
|
|
442
454
|
} catch (e) {
|
|
443
|
-
|
|
444
|
-
let error = originalError;
|
|
445
|
-
const summaryError = error instanceof core.SummaryError ? error : void 0;
|
|
446
|
-
if (summaryError) {
|
|
447
|
-
error = summaryError.cause;
|
|
448
|
-
}
|
|
449
|
-
const message = renderErrors(error, { debug: options.debug, prefixText: pc3__default.default.red(originalError?.message) });
|
|
450
|
-
spinner.fail([message, ...summaryError?.summary || []].join("\n"));
|
|
451
|
-
process.exit(1);
|
|
455
|
+
programCatcher(e, options);
|
|
452
456
|
}
|
|
453
|
-
})
|
|
457
|
+
});
|
|
454
458
|
|
|
455
459
|
// src/index.ts
|
|
456
460
|
function runCLI(argv) {
|