@kubb/cli 3.16.2 → 3.16.4
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/chunk-DWy1uDak.cjs +39 -0
- package/dist/generate-B9o-QjSi.cjs +6641 -0
- package/dist/generate-B9o-QjSi.cjs.map +1 -0
- package/dist/generate-BpnRmhKq.cjs +255 -0
- package/dist/generate-BpnRmhKq.cjs.map +1 -0
- package/dist/generate-COcFbC_i.js +254 -0
- package/dist/generate-COcFbC_i.js.map +1 -0
- package/dist/generate-CUJ2_P-U.js +6669 -0
- package/dist/generate-CUJ2_P-U.js.map +1 -0
- package/dist/index.cjs +53 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +52 -48
- package/dist/index.js.map +1 -1
- package/dist/mcp-Cmiw4RpU.cjs +44 -0
- package/dist/mcp-Cmiw4RpU.cjs.map +1 -0
- package/dist/mcp-DcaOAt6B.js +43 -0
- package/dist/mcp-DcaOAt6B.js.map +1 -0
- package/dist/validate-ClewPP5U.cjs +55 -0
- package/dist/validate-ClewPP5U.cjs.map +1 -0
- package/dist/validate-DD5UaudC.js +54 -0
- package/dist/validate-DD5UaudC.js.map +1 -0
- package/package.json +19 -19
- package/src/commands/generate.ts +10 -13
- package/src/commands/mcp.ts +2 -2
- package/src/runners/generate.ts +4 -4
- package/src/utils/Writables.ts +2 -2
- package/src/utils/executeHooks.ts +3 -3
- package/src/utils/getSummary.ts +8 -8
- package/src/utils/watcher.ts +3 -3
- package/dist/chunk-OKWBGMAG.cjs +0 -52
- package/dist/chunk-OKWBGMAG.cjs.map +0 -1
- package/dist/generate-65TMSGIL.js +0 -273
- package/dist/generate-65TMSGIL.js.map +0 -1
- package/dist/generate-HUWFJ4IA.js +0 -209
- package/dist/generate-HUWFJ4IA.js.map +0 -1
- package/dist/generate-IO6M6WPG.cjs +0 -7590
- package/dist/generate-IO6M6WPG.cjs.map +0 -1
- package/dist/generate-YZYI2YSX.cjs +0 -311
- package/dist/generate-YZYI2YSX.cjs.map +0 -1
- package/dist/mcp-KL42HRWB.cjs +0 -57
- package/dist/mcp-KL42HRWB.cjs.map +0 -1
- package/dist/mcp-LTBICXYR.js +0 -49
- package/dist/mcp-LTBICXYR.js.map +0 -1
- package/dist/validate-7QEOABSE.cjs +0 -67
- package/dist/validate-7QEOABSE.cjs.map +0 -1
- package/dist/validate-ONN45RYY.js +0 -58
- package/dist/validate-ONN45RYY.js.map +0 -1
package/src/commands/generate.ts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import * as process from 'node:process'
|
|
3
|
+
import { isInputPath, PromiseManager } from '@kubb/core'
|
|
4
|
+
import { createLogger, LogMapper } from '@kubb/core/logger'
|
|
2
5
|
import type { ArgsDef, ParsedArgs } from 'citty'
|
|
3
|
-
import {
|
|
4
|
-
|
|
6
|
+
import { defineCommand, showUsage } from 'citty'
|
|
7
|
+
import type { SingleBar } from 'cli-progress'
|
|
8
|
+
import open from 'open'
|
|
9
|
+
import pc from 'picocolors'
|
|
5
10
|
import { getConfig } from '../utils/getConfig.ts'
|
|
6
11
|
import { getCosmiConfig } from '../utils/getCosmiConfig.ts'
|
|
7
12
|
import { startWatcher } from '../utils/watcher.ts'
|
|
8
13
|
|
|
9
|
-
import path from 'node:path'
|
|
10
|
-
import * as process from 'node:process'
|
|
11
|
-
import { PromiseManager, isInputPath } from '@kubb/core'
|
|
12
|
-
import { LogMapper, createLogger } from '@kubb/core/logger'
|
|
13
|
-
|
|
14
|
-
import open from 'open'
|
|
15
|
-
import type { SingleBar } from 'cli-progress'
|
|
16
|
-
|
|
17
14
|
declare global {
|
|
18
15
|
var isDevtoolsEnabled: any
|
|
19
16
|
}
|
|
@@ -90,7 +87,7 @@ const command = defineCommand({
|
|
|
90
87
|
logger.emit('start', 'Loading config')
|
|
91
88
|
|
|
92
89
|
const result = await getCosmiConfig('kubb', args.config)
|
|
93
|
-
logger.emit('success', `Config loaded(${
|
|
90
|
+
logger.emit('success', `Config loaded(${pc.dim(path.relative(process.cwd(), result.filepath))})`)
|
|
94
91
|
|
|
95
92
|
const config = await getConfig(result, args)
|
|
96
93
|
|
|
@@ -167,7 +164,7 @@ const command = defineCommand({
|
|
|
167
164
|
if (isInputPath(config)) {
|
|
168
165
|
return startWatcher([input || config.input.path], async (paths) => {
|
|
169
166
|
await start()
|
|
170
|
-
logger.emit('start',
|
|
167
|
+
logger.emit('start', pc.yellow(pc.bold(`Watching for changes in ${paths.join(' and ')}`)))
|
|
171
168
|
})
|
|
172
169
|
}
|
|
173
170
|
}
|
package/src/commands/mcp.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ArgsDef, ParsedArgs } from 'citty'
|
|
2
2
|
import { defineCommand, showUsage } from 'citty'
|
|
3
3
|
import consola from 'consola'
|
|
4
|
-
import
|
|
4
|
+
import pc from 'picocolors'
|
|
5
5
|
import { createJiti } from 'jiti'
|
|
6
6
|
|
|
7
7
|
const jiti = createJiti(import.meta.url, {
|
|
@@ -42,7 +42,7 @@ const command = defineCommand({
|
|
|
42
42
|
const { startServer } = mod
|
|
43
43
|
try {
|
|
44
44
|
consola.start('Starting MCP server...')
|
|
45
|
-
consola.warn(
|
|
45
|
+
consola.warn(pc.yellow('This feature is still under development — use with caution'))
|
|
46
46
|
await startServer()
|
|
47
47
|
} catch (e) {
|
|
48
48
|
consola.error((e as Error)?.message)
|
package/src/runners/generate.ts
CHANGED
|
@@ -2,7 +2,7 @@ import process from 'node:process'
|
|
|
2
2
|
import { type Config, safeBuild, setup } from '@kubb/core'
|
|
3
3
|
import { createLogger, LogMapper } from '@kubb/core/logger'
|
|
4
4
|
import { Presets, SingleBar } from 'cli-progress'
|
|
5
|
-
import
|
|
5
|
+
import pc from 'picocolors'
|
|
6
6
|
import type { Args } from '../commands/generate.ts'
|
|
7
7
|
import { executeHooks } from '../utils/executeHooks.ts'
|
|
8
8
|
import { getErrorCauses } from '../utils/getErrorCauses.ts'
|
|
@@ -83,7 +83,7 @@ export async function generate({ input, config, progressCache, args }: GenerateP
|
|
|
83
83
|
logger,
|
|
84
84
|
})
|
|
85
85
|
|
|
86
|
-
logger.emit('start', `Building ${logger.logLevel !== LogMapper.silent ?
|
|
86
|
+
logger.emit('start', `Building ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)
|
|
87
87
|
|
|
88
88
|
const { files, error } = await safeBuild({
|
|
89
89
|
config: definedConfig,
|
|
@@ -109,7 +109,7 @@ export async function generate({ input, config, progressCache, args }: GenerateP
|
|
|
109
109
|
|
|
110
110
|
if (error && logger.consola) {
|
|
111
111
|
logger.consola?.resumeLogs()
|
|
112
|
-
logger.consola.error(`Build failed ${logger.logLevel !== LogMapper.silent ?
|
|
112
|
+
logger.consola.error(`Build failed ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)
|
|
113
113
|
|
|
114
114
|
logger.consola.box({
|
|
115
115
|
title: `${config.name || ''}`,
|
|
@@ -137,7 +137,7 @@ export async function generate({ input, config, progressCache, args }: GenerateP
|
|
|
137
137
|
await executeHooks({ hooks: config.hooks, logger })
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
logger.consola?.log(`⚡Build completed ${logger.logLevel !== LogMapper.silent ?
|
|
140
|
+
logger.consola?.log(`⚡Build completed ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)
|
|
141
141
|
|
|
142
142
|
logger.consola?.box({
|
|
143
143
|
title: `${config.name || ''}`,
|
package/src/utils/Writables.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Writable } from 'node:stream'
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import pc from 'picocolors'
|
|
4
4
|
|
|
5
5
|
import * as process from 'node:process'
|
|
6
6
|
import type { WritableOptions } from 'node:stream'
|
|
@@ -16,7 +16,7 @@ export class ConsolaWritable extends Writable {
|
|
|
16
16
|
this.consola = consola
|
|
17
17
|
}
|
|
18
18
|
_write(chunk: any, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {
|
|
19
|
-
process.stdout.write(`${
|
|
19
|
+
process.stdout.write(`${pc.dim(chunk?.toString())}`)
|
|
20
20
|
|
|
21
21
|
callback()
|
|
22
22
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Logger } from '@kubb/core/logger'
|
|
2
2
|
import { execa } from 'execa'
|
|
3
3
|
import { parseArgsStringToArgv } from 'string-argv'
|
|
4
|
-
import
|
|
4
|
+
import pc from 'picocolors'
|
|
5
5
|
|
|
6
6
|
import { ConsolaWritable } from './Writables.ts'
|
|
7
7
|
|
|
@@ -24,7 +24,7 @@ export async function executeHooks({ hooks, logger }: ExecutingHooksProps): Prom
|
|
|
24
24
|
continue
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
logger?.emit('start', `Executing hook ${logger.logLevel !== LogMapper.silent ?
|
|
27
|
+
logger?.emit('start', `Executing hook ${logger.logLevel !== LogMapper.silent ? pc.dim(command) : ''}`)
|
|
28
28
|
|
|
29
29
|
await execa(cmd, _args, {
|
|
30
30
|
detached: true,
|
|
@@ -32,7 +32,7 @@ export async function executeHooks({ hooks, logger }: ExecutingHooksProps): Prom
|
|
|
32
32
|
stripFinalNewline: true,
|
|
33
33
|
})
|
|
34
34
|
|
|
35
|
-
logger?.emit('success', `Executed hook ${logger.logLevel !== LogMapper.silent ?
|
|
35
|
+
logger?.emit('success', `Executed hook ${logger.logLevel !== LogMapper.silent ? pc.dim(command) : ''}`)
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
logger?.emit('success', 'Executed hooks')
|
package/src/utils/getSummary.ts
CHANGED
|
@@ -2,7 +2,7 @@ import path from 'node:path'
|
|
|
2
2
|
|
|
3
3
|
import { randomCliColour } from '@kubb/core/logger'
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import pc from 'picocolors'
|
|
6
6
|
|
|
7
7
|
import { parseHrtimeToSeconds } from './parseHrtimeToSeconds.ts'
|
|
8
8
|
|
|
@@ -32,20 +32,20 @@ export function getSummary({ pluginManager, filesCreated, status, hrStart, confi
|
|
|
32
32
|
const meta = {
|
|
33
33
|
plugins:
|
|
34
34
|
status === 'success'
|
|
35
|
-
? `${
|
|
36
|
-
: `${
|
|
35
|
+
? `${pc.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total`
|
|
36
|
+
: `${pc.red(`${failedPlugins?.length ?? 1} failed`)}, ${pluginsCount} total`,
|
|
37
37
|
pluginsFailed: status === 'failed' ? failedPlugins?.map((name) => randomCliColour(name))?.join(', ') : undefined,
|
|
38
38
|
filesCreated: filesCreated,
|
|
39
|
-
time: `${
|
|
39
|
+
time: `${pc.yellow(`${elapsedSeconds}s`)}`,
|
|
40
40
|
output: path.isAbsolute(config.root) ? path.resolve(config.root, config.output.path) : config.root,
|
|
41
41
|
} as const
|
|
42
42
|
|
|
43
43
|
logs.add(
|
|
44
44
|
[
|
|
45
|
-
[`${
|
|
46
|
-
[`${
|
|
47
|
-
[`${
|
|
48
|
-
[`${
|
|
45
|
+
[`${pc.bold('Plugins:')} ${meta.plugins}`, true],
|
|
46
|
+
[`${pc.dim('Failed:')} ${meta.pluginsFailed || 'none'}`, !!meta.pluginsFailed],
|
|
47
|
+
[`${pc.bold('Generated:')} ${meta.filesCreated} files in ${meta.time}`, true],
|
|
48
|
+
[`${pc.bold('Output:')} ${meta.output}`, true],
|
|
49
49
|
]
|
|
50
50
|
.map((item) => {
|
|
51
51
|
if (item.at(1)) {
|
package/src/utils/watcher.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createLogger } from '@kubb/core/logger'
|
|
2
|
-
import
|
|
2
|
+
import pc from 'picocolors'
|
|
3
3
|
|
|
4
4
|
export async function startWatcher(path: string[], cb: (path: string[]) => Promise<void>): Promise<void> {
|
|
5
5
|
const { watch } = await import('chokidar')
|
|
@@ -12,12 +12,12 @@ export async function startWatcher(path: string[], cb: (path: string[]) => Promi
|
|
|
12
12
|
ignored,
|
|
13
13
|
})
|
|
14
14
|
watcher.on('all', (type, file) => {
|
|
15
|
-
logger?.emit('info',
|
|
15
|
+
logger?.emit('info', pc.yellow(pc.bold(`Change detected: ${type} ${file}`)))
|
|
16
16
|
|
|
17
17
|
try {
|
|
18
18
|
cb(path)
|
|
19
19
|
} catch (_e) {
|
|
20
|
-
logger?.emit('warning',
|
|
20
|
+
logger?.emit('warning', pc.red('Watcher failed'))
|
|
21
21
|
}
|
|
22
22
|
})
|
|
23
23
|
}
|
package/dist/chunk-OKWBGMAG.cjs
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
10
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
11
|
-
}) : x)(function(x) {
|
|
12
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
13
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
14
|
-
});
|
|
15
|
-
var __esm = (fn, res) => function __init() {
|
|
16
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
17
|
-
};
|
|
18
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
19
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
20
|
-
};
|
|
21
|
-
var __copyProps = (to, from, except, desc) => {
|
|
22
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
-
for (let key of __getOwnPropNames(from))
|
|
24
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
25
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
26
|
-
}
|
|
27
|
-
return to;
|
|
28
|
-
};
|
|
29
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
-
mod
|
|
36
|
-
));
|
|
37
|
-
|
|
38
|
-
// ../../node_modules/.pnpm/tsup@8.5.0_@microsoft+api-extractor@7.52.10_@types+node@20.19.10__jiti@2.5.1_postcss@8.5.6_typescript@5.9.2_yaml@2.7.1/node_modules/tsup/assets/cjs_shims.js
|
|
39
|
-
var getImportMetaUrl; exports.importMetaUrl = void 0;
|
|
40
|
-
var init_cjs_shims = __esm({
|
|
41
|
-
"../../node_modules/.pnpm/tsup@8.5.0_@microsoft+api-extractor@7.52.10_@types+node@20.19.10__jiti@2.5.1_postcss@8.5.6_typescript@5.9.2_yaml@2.7.1/node_modules/tsup/assets/cjs_shims.js"() {
|
|
42
|
-
getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
43
|
-
exports.importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
exports.__commonJS = __commonJS;
|
|
48
|
-
exports.__require = __require;
|
|
49
|
-
exports.__toESM = __toESM;
|
|
50
|
-
exports.init_cjs_shims = init_cjs_shims;
|
|
51
|
-
//# sourceMappingURL=chunk-OKWBGMAG.cjs.map
|
|
52
|
-
//# sourceMappingURL=chunk-OKWBGMAG.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.5.0_@microsoft+api-extractor@7.52.10_@types+node@20.19.10__jiti@2.5.1_postcss@8.5.6_typescript@5.9.2_yaml@2.7.1/node_modules/tsup/assets/cjs_shims.js"],"names":["importMetaUrl"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAKM,gBAMO,CAAA,CAAAA;AAXb,IAAA,cAAA,GAAA,KAAA,CAAA;AAAA,EAAA,uLAAA,GAAA;AAKA,IAAM,gBAAA,GAAmB,MACvB,OAAO,QAAA,KAAa,cAChB,IAAI,GAAA,CAAI,CAAQ,KAAA,EAAA,UAAU,CAAE,CAAA,CAAA,CAAE,OAC7B,QAAS,CAAA,aAAA,IAAiB,SAAS,aAAc,CAAA,GAAA,IAClD,IAAI,GAAI,CAAA,SAAA,EAAW,QAAS,CAAA,OAAO,CAAE,CAAA,IAAA;AAEpC,IAAMA,wCAAiD,gBAAA,EAAA;AAAA;AAAA,CAAA","file":"chunk-OKWBGMAG.cjs","sourcesContent":["// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () =>\n typeof document === 'undefined'\n ? new URL(`file:${__filename}`).href\n : (document.currentScript && document.currentScript.src) ||\n new URL('main.js', document.baseURI).href\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n"]}
|
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
import { defineCommand, showUsage } from 'citty';
|
|
2
|
-
import { colors } from 'consola/utils';
|
|
3
|
-
import { isPromise } from '@kubb/core/utils';
|
|
4
|
-
import { cosmiconfig } from 'cosmiconfig';
|
|
5
|
-
import { createJiti } from 'jiti';
|
|
6
|
-
import { LogMapper, createLogger } from '@kubb/core/logger';
|
|
7
|
-
import path from 'path';
|
|
8
|
-
import * as process from 'process';
|
|
9
|
-
import { isInputPath, PromiseManager } from '@kubb/core';
|
|
10
|
-
import open from 'open';
|
|
11
|
-
|
|
12
|
-
// src/commands/generate.ts
|
|
13
|
-
|
|
14
|
-
// src/utils/getPlugins.ts
|
|
15
|
-
function isJSONPlugins(plugins) {
|
|
16
|
-
return !!plugins?.some((plugin) => {
|
|
17
|
-
return Array.isArray(plugin) && typeof plugin?.at(0) === "string";
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
function isObjectPlugins(plugins) {
|
|
21
|
-
return plugins instanceof Object && !Array.isArray(plugins);
|
|
22
|
-
}
|
|
23
|
-
function getPlugins(plugins) {
|
|
24
|
-
if (isObjectPlugins(plugins)) {
|
|
25
|
-
throw new Error("Object plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json");
|
|
26
|
-
}
|
|
27
|
-
if (isJSONPlugins(plugins)) {
|
|
28
|
-
throw new Error("JSON plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json");
|
|
29
|
-
}
|
|
30
|
-
return Promise.resolve(plugins);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// src/utils/getConfig.ts
|
|
34
|
-
async function getConfig(result, args2) {
|
|
35
|
-
const config = result?.config;
|
|
36
|
-
let kubbUserConfig = Promise.resolve(config);
|
|
37
|
-
if (typeof config === "function") {
|
|
38
|
-
const possiblePromise = config(args2);
|
|
39
|
-
if (isPromise(possiblePromise)) {
|
|
40
|
-
kubbUserConfig = possiblePromise;
|
|
41
|
-
}
|
|
42
|
-
kubbUserConfig = Promise.resolve(possiblePromise);
|
|
43
|
-
}
|
|
44
|
-
let JSONConfig = await kubbUserConfig;
|
|
45
|
-
if (Array.isArray(JSONConfig)) {
|
|
46
|
-
const results = [];
|
|
47
|
-
for (const item of JSONConfig) {
|
|
48
|
-
const plugins = item.plugins ? await getPlugins(item.plugins) : void 0;
|
|
49
|
-
results.push({
|
|
50
|
-
...item,
|
|
51
|
-
plugins
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
return results;
|
|
55
|
-
}
|
|
56
|
-
JSONConfig = {
|
|
57
|
-
...JSONConfig,
|
|
58
|
-
plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
|
|
59
|
-
};
|
|
60
|
-
return JSONConfig;
|
|
61
|
-
}
|
|
62
|
-
var tsLoader = async (configFile) => {
|
|
63
|
-
const jiti = createJiti(import.meta.url, {
|
|
64
|
-
jsx: {
|
|
65
|
-
runtime: "automatic",
|
|
66
|
-
importSource: "@kubb/react"
|
|
67
|
-
},
|
|
68
|
-
sourceMaps: true
|
|
69
|
-
});
|
|
70
|
-
const mod = await jiti.import(configFile, { default: true });
|
|
71
|
-
return mod;
|
|
72
|
-
};
|
|
73
|
-
async function getCosmiConfig(moduleName, config) {
|
|
74
|
-
const searchPlaces = [
|
|
75
|
-
"package.json",
|
|
76
|
-
`.${moduleName}rc`,
|
|
77
|
-
`.${moduleName}rc.json`,
|
|
78
|
-
`.${moduleName}rc.yaml`,
|
|
79
|
-
`.${moduleName}rc.yml`,
|
|
80
|
-
`.${moduleName}rc.ts`,
|
|
81
|
-
`.${moduleName}rc.js`,
|
|
82
|
-
`.${moduleName}rc.mjs`,
|
|
83
|
-
`.${moduleName}rc.cjs`,
|
|
84
|
-
`${moduleName}.config.ts`,
|
|
85
|
-
`${moduleName}.config.js`,
|
|
86
|
-
`${moduleName}.config.mjs`,
|
|
87
|
-
`${moduleName}.config.cjs`
|
|
88
|
-
];
|
|
89
|
-
const explorer = cosmiconfig(moduleName, {
|
|
90
|
-
cache: false,
|
|
91
|
-
searchPlaces: [
|
|
92
|
-
...searchPlaces.map((searchPlace) => {
|
|
93
|
-
return `.config/${searchPlace}`;
|
|
94
|
-
}),
|
|
95
|
-
...searchPlaces.map((searchPlace) => {
|
|
96
|
-
return `configs/${searchPlace}`;
|
|
97
|
-
}),
|
|
98
|
-
...searchPlaces
|
|
99
|
-
],
|
|
100
|
-
loaders: {
|
|
101
|
-
".ts": tsLoader
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
const result = config ? await explorer.load(config) : await explorer.search();
|
|
105
|
-
if (result?.isEmpty || !result || !result.config) {
|
|
106
|
-
throw new Error("Config not defined, create a kubb.config.js or pass through your config with the option --config");
|
|
107
|
-
}
|
|
108
|
-
return result;
|
|
109
|
-
}
|
|
110
|
-
async function startWatcher(path2, cb) {
|
|
111
|
-
const { watch } = await import('chokidar');
|
|
112
|
-
const logger = createLogger();
|
|
113
|
-
const ignored = "**/{.git,node_modules}/**";
|
|
114
|
-
const watcher = watch(path2, {
|
|
115
|
-
ignorePermissionErrors: true,
|
|
116
|
-
ignored
|
|
117
|
-
});
|
|
118
|
-
watcher.on("all", (type, file) => {
|
|
119
|
-
logger?.emit("info", colors.yellow(colors.bold(`Change detected: ${type} ${file}`)));
|
|
120
|
-
try {
|
|
121
|
-
cb(path2);
|
|
122
|
-
} catch (_e) {
|
|
123
|
-
logger?.emit("warning", colors.red("Watcher failed"));
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
var args = {
|
|
128
|
-
config: {
|
|
129
|
-
type: "string",
|
|
130
|
-
description: "Path to the Kubb config",
|
|
131
|
-
alias: "c"
|
|
132
|
-
},
|
|
133
|
-
logLevel: {
|
|
134
|
-
type: "string",
|
|
135
|
-
description: "Info, silent or debug",
|
|
136
|
-
alias: "l",
|
|
137
|
-
default: "info",
|
|
138
|
-
valueHint: "silent|info|debug"
|
|
139
|
-
},
|
|
140
|
-
watch: {
|
|
141
|
-
type: "boolean",
|
|
142
|
-
description: "Watch mode based on the input file",
|
|
143
|
-
alias: "w",
|
|
144
|
-
default: false
|
|
145
|
-
},
|
|
146
|
-
debug: {
|
|
147
|
-
type: "boolean",
|
|
148
|
-
description: "Override logLevel to debug",
|
|
149
|
-
alias: "d",
|
|
150
|
-
default: false
|
|
151
|
-
},
|
|
152
|
-
ui: {
|
|
153
|
-
type: "boolean",
|
|
154
|
-
description: "Open ui",
|
|
155
|
-
alias: "u",
|
|
156
|
-
default: false
|
|
157
|
-
},
|
|
158
|
-
help: {
|
|
159
|
-
type: "boolean",
|
|
160
|
-
description: "Show help",
|
|
161
|
-
alias: "h",
|
|
162
|
-
default: false
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
var command = defineCommand({
|
|
166
|
-
meta: {
|
|
167
|
-
name: "generate",
|
|
168
|
-
description: "[input] Generate files based on a 'kubb.config.ts' file"
|
|
169
|
-
},
|
|
170
|
-
args,
|
|
171
|
-
async run(commandContext) {
|
|
172
|
-
let name = "";
|
|
173
|
-
const progressCache = /* @__PURE__ */ new Map();
|
|
174
|
-
const { args: args2 } = commandContext;
|
|
175
|
-
const input = args2._[0];
|
|
176
|
-
if (args2.help) {
|
|
177
|
-
return showUsage(command);
|
|
178
|
-
}
|
|
179
|
-
if (args2.debug) {
|
|
180
|
-
args2.logLevel = "debug";
|
|
181
|
-
}
|
|
182
|
-
const logLevel = LogMapper[args2.logLevel] || 3;
|
|
183
|
-
const logger = createLogger({
|
|
184
|
-
logLevel
|
|
185
|
-
});
|
|
186
|
-
const { generate } = await import('./generate-HUWFJ4IA.js');
|
|
187
|
-
logger.emit("start", "Loading config");
|
|
188
|
-
const result = await getCosmiConfig("kubb", args2.config);
|
|
189
|
-
logger.emit("success", `Config loaded(${colors.dim(path.relative(process.cwd(), result.filepath))})`);
|
|
190
|
-
const config = await getConfig(result, args2);
|
|
191
|
-
const start = async () => {
|
|
192
|
-
if (Array.isArray(config)) {
|
|
193
|
-
const promiseManager = new PromiseManager();
|
|
194
|
-
const promises = config.map((c) => () => {
|
|
195
|
-
name = c.name || "";
|
|
196
|
-
progressCache.clear();
|
|
197
|
-
return generate({
|
|
198
|
-
input,
|
|
199
|
-
config: c,
|
|
200
|
-
args: args2,
|
|
201
|
-
progressCache
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
await promiseManager.run("seq", promises);
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
progressCache.clear();
|
|
208
|
-
await generate({
|
|
209
|
-
input,
|
|
210
|
-
config,
|
|
211
|
-
progressCache,
|
|
212
|
-
args: args2
|
|
213
|
-
});
|
|
214
|
-
return;
|
|
215
|
-
};
|
|
216
|
-
if (args2.ui) {
|
|
217
|
-
const { startServer } = await import('@kubb/ui');
|
|
218
|
-
await startServer(
|
|
219
|
-
{
|
|
220
|
-
stop: () => process.exit(1),
|
|
221
|
-
restart: () => start(),
|
|
222
|
-
getMeta: () => {
|
|
223
|
-
const entries = [...progressCache.entries()];
|
|
224
|
-
const percentages = entries.reduce(
|
|
225
|
-
(acc, [key, singleBar]) => {
|
|
226
|
-
acc[key] = singleBar.getProgress();
|
|
227
|
-
return acc;
|
|
228
|
-
},
|
|
229
|
-
{}
|
|
230
|
-
);
|
|
231
|
-
return {
|
|
232
|
-
name,
|
|
233
|
-
percentages
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
(info) => {
|
|
238
|
-
const url = `${info.address}:${info.port}`.replace("::", "http://localhost");
|
|
239
|
-
logger.consola?.start(`Starting ui on ${url}`);
|
|
240
|
-
open(url);
|
|
241
|
-
}
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
if (args2.watch) {
|
|
245
|
-
if (Array.isArray(config)) {
|
|
246
|
-
throw new Error("Cannot use watcher with multiple Configs(array)");
|
|
247
|
-
}
|
|
248
|
-
if (isInputPath(config)) {
|
|
249
|
-
return startWatcher([input || config.input.path], async (paths) => {
|
|
250
|
-
await start();
|
|
251
|
-
logger.emit("start", colors.yellow(colors.bold(`Watching for changes in ${paths.join(" and ")}`)));
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
await start();
|
|
256
|
-
if (globalThis.isDevtoolsEnabled) {
|
|
257
|
-
const canRestart = await logger.consola?.prompt("Restart(could be used to validate the profiler)?", {
|
|
258
|
-
type: "confirm",
|
|
259
|
-
initial: false
|
|
260
|
-
});
|
|
261
|
-
if (canRestart) {
|
|
262
|
-
await start();
|
|
263
|
-
} else {
|
|
264
|
-
process.exit(1);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
var generate_default = command;
|
|
270
|
-
|
|
271
|
-
export { generate_default as default };
|
|
272
|
-
//# sourceMappingURL=generate-65TMSGIL.js.map
|
|
273
|
-
//# sourceMappingURL=generate-65TMSGIL.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/getPlugins.ts","../src/utils/getConfig.ts","../src/utils/getCosmiConfig.ts","../src/utils/watcher.ts","../src/commands/generate.ts"],"names":["args","path","createLogger","colors"],"mappings":";;;;;;;;;;;;;;AAEA,SAAS,cAAc,OAAgC,EAAA;AACrD,EAAA,OAAO,CAAC,CAAE,OAAiB,EAAA,IAAA,CAAK,CAAC,MAAgB,KAAA;AAC/C,IAAO,OAAA,KAAA,CAAM,QAAQ,MAAM,CAAA,IAAK,OAAO,MAAQ,EAAA,EAAA,CAAG,CAAC,CAAM,KAAA,QAAA;AAAA,GAC1D,CAAA;AACH;AAEA,SAAS,gBAAgB,OAAgD,EAAA;AACvE,EAAA,OAAO,OAAmB,YAAA,MAAA,IAAU,CAAC,KAAA,CAAM,QAAQ,OAAO,CAAA;AAC5D;AAEO,SAAS,WAAW,OAAgE,EAAA;AACzF,EAAI,IAAA,eAAA,CAAgB,OAAO,CAAG,EAAA;AAC5B,IAAM,MAAA,IAAI,MAAM,sGAAsG,CAAA;AAAA;AAGxH,EAAI,IAAA,aAAA,CAAc,OAAO,CAAG,EAAA;AAC1B,IAAM,MAAA,IAAI,MAAM,oGAAoG,CAAA;AAAA;AAGtH,EAAO,OAAA,OAAA,CAAQ,QAAQ,O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WAAA,CAAY,MAAM,CAAG,EAAA;AACvB,QAAO,OAAA,YAAA,CAAa,CAAC,KAAS,IAAA,MAAA,CAAO,MAAM,IAAI,CAAA,EAAG,OAAO,KAAU,KAAA;AACjE,UAAA,MAAM,KAAM,EAAA;AACZ,UAAA,MAAA,CAAO,IAAK,CAAA,OAAA,EAASG,MAAO,CAAA,MAAA,CAAOA,MAAO,CAAA,IAAA,CAAK,CAA2B,wBAAA,EAAA,KAAA,CAAM,IAAK,CAAA,OAAO,CAAC,CAAA,CAAE,CAAC,CAAC,CAAA;AAAA,SAClG,CAAA;AAAA;AACH;AAGF,IAAA,MAAM,KAAM,EAAA;AAEZ,IAAA,IAAI,WAAW,iBAAmB,EAAA;AAChC,MAAA,MAAM,UAAa,GAAA,MAAM,MAAO,CAAA,OAAA,EAAS,OAAO,kDAAoD,EAAA;AAAA,QAClG,IAAM,EAAA,SAAA;AAAA,QACN,OAAS,EAAA;AAAA,OACV,CAAA;AAED,MAAA,IAAI,UAAY,EAAA;AACd,QAAA,MAAM,KAAM,EAAA;AAAA,OACP,MAAA;AACL,QAAQ,aAAK,CAAC,CAAA;AAAA;AAChB;AACF;AAEJ,CAAC,CAAA;AAED,IAAO,gBAAQ,GAAA","file":"generate-65TMSGIL.js","sourcesContent":["import type { UserConfig } from '@kubb/core'\n\nfunction isJSONPlugins(plugins: UserConfig['plugins']) {\n return !!(plugins as any)?.some((plugin: any) => {\n return Array.isArray(plugin) && typeof plugin?.at(0) === 'string'\n })\n}\n\nfunction isObjectPlugins(plugins: UserConfig['plugins']): plugins is any {\n return plugins instanceof Object && !Array.isArray(plugins)\n}\n\nexport function getPlugins(plugins: UserConfig['plugins']): Promise<UserConfig['plugins']> {\n if (isObjectPlugins(plugins)) {\n throw new Error('Object plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json')\n }\n\n if (isJSONPlugins(plugins)) {\n throw new Error('JSON plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json')\n }\n\n return Promise.resolve(plugins)\n}\n","import { isPromise } from '@kubb/core/utils'\n\nimport { getPlugins } from './getPlugins.ts'\n\nimport type { Config, UserConfig } from '@kubb/core'\nimport type { Args } from '../commands/generate.ts'\nimport type { CosmiconfigResult } from './getCosmiConfig.ts'\n\n/**\n * Converting UserConfig to Config without a change in the object beside the JSON convert.\n */\nexport async function getConfig(result: CosmiconfigResult, args: Args): Promise<Array<Config> | Config> {\n const config = result?.config\n let kubbUserConfig = Promise.resolve(config) as Promise<UserConfig | Array<UserConfig>>\n\n // for ts or js files\n if (typeof config === 'function') {\n const possiblePromise = config(args)\n if (isPromise(possiblePromise)) {\n kubbUserConfig = possiblePromise\n }\n kubbUserConfig = Promise.resolve(possiblePromise)\n }\n\n let JSONConfig = await kubbUserConfig\n\n if (Array.isArray(JSONConfig)) {\n const results: Array<Config> = []\n\n for (const item of JSONConfig) {\n const plugins = item.plugins ? await getPlugins(item.plugins) : undefined\n\n results.push({\n ...item,\n plugins,\n } as Config)\n }\n\n return results\n }\n\n JSONConfig = {\n ...JSONConfig,\n plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : undefined,\n }\n\n return JSONConfig as Config\n}\n","import { cosmiconfig } from 'cosmiconfig'\nimport { createJiti } from 'jiti'\n\nimport type { UserConfig, defineConfig } from '@kubb/core'\n\nexport type CosmiconfigResult = {\n filepath: string\n isEmpty?: boolean\n config: ReturnType<typeof defineConfig> | UserConfig\n}\n\nconst tsLoader = async (configFile: string) => {\n const jiti = createJiti(import.meta.url, {\n jsx: {\n runtime: 'automatic',\n importSource: '@kubb/react',\n },\n sourceMaps: true,\n })\n\n const mod = await jiti.import(configFile, { default: true })\n\n return mod\n}\n\nexport async function getCosmiConfig(moduleName: string, config?: string): Promise<CosmiconfigResult> {\n const searchPlaces = [\n 'package.json',\n `.${moduleName}rc`,\n `.${moduleName}rc.json`,\n `.${moduleName}rc.yaml`,\n `.${moduleName}rc.yml`,\n\n `.${moduleName}rc.ts`,\n `.${moduleName}rc.js`,\n `.${moduleName}rc.mjs`,\n `.${moduleName}rc.cjs`,\n\n `${moduleName}.config.ts`,\n `${moduleName}.config.js`,\n `${moduleName}.config.mjs`,\n `${moduleName}.config.cjs`,\n ]\n const explorer = cosmiconfig(moduleName, {\n cache: false,\n searchPlaces: [\n ...searchPlaces.map((searchPlace) => {\n return `.config/${searchPlace}`\n }),\n ...searchPlaces.map((searchPlace) => {\n return `configs/${searchPlace}`\n }),\n ...searchPlaces,\n ],\n loaders: {\n '.ts': tsLoader,\n },\n })\n\n const result = config ? await explorer.load(config) : await explorer.search()\n\n if (result?.isEmpty || !result || !result.config) {\n throw new Error('Config not defined, create a kubb.config.js or pass through your config with the option --config')\n }\n\n return result as CosmiconfigResult\n}\n","import { createLogger } from '@kubb/core/logger'\nimport { colors } from 'consola/utils'\n\nexport async function startWatcher(path: string[], cb: (path: string[]) => Promise<void>): Promise<void> {\n const { watch } = await import('chokidar')\n const logger = createLogger()\n\n const ignored = '**/{.git,node_modules}/**'\n\n const watcher = watch(path, {\n ignorePermissionErrors: true,\n ignored,\n })\n watcher.on('all', (type, file) => {\n logger?.emit('info', colors.yellow(colors.bold(`Change detected: ${type} ${file}`)))\n\n try {\n cb(path)\n } catch (_e) {\n logger?.emit('warning', colors.red('Watcher failed'))\n }\n })\n}\n","import { defineCommand, showUsage } from 'citty'\nimport type { ArgsDef, ParsedArgs } from 'citty'\nimport { colors } from 'consola/utils'\n\nimport { getConfig } from '../utils/getConfig.ts'\nimport { getCosmiConfig } from '../utils/getCosmiConfig.ts'\nimport { startWatcher } from '../utils/watcher.ts'\n\nimport path from 'node:path'\nimport * as process from 'node:process'\nimport { PromiseManager, isInputPath } from '@kubb/core'\nimport { LogMapper, createLogger } from '@kubb/core/logger'\n\nimport open from 'open'\nimport type { SingleBar } from 'cli-progress'\n\ndeclare global {\n var isDevtoolsEnabled: any\n}\n\nconst args = {\n config: {\n type: 'string',\n description: 'Path to the Kubb config',\n alias: 'c',\n },\n logLevel: {\n type: 'string',\n description: 'Info, silent or debug',\n alias: 'l',\n default: 'info',\n valueHint: 'silent|info|debug',\n },\n watch: {\n type: 'boolean',\n description: 'Watch mode based on the input file',\n alias: 'w',\n default: false,\n },\n debug: {\n type: 'boolean',\n description: 'Override logLevel to debug',\n alias: 'd',\n default: false,\n },\n ui: {\n type: 'boolean',\n description: 'Open ui',\n alias: 'u',\n default: false,\n },\n help: {\n type: 'boolean',\n description: 'Show help',\n alias: 'h',\n default: false,\n },\n} as const satisfies ArgsDef\n\nexport type Args = ParsedArgs<typeof args>\n\nconst command = defineCommand({\n meta: {\n name: 'generate',\n description: \"[input] Generate files based on a 'kubb.config.ts' file\",\n },\n args,\n async run(commandContext) {\n let name = ''\n const progressCache = new Map<string, SingleBar>()\n\n const { args } = commandContext\n\n const input = args._[0]\n\n if (args.help) {\n return showUsage(command)\n }\n\n if (args.debug) {\n args.logLevel = 'debug'\n }\n\n const logLevel = LogMapper[args.logLevel as keyof typeof LogMapper] || 3\n const logger = createLogger({\n logLevel,\n })\n const { generate } = await import('../runners/generate.ts')\n\n logger.emit('start', 'Loading config')\n\n const result = await getCosmiConfig('kubb', args.config)\n logger.emit('success', `Config loaded(${colors.dim(path.relative(process.cwd(), result.filepath))})`)\n\n const config = await getConfig(result, args)\n\n const start = async () => {\n if (Array.isArray(config)) {\n const promiseManager = new PromiseManager()\n const promises = config.map((c) => () => {\n name = c.name || ''\n progressCache.clear()\n\n return generate({\n input,\n config: c,\n args,\n progressCache,\n })\n })\n\n await promiseManager.run('seq', promises)\n return\n }\n\n progressCache.clear()\n\n await generate({\n input,\n config,\n progressCache,\n args,\n })\n\n return\n }\n\n if (args.ui) {\n const { startServer } = await import('@kubb/ui')\n\n await startServer(\n {\n stop: () => process.exit(1),\n restart: () => start(),\n getMeta: () => {\n const entries = [...progressCache.entries()]\n\n const percentages = entries.reduce(\n (acc, [key, singleBar]) => {\n acc[key] = singleBar.getProgress()\n\n return acc\n },\n {} as Record<string, number>,\n )\n\n return {\n name,\n percentages,\n }\n },\n },\n (info) => {\n const url = `${info.address}:${info.port}`.replace('::', 'http://localhost')\n logger.consola?.start(`Starting ui on ${url}`)\n\n open(url)\n },\n )\n }\n\n if (args.watch) {\n if (Array.isArray(config)) {\n throw new Error('Cannot use watcher with multiple Configs(array)')\n }\n\n if (isInputPath(config)) {\n return startWatcher([input || config.input.path], async (paths) => {\n await start()\n logger.emit('start', colors.yellow(colors.bold(`Watching for changes in ${paths.join(' and ')}`)))\n })\n }\n }\n\n await start()\n\n if (globalThis.isDevtoolsEnabled) {\n const canRestart = await logger.consola?.prompt('Restart(could be used to validate the profiler)?', {\n type: 'confirm',\n initial: false,\n })\n\n if (canRestart) {\n await start()\n } else {\n process.exit(1)\n }\n }\n },\n})\n\nexport default command\n"]}
|