@kubb/cli 5.0.0-beta.54 → 5.0.0-beta.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/dist/{Telemetry-DC5WVMB9.cjs → Telemetry-BuDSora3.cjs} +83 -112
- package/dist/Telemetry-BuDSora3.cjs.map +1 -0
- package/dist/{Telemetry-BZH4YIxq.js → Telemetry-C66uYyC2.js} +82 -111
- package/dist/Telemetry-C66uYyC2.js.map +1 -0
- package/dist/define-C4AB3POr.cjs.map +1 -1
- package/dist/define-C63T4jp6.js.map +1 -1
- package/dist/{generate-CSu0xUcm.js → generate-DZlEPvGX.js} +3 -9
- package/dist/generate-DZlEPvGX.js.map +1 -0
- package/dist/{generate-BRt2AlAO.cjs → generate-wadnaW25.cjs} +3 -9
- package/dist/generate-wadnaW25.cjs.map +1 -0
- package/dist/index.cjs +8 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +8 -22
- package/dist/index.js.map +1 -1
- package/dist/{init-YMqAAWFE.cjs → init-B8In4PV3.cjs} +3 -3
- package/dist/{init-YMqAAWFE.cjs.map → init-B8In4PV3.cjs.map} +1 -1
- package/dist/{init-CnVtpZfe.js → init-DAyMW8Tb.js} +3 -3
- package/dist/{init-CnVtpZfe.js.map → init-DAyMW8Tb.js.map} +1 -1
- package/dist/{mcp-CnP9ZVBz.js → mcp-BpenB6vE.js} +3 -3
- package/dist/{mcp-CnP9ZVBz.js.map → mcp-BpenB6vE.js.map} +1 -1
- package/dist/{mcp-B2wwhU2v.cjs → mcp-nVpSgCz-.cjs} +3 -3
- package/dist/{mcp-B2wwhU2v.cjs.map → mcp-nVpSgCz-.cjs.map} +1 -1
- package/dist/package-BSMI4dNK.js +6 -0
- package/dist/package-BSMI4dNK.js.map +1 -0
- package/dist/{package-C8wmoP1B.cjs → package-CsEMNf0Q.cjs} +2 -2
- package/dist/package-CsEMNf0Q.cjs.map +1 -0
- package/dist/{run-C-omuksC.js → run-BG7Giryi.js} +36 -99
- package/dist/run-BG7Giryi.js.map +1 -0
- package/dist/{run-DMWGLJUx.cjs → run-Bj64iPU_.cjs} +2 -2
- package/dist/{run-DMWGLJUx.cjs.map → run-Bj64iPU_.cjs.map} +1 -1
- package/dist/{run-Cou32en2.js → run-CSYH_DiQ.js} +83 -165
- package/dist/run-CSYH_DiQ.js.map +1 -0
- package/dist/{run-C7cr0qhi.js → run-CUkZ6gnP.js} +2 -2
- package/dist/{run-C7cr0qhi.js.map → run-CUkZ6gnP.js.map} +1 -1
- package/dist/{run-DGMgkbD3.cjs → run-DCXY-eRK.cjs} +2 -2
- package/dist/{run-DGMgkbD3.cjs.map → run-DCXY-eRK.cjs.map} +1 -1
- package/dist/{run-4WGNek3a.cjs → run-DWqZHzYL.cjs} +86 -168
- package/dist/run-DWqZHzYL.cjs.map +1 -0
- package/dist/{run-BtjzfTz3.cjs → run-DpKny2hT.cjs} +30 -93
- package/dist/run-DpKny2hT.cjs.map +1 -0
- package/dist/{run-DLVIbuN0.js → run-OWQyNzZx.js} +2 -2
- package/dist/{run-DLVIbuN0.js.map → run-OWQyNzZx.js.map} +1 -1
- package/dist/tools-BU99bhi8.js +152 -0
- package/dist/tools-BU99bhi8.js.map +1 -0
- package/dist/tools-_Xp8-_zy.cjs +175 -0
- package/dist/tools-_Xp8-_zy.cjs.map +1 -0
- package/dist/{validate-Bqf5fxQp.cjs → validate-CJZ7XveW.cjs} +3 -3
- package/dist/{validate-Bqf5fxQp.cjs.map → validate-CJZ7XveW.cjs.map} +1 -1
- package/dist/{validate-BlNh3LLm.js → validate-DPgK_e7n.js} +3 -3
- package/dist/{validate-BlNh3LLm.js.map → validate-DPgK_e7n.js.map} +1 -1
- package/package.json +5 -5
- package/src/Telemetry.ts +20 -22
- package/src/commands/generate.ts +0 -6
- package/src/constants.ts +1 -1
- package/src/index.ts +4 -21
- package/src/runners/generate/run.ts +12 -16
- package/src/runners/generate/utils.ts +18 -19
- package/src/runners/init/utils.ts +9 -3
- package/dist/Telemetry-BZH4YIxq.js.map +0 -1
- package/dist/Telemetry-DC5WVMB9.cjs.map +0 -1
- package/dist/generate-BRt2AlAO.cjs.map +0 -1
- package/dist/generate-CSu0xUcm.js.map +0 -1
- package/dist/package-C8wmoP1B.cjs.map +0 -1
- package/dist/package-CNNBB6JV.js +0 -6
- package/dist/package-CNNBB6JV.js.map +0 -1
- package/dist/run-4WGNek3a.cjs.map +0 -1
- package/dist/run-BtjzfTz3.cjs.map +0 -1
- package/dist/run-C-omuksC.js.map +0 -1
- package/dist/run-Cou32en2.js.map +0 -1
- package/dist/shell-DsgkfUSW.js +0 -51
- package/dist/shell-DsgkfUSW.js.map +0 -1
- package/dist/shell-Lh-vLWwH.cjs +0 -62
- package/dist/shell-Lh-vLWwH.cjs.map +0 -1
|
@@ -1,66 +1,11 @@
|
|
|
1
1
|
import "./chunk-C0LytTxp.js";
|
|
2
|
-
import { t as
|
|
2
|
+
import { t as detectPackageManager } from "./tools-BU99bhi8.js";
|
|
3
3
|
import { styleText } from "node:util";
|
|
4
|
-
import fs
|
|
5
|
-
import path
|
|
6
|
-
import process
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import process from "node:process";
|
|
7
7
|
import * as clack from "@clack/prompts";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Metadata for each supported package manager, keyed by its short name.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* packageManagers.pnpm.installCommand // ['add', '-D']
|
|
15
|
-
* packageManagers.npm.lockFile // 'package-lock.json'
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
const packageManagers = {
|
|
19
|
-
pnpm: {
|
|
20
|
-
name: "pnpm",
|
|
21
|
-
lockFile: "pnpm-lock.yaml",
|
|
22
|
-
installCommand: ["add", "-D"]
|
|
23
|
-
},
|
|
24
|
-
yarn: {
|
|
25
|
-
name: "yarn",
|
|
26
|
-
lockFile: "yarn.lock",
|
|
27
|
-
installCommand: ["add", "-D"]
|
|
28
|
-
},
|
|
29
|
-
bun: {
|
|
30
|
-
name: "bun",
|
|
31
|
-
lockFile: "bun.lockb",
|
|
32
|
-
installCommand: ["add", "-d"]
|
|
33
|
-
},
|
|
34
|
-
npm: {
|
|
35
|
-
name: "npm",
|
|
36
|
-
lockFile: "package-lock.json",
|
|
37
|
-
installCommand: ["install", "--save-dev"]
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Detects the active package manager for the given directory.
|
|
42
|
-
* Resolution order: `packageManager` field in `package.json`, then presence of a lock file.
|
|
43
|
-
* Falls back to `npm` when no signal is found.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts
|
|
47
|
-
* detectPackageManager('/my/project') // { name: 'pnpm', lockFile: 'pnpm-lock.yaml', ... }
|
|
48
|
-
* detectPackageManager() // falls back to npm when no lock file is found
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
function detectPackageManager(cwd = process.cwd()) {
|
|
52
|
-
const packageJsonPath = join(cwd, "package.json");
|
|
53
|
-
if (existsSync(packageJsonPath)) try {
|
|
54
|
-
const pmField = JSON.parse(readFileSync(packageJsonPath, "utf-8")).packageManager;
|
|
55
|
-
if (typeof pmField === "string") {
|
|
56
|
-
const name = pmField.split("@")[0];
|
|
57
|
-
if (name && name in packageManagers) return packageManagers[name];
|
|
58
|
-
}
|
|
59
|
-
} catch {}
|
|
60
|
-
for (const pm of Object.values(packageManagers)) if (existsSync(join(cwd, pm.lockFile))) return pm;
|
|
61
|
-
return packageManagers.npm;
|
|
62
|
-
}
|
|
63
|
-
//#endregion
|
|
8
|
+
import { x } from "tinyexec";
|
|
64
9
|
//#region ../../internals/shared/src/constants.ts
|
|
65
10
|
const KUBB_CONFIG_FILENAME = "kubb.config.ts";
|
|
66
11
|
const initDefaults = {
|
|
@@ -142,36 +87,16 @@ const availablePlugins = [
|
|
|
142
87
|
}
|
|
143
88
|
];
|
|
144
89
|
const pluginDefaultConfigs = {
|
|
145
|
-
"plugin-ts": `pluginTs(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
"plugin-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
"plugin-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
"plugin-
|
|
155
|
-
output: { path: 'hooks' },
|
|
156
|
-
})`,
|
|
157
|
-
"plugin-zod": `pluginZod({
|
|
158
|
-
output: { path: 'zod' },
|
|
159
|
-
})`,
|
|
160
|
-
"plugin-faker": `pluginFaker({
|
|
161
|
-
output: { path: 'mocks' },
|
|
162
|
-
})`,
|
|
163
|
-
"plugin-msw": `pluginMsw({
|
|
164
|
-
output: { path: 'msw' },
|
|
165
|
-
})`,
|
|
166
|
-
"plugin-cypress": `pluginCypress({
|
|
167
|
-
output: { path: 'cypress' },
|
|
168
|
-
})`,
|
|
169
|
-
"plugin-mcp": `pluginMcp({
|
|
170
|
-
output: { path: 'mcp' },
|
|
171
|
-
})`,
|
|
172
|
-
"plugin-redoc": `pluginRedoc({
|
|
173
|
-
output: { path: 'redoc' },
|
|
174
|
-
})`
|
|
90
|
+
"plugin-ts": `pluginTs()`,
|
|
91
|
+
"plugin-client": `pluginClient()`,
|
|
92
|
+
"plugin-react-query": `pluginReactQuery()`,
|
|
93
|
+
"plugin-vue-query": `pluginVueQuery()`,
|
|
94
|
+
"plugin-zod": `pluginZod()`,
|
|
95
|
+
"plugin-faker": `pluginFaker()`,
|
|
96
|
+
"plugin-msw": `pluginMsw()`,
|
|
97
|
+
"plugin-cypress": `pluginCypress()`,
|
|
98
|
+
"plugin-mcp": `pluginMcp()`,
|
|
99
|
+
"plugin-redoc": `pluginRedoc()`
|
|
175
100
|
};
|
|
176
101
|
//#endregion
|
|
177
102
|
//#region ../../internals/shared/src/init.ts
|
|
@@ -201,31 +126,43 @@ ${selectedPlugins.map((plugin) => {
|
|
|
201
126
|
/**
|
|
202
127
|
* Returns `true` when a `package.json` exists at `cwd`.
|
|
203
128
|
*/
|
|
204
|
-
function hasPackageJson(cwd = process
|
|
129
|
+
function hasPackageJson(cwd = process.cwd()) {
|
|
205
130
|
return fs.existsSync(path.join(cwd, "package.json"));
|
|
206
131
|
}
|
|
207
132
|
/**
|
|
208
133
|
* Initializes a new `package.json` at `cwd` using the detected package manager.
|
|
209
134
|
*/
|
|
210
135
|
async function initPackageJson(cwd, packageManager) {
|
|
211
|
-
await
|
|
136
|
+
await x(packageManager.name, {
|
|
212
137
|
npm: ["init", "-y"],
|
|
213
138
|
pnpm: ["init"],
|
|
214
139
|
yarn: ["init", "-y"],
|
|
215
140
|
bun: ["init", "-y"]
|
|
216
|
-
}[packageManager.name], {
|
|
141
|
+
}[packageManager.name], {
|
|
142
|
+
nodeOptions: {
|
|
143
|
+
cwd,
|
|
144
|
+
stdio: "inherit"
|
|
145
|
+
},
|
|
146
|
+
throwOnError: true
|
|
147
|
+
});
|
|
217
148
|
}
|
|
218
149
|
/**
|
|
219
150
|
* Installs the given packages at `cwd` using the detected package manager.
|
|
220
151
|
*/
|
|
221
|
-
async function installPackages(packages, packageManager, cwd = process
|
|
222
|
-
await
|
|
152
|
+
async function installPackages(packages, packageManager, cwd = process.cwd()) {
|
|
153
|
+
await x(packageManager.name, [...packageManager.installCommand, ...packages], {
|
|
154
|
+
nodeOptions: {
|
|
155
|
+
cwd,
|
|
156
|
+
stdio: "inherit"
|
|
157
|
+
},
|
|
158
|
+
throwOnError: true
|
|
159
|
+
});
|
|
223
160
|
}
|
|
224
161
|
//#endregion
|
|
225
162
|
//#region src/runners/init/run.ts
|
|
226
163
|
function cancelAndExit(message = "Operation canceled.") {
|
|
227
164
|
clack.cancel(message);
|
|
228
|
-
process
|
|
165
|
+
process.exit(0);
|
|
229
166
|
}
|
|
230
167
|
/**
|
|
231
168
|
* Runs the interactive Kubb scaffolding wizard.
|
|
@@ -233,7 +170,7 @@ function cancelAndExit(message = "Operation canceled.") {
|
|
|
233
170
|
* Pass `yes: true` to skip all prompts and use defaults.
|
|
234
171
|
*/
|
|
235
172
|
async function run({ yes, version, input: inputFlag, output: outputFlag, plugins: pluginsFlag }) {
|
|
236
|
-
const cwd = process
|
|
173
|
+
const cwd = process.cwd();
|
|
237
174
|
clack.intro(styleText("bgCyan", styleText("black", " Kubb Init ")));
|
|
238
175
|
/**
|
|
239
176
|
* Returns `flag` when provided, the `defaultValue` when `yes` is set,
|
|
@@ -350,10 +287,10 @@ async function run({ yes, version, input: inputFlag, output: outputFlag, plugins
|
|
|
350
287
|
} catch (error) {
|
|
351
288
|
clack.log.error(styleText("red", "An error occurred during initialization"));
|
|
352
289
|
if (error instanceof Error) clack.log.error(error.message);
|
|
353
|
-
process
|
|
290
|
+
process.exit(1);
|
|
354
291
|
}
|
|
355
292
|
}
|
|
356
293
|
//#endregion
|
|
357
294
|
export { run };
|
|
358
295
|
|
|
359
|
-
//# sourceMappingURL=run-
|
|
296
|
+
//# sourceMappingURL=run-BG7Giryi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-BG7Giryi.js","names":[],"sources":["../../../internals/shared/src/constants.ts","../../../internals/shared/src/init.ts","../src/runners/init/utils.ts","../src/runners/init/run.ts"],"sourcesContent":["import type { PluginOption } from './types.ts'\n\nexport const KUBB_CONFIG_FILENAME = 'kubb.config.ts' as const\n\nexport const initDefaults = {\n inputPath: './openapi.yaml',\n outputPath: './src/gen',\n plugins: ['plugin-ts'],\n} as const\n\nexport const availablePlugins: Array<PluginOption> = [\n {\n value: 'plugin-ts',\n label: 'TypeScript',\n hint: 'Recommended',\n packageName: '@kubb/plugin-ts',\n importName: 'pluginTs',\n category: 'types',\n },\n {\n value: 'plugin-client',\n label: 'Client (Fetch/Axios)',\n packageName: '@kubb/plugin-client',\n importName: 'pluginClient',\n category: 'client',\n },\n {\n value: 'plugin-react-query',\n label: 'React Query / TanStack Query',\n packageName: '@kubb/plugin-react-query',\n importName: 'pluginReactQuery',\n category: 'framework',\n },\n {\n value: 'plugin-vue-query',\n label: 'Vue Query',\n packageName: '@kubb/plugin-vue-query',\n importName: 'pluginVueQuery',\n category: 'framework',\n },\n {\n value: 'plugin-zod',\n label: 'Zod Schemas',\n packageName: '@kubb/plugin-zod',\n importName: 'pluginZod',\n category: 'validation',\n },\n {\n value: 'plugin-faker',\n label: 'Faker.js Mocks',\n packageName: '@kubb/plugin-faker',\n importName: 'pluginFaker',\n category: 'mocks',\n },\n {\n value: 'plugin-msw',\n label: 'MSW Handlers',\n packageName: '@kubb/plugin-msw',\n importName: 'pluginMsw',\n category: 'mocks',\n },\n {\n value: 'plugin-cypress',\n label: 'Cypress Tests',\n packageName: '@kubb/plugin-cypress',\n importName: 'pluginCypress',\n category: 'testing',\n },\n {\n value: 'plugin-mcp',\n label: 'MCP Server (AI / Model Context Protocol)',\n packageName: '@kubb/plugin-mcp',\n importName: 'pluginMcp',\n category: 'ai',\n },\n {\n value: 'plugin-redoc',\n label: 'ReDoc Documentation',\n packageName: '@kubb/plugin-redoc',\n importName: 'pluginRedoc',\n category: 'documentation',\n },\n]\n\nexport const pluginDefaultConfigs = {\n 'plugin-ts': `pluginTs()`,\n 'plugin-client': `pluginClient()`,\n 'plugin-react-query': `pluginReactQuery()`,\n 'plugin-vue-query': `pluginVueQuery()`,\n 'plugin-zod': `pluginZod()`,\n 'plugin-faker': `pluginFaker()`,\n 'plugin-msw': `pluginMsw()`,\n 'plugin-cypress': `pluginCypress()`,\n 'plugin-mcp': `pluginMcp()`,\n 'plugin-redoc': `pluginRedoc()`,\n} as const satisfies Record<string, string>\n","import { pluginDefaultConfigs } from './constants.ts'\nimport type { PluginOption } from './types.ts'\n\nexport function generateConfigFile({\n selectedPlugins,\n inputPath,\n outputPath,\n}: {\n selectedPlugins: Array<PluginOption>\n inputPath: string\n outputPath: string\n}): string {\n const imports = selectedPlugins.map((plugin) => `import { ${plugin.importName} } from '${plugin.packageName}'`).join('\\n')\n\n const pluginConfigs = selectedPlugins\n .map((plugin) => {\n const config = (pluginDefaultConfigs as Record<string, string>)[plugin.value] ?? `${plugin.importName}()`\n return ` ${config},`\n })\n .join('\\n')\n\n return `import { defineConfig } from 'kubb'\n${imports}\n\nexport default defineConfig({\n root: '.',\n input: {\n path: '${inputPath}',\n },\n output: {\n path: '${outputPath}',\n clean: true,\n },\n plugins: [\n${pluginConfigs}\n ],\n})\n`\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport type { PackageManagerInfo, PackageManagerName } from '@internals/utils'\nimport { x } from 'tinyexec'\n\n/**\n * Returns `true` when a `package.json` exists at `cwd`.\n */\nexport function hasPackageJson(cwd: string = process.cwd()): boolean {\n return fs.existsSync(path.join(cwd, 'package.json'))\n}\n\n/**\n * Initializes a new `package.json` at `cwd` using the detected package manager.\n */\nexport async function initPackageJson(cwd: string, packageManager: PackageManagerInfo): Promise<void> {\n const commands: Record<PackageManagerName, Array<string>> = {\n npm: ['init', '-y'],\n pnpm: ['init'],\n yarn: ['init', '-y'],\n bun: ['init', '-y'],\n }\n\n await x(packageManager.name, commands[packageManager.name], {\n nodeOptions: { cwd, stdio: 'inherit' },\n throwOnError: true,\n })\n}\n\n/**\n * Installs the given packages at `cwd` using the detected package manager.\n */\nexport async function installPackages(packages: Array<string>, packageManager: PackageManagerInfo, cwd: string = process.cwd()): Promise<void> {\n await x(packageManager.name, [...packageManager.installCommand, ...packages], {\n nodeOptions: { cwd, stdio: 'inherit' },\n throwOnError: true,\n })\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { detectPackageManager } from '@internals/utils'\nimport { availablePlugins, generateConfigFile, initDefaults, KUBB_CONFIG_FILENAME, type PluginOption } from '@internals/shared'\nimport { hasPackageJson, initPackageJson, installPackages } from './utils.ts'\n\nfunction cancelAndExit(message = 'Operation canceled.'): never {\n clack.cancel(message)\n process.exit(0)\n}\n\ntype InitOptions = {\n /**\n * When `true`, skips all interactive prompts and uses default values.\n */\n yes: boolean\n /**\n * Current `@kubb/cli` version string, shown in the outro and used for package installation.\n */\n version: string\n /**\n * Input path flag value from `--input`. When provided, skips the input prompt.\n */\n input?: string\n /**\n * Output directory flag value from `--output`. When provided, skips the output prompt.\n */\n output?: string\n /**\n * Comma-separated plugin list from `--plugins`, e.g. `'plugin-ts,plugin-zod'`. When provided, skips the plugin selection prompt.\n */\n plugins?: string\n}\n\n/**\n * Runs the interactive Kubb scaffolding wizard.\n * Detects the package manager, prompts for input/output paths and plugins, installs packages, and writes `kubb.config.ts`.\n * Pass `yes: true` to skip all prompts and use defaults.\n */\nexport async function run({ yes, version, input: inputFlag, output: outputFlag, plugins: pluginsFlag }: InitOptions): Promise<void> {\n const cwd = process.cwd()\n\n clack.intro(styleText('bgCyan', styleText('black', ' Kubb Init ')))\n\n /**\n * Returns `flag` when provided, the `defaultValue` when `yes` is set,\n * or calls `prompt()` for interactive input. Exits on cancellation.\n */\n async function resolveOrPrompt<T>(flag: T | undefined, defaultValue: T, logLabel: string, prompt: () => Promise<T | symbol>): Promise<T> {\n if (flag !== undefined) {\n clack.log.info(`${logLabel}: ${styleText('cyan', String(flag))}`)\n return flag\n }\n if (yes) {\n clack.log.info(`${logLabel}: ${styleText('cyan', String(defaultValue))}`)\n return defaultValue\n }\n const result = await prompt()\n if (clack.isCancel(result)) cancelAndExit()\n return result as T\n }\n\n try {\n // Check/create package.json, detect package manager once after the block\n if (!hasPackageJson(cwd)) {\n if (!yes) {\n const shouldInit = await clack.confirm({\n message: 'No package.json found. Would you like to create one?',\n initialValue: true,\n })\n\n if (clack.isCancel(shouldInit) || !shouldInit) {\n cancelAndExit()\n }\n }\n\n const packageManager = detectPackageManager(cwd)\n const spinner = clack.spinner()\n spinner.start(`Initializing package.json with ${packageManager.name}`)\n await initPackageJson(cwd, packageManager)\n spinner.stop(`Created package.json with ${packageManager.name}`)\n }\n\n const packageManager = detectPackageManager(cwd)\n if (hasPackageJson(cwd)) {\n clack.log.info(`Detected package manager: ${styleText('cyan', packageManager.name)}`)\n }\n\n // Prompt for OpenAPI spec path\n const inputPath = await resolveOrPrompt(inputFlag, initDefaults.inputPath, 'Using input path', () =>\n clack.text({\n message: 'Where is your OpenAPI specification located?',\n placeholder: initDefaults.inputPath,\n defaultValue: initDefaults.inputPath,\n validate: (value) => {\n if (!value) return 'Input path is required'\n },\n }),\n )\n\n // Prompt for output directory\n const outputPath = await resolveOrPrompt(outputFlag, initDefaults.outputPath, 'Using output path', () =>\n clack.text({\n message: 'Where should the generated files be output?',\n placeholder: initDefaults.outputPath,\n defaultValue: initDefaults.outputPath,\n validate: (value) => {\n if (!value) return 'Output path is required'\n },\n }),\n )\n\n // Plugin selection\n const defaultPlugins = availablePlugins.filter((p) => (initDefaults.plugins as ReadonlyArray<string>).includes(p.value))\n const pluginLabel = (plugins: Array<PluginOption>) => styleText('cyan', plugins.map((p) => p.label).join(', '))\n\n const selectedPlugins: Array<PluginOption> = await (async () => {\n if (pluginsFlag) {\n const requested = pluginsFlag\n .split(',')\n .map((v) => v.trim())\n .filter(Boolean)\n const plugins = availablePlugins.filter((p) => requested.includes(p.value))\n if (plugins.length === 0) {\n clack.log.warn(`No valid plugins found in --plugins value; falling back to default: ${pluginLabel(defaultPlugins)}`)\n return defaultPlugins\n }\n clack.log.info(`Using plugins: ${pluginLabel(plugins)}`)\n return plugins\n }\n if (yes) {\n clack.log.info(`Using plugins: ${pluginLabel(defaultPlugins)}`)\n return defaultPlugins\n }\n const values = await clack.multiselect({\n message: 'Select plugins to use:',\n options: availablePlugins.map(({ value, label, hint }) => ({ value, label, hint })),\n initialValues: [...initDefaults.plugins],\n required: true,\n })\n if (clack.isCancel(values)) cancelAndExit()\n return availablePlugins.filter((p) => (values as Array<string>).includes(p.value))\n })()\n\n // Install packages\n const packagesToInstall = ['kubb', ...selectedPlugins.map((p) => p.packageName)]\n\n const spinner = clack.spinner()\n spinner.start(`Installing ${packagesToInstall.length} packages with ${packageManager.name}`)\n\n try {\n await installPackages(packagesToInstall, packageManager, cwd)\n spinner.stop(`Installed ${packagesToInstall.length} packages`)\n } catch (error) {\n spinner.stop('Installation failed')\n throw error\n }\n\n // Generate config file\n const configSpinner = clack.spinner()\n configSpinner.start(`Creating ${KUBB_CONFIG_FILENAME}`)\n\n const configContent = generateConfigFile({ selectedPlugins, inputPath, outputPath })\n const configPath = path.join(cwd, KUBB_CONFIG_FILENAME)\n\n if (fs.existsSync(configPath)) {\n configSpinner.stop(`${KUBB_CONFIG_FILENAME} already exists`)\n\n if (!yes) {\n const shouldOverwrite = await clack.confirm({\n message: `${KUBB_CONFIG_FILENAME} already exists. Overwrite?`,\n initialValue: false,\n })\n\n if (clack.isCancel(shouldOverwrite) || !shouldOverwrite) {\n cancelAndExit('Keeping existing configuration. Packages have been installed.')\n }\n }\n\n configSpinner.start(`Overwriting ${KUBB_CONFIG_FILENAME}`)\n }\n\n await fs.promises.writeFile(configPath, configContent, 'utf-8')\n\n configSpinner.stop(`Created ${KUBB_CONFIG_FILENAME}`)\n\n clack.outro(\n styleText('green', '✓ All set!') +\n '\\n\\n' +\n styleText('dim', 'Next steps:') +\n '\\n' +\n styleText('cyan', ` 1. Make sure your OpenAPI spec is at: ${inputPath}`) +\n '\\n' +\n styleText('cyan', ' 2. Generate code with: npx kubb generate') +\n '\\n' +\n styleText('cyan', ` 3. Find generated files in: ${outputPath}`) +\n '\\n\\n' +\n styleText('dim', `Using ${packageManager.name} • Kubb v${version}`),\n )\n } catch (error) {\n clack.log.error(styleText('red', 'An error occurred during initialization'))\n if (error instanceof Error) {\n clack.log.error(error.message)\n }\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;AAEA,MAAa,uBAAuB;AAEpC,MAAa,eAAe;CAC1B,WAAW;CACX,YAAY;CACZ,SAAS,CAAC,WAAW;AACvB;AAEA,MAAa,mBAAwC;CACnD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACN,aAAa;EACb,YAAY;EACZ,UAAU;CACZ;CACA;E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CAAC,iBACtC,cAAc,+DAA+D;GAEjF;GAEA,cAAc,MAAM,eAAe,sBAAsB;EAC3D;EAEA,MAAM,GAAG,SAAS,UAAU,YAAY,eAAe,OAAO;EAE9D,cAAc,KAAK,WAAW,sBAAsB;EAEpD,MAAM,MACJ,UAAU,SAAS,YAAY,IAC7B,SACA,UAAU,OAAO,aAAa,IAC9B,OACA,UAAU,QAAQ,2CAA2C,WAAW,IACxE,OACA,UAAU,QAAQ,4CAA4C,IAC9D,OACA,UAAU,QAAQ,iCAAiC,YAAY,IAC/D,SACA,UAAU,OAAO,SAAS,eAAe,KAAK,WAAW,SAAS,CACtE;CACF,SAAS,OAAO;EACd,MAAM,IAAI,MAAM,UAAU,OAAO,yCAAyC,CAAC;EAC3E,IAAI,iBAAiB,OACnB,MAAM,IAAI,MAAM,MAAM,OAAO;EAE/B,QAAQ,KAAK,CAAC;CAChB;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-Bx3C2hgW.cjs");
|
|
2
2
|
const require_errors = require("./errors-DykI11xo.cjs");
|
|
3
|
-
const require_Telemetry = require("./Telemetry-
|
|
3
|
+
const require_Telemetry = require("./Telemetry-BuDSora3.cjs");
|
|
4
4
|
let node_util = require("node:util");
|
|
5
5
|
let node_process = require("node:process");
|
|
6
6
|
node_process = require_chunk.__toESM(node_process, 1);
|
|
@@ -49,4 +49,4 @@ async function run({ input, version }, dependencies = { loadValidateModule }) {
|
|
|
49
49
|
//#endregion
|
|
50
50
|
exports.run = run;
|
|
51
51
|
|
|
52
|
-
//# sourceMappingURL=run-
|
|
52
|
+
//# sourceMappingURL=run-Bj64iPU_.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-
|
|
1
|
+
{"version":3,"file":"run-Bj64iPU_.cjs","names":["process","Telemetry","getErrorMessage"],"sources":["../src/runners/validate/run.ts"],"sourcesContent":["import process from 'node:process'\nimport { styleText } from 'node:util'\nimport { getErrorMessage } from '@internals/utils'\nimport { Telemetry } from '../../Telemetry.ts'\n\ntype ValidateOptions = {\n /**\n * Path or URL to the OpenAPI/Swagger file to validate.\n */\n input: string\n /**\n * Current `@kubb/cli` version string, used for the telemetry payload.\n */\n version: string\n}\n\ntype ValidateModule = typeof import('@kubb/adapter-oas')\ntype ValidateDependencies = {\n /**\n * Loads `@kubb/adapter-oas`. Injected so tests can substitute a mock.\n */\n loadValidateModule: () => Promise<ValidateModule>\n}\n\n/**\n * Dynamically loads `@kubb/adapter-oas` for OpenAPI validation.\n */\nexport function loadValidateModule(): Promise<ValidateModule> {\n return import('@kubb/adapter-oas') as Promise<ValidateModule>\n}\n\n/**\n * Validates an OpenAPI/Swagger file at `input` using `@kubb/adapter-oas`.\n * Exits the process with code 1 on validation failure or missing dependency.\n */\nexport async function run({ input, version }: ValidateOptions, dependencies: ValidateDependencies = { loadValidateModule }): Promise<void> {\n const hrStart = process.hrtime()\n const report = (status: 'success' | 'failed') => Telemetry.send(Telemetry.build({ command: 'validate', kubbVersion: version, hrStart, status }))\n try {\n const { adapterOas } = await dependencies.loadValidateModule()\n const adapter = adapterOas()\n if (!adapter.validate) {\n throw new Error('The loaded adapter does not support validation.')\n }\n await adapter.validate(input, { throwOnError: true })\n await report('success')\n console.log('✅ Validation success')\n } catch (error) {\n await report('failed')\n if (error instanceof Error && /@kubb\\/adapter-oas/.test(error.message)) {\n console.error(styleText('red', 'The @kubb/adapter-oas package is not installed.'))\n console.error('')\n console.error('Install it with:')\n console.error(styleText('cyan', ' npm install @kubb/adapter-oas'))\n console.error(styleText('cyan', ' # or'))\n console.error(styleText('cyan', ' pnpm install @kubb/adapter-oas'))\n console.error('')\n }\n console.error('❌ Validation failed')\n console.error(getErrorMessage(error))\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;AA2BA,SAAgB,qBAA8C;CAC5D,OAAO,OAAO;AAChB;;;;;AAMA,eAAsB,IAAI,EAAE,OAAO,WAA4B,eAAqC,EAAE,mBAAmB,GAAkB;CACzI,MAAM,UAAUA,aAAAA,QAAQ,OAAO;CAC/B,MAAM,UAAU,WAAiCC,kBAAAA,UAAU,KAAKA,kBAAAA,UAAU,MAAM;EAAE,SAAS;EAAY,aAAa;EAAS;EAAS;CAAO,CAAC,CAAC;CAC/I,IAAI;EACF,MAAM,EAAE,eAAe,MAAM,aAAa,mBAAmB;EAC7D,MAAM,UAAU,WAAW;EAC3B,IAAI,CAAC,QAAQ,UACX,MAAM,IAAI,MAAM,iDAAiD;EAEnE,MAAM,QAAQ,SAAS,OAAO,EAAE,cAAc,KAAK,CAAC;EACpD,MAAM,OAAO,SAAS;EACtB,QAAQ,IAAI,sBAAsB;CACpC,SAAS,OAAO;EACd,MAAM,OAAO,QAAQ;EACrB,IAAI,iBAAiB,SAAS,qBAAqB,KAAK,MAAM,OAAO,GAAG;GACtE,QAAQ,OAAA,GAAA,UAAA,UAAA,CAAgB,OAAO,iDAAiD,CAAC;GACjF,QAAQ,MAAM,EAAE;GAChB,QAAQ,MAAM,kBAAkB;GAChC,QAAQ,OAAA,GAAA,UAAA,UAAA,CAAgB,QAAQ,iCAAiC,CAAC;GAClE,QAAQ,OAAA,GAAA,UAAA,UAAA,CAAgB,QAAQ,QAAQ,CAAC;GACzC,QAAQ,OAAA,GAAA,UAAA,UAAA,CAAgB,QAAQ,kCAAkC,CAAC;GACnE,QAAQ,MAAM,EAAE;EAClB;EACA,QAAQ,MAAM,qBAAqB;EACnC,QAAQ,MAAMC,eAAAA,gBAAgB,KAAK,CAAC;EACpC,aAAA,QAAQ,KAAK,CAAC;CAChB;AACF"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import "./chunk-C0LytTxp.js";
|
|
2
2
|
import { n as toCause, r as toError } from "./errors-BsemQCMn.js";
|
|
3
|
-
import { a as
|
|
4
|
-
import { n as
|
|
5
|
-
import { t as version } from "./package-
|
|
3
|
+
import { a as runtime, i as WATCHER_IGNORED_PATHS, n as KUBB_NPM_PACKAGE_URL, o as canUseTTY, t as Telemetry } from "./Telemetry-C66uYyC2.js";
|
|
4
|
+
import { i as linters, n as detectTool, r as formatters } from "./tools-BU99bhi8.js";
|
|
5
|
+
import { t as version } from "./package-BSMI4dNK.js";
|
|
6
6
|
import { styleText } from "node:util";
|
|
7
7
|
import { EventEmitter } from "node:events";
|
|
8
8
|
import { hash } from "node:crypto";
|
|
9
|
-
import { spawn } from "node:child_process";
|
|
10
9
|
import { existsSync } from "node:fs";
|
|
11
10
|
import path, { relative } from "node:path";
|
|
12
11
|
import process$1 from "node:process";
|
|
13
12
|
import * as clack from "@clack/prompts";
|
|
14
13
|
import { Diagnostics, cliReporter, createKubb, logLevel } from "@kubb/core";
|
|
15
|
-
import {
|
|
14
|
+
import { pathToFileURL } from "node:url";
|
|
16
15
|
import { createJiti } from "jiti";
|
|
16
|
+
import { cosmiconfig } from "cosmiconfig";
|
|
17
17
|
import { NonZeroExitError, x } from "tinyexec";
|
|
18
18
|
//#region ../../internals/utils/src/asyncEventEmitter.ts
|
|
19
19
|
/**
|
|
@@ -300,134 +300,6 @@ function formatMsWithColor(ms) {
|
|
|
300
300
|
return styleText("red", formatted);
|
|
301
301
|
}
|
|
302
302
|
//#endregion
|
|
303
|
-
//#region ../../internals/utils/src/formatters.ts
|
|
304
|
-
/**
|
|
305
|
-
* CLI command descriptors for each supported code formatter.
|
|
306
|
-
*
|
|
307
|
-
* Each entry contains the executable `command`, an `args` factory that maps an
|
|
308
|
-
* output path to the correct argument list, and an `errorMessage` shown when
|
|
309
|
-
* the formatter is not found.
|
|
310
|
-
*/
|
|
311
|
-
const formatters = {
|
|
312
|
-
prettier: {
|
|
313
|
-
command: "prettier",
|
|
314
|
-
args: (outputPath) => [
|
|
315
|
-
"--ignore-unknown",
|
|
316
|
-
"--write",
|
|
317
|
-
outputPath
|
|
318
|
-
],
|
|
319
|
-
errorMessage: "Prettier not found"
|
|
320
|
-
},
|
|
321
|
-
biome: {
|
|
322
|
-
command: "biome",
|
|
323
|
-
args: (outputPath) => [
|
|
324
|
-
"format",
|
|
325
|
-
"--write",
|
|
326
|
-
outputPath
|
|
327
|
-
],
|
|
328
|
-
errorMessage: "Biome not found"
|
|
329
|
-
},
|
|
330
|
-
oxfmt: {
|
|
331
|
-
command: "oxfmt",
|
|
332
|
-
args: (outputPath) => [outputPath],
|
|
333
|
-
errorMessage: "Oxfmt not found"
|
|
334
|
-
}
|
|
335
|
-
};
|
|
336
|
-
async function isFormatterAvailable(formatter) {
|
|
337
|
-
return new Promise((resolve) => {
|
|
338
|
-
const child = spawn(formatter, ["--version"], { stdio: "ignore" });
|
|
339
|
-
child.on("close", (code) => resolve(code === 0));
|
|
340
|
-
child.on("error", () => resolve(false));
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Detects the first available code formatter on the current system.
|
|
345
|
-
*
|
|
346
|
-
* - Checks in preference order: `oxfmt`, `biome`, `prettier`.
|
|
347
|
-
* - Returns `null` when none are found.
|
|
348
|
-
*
|
|
349
|
-
* @example
|
|
350
|
-
* ```ts
|
|
351
|
-
* const formatter = await detectFormatter()
|
|
352
|
-
* if (formatter) {
|
|
353
|
-
* console.log(`Using ${formatter} for formatting`)
|
|
354
|
-
* }
|
|
355
|
-
* ```
|
|
356
|
-
*/
|
|
357
|
-
async function detectFormatter() {
|
|
358
|
-
const formatterNames = new Set([
|
|
359
|
-
"oxfmt",
|
|
360
|
-
"biome",
|
|
361
|
-
"prettier"
|
|
362
|
-
]);
|
|
363
|
-
for (const formatter of formatterNames) if (await isFormatterAvailable(formatter)) return formatter;
|
|
364
|
-
return null;
|
|
365
|
-
}
|
|
366
|
-
//#endregion
|
|
367
|
-
//#region ../../internals/utils/src/linters.ts
|
|
368
|
-
/**
|
|
369
|
-
* CLI command descriptors for each supported linter.
|
|
370
|
-
*
|
|
371
|
-
* Each entry contains the executable `command`, an `args` factory that maps an
|
|
372
|
-
* output path to the correct argument list, and an `errorMessage` shown when
|
|
373
|
-
* the linter is not found.
|
|
374
|
-
*/
|
|
375
|
-
const linters = {
|
|
376
|
-
eslint: {
|
|
377
|
-
command: "eslint",
|
|
378
|
-
args: (outputPath) => [outputPath, "--fix"],
|
|
379
|
-
errorMessage: "Eslint not found"
|
|
380
|
-
},
|
|
381
|
-
biome: {
|
|
382
|
-
command: "biome",
|
|
383
|
-
args: (outputPath) => [
|
|
384
|
-
"lint",
|
|
385
|
-
"--fix",
|
|
386
|
-
outputPath
|
|
387
|
-
],
|
|
388
|
-
errorMessage: "Biome not found"
|
|
389
|
-
},
|
|
390
|
-
oxlint: {
|
|
391
|
-
command: "oxlint",
|
|
392
|
-
args: (outputPath) => [
|
|
393
|
-
"--fix",
|
|
394
|
-
"--no-ignore",
|
|
395
|
-
outputPath
|
|
396
|
-
],
|
|
397
|
-
errorMessage: "Oxlint not found"
|
|
398
|
-
}
|
|
399
|
-
};
|
|
400
|
-
async function isLinterAvailable(linter) {
|
|
401
|
-
return new Promise((resolve) => {
|
|
402
|
-
const child = spawn(linter, ["--version"], { stdio: "ignore" });
|
|
403
|
-
child.on("close", (code) => resolve(code === 0));
|
|
404
|
-
child.on("error", () => resolve(false));
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* Detects the first available linter on the current system.
|
|
409
|
-
*
|
|
410
|
-
* - Checks in preference order: `oxlint`, `biome`, `eslint`.
|
|
411
|
-
* - Returns `null` when none are found.
|
|
412
|
-
*
|
|
413
|
-
* @example
|
|
414
|
-
* ```ts
|
|
415
|
-
* const linter = await detectLinter()
|
|
416
|
-
* if (linter) {
|
|
417
|
-
* console.log(`Using ${linter} for linting`)
|
|
418
|
-
* }
|
|
419
|
-
* ```
|
|
420
|
-
*/
|
|
421
|
-
async function detectLinter() {
|
|
422
|
-
const linterNames = new Set([
|
|
423
|
-
"oxlint",
|
|
424
|
-
"biome",
|
|
425
|
-
"eslint"
|
|
426
|
-
]);
|
|
427
|
-
for (const linter of linterNames) if (await isLinterAvailable(linter)) return linter;
|
|
428
|
-
return null;
|
|
429
|
-
}
|
|
430
|
-
//#endregion
|
|
431
303
|
//#region src/loggers/defineLogger.ts
|
|
432
304
|
/**
|
|
433
305
|
* Defines a typed logger. The `install` method subscribes to lifecycle events
|
|
@@ -985,15 +857,53 @@ function selectReporters(reporters, names) {
|
|
|
985
857
|
return selected;
|
|
986
858
|
}
|
|
987
859
|
//#endregion
|
|
988
|
-
//#region
|
|
989
|
-
|
|
860
|
+
//#region ../../internals/shared/src/loader.ts
|
|
861
|
+
/**
|
|
862
|
+
* jiti options for loading Kubb config modules: the automatic JSX runtime pointed at
|
|
863
|
+
* `@kubb/renderer-jsx`, and `moduleCache` off so a re-load re-evaluates the file.
|
|
864
|
+
*/
|
|
865
|
+
const JITI_OPTIONS = {
|
|
990
866
|
jsx: {
|
|
991
867
|
runtime: "automatic",
|
|
992
868
|
importSource: "@kubb/renderer-jsx"
|
|
993
869
|
},
|
|
994
870
|
moduleCache: false
|
|
995
|
-
}
|
|
996
|
-
|
|
871
|
+
};
|
|
872
|
+
/**
|
|
873
|
+
* Creates a runtime-aware loader for Kubb's TypeScript and JavaScript config modules.
|
|
874
|
+
*
|
|
875
|
+
* On Bun and Deno it imports the file natively, skipping jiti's transform step, and falls back to
|
|
876
|
+
* jiti only when the native import throws. On Node it always uses jiti, which transpiles TypeScript
|
|
877
|
+
* and the `@kubb/renderer-jsx` JSX runtime on the fly. The jiti instance is created lazily, so the
|
|
878
|
+
* Bun/Deno happy path never pays for it.
|
|
879
|
+
*
|
|
880
|
+
* @example
|
|
881
|
+
* ```ts
|
|
882
|
+
* const config = await createModuleLoader().load('/abs/kubb.config.ts', { default: true })
|
|
883
|
+
* ```
|
|
884
|
+
*/
|
|
885
|
+
function createModuleLoader() {
|
|
886
|
+
let jiti;
|
|
887
|
+
const getJiti = () => jiti ??= createJiti(import.meta.url, JITI_OPTIONS);
|
|
888
|
+
const viaJiti = (filePath, options) => options?.default ? getJiti().import(filePath, { default: true }) : getJiti().import(filePath);
|
|
889
|
+
const viaNative = async (filePath, options) => {
|
|
890
|
+
const href = pathToFileURL(filePath).href;
|
|
891
|
+
const mod = await (options?.bust != null ? import(`${href}?t=${options.bust}`) : import(href));
|
|
892
|
+
return options?.default ? mod.default ?? mod : mod;
|
|
893
|
+
};
|
|
894
|
+
return { async load(filePath, options) {
|
|
895
|
+
if (runtime.isBun || runtime.isDeno) try {
|
|
896
|
+
return await viaNative(filePath, options);
|
|
897
|
+
} catch {
|
|
898
|
+
return viaJiti(filePath, options);
|
|
899
|
+
}
|
|
900
|
+
return viaJiti(filePath, options);
|
|
901
|
+
} };
|
|
902
|
+
}
|
|
903
|
+
//#endregion
|
|
904
|
+
//#region src/runners/generate/utils.ts
|
|
905
|
+
const loader = createModuleLoader();
|
|
906
|
+
const tsLoader = (configFile) => loader.load(configFile, { default: true });
|
|
997
907
|
const MODULE_NAME = "kubb";
|
|
998
908
|
const BASE_SEARCH_PLACES = [
|
|
999
909
|
"package.json",
|
|
@@ -1042,32 +952,35 @@ async function getCosmiConfig(configFile) {
|
|
|
1042
952
|
* Discovers the Kubb config via cosmiconfig and resolves it into a normalized array of configs.
|
|
1043
953
|
* Every config in the result is guaranteed to have a `plugins` array.
|
|
1044
954
|
*/
|
|
1045
|
-
async function getConfigs({ configPath, input, watch, logLevel
|
|
955
|
+
async function getConfigs({ configPath, input, watch, logLevel }) {
|
|
1046
956
|
const result = await getCosmiConfig(configPath);
|
|
1047
957
|
const cli = {
|
|
1048
958
|
config: configPath,
|
|
1049
959
|
input,
|
|
1050
960
|
watch,
|
|
1051
|
-
logLevel
|
|
1052
|
-
noCache
|
|
961
|
+
logLevel
|
|
1053
962
|
};
|
|
1054
963
|
const resolved = await (typeof result.config === "function" ? result.config(cli) : result.config);
|
|
1055
964
|
const userConfigs = Array.isArray(resolved) ? resolved : [resolved];
|
|
1056
965
|
return {
|
|
1057
966
|
configPath: result.filepath,
|
|
1058
|
-
configs: userConfigs.map((item) => {
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
};
|
|
1063
|
-
return noCache ? {
|
|
1064
|
-
...config,
|
|
1065
|
-
cache: void 0
|
|
1066
|
-
} : config;
|
|
1067
|
-
})
|
|
967
|
+
configs: userConfigs.map((item) => ({
|
|
968
|
+
...item,
|
|
969
|
+
plugins: item.plugins ?? []
|
|
970
|
+
}))
|
|
1068
971
|
};
|
|
1069
972
|
}
|
|
1070
973
|
/**
|
|
974
|
+
* Tokenizes a shell command string, respecting single and double quotes.
|
|
975
|
+
*
|
|
976
|
+
* @example
|
|
977
|
+
* tokenize('git commit -m "initial commit"')
|
|
978
|
+
* // → ['git', 'commit', '-m', 'initial commit']
|
|
979
|
+
*/
|
|
980
|
+
function tokenize(command) {
|
|
981
|
+
return (command.match(/[^\s"']+|"([^"]*)"|'([^']*)'/g) ?? []).map((token) => token.replace(/^["']|["']$/g, ""));
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
1071
984
|
* Runs the `done` hooks defined in a Kubb config in sequence.
|
|
1072
985
|
*/
|
|
1073
986
|
async function executeHooks({ configHooks, hooks }) {
|
|
@@ -1278,7 +1191,11 @@ async function generate(options) {
|
|
|
1278
1191
|
const toolPasses = [config.output.format && {
|
|
1279
1192
|
code: Diagnostics.code.formatFailed,
|
|
1280
1193
|
toolValue: config.output.format,
|
|
1281
|
-
detect:
|
|
1194
|
+
detect: () => detectTool([
|
|
1195
|
+
"oxfmt",
|
|
1196
|
+
"biome",
|
|
1197
|
+
"prettier"
|
|
1198
|
+
]),
|
|
1282
1199
|
toolMap: formatters,
|
|
1283
1200
|
toolLabel: "formatter",
|
|
1284
1201
|
successPrefix: "Formatting",
|
|
@@ -1288,7 +1205,11 @@ async function generate(options) {
|
|
|
1288
1205
|
}, config.output.lint && {
|
|
1289
1206
|
code: Diagnostics.code.lintFailed,
|
|
1290
1207
|
toolValue: config.output.lint,
|
|
1291
|
-
detect:
|
|
1208
|
+
detect: () => detectTool([
|
|
1209
|
+
"oxlint",
|
|
1210
|
+
"biome",
|
|
1211
|
+
"eslint"
|
|
1212
|
+
]),
|
|
1292
1213
|
toolMap: linters,
|
|
1293
1214
|
toolLabel: "linter",
|
|
1294
1215
|
successPrefix: "Linting",
|
|
@@ -1363,22 +1284,20 @@ function outputDiagnostic(code, label, caughtError) {
|
|
|
1363
1284
|
};
|
|
1364
1285
|
}
|
|
1365
1286
|
async function checkForUpdate(hooks) {
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
} catch {}
|
|
1374
|
-
});
|
|
1287
|
+
try {
|
|
1288
|
+
const data = await (await fetch(KUBB_NPM_PACKAGE_URL)).json();
|
|
1289
|
+
if (data.version && version < data.version) await Diagnostics.emit(hooks, Diagnostics.update({
|
|
1290
|
+
currentVersion: version,
|
|
1291
|
+
latestVersion: data.version
|
|
1292
|
+
}));
|
|
1293
|
+
} catch {}
|
|
1375
1294
|
}
|
|
1376
1295
|
/**
|
|
1377
1296
|
* Runs the full Kubb generation lifecycle for the given CLI options.
|
|
1378
1297
|
* Loads configs, sets up the selected reporters (CLI `--reporter` overrides `config.reporters`),
|
|
1379
1298
|
* checks for a newer version, and calls `generate` for each config entry.
|
|
1380
1299
|
*/
|
|
1381
|
-
async function run({ input, configPath, logLevel: logLevelKey, watch, reporters: cliReporters
|
|
1300
|
+
async function run({ input, configPath, logLevel: logLevelKey, watch, reporters: cliReporters }) {
|
|
1382
1301
|
const logLevel$2 = logLevel[logLevelKey] ?? logLevel.info;
|
|
1383
1302
|
const hooks = new AsyncEventEmitter();
|
|
1384
1303
|
let configs;
|
|
@@ -1388,8 +1307,7 @@ async function run({ input, configPath, logLevel: logLevelKey, watch, reporters:
|
|
|
1388
1307
|
configPath,
|
|
1389
1308
|
input,
|
|
1390
1309
|
watch,
|
|
1391
|
-
logLevel: logLevelKey
|
|
1392
|
-
noCache
|
|
1310
|
+
logLevel: logLevelKey
|
|
1393
1311
|
});
|
|
1394
1312
|
configs = loaded.configs;
|
|
1395
1313
|
resolvedConfigPath = loaded.configPath;
|
|
@@ -1452,4 +1370,4 @@ async function run({ input, configPath, logLevel: logLevelKey, watch, reporters:
|
|
|
1452
1370
|
//#endregion
|
|
1453
1371
|
export { run };
|
|
1454
1372
|
|
|
1455
|
-
//# sourceMappingURL=run-
|
|
1373
|
+
//# sourceMappingURL=run-CSYH_DiQ.js.map
|