@kubb/cli 1.1.5 → 1.1.7
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 +87 -87
- package/dist/index.js +86 -86
- package/package.json +8 -7
- package/src/index.ts +5 -6
- package/src/init.ts +3 -3
- package/src/run.ts +9 -10
- package/src/utils/getConfig.ts +1 -1
- package/src/utils/getCosmiConfig.ts +4 -2
- package/src/utils/getPlugins.ts +2 -2
- package/src/utils/importModule.ts +5 -4
- package/src/utils/mocks/noop.cjs +3 -0
- package/src/utils/mocks/noop.js +3 -0
- package/src/utils/watcher.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -4,26 +4,26 @@
|
|
|
4
4
|
var mod = require('module');
|
|
5
5
|
var pathParser = require('path');
|
|
6
6
|
var commander = require('commander');
|
|
7
|
-
var pc = require('picocolors');
|
|
8
7
|
var ora = require('ora');
|
|
8
|
+
var pc2 = require('picocolors');
|
|
9
|
+
var core = require('@kubb/core');
|
|
9
10
|
var execa = require('execa');
|
|
10
|
-
var stringArgv = require('string-argv');
|
|
11
11
|
var PrettyError = require('pretty-error');
|
|
12
|
-
var
|
|
12
|
+
var stringArgv = require('string-argv');
|
|
13
13
|
var url = require('url');
|
|
14
14
|
var cosmiconfig = require('cosmiconfig');
|
|
15
|
-
var yaml = require('yaml');
|
|
16
15
|
var tsNode = require('ts-node');
|
|
16
|
+
var yaml = require('yaml');
|
|
17
17
|
|
|
18
18
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
19
|
|
|
20
20
|
var mod__default = /*#__PURE__*/_interopDefault(mod);
|
|
21
21
|
var pathParser__default = /*#__PURE__*/_interopDefault(pathParser);
|
|
22
|
-
var pc__default = /*#__PURE__*/_interopDefault(pc);
|
|
23
22
|
var ora__default = /*#__PURE__*/_interopDefault(ora);
|
|
23
|
+
var pc2__default = /*#__PURE__*/_interopDefault(pc2);
|
|
24
24
|
var PrettyError__default = /*#__PURE__*/_interopDefault(PrettyError);
|
|
25
|
-
var yaml__default = /*#__PURE__*/_interopDefault(yaml);
|
|
26
25
|
var tsNode__default = /*#__PURE__*/_interopDefault(tsNode);
|
|
26
|
+
var yaml__default = /*#__PURE__*/_interopDefault(yaml);
|
|
27
27
|
|
|
28
28
|
const require$1 = mod.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('out.js', document.baseURI).href)));
|
|
29
29
|
var __require = /* @__PURE__ */ ((x) => typeof require$1 !== "undefined" ? require$1 : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
@@ -34,9 +34,60 @@ var __require = /* @__PURE__ */ ((x) => typeof require$1 !== "undefined" ? requi
|
|
|
34
34
|
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
// package.json
|
|
38
|
+
var version = "1.1.7";
|
|
39
|
+
var presets = {
|
|
40
|
+
simple: {
|
|
41
|
+
"kubb.config": `
|
|
42
|
+
import { defineConfig } from '@kubb/core'
|
|
43
|
+
import createSwagger from '@kubb/swagger'
|
|
44
|
+
import createSwaggerTS from '@kubb/swagger-ts'
|
|
45
|
+
import createSwaggerTanstackQuery from '@kubb/swagger-tanstack-query'
|
|
46
|
+
|
|
47
|
+
export default defineConfig({
|
|
48
|
+
root: '.',
|
|
49
|
+
input: {
|
|
50
|
+
path: 'https://petstore3.swagger.io/api/v3/openapi.json',
|
|
51
|
+
},
|
|
52
|
+
output: {
|
|
53
|
+
path: './src/gen',
|
|
54
|
+
clean: true,
|
|
55
|
+
},
|
|
56
|
+
hooks: {
|
|
57
|
+
done: 'echo "\u{1F389} done"',
|
|
58
|
+
},
|
|
59
|
+
logLevel: 'info',
|
|
60
|
+
plugins: [createSwagger({}), createSwaggerTS({ output: 'models', enumType: 'enum' }), createSwaggerTanstackQuery({ output: './hooks' })],
|
|
61
|
+
})
|
|
62
|
+
`,
|
|
63
|
+
packages: ["@kubb/core", "@kubb/cli", "@kubb/swagger", "@kubb/swagger-ts", "@kubb/swagger-tanstack-query"]
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
async function init({ spinner: spinner2, preset = "simple", logLevel = "silent", packageManager = "pnpm" }) {
|
|
67
|
+
try {
|
|
68
|
+
const presetMeta = presets[preset];
|
|
69
|
+
const path = pathParser__default.default.resolve(process.cwd(), "./kubb.config.js");
|
|
70
|
+
const installCommand = packageManager === "npm" ? "install" : "add";
|
|
71
|
+
spinner2.start(`\u{1F4C0} Writing \`kubb.config.js\` ${pc2__default.default.dim(path)}`);
|
|
72
|
+
await core.write(presetMeta["kubb.config"], path);
|
|
73
|
+
spinner2.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${pc2__default.default.dim(path)}`);
|
|
74
|
+
const data = await Promise.all([
|
|
75
|
+
execa.$`npm init es6 -y`,
|
|
76
|
+
...presetMeta.packages.map(async (pack) => {
|
|
77
|
+
spinner2.start(`\u{1F4C0} Installing ${pc2__default.default.dim(pack)}`);
|
|
78
|
+
const { stdout } = await execa.$({ preferLocal: false })`${packageManager} ${installCommand} ${pack}`;
|
|
79
|
+
spinner2.succeed(`\u{1F4C0} Installed ${pc2__default.default.dim(pack)}`);
|
|
80
|
+
return stdout;
|
|
81
|
+
})
|
|
82
|
+
]);
|
|
83
|
+
if (logLevel === "info") {
|
|
84
|
+
data.forEach((text) => console.log(text));
|
|
85
|
+
}
|
|
86
|
+
} catch (error) {
|
|
87
|
+
spinner2.fail(pc2__default.default.red(`Something went wrong
|
|
88
|
+
|
|
89
|
+
${error?.message}`));
|
|
90
|
+
}
|
|
40
91
|
}
|
|
41
92
|
|
|
42
93
|
// src/utils/parseHrtimeToSeconds.ts
|
|
@@ -45,6 +96,11 @@ function parseHrtimeToSeconds(hrtime) {
|
|
|
45
96
|
return seconds;
|
|
46
97
|
}
|
|
47
98
|
|
|
99
|
+
// src/utils/parseText.ts
|
|
100
|
+
function parseText(baseText, config, logLevel = "silent") {
|
|
101
|
+
return `${baseText}${config[logLevel] || ""}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
48
104
|
// src/run.ts
|
|
49
105
|
async function run({ config, options, spinner: spinner2 }) {
|
|
50
106
|
const hrstart = process.hrtime();
|
|
@@ -70,9 +126,9 @@ async function run({ config, options, spinner: spinner2 }) {
|
|
|
70
126
|
}
|
|
71
127
|
const promises = commands.map(async (command) => {
|
|
72
128
|
const [cmd, ..._args] = [...stringArgv.parseArgsStringToArgv(command)];
|
|
73
|
-
spinner2.start(parseText(`\u{1FA82} Executing hooks(${
|
|
129
|
+
spinner2.start(parseText(`\u{1FA82} Executing hooks(${pc2__default.default.yellow("done")})`, { info: ` ${pc2__default.default.dim(command)}` }, logLevel));
|
|
74
130
|
const { stdout } = await execa.execa(cmd, _args);
|
|
75
|
-
spinner2.succeed(parseText(`\u{1FA82} Executing hooks(${
|
|
131
|
+
spinner2.succeed(parseText(`\u{1FA82} Executing hooks(${pc2__default.default.yellow("done")})`, { info: ` ${pc2__default.default.dim(command)}` }, logLevel));
|
|
76
132
|
if (logLevel === "info") {
|
|
77
133
|
console.log(stdout);
|
|
78
134
|
}
|
|
@@ -96,20 +152,20 @@ async function run({ config, options, spinner: spinner2 }) {
|
|
|
96
152
|
return 0;
|
|
97
153
|
});
|
|
98
154
|
const meta = {
|
|
99
|
-
plugins: status === "success" ? `${
|
|
155
|
+
plugins: status === "success" ? `${pc2__default.default.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total` : `${pc2__default.default.red(`${pluginsCount - buildStartPlugins.length} failed`)}, ${pluginsCount} total`,
|
|
100
156
|
filesCreated: files.length,
|
|
101
|
-
time:
|
|
157
|
+
time: pc2__default.default.yellow(`${elapsedSeconds}s`),
|
|
102
158
|
output: pathParser__default.default.resolve(config.root, config.output.path)
|
|
103
159
|
};
|
|
104
160
|
console.log(`
|
|
105
|
-
${
|
|
106
|
-
${
|
|
107
|
-
${
|
|
108
|
-
${
|
|
161
|
+
${pc2__default.default.bold("Plugins:")} ${meta.plugins}
|
|
162
|
+
${pc2__default.default.bold("Generated:")} ${meta.filesCreated} files
|
|
163
|
+
${pc2__default.default.bold("Time:")} ${meta.time}
|
|
164
|
+
${pc2__default.default.bold("Output:")} ${meta.output}
|
|
109
165
|
`);
|
|
110
166
|
if (options.debug) {
|
|
111
|
-
console.log(`${
|
|
112
|
-
console.log(`${files.map((file) => `${
|
|
167
|
+
console.log(`${pc2__default.default.bold("Generated files:")}`);
|
|
168
|
+
console.log(`${files.map((file) => `${pc2__default.default.blue(file.meta?.pluginName)} ${file.path}`).join("\n")}`);
|
|
113
169
|
}
|
|
114
170
|
};
|
|
115
171
|
const printErrors = (error) => {
|
|
@@ -119,7 +175,7 @@ ${pc__default.default.bold("Generated:")} ${meta.filesCreated} files
|
|
|
119
175
|
return;
|
|
120
176
|
}
|
|
121
177
|
if (options.debug) {
|
|
122
|
-
spinner2.fail(
|
|
178
|
+
spinner2.fail(pc2__default.default.red(`Something went wrong
|
|
123
179
|
|
|
124
180
|
`));
|
|
125
181
|
const causedError = error?.cause;
|
|
@@ -128,7 +184,7 @@ ${pc__default.default.bold("Generated:")} ${meta.filesCreated} files
|
|
|
128
184
|
console.log(pe.render(causedError));
|
|
129
185
|
}
|
|
130
186
|
} else {
|
|
131
|
-
spinner2.fail(
|
|
187
|
+
spinner2.fail(pc2__default.default.red(`Something went wrong
|
|
132
188
|
|
|
133
189
|
${error?.message}`));
|
|
134
190
|
}
|
|
@@ -137,7 +193,7 @@ ${error?.message}`));
|
|
|
137
193
|
const { root, ...userConfig } = config;
|
|
138
194
|
const logLevel = options.logLevel ?? userConfig.logLevel ?? "silent";
|
|
139
195
|
const inputPath = options.input ?? userConfig.input.path;
|
|
140
|
-
spinner2.start(parseText(`\u{1F680} Building`, { info: `(${
|
|
196
|
+
spinner2.start(parseText(`\u{1F680} Building`, { info: `(${pc2__default.default.dim(inputPath)})` }, logLevel));
|
|
141
197
|
const output = await core.build({
|
|
142
198
|
config: {
|
|
143
199
|
root: process.cwd(),
|
|
@@ -154,7 +210,7 @@ ${error?.message}`));
|
|
|
154
210
|
},
|
|
155
211
|
logger
|
|
156
212
|
});
|
|
157
|
-
spinner2.succeed(parseText(`\u{1F680} Build completed`, { info: `(${
|
|
213
|
+
spinner2.succeed(parseText(`\u{1F680} Build completed`, { info: `(${pc2__default.default.dim(inputPath)})` }, logLevel));
|
|
158
214
|
await onDone(config.hooks, logLevel);
|
|
159
215
|
printSummary(output.pluginManager, "success");
|
|
160
216
|
} catch (error) {
|
|
@@ -179,7 +235,7 @@ async function importModule(path, cwd) {
|
|
|
179
235
|
location = require2.resolve(path);
|
|
180
236
|
}
|
|
181
237
|
const module = await import(url.pathToFileURL(location).href);
|
|
182
|
-
return module
|
|
238
|
+
return module?.default ?? module;
|
|
183
239
|
}
|
|
184
240
|
|
|
185
241
|
// src/utils/getPlugins.ts
|
|
@@ -238,20 +294,20 @@ async function startWatcher(cb, options) {
|
|
|
238
294
|
ignorePermissionErrors: true,
|
|
239
295
|
ignored
|
|
240
296
|
});
|
|
241
|
-
watcher.on("all",
|
|
242
|
-
spinner2.succeed(
|
|
297
|
+
watcher.on("all", (type, file) => {
|
|
298
|
+
spinner2.succeed(pc2__default.default.yellow(pc2__default.default.bold(`Change detected: ${type} ${file}`)));
|
|
243
299
|
spinner2.spinner = "clock";
|
|
244
300
|
try {
|
|
245
|
-
|
|
301
|
+
cb(options.path);
|
|
246
302
|
} catch (e) {
|
|
247
|
-
spinner2.warn(
|
|
303
|
+
spinner2.warn(pc2__default.default.red("Watcher failed"));
|
|
248
304
|
}
|
|
249
305
|
});
|
|
250
306
|
}
|
|
251
307
|
var jsLoader = async (configFile) => {
|
|
252
308
|
return importModule(configFile);
|
|
253
309
|
};
|
|
254
|
-
var tsLoader =
|
|
310
|
+
var tsLoader = (configFile) => {
|
|
255
311
|
let registerer = { enabled() {
|
|
256
312
|
} };
|
|
257
313
|
try {
|
|
@@ -309,62 +365,6 @@ async function getCosmiConfig(moduleName2, config) {
|
|
|
309
365
|
}
|
|
310
366
|
return result;
|
|
311
367
|
}
|
|
312
|
-
var presets = {
|
|
313
|
-
simple: {
|
|
314
|
-
"kubb.config": `
|
|
315
|
-
import { defineConfig } from '@kubb/core'
|
|
316
|
-
import createSwagger from '@kubb/swagger'
|
|
317
|
-
import createSwaggerTS from '@kubb/swagger-ts'
|
|
318
|
-
import createSwaggerTanstackQuery from '@kubb/swagger-tanstack-query'
|
|
319
|
-
|
|
320
|
-
export default defineConfig({
|
|
321
|
-
root: '.',
|
|
322
|
-
input: {
|
|
323
|
-
path: 'https://petstore3.swagger.io/api/v3/openapi.json',
|
|
324
|
-
},
|
|
325
|
-
output: {
|
|
326
|
-
path: './src/gen',
|
|
327
|
-
clean: true,
|
|
328
|
-
},
|
|
329
|
-
hooks: {
|
|
330
|
-
done: 'echo "\u{1F389} done"',
|
|
331
|
-
},
|
|
332
|
-
logLevel: 'info',
|
|
333
|
-
plugins: [createSwagger({}), createSwaggerTS({ output: 'models', enumType: 'enum' }), createSwaggerTanstackQuery({ output: './hooks' })],
|
|
334
|
-
})
|
|
335
|
-
`,
|
|
336
|
-
packages: ["@kubb/core", "@kubb/cli", "@kubb/swagger", "@kubb/swagger-ts", "@kubb/swagger-tanstack-query"]
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
async function init({ spinner: spinner2, preset = "simple", logLevel = "silent", packageManager = "pnpm" }) {
|
|
340
|
-
try {
|
|
341
|
-
const presetMeta = presets[preset];
|
|
342
|
-
const path = pathParser__default.default.resolve(process.cwd(), "./kubb.config.js");
|
|
343
|
-
const installCommand = packageManager === "npm" ? "install" : "add";
|
|
344
|
-
spinner2.start(`\u{1F4C0} Writing \`kubb.config.js\` ${pc__default.default.dim(path)}`);
|
|
345
|
-
await core.write(presetMeta["kubb.config"], path);
|
|
346
|
-
spinner2.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${pc__default.default.dim(path)}`);
|
|
347
|
-
const data = await Promise.all([
|
|
348
|
-
execa.$`npm init es6 -y`,
|
|
349
|
-
...presetMeta.packages.map(async (pack) => {
|
|
350
|
-
spinner2.start(`\u{1F4C0} Installing ${pc__default.default.dim(pack)}`);
|
|
351
|
-
const { stdout } = await execa.$({ preferLocal: false })`${packageManager} ${installCommand} ${pack}`;
|
|
352
|
-
spinner2.succeed(`\u{1F4C0} Installed ${pc__default.default.dim(pack)}`);
|
|
353
|
-
return stdout;
|
|
354
|
-
})
|
|
355
|
-
]);
|
|
356
|
-
if (logLevel === "info") {
|
|
357
|
-
data.forEach((text) => console.log(text));
|
|
358
|
-
}
|
|
359
|
-
} catch (error) {
|
|
360
|
-
spinner2.fail(pc__default.default.red(`Something went wrong
|
|
361
|
-
|
|
362
|
-
${error?.message}`));
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
// package.json
|
|
367
|
-
var version = "1.1.5";
|
|
368
368
|
|
|
369
369
|
// src/index.ts
|
|
370
370
|
var moduleName = "kubb";
|
|
@@ -381,14 +381,14 @@ var program = new commander.Command(moduleName).description("Kubb").action(async
|
|
|
381
381
|
}
|
|
382
382
|
spinner.start("\u{1F4BE} Loading config");
|
|
383
383
|
const result = await getCosmiConfig(moduleName, options.config);
|
|
384
|
-
spinner.succeed(`\u{1F4BE} Config loaded(${
|
|
384
|
+
spinner.succeed(`\u{1F4BE} Config loaded(${pc2__default.default.dim(pathParser__default.default.relative(process.cwd(), result.filepath))})`);
|
|
385
385
|
if (options.watch) {
|
|
386
386
|
const config = await getConfig(result, options);
|
|
387
387
|
startWatcher(
|
|
388
388
|
async (paths) => {
|
|
389
389
|
await run({ config, spinner, options });
|
|
390
390
|
spinner.spinner = "simpleDotsScrolling";
|
|
391
|
-
spinner.start(
|
|
391
|
+
spinner.start(pc2__default.default.yellow(pc2__default.default.bold(`Watching for changes in ${paths.join(" and ")}`)));
|
|
392
392
|
},
|
|
393
393
|
{
|
|
394
394
|
spinner,
|
package/dist/index.js
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
import { createRequire } from 'module';
|
|
3
3
|
import pathParser from 'node:path';
|
|
4
4
|
import { Command, Option } from 'commander';
|
|
5
|
-
import pc from 'picocolors';
|
|
6
5
|
import ora from 'ora';
|
|
6
|
+
import pc2 from 'picocolors';
|
|
7
|
+
import { write, build, PluginError, ParallelPluginError, isPromise } from '@kubb/core';
|
|
7
8
|
import { $, execa } from 'execa';
|
|
8
|
-
import { parseArgsStringToArgv } from 'string-argv';
|
|
9
9
|
import PrettyError from 'pretty-error';
|
|
10
|
-
import {
|
|
11
|
-
import { pathToFileURL } from 'node:url';
|
|
10
|
+
import { parseArgsStringToArgv } from 'string-argv';
|
|
12
11
|
import mod from 'node:module';
|
|
12
|
+
import { pathToFileURL } from 'node:url';
|
|
13
13
|
import { cosmiconfig } from 'cosmiconfig';
|
|
14
|
-
import yaml from 'yaml';
|
|
15
14
|
import tsNode from 'ts-node';
|
|
15
|
+
import yaml from 'yaml';
|
|
16
16
|
|
|
17
17
|
const require = createRequire(import.meta.url);
|
|
18
18
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
@@ -23,9 +23,60 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
23
23
|
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
// package.json
|
|
27
|
+
var version = "1.1.7";
|
|
28
|
+
var presets = {
|
|
29
|
+
simple: {
|
|
30
|
+
"kubb.config": `
|
|
31
|
+
import { defineConfig } from '@kubb/core'
|
|
32
|
+
import createSwagger from '@kubb/swagger'
|
|
33
|
+
import createSwaggerTS from '@kubb/swagger-ts'
|
|
34
|
+
import createSwaggerTanstackQuery from '@kubb/swagger-tanstack-query'
|
|
35
|
+
|
|
36
|
+
export default defineConfig({
|
|
37
|
+
root: '.',
|
|
38
|
+
input: {
|
|
39
|
+
path: 'https://petstore3.swagger.io/api/v3/openapi.json',
|
|
40
|
+
},
|
|
41
|
+
output: {
|
|
42
|
+
path: './src/gen',
|
|
43
|
+
clean: true,
|
|
44
|
+
},
|
|
45
|
+
hooks: {
|
|
46
|
+
done: 'echo "\u{1F389} done"',
|
|
47
|
+
},
|
|
48
|
+
logLevel: 'info',
|
|
49
|
+
plugins: [createSwagger({}), createSwaggerTS({ output: 'models', enumType: 'enum' }), createSwaggerTanstackQuery({ output: './hooks' })],
|
|
50
|
+
})
|
|
51
|
+
`,
|
|
52
|
+
packages: ["@kubb/core", "@kubb/cli", "@kubb/swagger", "@kubb/swagger-ts", "@kubb/swagger-tanstack-query"]
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
async function init({ spinner: spinner2, preset = "simple", logLevel = "silent", packageManager = "pnpm" }) {
|
|
56
|
+
try {
|
|
57
|
+
const presetMeta = presets[preset];
|
|
58
|
+
const path = pathParser.resolve(process.cwd(), "./kubb.config.js");
|
|
59
|
+
const installCommand = packageManager === "npm" ? "install" : "add";
|
|
60
|
+
spinner2.start(`\u{1F4C0} Writing \`kubb.config.js\` ${pc2.dim(path)}`);
|
|
61
|
+
await write(presetMeta["kubb.config"], path);
|
|
62
|
+
spinner2.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${pc2.dim(path)}`);
|
|
63
|
+
const data = await Promise.all([
|
|
64
|
+
$`npm init es6 -y`,
|
|
65
|
+
...presetMeta.packages.map(async (pack) => {
|
|
66
|
+
spinner2.start(`\u{1F4C0} Installing ${pc2.dim(pack)}`);
|
|
67
|
+
const { stdout } = await $({ preferLocal: false })`${packageManager} ${installCommand} ${pack}`;
|
|
68
|
+
spinner2.succeed(`\u{1F4C0} Installed ${pc2.dim(pack)}`);
|
|
69
|
+
return stdout;
|
|
70
|
+
})
|
|
71
|
+
]);
|
|
72
|
+
if (logLevel === "info") {
|
|
73
|
+
data.forEach((text) => console.log(text));
|
|
74
|
+
}
|
|
75
|
+
} catch (error) {
|
|
76
|
+
spinner2.fail(pc2.red(`Something went wrong
|
|
77
|
+
|
|
78
|
+
${error?.message}`));
|
|
79
|
+
}
|
|
29
80
|
}
|
|
30
81
|
|
|
31
82
|
// src/utils/parseHrtimeToSeconds.ts
|
|
@@ -34,6 +85,11 @@ function parseHrtimeToSeconds(hrtime) {
|
|
|
34
85
|
return seconds;
|
|
35
86
|
}
|
|
36
87
|
|
|
88
|
+
// src/utils/parseText.ts
|
|
89
|
+
function parseText(baseText, config, logLevel = "silent") {
|
|
90
|
+
return `${baseText}${config[logLevel] || ""}`;
|
|
91
|
+
}
|
|
92
|
+
|
|
37
93
|
// src/run.ts
|
|
38
94
|
async function run({ config, options, spinner: spinner2 }) {
|
|
39
95
|
const hrstart = process.hrtime();
|
|
@@ -59,9 +115,9 @@ async function run({ config, options, spinner: spinner2 }) {
|
|
|
59
115
|
}
|
|
60
116
|
const promises = commands.map(async (command) => {
|
|
61
117
|
const [cmd, ..._args] = [...parseArgsStringToArgv(command)];
|
|
62
|
-
spinner2.start(parseText(`\u{1FA82} Executing hooks(${
|
|
118
|
+
spinner2.start(parseText(`\u{1FA82} Executing hooks(${pc2.yellow("done")})`, { info: ` ${pc2.dim(command)}` }, logLevel));
|
|
63
119
|
const { stdout } = await execa(cmd, _args);
|
|
64
|
-
spinner2.succeed(parseText(`\u{1FA82} Executing hooks(${
|
|
120
|
+
spinner2.succeed(parseText(`\u{1FA82} Executing hooks(${pc2.yellow("done")})`, { info: ` ${pc2.dim(command)}` }, logLevel));
|
|
65
121
|
if (logLevel === "info") {
|
|
66
122
|
console.log(stdout);
|
|
67
123
|
}
|
|
@@ -85,20 +141,20 @@ async function run({ config, options, spinner: spinner2 }) {
|
|
|
85
141
|
return 0;
|
|
86
142
|
});
|
|
87
143
|
const meta = {
|
|
88
|
-
plugins: status === "success" ? `${
|
|
144
|
+
plugins: status === "success" ? `${pc2.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total` : `${pc2.red(`${pluginsCount - buildStartPlugins.length} failed`)}, ${pluginsCount} total`,
|
|
89
145
|
filesCreated: files.length,
|
|
90
|
-
time:
|
|
146
|
+
time: pc2.yellow(`${elapsedSeconds}s`),
|
|
91
147
|
output: pathParser.resolve(config.root, config.output.path)
|
|
92
148
|
};
|
|
93
149
|
console.log(`
|
|
94
|
-
${
|
|
95
|
-
${
|
|
96
|
-
${
|
|
97
|
-
${
|
|
150
|
+
${pc2.bold("Plugins:")} ${meta.plugins}
|
|
151
|
+
${pc2.bold("Generated:")} ${meta.filesCreated} files
|
|
152
|
+
${pc2.bold("Time:")} ${meta.time}
|
|
153
|
+
${pc2.bold("Output:")} ${meta.output}
|
|
98
154
|
`);
|
|
99
155
|
if (options.debug) {
|
|
100
|
-
console.log(`${
|
|
101
|
-
console.log(`${files.map((file) => `${
|
|
156
|
+
console.log(`${pc2.bold("Generated files:")}`);
|
|
157
|
+
console.log(`${files.map((file) => `${pc2.blue(file.meta?.pluginName)} ${file.path}`).join("\n")}`);
|
|
102
158
|
}
|
|
103
159
|
};
|
|
104
160
|
const printErrors = (error) => {
|
|
@@ -108,7 +164,7 @@ ${pc.bold("Generated:")} ${meta.filesCreated} files
|
|
|
108
164
|
return;
|
|
109
165
|
}
|
|
110
166
|
if (options.debug) {
|
|
111
|
-
spinner2.fail(
|
|
167
|
+
spinner2.fail(pc2.red(`Something went wrong
|
|
112
168
|
|
|
113
169
|
`));
|
|
114
170
|
const causedError = error?.cause;
|
|
@@ -117,7 +173,7 @@ ${pc.bold("Generated:")} ${meta.filesCreated} files
|
|
|
117
173
|
console.log(pe.render(causedError));
|
|
118
174
|
}
|
|
119
175
|
} else {
|
|
120
|
-
spinner2.fail(
|
|
176
|
+
spinner2.fail(pc2.red(`Something went wrong
|
|
121
177
|
|
|
122
178
|
${error?.message}`));
|
|
123
179
|
}
|
|
@@ -126,7 +182,7 @@ ${error?.message}`));
|
|
|
126
182
|
const { root, ...userConfig } = config;
|
|
127
183
|
const logLevel = options.logLevel ?? userConfig.logLevel ?? "silent";
|
|
128
184
|
const inputPath = options.input ?? userConfig.input.path;
|
|
129
|
-
spinner2.start(parseText(`\u{1F680} Building`, { info: `(${
|
|
185
|
+
spinner2.start(parseText(`\u{1F680} Building`, { info: `(${pc2.dim(inputPath)})` }, logLevel));
|
|
130
186
|
const output = await build({
|
|
131
187
|
config: {
|
|
132
188
|
root: process.cwd(),
|
|
@@ -143,7 +199,7 @@ ${error?.message}`));
|
|
|
143
199
|
},
|
|
144
200
|
logger
|
|
145
201
|
});
|
|
146
|
-
spinner2.succeed(parseText(`\u{1F680} Build completed`, { info: `(${
|
|
202
|
+
spinner2.succeed(parseText(`\u{1F680} Build completed`, { info: `(${pc2.dim(inputPath)})` }, logLevel));
|
|
147
203
|
await onDone(config.hooks, logLevel);
|
|
148
204
|
printSummary(output.pluginManager, "success");
|
|
149
205
|
} catch (error) {
|
|
@@ -168,7 +224,7 @@ async function importModule(path, cwd) {
|
|
|
168
224
|
location = require2.resolve(path);
|
|
169
225
|
}
|
|
170
226
|
const module = await import(pathToFileURL(location).href);
|
|
171
|
-
return module
|
|
227
|
+
return module?.default ?? module;
|
|
172
228
|
}
|
|
173
229
|
|
|
174
230
|
// src/utils/getPlugins.ts
|
|
@@ -227,20 +283,20 @@ async function startWatcher(cb, options) {
|
|
|
227
283
|
ignorePermissionErrors: true,
|
|
228
284
|
ignored
|
|
229
285
|
});
|
|
230
|
-
watcher.on("all",
|
|
231
|
-
spinner2.succeed(
|
|
286
|
+
watcher.on("all", (type, file) => {
|
|
287
|
+
spinner2.succeed(pc2.yellow(pc2.bold(`Change detected: ${type} ${file}`)));
|
|
232
288
|
spinner2.spinner = "clock";
|
|
233
289
|
try {
|
|
234
|
-
|
|
290
|
+
cb(options.path);
|
|
235
291
|
} catch (e) {
|
|
236
|
-
spinner2.warn(
|
|
292
|
+
spinner2.warn(pc2.red("Watcher failed"));
|
|
237
293
|
}
|
|
238
294
|
});
|
|
239
295
|
}
|
|
240
296
|
var jsLoader = async (configFile) => {
|
|
241
297
|
return importModule(configFile);
|
|
242
298
|
};
|
|
243
|
-
var tsLoader =
|
|
299
|
+
var tsLoader = (configFile) => {
|
|
244
300
|
let registerer = { enabled() {
|
|
245
301
|
} };
|
|
246
302
|
try {
|
|
@@ -298,62 +354,6 @@ async function getCosmiConfig(moduleName2, config) {
|
|
|
298
354
|
}
|
|
299
355
|
return result;
|
|
300
356
|
}
|
|
301
|
-
var presets = {
|
|
302
|
-
simple: {
|
|
303
|
-
"kubb.config": `
|
|
304
|
-
import { defineConfig } from '@kubb/core'
|
|
305
|
-
import createSwagger from '@kubb/swagger'
|
|
306
|
-
import createSwaggerTS from '@kubb/swagger-ts'
|
|
307
|
-
import createSwaggerTanstackQuery from '@kubb/swagger-tanstack-query'
|
|
308
|
-
|
|
309
|
-
export default defineConfig({
|
|
310
|
-
root: '.',
|
|
311
|
-
input: {
|
|
312
|
-
path: 'https://petstore3.swagger.io/api/v3/openapi.json',
|
|
313
|
-
},
|
|
314
|
-
output: {
|
|
315
|
-
path: './src/gen',
|
|
316
|
-
clean: true,
|
|
317
|
-
},
|
|
318
|
-
hooks: {
|
|
319
|
-
done: 'echo "\u{1F389} done"',
|
|
320
|
-
},
|
|
321
|
-
logLevel: 'info',
|
|
322
|
-
plugins: [createSwagger({}), createSwaggerTS({ output: 'models', enumType: 'enum' }), createSwaggerTanstackQuery({ output: './hooks' })],
|
|
323
|
-
})
|
|
324
|
-
`,
|
|
325
|
-
packages: ["@kubb/core", "@kubb/cli", "@kubb/swagger", "@kubb/swagger-ts", "@kubb/swagger-tanstack-query"]
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
async function init({ spinner: spinner2, preset = "simple", logLevel = "silent", packageManager = "pnpm" }) {
|
|
329
|
-
try {
|
|
330
|
-
const presetMeta = presets[preset];
|
|
331
|
-
const path = pathParser.resolve(process.cwd(), "./kubb.config.js");
|
|
332
|
-
const installCommand = packageManager === "npm" ? "install" : "add";
|
|
333
|
-
spinner2.start(`\u{1F4C0} Writing \`kubb.config.js\` ${pc.dim(path)}`);
|
|
334
|
-
await write(presetMeta["kubb.config"], path);
|
|
335
|
-
spinner2.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${pc.dim(path)}`);
|
|
336
|
-
const data = await Promise.all([
|
|
337
|
-
$`npm init es6 -y`,
|
|
338
|
-
...presetMeta.packages.map(async (pack) => {
|
|
339
|
-
spinner2.start(`\u{1F4C0} Installing ${pc.dim(pack)}`);
|
|
340
|
-
const { stdout } = await $({ preferLocal: false })`${packageManager} ${installCommand} ${pack}`;
|
|
341
|
-
spinner2.succeed(`\u{1F4C0} Installed ${pc.dim(pack)}`);
|
|
342
|
-
return stdout;
|
|
343
|
-
})
|
|
344
|
-
]);
|
|
345
|
-
if (logLevel === "info") {
|
|
346
|
-
data.forEach((text) => console.log(text));
|
|
347
|
-
}
|
|
348
|
-
} catch (error) {
|
|
349
|
-
spinner2.fail(pc.red(`Something went wrong
|
|
350
|
-
|
|
351
|
-
${error?.message}`));
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
// package.json
|
|
356
|
-
var version = "1.1.5";
|
|
357
357
|
|
|
358
358
|
// src/index.ts
|
|
359
359
|
var moduleName = "kubb";
|
|
@@ -370,14 +370,14 @@ var program = new Command(moduleName).description("Kubb").action(async (options)
|
|
|
370
370
|
}
|
|
371
371
|
spinner.start("\u{1F4BE} Loading config");
|
|
372
372
|
const result = await getCosmiConfig(moduleName, options.config);
|
|
373
|
-
spinner.succeed(`\u{1F4BE} Config loaded(${
|
|
373
|
+
spinner.succeed(`\u{1F4BE} Config loaded(${pc2.dim(pathParser.relative(process.cwd(), result.filepath))})`);
|
|
374
374
|
if (options.watch) {
|
|
375
375
|
const config = await getConfig(result, options);
|
|
376
376
|
startWatcher(
|
|
377
377
|
async (paths) => {
|
|
378
378
|
await run({ config, spinner, options });
|
|
379
379
|
spinner.spinner = "simpleDotsScrolling";
|
|
380
|
-
spinner.start(
|
|
380
|
+
spinner.start(pc2.yellow(pc2.bold(`Watching for changes in ${paths.join(" and ")}`)));
|
|
381
381
|
},
|
|
382
382
|
{
|
|
383
383
|
spinner,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Generator cli",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -43,28 +43,29 @@
|
|
|
43
43
|
"yaml": "^2.3.1",
|
|
44
44
|
"@swc/core": "^1.3.62",
|
|
45
45
|
"pretty-error": "^4.0.0",
|
|
46
|
-
"@kubb/core": "1.1.
|
|
46
|
+
"@kubb/core": "1.1.7"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@types/node": "^20.2.5",
|
|
50
49
|
"tsup": "^6.7.0",
|
|
50
|
+
"@types/node": "^20.2.5",
|
|
51
51
|
"typescript": "^5.1.3",
|
|
52
|
-
"@kubb/swagger": "1.1.
|
|
52
|
+
"@kubb/swagger": "1.1.7",
|
|
53
|
+
"@kubb/tsup-config": "0.1.0"
|
|
53
54
|
},
|
|
54
55
|
"publishConfig": {
|
|
55
56
|
"access": "public",
|
|
56
57
|
"registry": "https://registry.npmjs.org/"
|
|
57
58
|
},
|
|
58
59
|
"engines": {
|
|
59
|
-
"node": ">=
|
|
60
|
+
"node": ">=18",
|
|
60
61
|
"pnpm": ">=8"
|
|
61
62
|
},
|
|
62
63
|
"scripts": {
|
|
63
64
|
"build": "tsup",
|
|
64
65
|
"start": "tsup --watch",
|
|
65
66
|
"release": "pnpm publish --no-git-check",
|
|
66
|
-
"
|
|
67
|
-
"
|
|
67
|
+
"lint": "eslint \"**/*.{ts,tsx}\"",
|
|
68
|
+
"lint-fix": "eslint \"**/*.{ts,tsx}\" --quiet --fix",
|
|
68
69
|
"test": "vitest --passWithNoTests",
|
|
69
70
|
"upgrade": "pnpm update",
|
|
70
71
|
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
package/src/index.ts
CHANGED
|
@@ -3,16 +3,15 @@
|
|
|
3
3
|
import pathParser from 'node:path'
|
|
4
4
|
|
|
5
5
|
import { Command, Option } from 'commander'
|
|
6
|
-
import pc from 'picocolors'
|
|
7
6
|
import ora from 'ora'
|
|
7
|
+
import pc from 'picocolors'
|
|
8
8
|
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
import { run } from './run.ts'
|
|
12
|
-
import { startWatcher, getConfig, getCosmiConfig } from './utils/index.ts'
|
|
9
|
+
import { version } from '../package.json'
|
|
13
10
|
import { init } from './init.ts'
|
|
11
|
+
import { run } from './run.ts'
|
|
12
|
+
import { getConfig, getCosmiConfig, startWatcher } from './utils/index.ts'
|
|
14
13
|
|
|
15
|
-
import {
|
|
14
|
+
import type { CLIOptions } from '@kubb/core'
|
|
16
15
|
|
|
17
16
|
const moduleName = 'kubb'
|
|
18
17
|
|
package/src/init.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import pathParser from 'node:path'
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { write } from '@kubb/core'
|
|
4
|
+
|
|
4
5
|
import { $ } from 'execa'
|
|
6
|
+
import pc from 'picocolors'
|
|
5
7
|
|
|
6
8
|
import type { LogLevel } from '@kubb/core'
|
|
7
|
-
import { write } from '@kubb/core'
|
|
8
|
-
|
|
9
9
|
import type { Ora } from 'ora'
|
|
10
10
|
|
|
11
11
|
export type Preset = 'simple'
|
package/src/run.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import pathParser from 'node:path'
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import { build, ParallelPluginError, PluginError } from '@kubb/core'
|
|
5
|
+
|
|
5
6
|
import { execa } from 'execa'
|
|
6
|
-
import
|
|
7
|
+
import pc from 'picocolors'
|
|
7
8
|
import PrettyError from 'pretty-error'
|
|
9
|
+
import { parseArgsStringToArgv } from 'string-argv'
|
|
8
10
|
|
|
9
|
-
import { ParallelPluginError, PluginError, build } from '@kubb/core'
|
|
10
|
-
import type { Logger, CLIOptions, KubbConfig, BuildOutput, LogLevel } from '@kubb/core'
|
|
11
|
-
|
|
12
|
-
import { parseText } from './utils/parseText.ts'
|
|
13
11
|
import { parseHrtimeToSeconds } from './utils/parseHrtimeToSeconds.ts'
|
|
12
|
+
import { parseText } from './utils/parseText.ts'
|
|
14
13
|
|
|
14
|
+
import type { BuildOutput, CLIOptions, KubbConfig, Logger, LogLevel } from '@kubb/core'
|
|
15
15
|
import type { Ora } from 'ora'
|
|
16
16
|
|
|
17
17
|
type RunProps = {
|
|
@@ -109,7 +109,7 @@ ${pc.bold('Generated:')} ${meta.filesCreated} files
|
|
|
109
109
|
|
|
110
110
|
if (options.debug) {
|
|
111
111
|
spinner.fail(pc.red(`Something went wrong\n\n`))
|
|
112
|
-
const causedError =
|
|
112
|
+
const causedError = error?.cause as Error
|
|
113
113
|
|
|
114
114
|
console.log(pe.render(error))
|
|
115
115
|
|
|
@@ -117,12 +117,11 @@ ${pc.bold('Generated:')} ${meta.filesCreated} files
|
|
|
117
117
|
console.log(pe.render(causedError))
|
|
118
118
|
}
|
|
119
119
|
} else {
|
|
120
|
-
spinner.fail(pc.red(`Something went wrong\n\n${
|
|
120
|
+
spinner.fail(pc.red(`Something went wrong\n\n${error?.message}`))
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
try {
|
|
125
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars, unused-imports/no-unused-vars
|
|
126
125
|
const { root, ...userConfig } = config
|
|
127
126
|
const logLevel = options.logLevel ?? userConfig.logLevel ?? 'silent'
|
|
128
127
|
const inputPath = options.input ?? userConfig.input.path
|
|
@@ -152,7 +151,7 @@ ${pc.bold('Generated:')} ${meta.filesCreated} files
|
|
|
152
151
|
|
|
153
152
|
printSummary(output.pluginManager, 'success')
|
|
154
153
|
} catch (error: any) {
|
|
155
|
-
printErrors(error)
|
|
154
|
+
printErrors(error as Error)
|
|
156
155
|
|
|
157
156
|
if (error instanceof PluginError || error instanceof ParallelPluginError) {
|
|
158
157
|
printSummary(error.pluginManager, 'failed')
|
package/src/utils/getConfig.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { KubbUserConfig, KubbConfig, CLIOptions } from '@kubb/core'
|
|
2
1
|
import { isPromise } from '@kubb/core'
|
|
3
2
|
|
|
4
3
|
import { getPlugins } from './getPlugins.ts'
|
|
5
4
|
|
|
5
|
+
import type { CLIOptions, KubbConfig, KubbUserConfig } from '@kubb/core'
|
|
6
6
|
import type { CosmiconfigResult } from '../types.ts'
|
|
7
7
|
|
|
8
8
|
export async function getConfig(result: CosmiconfigResult, options: CLIOptions): Promise<KubbConfig> {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
1
2
|
import { cosmiconfig } from 'cosmiconfig'
|
|
2
|
-
import yaml from 'yaml'
|
|
3
3
|
import tsNode from 'ts-node'
|
|
4
|
+
import yaml from 'yaml'
|
|
4
5
|
|
|
5
6
|
import { importModule } from './importModule.ts'
|
|
6
7
|
|
|
@@ -11,7 +12,7 @@ const jsLoader = async (configFile: string) => {
|
|
|
11
12
|
}
|
|
12
13
|
// TODO fix tsLoader for node 20
|
|
13
14
|
// https://github.com/TypeStrong/ts-node/issues/1997
|
|
14
|
-
const tsLoader =
|
|
15
|
+
const tsLoader = (configFile: string) => {
|
|
15
16
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
16
17
|
let registerer = { enabled() {} }
|
|
17
18
|
|
|
@@ -24,6 +25,7 @@ const tsLoader = async (configFile: string) => {
|
|
|
24
25
|
})
|
|
25
26
|
|
|
26
27
|
const module = require(configFile)
|
|
28
|
+
|
|
27
29
|
return module.default
|
|
28
30
|
} catch (err: any) {
|
|
29
31
|
if (err.code === 'MODULE_NOT_FOUND') {
|
package/src/utils/getPlugins.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
2
|
// @ts-nocheck
|
|
3
3
|
|
|
4
|
-
import type { KubbUserConfig, KubbJSONPlugin, KubbObjectPlugin } from '@kubb/core'
|
|
5
|
-
|
|
6
4
|
import { importModule } from './importModule.ts'
|
|
7
5
|
|
|
6
|
+
import type { KubbJSONPlugin, KubbObjectPlugin, KubbUserConfig } from '@kubb/core'
|
|
7
|
+
|
|
8
8
|
function isJSONPlugins(plugins: KubbUserConfig['plugins'] | KubbJSONPlugin[]): plugins is KubbJSONPlugin[] {
|
|
9
9
|
return !!(plugins as KubbJSONPlugin[])?.some((plugin) => {
|
|
10
10
|
return typeof plugin?.[0] === 'string'
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
2
2
|
import mod from 'node:module'
|
|
3
|
+
import { pathToFileURL } from 'node:url'
|
|
3
4
|
|
|
4
5
|
const SLASHES = new Set(['/', '\\'])
|
|
5
6
|
|
|
@@ -13,7 +14,7 @@ const SLASHES = new Set(['/', '\\'])
|
|
|
13
14
|
* @param {string} directory The directory to check.
|
|
14
15
|
* @returns {string} The normalized directory.
|
|
15
16
|
*/
|
|
16
|
-
function normalizeDirectory(directory: string) {
|
|
17
|
+
export function normalizeDirectory(directory: string) {
|
|
17
18
|
if (!SLASHES.has(directory[directory.length - 1])) {
|
|
18
19
|
return `${directory}/`
|
|
19
20
|
}
|
|
@@ -21,7 +22,7 @@ function normalizeDirectory(directory: string) {
|
|
|
21
22
|
return directory
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
export async function importModule(path: string, cwd?: string) {
|
|
25
|
+
export async function importModule(path: string, cwd?: string): Promise<any> {
|
|
25
26
|
let location = path
|
|
26
27
|
|
|
27
28
|
if (cwd) {
|
|
@@ -31,5 +32,5 @@ export async function importModule(path: string, cwd?: string) {
|
|
|
31
32
|
|
|
32
33
|
const module = await import(pathToFileURL(location).href)
|
|
33
34
|
|
|
34
|
-
return module
|
|
35
|
+
return module?.default ?? module
|
|
35
36
|
}
|
package/src/utils/watcher.ts
CHANGED
|
@@ -16,13 +16,13 @@ export async function startWatcher(cb: (path: string[]) => Promise<void>, option
|
|
|
16
16
|
ignorePermissionErrors: true,
|
|
17
17
|
ignored,
|
|
18
18
|
})
|
|
19
|
-
watcher.on('all',
|
|
19
|
+
watcher.on('all', (type, file) => {
|
|
20
20
|
spinner.succeed(pc.yellow(pc.bold(`Change detected: ${type} ${file}`)))
|
|
21
21
|
// revert back
|
|
22
22
|
spinner.spinner = 'clock'
|
|
23
23
|
|
|
24
24
|
try {
|
|
25
|
-
|
|
25
|
+
cb(options.path)
|
|
26
26
|
} catch (e) {
|
|
27
27
|
spinner.warn(pc.red('Watcher failed'))
|
|
28
28
|
}
|