@kubb/cli 5.0.0-beta.1 → 5.0.0-beta.10
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 +177 -26
- package/dist/agent-Bx2yllmS.js +68 -0
- package/dist/agent-Bx2yllmS.js.map +1 -0
- package/dist/agent-CeLwj5im.cjs +70 -0
- package/dist/agent-CeLwj5im.cjs.map +1 -0
- package/dist/{chunk--u3MIqq1.js → chunk-BvFE5Tac.js} +1 -0
- package/dist/constants-B2JTeRBb.js +42 -0
- package/dist/constants-B2JTeRBb.js.map +1 -0
- package/dist/constants-BINTA5VZ.cjs +77 -0
- package/dist/constants-BINTA5VZ.cjs.map +1 -0
- package/dist/constants-BYGmiFs0.cjs +139 -0
- package/dist/constants-BYGmiFs0.cjs.map +1 -0
- package/dist/constants-DSJ-Xrbv.js +116 -0
- package/dist/constants-DSJ-Xrbv.js.map +1 -0
- package/dist/define-Bdn8j5VM.cjs.map +1 -1
- package/dist/{define-Ctii4bel.js → define-m_fp-Aqm.js} +2 -2
- package/dist/{define-Ctii4bel.js.map → define-m_fp-Aqm.js.map} +1 -1
- package/dist/{errors-CjPmyZHy.js → errors-CINO1EIv.js} +2 -2
- package/dist/{errors-CjPmyZHy.js.map → errors-CINO1EIv.js.map} +1 -1
- package/dist/errors-CLCjoSg0.cjs.map +1 -1
- package/dist/{generate-BaJRhbCS.js → generate-BLvcvoIj.js} +12 -6
- package/dist/generate-BLvcvoIj.js.map +1 -0
- package/dist/{generate-TL8zY_IT.cjs → generate-drLxTAnz.cjs} +10 -4
- package/dist/generate-drLxTAnz.cjs.map +1 -0
- package/dist/index.cjs +20 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +22 -13
- package/dist/index.js.map +1 -1
- package/dist/init-CGu7JZEF.js +53 -0
- package/dist/init-CGu7JZEF.js.map +1 -0
- package/dist/init-CyCjvIEF.cjs +53 -0
- package/dist/init-CyCjvIEF.cjs.map +1 -0
- package/dist/mcp-Cq2sylQC.js +39 -0
- package/dist/mcp-Cq2sylQC.js.map +1 -0
- package/dist/mcp-DSF5gpI-.cjs +39 -0
- package/dist/mcp-DSF5gpI-.cjs.map +1 -0
- package/dist/{package-Cdo6lNjF.cjs → package-DZ-6zAIO.cjs} +2 -2
- package/dist/package-DZ-6zAIO.cjs.map +1 -0
- package/dist/package-OLYIpjqw.js +6 -0
- package/dist/package-OLYIpjqw.js.map +1 -0
- package/dist/{generate-CuxArvEk.js → run-Bfbr3RaM.js} +322 -337
- package/dist/run-Bfbr3RaM.js.map +1 -0
- package/dist/{agent-Ev5hU5hH.js → run-BzpYYOQs.js} +53 -44
- package/dist/run-BzpYYOQs.js.map +1 -0
- package/dist/run-CCZ24VKk.js +51 -0
- package/dist/run-CCZ24VKk.js.map +1 -0
- package/dist/{init-eNRlotJK.js → run-CF97BWVa.js} +102 -147
- package/dist/run-CF97BWVa.js.map +1 -0
- package/dist/run-CQbj3ley.cjs +52 -0
- package/dist/run-CQbj3ley.cjs.map +1 -0
- package/dist/{generate-UCP0qpDp.cjs → run-CVlrIZoW.cjs} +319 -334
- package/dist/run-CVlrIZoW.cjs.map +1 -0
- package/dist/run-D0hmRpHy.js +49 -0
- package/dist/run-D0hmRpHy.js.map +1 -0
- package/dist/{agent-B_pirbeB.cjs → run-DwdAwnLG.cjs} +51 -42
- package/dist/run-DwdAwnLG.cjs.map +1 -0
- package/dist/run-Lr0Ctnu0.cjs +50 -0
- package/dist/run-Lr0Ctnu0.cjs.map +1 -0
- package/dist/{init-CZ5Xq2Hd.cjs → run-YsoCk5we.cjs} +100 -145
- package/dist/run-YsoCk5we.cjs.map +1 -0
- package/dist/shell-475fQKaX.cjs.map +1 -1
- package/dist/{shell-DLzN4fRo.js → shell-CN6DNqeC.js} +2 -2
- package/dist/{shell-DLzN4fRo.js.map → shell-CN6DNqeC.js.map} +1 -1
- package/dist/{telemetry-DN95_2pF.cjs → telemetry-B2iWkY5e.cjs} +5 -7
- package/dist/telemetry-B2iWkY5e.cjs.map +1 -0
- package/dist/{telemetry-LgT_sdPe.js → telemetry-BkektVz6.js} +6 -8
- package/dist/telemetry-BkektVz6.js.map +1 -0
- package/dist/validate-CAUqLaGt.js +26 -0
- package/dist/validate-CAUqLaGt.js.map +1 -0
- package/dist/validate-J6AEd5zK.cjs +26 -0
- package/dist/validate-J6AEd5zK.cjs.map +1 -0
- package/package.json +22 -14
- package/src/commands/agent/start.ts +10 -7
- package/src/commands/agent.ts +3 -1
- package/src/commands/generate.ts +5 -3
- package/src/commands/init.ts +34 -3
- package/src/commands/mcp.ts +28 -4
- package/src/commands/validate.ts +6 -4
- package/src/constants.ts +2 -58
- package/src/index.ts +5 -3
- package/src/loggers/clackLogger.ts +45 -43
- package/src/loggers/fileSystemLogger.ts +26 -13
- package/src/loggers/githubActionsLogger.ts +13 -25
- package/src/loggers/plainLogger.ts +12 -23
- package/src/loggers/types.ts +6 -0
- package/src/loggers/utils.ts +155 -9
- package/src/runners/agent/run.ts +113 -0
- package/src/runners/agent/utils.ts +98 -0
- package/src/runners/generate/run.ts +276 -0
- package/src/runners/generate/utils.ts +209 -0
- package/src/runners/init/run.ts +211 -0
- package/src/{utils/packageManager.ts → runners/init/utils.ts} +10 -0
- package/src/runners/mcp/run.ts +55 -0
- package/src/runners/validate/run.ts +63 -0
- package/src/{utils/telemetry.ts → telemetry.ts} +12 -5
- package/dist/agent-B_pirbeB.cjs.map +0 -1
- package/dist/agent-CUmEyiqY.cjs +0 -58
- package/dist/agent-CUmEyiqY.cjs.map +0 -1
- package/dist/agent-Ev5hU5hH.js.map +0 -1
- package/dist/agent-v_2S-bnN.js +0 -56
- package/dist/agent-v_2S-bnN.js.map +0 -1
- package/dist/constants-CnDXa1R6.cjs +0 -148
- package/dist/constants-CnDXa1R6.cjs.map +0 -1
- package/dist/constants-aL3CP_Wq.js +0 -95
- package/dist/constants-aL3CP_Wq.js.map +0 -1
- package/dist/generate-BaJRhbCS.js.map +0 -1
- package/dist/generate-CuxArvEk.js.map +0 -1
- package/dist/generate-TL8zY_IT.cjs.map +0 -1
- package/dist/generate-UCP0qpDp.cjs.map +0 -1
- package/dist/init-CZ5Xq2Hd.cjs.map +0 -1
- package/dist/init-DRR_YWIq.cjs +0 -25
- package/dist/init-DRR_YWIq.cjs.map +0 -1
- package/dist/init-DSnRd1RJ.js +0 -25
- package/dist/init-DSnRd1RJ.js.map +0 -1
- package/dist/init-eNRlotJK.js.map +0 -1
- package/dist/mcp-CLcDV4Jm.cjs +0 -41
- package/dist/mcp-CLcDV4Jm.cjs.map +0 -1
- package/dist/mcp-D7EIR9fR.js +0 -40
- package/dist/mcp-D7EIR9fR.js.map +0 -1
- package/dist/mcp-Dakxi9CL.js +0 -16
- package/dist/mcp-Dakxi9CL.js.map +0 -1
- package/dist/mcp-Dr_RY-hd.cjs +0 -16
- package/dist/mcp-Dr_RY-hd.cjs.map +0 -1
- package/dist/package-Cdo6lNjF.cjs.map +0 -1
- package/dist/package-DPooAj2l.js +0 -6
- package/dist/package-DPooAj2l.js.map +0 -1
- package/dist/telemetry-DN95_2pF.cjs.map +0 -1
- package/dist/telemetry-LgT_sdPe.js.map +0 -1
- package/dist/validate-B1o-rY9o.js +0 -25
- package/dist/validate-B1o-rY9o.js.map +0 -1
- package/dist/validate-CXFY-mHL.cjs +0 -25
- package/dist/validate-CXFY-mHL.cjs.map +0 -1
- package/dist/validate-kLJoT_hi.js +0 -33
- package/dist/validate-kLJoT_hi.js.map +0 -1
- package/dist/validate-yKKzqEZ5.cjs +0 -34
- package/dist/validate-yKKzqEZ5.cjs.map +0 -1
- package/src/runners/agent.ts +0 -149
- package/src/runners/generate.ts +0 -333
- package/src/runners/init.ts +0 -296
- package/src/runners/mcp.ts +0 -45
- package/src/runners/validate.ts +0 -39
- package/src/types.ts +0 -11
- package/src/utils/Writables.ts +0 -17
- package/src/utils/executeHooks.ts +0 -45
- package/src/utils/flags.ts +0 -9
- package/src/utils/getConfig.ts +0 -10
- package/src/utils/getCosmiConfig.ts +0 -80
- package/src/utils/getSummary.ts +0 -68
- package/src/utils/runHook.ts +0 -91
- package/src/utils/watcher.ts +0 -19
package/package.json
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/cli",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "5.0.0-beta.10",
|
|
4
|
+
"description": "Official CLI for Kubb. Run kubb generate, kubb init, kubb validate, kubb mcp, and kubb agent to manage the full code generation lifecycle from OpenAPI/Swagger specs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
7
7
|
"code-generator",
|
|
8
8
|
"codegen",
|
|
9
|
-
"command-line",
|
|
10
|
-
"command-line-tool",
|
|
11
9
|
"kubb",
|
|
12
|
-
"oas",
|
|
13
10
|
"openapi",
|
|
14
|
-
"plugins",
|
|
15
11
|
"sdk-generator",
|
|
16
12
|
"swagger",
|
|
17
|
-
"terminal",
|
|
18
13
|
"typescript"
|
|
19
14
|
],
|
|
20
15
|
"license": "MIT",
|
|
@@ -55,17 +50,30 @@
|
|
|
55
50
|
"@clack/prompts": "^1.3.0",
|
|
56
51
|
"chokidar": "^5.0.0",
|
|
57
52
|
"cosmiconfig": "^9.0.1",
|
|
53
|
+
"jiti": "^2.7.0",
|
|
58
54
|
"tinyexec": "^1.1.2",
|
|
59
|
-
"
|
|
60
|
-
"@kubb/adapter-oas": "5.0.0-beta.1",
|
|
61
|
-
"@kubb/core": "5.0.0-beta.1"
|
|
55
|
+
"@kubb/core": "5.0.0-beta.10"
|
|
62
56
|
},
|
|
63
57
|
"devDependencies": {
|
|
64
|
-
"@internals/
|
|
58
|
+
"@internals/shared": "0.0.0",
|
|
59
|
+
"@internals/utils": "0.0.0",
|
|
60
|
+
"@kubb/adapter-oas": "5.0.0-beta.10"
|
|
65
61
|
},
|
|
66
|
-
"
|
|
67
|
-
"@kubb/
|
|
68
|
-
"@kubb/
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"@kubb/adapter-oas": "5.0.0-beta.10",
|
|
64
|
+
"@kubb/agent": "5.0.0-beta.10",
|
|
65
|
+
"@kubb/mcp": "5.0.0-beta.10"
|
|
66
|
+
},
|
|
67
|
+
"peerDependenciesMeta": {
|
|
68
|
+
"@kubb/adapter-oas": {
|
|
69
|
+
"optional": true
|
|
70
|
+
},
|
|
71
|
+
"@kubb/agent": {
|
|
72
|
+
"optional": true
|
|
73
|
+
},
|
|
74
|
+
"@kubb/mcp": {
|
|
75
|
+
"optional": true
|
|
76
|
+
}
|
|
69
77
|
},
|
|
70
78
|
"size-limit": [
|
|
71
79
|
{
|
|
@@ -4,26 +4,29 @@ import { agentDefaults } from '../../constants.ts'
|
|
|
4
4
|
|
|
5
5
|
export const command = defineCommand({
|
|
6
6
|
name: 'start',
|
|
7
|
-
description:
|
|
7
|
+
description:
|
|
8
|
+
'Start the Kubb Agent HTTP server. Exposes a REST API that accepts a kubb.config.ts patch and returns generated code as a stream. Use --allow-write to also write files to disk.',
|
|
9
|
+
examples: ['kubb agent start', 'kubb agent start --port 4000', 'kubb agent start --allow-write', 'kubb agent start --config ./kubb.config.ts --allow-all'],
|
|
8
10
|
options: {
|
|
9
11
|
config: {
|
|
10
12
|
type: 'string',
|
|
11
|
-
description: 'Path to the Kubb config',
|
|
13
|
+
description: 'Path to the Kubb config file',
|
|
12
14
|
short: 'c',
|
|
13
15
|
},
|
|
14
16
|
port: {
|
|
15
17
|
type: 'string',
|
|
16
|
-
description:
|
|
18
|
+
description: 'Port the HTTP server listens on',
|
|
17
19
|
short: 'p',
|
|
20
|
+
default: agentDefaults.port,
|
|
18
21
|
},
|
|
19
22
|
host: {
|
|
20
23
|
type: 'string',
|
|
21
|
-
description: '
|
|
24
|
+
description: 'Hostname the HTTP server binds to',
|
|
22
25
|
default: agentDefaults.host,
|
|
23
26
|
},
|
|
24
27
|
'allow-write': {
|
|
25
28
|
type: 'boolean',
|
|
26
|
-
description: '
|
|
29
|
+
description: 'Write generated files to the filesystem. When omitted, output is streamed only and no files are written.',
|
|
27
30
|
default: false,
|
|
28
31
|
},
|
|
29
32
|
'allow-all': {
|
|
@@ -33,9 +36,9 @@ export const command = defineCommand({
|
|
|
33
36
|
},
|
|
34
37
|
},
|
|
35
38
|
async run({ values }) {
|
|
36
|
-
const {
|
|
39
|
+
const { run } = await import('../../runners/agent/run.ts')
|
|
37
40
|
|
|
38
|
-
await
|
|
41
|
+
await run({
|
|
39
42
|
port: values.port !== undefined ? values.port : undefined,
|
|
40
43
|
host: values.host,
|
|
41
44
|
configPath: values.config,
|
package/src/commands/agent.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { command as startCommand } from './agent/start.ts'
|
|
|
3
3
|
|
|
4
4
|
export const command = defineCommand({
|
|
5
5
|
name: 'agent',
|
|
6
|
-
description:
|
|
6
|
+
description:
|
|
7
|
+
'Manage the Kubb Agent — an HTTP server that lets AI agents trigger code generation programmatically via a REST API. Useful when an AI workflow needs to generate code without direct CLI access.',
|
|
8
|
+
examples: ['kubb agent start', 'kubb agent start --port 4000 --allow-write', 'kubb agent start --config ./kubb.config.ts --allow-all'],
|
|
7
9
|
subCommands: [startCommand],
|
|
8
10
|
})
|
package/src/commands/generate.ts
CHANGED
|
@@ -2,8 +2,10 @@ import { defineCommand } from '@internals/utils'
|
|
|
2
2
|
|
|
3
3
|
export const command = defineCommand({
|
|
4
4
|
name: 'generate',
|
|
5
|
-
description:
|
|
5
|
+
description:
|
|
6
|
+
'Generate TypeScript types, API clients, React Query hooks, Zod schemas, and more from an OpenAPI specification. Reads kubb.config.ts by default. Pass an OpenAPI file path as the first argument to override the input without editing the config.',
|
|
6
7
|
arguments: ['[input]'],
|
|
8
|
+
examples: ['kubb generate', 'kubb generate ./openapi.yaml', 'kubb generate --config kubb.config.ts', 'kubb generate --watch'],
|
|
7
9
|
options: {
|
|
8
10
|
config: {
|
|
9
11
|
type: 'string',
|
|
@@ -45,9 +47,9 @@ export const command = defineCommand({
|
|
|
45
47
|
},
|
|
46
48
|
async run({ values, positionals }) {
|
|
47
49
|
const logLevel = values.debug ? 'debug' : values.verbose ? 'verbose' : values.silent ? 'silent' : values.logLevel
|
|
48
|
-
const {
|
|
50
|
+
const { run } = await import('../runners/generate/run.ts')
|
|
49
51
|
|
|
50
|
-
await
|
|
52
|
+
await run({
|
|
51
53
|
input: positionals[0],
|
|
52
54
|
configPath: values.config,
|
|
53
55
|
logLevel,
|
package/src/commands/init.ts
CHANGED
|
@@ -3,7 +3,14 @@ import { version } from '../../package.json'
|
|
|
3
3
|
|
|
4
4
|
export const command = defineCommand({
|
|
5
5
|
name: 'init',
|
|
6
|
-
description:
|
|
6
|
+
description:
|
|
7
|
+
'Scaffold a kubb.config.ts and install plugins for code generation from an OpenAPI spec. Run without flags for interactive setup, or pass --input, --output, and --plugins to skip the prompts.',
|
|
8
|
+
examples: [
|
|
9
|
+
'kubb init',
|
|
10
|
+
'kubb init --yes',
|
|
11
|
+
'kubb init --input ./openapi.yaml --output ./src/gen --plugins plugin-ts,plugin-zod',
|
|
12
|
+
'kubb init --plugins plugin-ts,plugin-client,plugin-react-query',
|
|
13
|
+
],
|
|
7
14
|
options: {
|
|
8
15
|
yes: {
|
|
9
16
|
type: 'boolean',
|
|
@@ -11,10 +18,34 @@ export const command = defineCommand({
|
|
|
11
18
|
short: 'y',
|
|
12
19
|
default: false,
|
|
13
20
|
},
|
|
21
|
+
input: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
description: 'Path to the OpenAPI specification',
|
|
24
|
+
short: 'i',
|
|
25
|
+
hint: 'path',
|
|
26
|
+
},
|
|
27
|
+
output: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
description: 'Output directory for generated files',
|
|
30
|
+
short: 'o',
|
|
31
|
+
hint: 'path',
|
|
32
|
+
},
|
|
33
|
+
plugins: {
|
|
34
|
+
type: 'string',
|
|
35
|
+
description:
|
|
36
|
+
'Comma-separated list of plugins to use (plugin-ts, plugin-client, plugin-react-query, plugin-vue-query, plugin-zod, plugin-faker, plugin-msw, plugin-cypress, plugin-mcp, plugin-redoc)',
|
|
37
|
+
hint: 'plugin-ts,plugin-zod,...',
|
|
38
|
+
},
|
|
14
39
|
},
|
|
15
40
|
async run({ values }) {
|
|
16
|
-
const {
|
|
41
|
+
const { run } = await import('../runners/init/run.ts')
|
|
17
42
|
|
|
18
|
-
await
|
|
43
|
+
await run({
|
|
44
|
+
yes: values.yes,
|
|
45
|
+
version,
|
|
46
|
+
input: values.input,
|
|
47
|
+
output: values.output,
|
|
48
|
+
plugins: values.plugins,
|
|
49
|
+
})
|
|
19
50
|
},
|
|
20
51
|
})
|
package/src/commands/mcp.ts
CHANGED
|
@@ -3,10 +3,34 @@ import { version } from '../../package.json'
|
|
|
3
3
|
|
|
4
4
|
export const command = defineCommand({
|
|
5
5
|
name: 'mcp',
|
|
6
|
-
description:
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
description:
|
|
7
|
+
'Start a Model Context Protocol (MCP) server that exposes Kubb code generation as tools for AI assistants. Once running, configure your AI client (Claude, Cursor, Windsurf, etc.) to connect to it — the assistant can then call kubb generate directly without leaving the chat.',
|
|
8
|
+
examples: [
|
|
9
|
+
'kubb mcp',
|
|
10
|
+
'kubb mcp --port 3001',
|
|
11
|
+
'# Then add to your MCP client config:',
|
|
12
|
+
'# { "mcpServers": { "kubb": { "command": "npx", "args": ["kubb", "mcp"] } } }',
|
|
13
|
+
],
|
|
14
|
+
options: {
|
|
15
|
+
port: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
short: 'p',
|
|
18
|
+
description: 'Port for HTTP MCP server (omit for stdio)',
|
|
19
|
+
hint: 'number',
|
|
20
|
+
},
|
|
21
|
+
host: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
description: 'Hostname to bind to (HTTP mode only)',
|
|
24
|
+
default: 'localhost',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
async run({ values }) {
|
|
28
|
+
const { run } = await import('../runners/mcp/run.ts')
|
|
9
29
|
|
|
10
|
-
await
|
|
30
|
+
await run({
|
|
31
|
+
version,
|
|
32
|
+
port: values.port,
|
|
33
|
+
host: values.host,
|
|
34
|
+
})
|
|
11
35
|
},
|
|
12
36
|
})
|
package/src/commands/validate.ts
CHANGED
|
@@ -3,18 +3,20 @@ import { version } from '../../package.json'
|
|
|
3
3
|
|
|
4
4
|
export const command = defineCommand({
|
|
5
5
|
name: 'validate',
|
|
6
|
-
description:
|
|
6
|
+
description:
|
|
7
|
+
'Parse and validate an OpenAPI/Swagger file for structural correctness. Reports schema errors, missing required fields, and malformed references. Use this before running generate to catch spec issues early.',
|
|
8
|
+
examples: ['kubb validate --input ./openapi.yaml', 'kubb validate --input https://petstore3.swagger.io/api/v3/openapi.json'],
|
|
7
9
|
options: {
|
|
8
10
|
input: {
|
|
9
11
|
type: 'string',
|
|
10
|
-
description: 'Path to Swagger
|
|
12
|
+
description: 'Path or URL to the OpenAPI/Swagger file to validate',
|
|
11
13
|
short: 'i',
|
|
12
14
|
required: true,
|
|
13
15
|
},
|
|
14
16
|
},
|
|
15
17
|
async run({ values }) {
|
|
16
|
-
const {
|
|
18
|
+
const { run } = await import('../runners/validate/run.ts')
|
|
17
19
|
|
|
18
|
-
await
|
|
20
|
+
await run({ input: values.input, version })
|
|
19
21
|
},
|
|
20
22
|
})
|
package/src/constants.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Default filename for the Kubb configuration file.
|
|
3
|
-
*
|
|
4
|
-
* Used by the `init` command when scaffolding new projects and by the `agent` default config.
|
|
5
|
-
*/
|
|
6
|
-
export const KUBB_CONFIG_FILENAME = 'kubb.config.ts' as const
|
|
1
|
+
import { KUBB_CONFIG_FILENAME } from '@internals/shared'
|
|
7
2
|
|
|
8
3
|
/**
|
|
9
4
|
* NPM registry endpoint used to check for @kubb/cli updates.
|
|
@@ -45,60 +40,9 @@ export const agentDefaults = {
|
|
|
45
40
|
host: 'localhost',
|
|
46
41
|
configFile: KUBB_CONFIG_FILENAME,
|
|
47
42
|
retryTimeout: '30000',
|
|
48
|
-
studioUrl: 'https://
|
|
43
|
+
studioUrl: 'https://kubb.studio',
|
|
49
44
|
/**
|
|
50
45
|
* Relative path from the @kubb/agent package root to the server entry.
|
|
51
46
|
*/
|
|
52
47
|
serverEntryPath: '.output/server/index.mjs',
|
|
53
48
|
} as const
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Default values used during interactive `init` scaffolding.
|
|
57
|
-
*/
|
|
58
|
-
export const initDefaults = {
|
|
59
|
-
inputPath: './openapi.yaml',
|
|
60
|
-
outputPath: './src/gen',
|
|
61
|
-
plugins: ['plugin-ts'],
|
|
62
|
-
} as const
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Maps each plugin value to the default config snippet inserted by `init`.
|
|
66
|
-
* The `satisfies` constraint ensures all values remain plain strings while
|
|
67
|
-
* `as const` keeps the object deeply immutable.
|
|
68
|
-
*/
|
|
69
|
-
export const pluginDefaultConfigs = {
|
|
70
|
-
'plugin-ts': `pluginTs({
|
|
71
|
-
output: { path: 'models' },
|
|
72
|
-
})`,
|
|
73
|
-
'plugin-client': `pluginClient({
|
|
74
|
-
output: { path: 'clients' },
|
|
75
|
-
})`,
|
|
76
|
-
'plugin-react-query': `pluginReactQuery({
|
|
77
|
-
output: { path: 'hooks' },
|
|
78
|
-
})`,
|
|
79
|
-
'plugin-vue-query': `pluginVueQuery({
|
|
80
|
-
output: { path: 'hooks' },
|
|
81
|
-
})`,
|
|
82
|
-
'plugin-zod': `pluginZod({
|
|
83
|
-
output: { path: 'zod' },
|
|
84
|
-
})`,
|
|
85
|
-
'plugin-faker': `pluginFaker({
|
|
86
|
-
output: { path: 'mocks' },
|
|
87
|
-
})`,
|
|
88
|
-
'plugin-msw': `pluginMsw({
|
|
89
|
-
output: { path: 'msw' },
|
|
90
|
-
})`,
|
|
91
|
-
'plugin-cypress': `pluginCypress({
|
|
92
|
-
output: { path: 'cypress' },
|
|
93
|
-
})`,
|
|
94
|
-
'plugin-mcp': `pluginMcp({
|
|
95
|
-
output: { path: 'mcp' },
|
|
96
|
-
})`,
|
|
97
|
-
'plugin-redoc': `pluginRedoc({
|
|
98
|
-
output: { path: 'redoc' },
|
|
99
|
-
})`,
|
|
100
|
-
} as const satisfies Record<string, string>
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Color palette used by randomCliColor() for deterministic plugin name coloring.
|
|
104
|
-
*/
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { styleText } from 'node:util'
|
|
2
|
-
import { createCLI } from '@internals/utils'
|
|
2
|
+
import { createCLI, isFlag } from '@internals/utils'
|
|
3
3
|
import { version } from '../package.json'
|
|
4
4
|
import { QUIET_FLAGS } from './constants.ts'
|
|
5
|
-
import {
|
|
6
|
-
import { isTelemetryDisabled } from './utils/telemetry.ts'
|
|
5
|
+
import { isTelemetryDisabled } from './telemetry.ts'
|
|
7
6
|
|
|
8
7
|
const cli = createCLI()
|
|
9
8
|
|
|
@@ -11,14 +10,17 @@ function shouldShowTelemetryNotice(argv: Array<string>): boolean {
|
|
|
11
10
|
if (isTelemetryDisabled()) {
|
|
12
11
|
return false
|
|
13
12
|
}
|
|
13
|
+
|
|
14
14
|
// Skip when the user is just asking for help or version info
|
|
15
15
|
if (argv.some((arg) => isFlag(QUIET_FLAGS, arg))) {
|
|
16
16
|
return false
|
|
17
17
|
}
|
|
18
|
+
|
|
18
19
|
// Skip in non-interactive / scripting contexts
|
|
19
20
|
if (!process.stdout.isTTY) {
|
|
20
21
|
return false
|
|
21
22
|
}
|
|
23
|
+
|
|
22
24
|
return true
|
|
23
25
|
}
|
|
24
26
|
|
|
@@ -4,10 +4,27 @@ import { styleText } from 'node:util'
|
|
|
4
4
|
import * as clack from '@clack/prompts'
|
|
5
5
|
import { formatMs, formatMsWithColor, getIntro, toCause } from '@internals/utils'
|
|
6
6
|
import { defineLogger, logLevel as logLevelMap } from '@kubb/core'
|
|
7
|
-
import { getSummary } from '
|
|
8
|
-
import { runHook } from '../utils/runHook.ts'
|
|
9
|
-
import { ClackWritable } from '../utils/Writables.ts'
|
|
7
|
+
import { getSummary } from './utils.ts'
|
|
10
8
|
import { buildProgressLine, formatCommandWithArgs, formatMessage } from './utils.ts'
|
|
9
|
+
import { Writable } from 'node:stream'
|
|
10
|
+
import type { WritableOptions } from 'node:stream'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Node.js `Writable` stream that forwards each chunk to a clack `taskLog` message.
|
|
14
|
+
* Used to pipe hook subprocess output into the clack task log UI.
|
|
15
|
+
*/
|
|
16
|
+
class ClackWritable extends Writable {
|
|
17
|
+
taskLog: ReturnType<typeof clack.taskLog>
|
|
18
|
+
constructor(taskLog: ReturnType<typeof clack.taskLog>, opts?: WritableOptions) {
|
|
19
|
+
super(opts)
|
|
20
|
+
|
|
21
|
+
this.taskLog = taskLog
|
|
22
|
+
}
|
|
23
|
+
_write(chunk: Buffer, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {
|
|
24
|
+
this.taskLog.message(`${styleText('dim', chunk.toString())}`)
|
|
25
|
+
callback()
|
|
26
|
+
}
|
|
27
|
+
}
|
|
11
28
|
|
|
12
29
|
/**
|
|
13
30
|
* TTY logger with beautiful UI and progress indicators for local development.
|
|
@@ -364,51 +381,15 @@ Run \`npm install -g @kubb/cli\` to update`,
|
|
|
364
381
|
clack.outro(text)
|
|
365
382
|
})
|
|
366
383
|
|
|
367
|
-
context.on('kubb:hook:start',
|
|
368
|
-
const commandWithArgs = formatCommandWithArgs(command, args)
|
|
369
|
-
const text = getMessage(`Hook ${styleText('dim', commandWithArgs)} started`)
|
|
370
|
-
|
|
371
|
-
// Skip hook execution if no id is provided (e.g., during benchmarks or tests)
|
|
372
|
-
if (!id) {
|
|
373
|
-
return
|
|
374
|
-
}
|
|
375
|
-
|
|
384
|
+
context.on('kubb:hook:start', ({ command, args }) => {
|
|
376
385
|
if (logLevel <= logLevelMap.silent) {
|
|
377
|
-
await runHook({
|
|
378
|
-
id,
|
|
379
|
-
command,
|
|
380
|
-
args,
|
|
381
|
-
commandWithArgs,
|
|
382
|
-
context,
|
|
383
|
-
sink: {
|
|
384
|
-
onStderr: (s) => console.error(s),
|
|
385
|
-
onStdout: (s) => console.log(s),
|
|
386
|
-
},
|
|
387
|
-
})
|
|
388
386
|
return
|
|
389
387
|
}
|
|
390
388
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
const logger = clack.taskLog({
|
|
394
|
-
title: getMessage(['Executing hook', logLevel >= logLevelMap.info ? styleText('dim', commandWithArgs) : undefined].filter(Boolean).join(' ')),
|
|
395
|
-
})
|
|
396
|
-
|
|
397
|
-
const writable = new ClackWritable(logger)
|
|
389
|
+
const commandWithArgs = formatCommandWithArgs(command, args)
|
|
390
|
+
const text = getMessage(`Hook ${styleText('dim', commandWithArgs)} started`)
|
|
398
391
|
|
|
399
|
-
|
|
400
|
-
id,
|
|
401
|
-
command,
|
|
402
|
-
args,
|
|
403
|
-
commandWithArgs,
|
|
404
|
-
context,
|
|
405
|
-
stream: true,
|
|
406
|
-
sink: {
|
|
407
|
-
onLine: (line) => writable.write(line),
|
|
408
|
-
onStderr: (s) => logger.error(s),
|
|
409
|
-
onStdout: (s) => logger.message(s),
|
|
410
|
-
},
|
|
411
|
-
})
|
|
392
|
+
clack.intro(text)
|
|
412
393
|
})
|
|
413
394
|
|
|
414
395
|
context.on('kubb:hook:end', ({ command, args }) => {
|
|
@@ -454,5 +435,26 @@ Run \`npm install -g @kubb/cli\` to update`,
|
|
|
454
435
|
context.on('kubb:lifecycle:end', () => {
|
|
455
436
|
reset()
|
|
456
437
|
})
|
|
438
|
+
|
|
439
|
+
return (commandWithArgs: string) => {
|
|
440
|
+
if (logLevel <= logLevelMap.silent) {
|
|
441
|
+
return {
|
|
442
|
+
onStdout: (s: string) => console.log(s),
|
|
443
|
+
onStderr: (s: string) => console.error(s),
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const logger = clack.taskLog({
|
|
448
|
+
title: getMessage(['Executing hook', logLevel >= logLevelMap.info ? styleText('dim', commandWithArgs) : undefined].filter(Boolean).join(' ')),
|
|
449
|
+
})
|
|
450
|
+
const writable = new ClackWritable(logger)
|
|
451
|
+
|
|
452
|
+
return {
|
|
453
|
+
stream: true,
|
|
454
|
+
onLine: (line: string) => writable.write(line),
|
|
455
|
+
onStdout: (s: string) => logger.message(s),
|
|
456
|
+
onStderr: (s: string) => logger.error(s),
|
|
457
|
+
}
|
|
458
|
+
}
|
|
457
459
|
},
|
|
458
460
|
})
|
|
@@ -4,14 +4,24 @@ import { formatMs, write } from '@internals/utils'
|
|
|
4
4
|
import { defineLogger } from '@kubb/core'
|
|
5
5
|
|
|
6
6
|
type CachedEvent = {
|
|
7
|
+
/**
|
|
8
|
+
* Timestamp when this event was captured, used to derive the log filename.
|
|
9
|
+
*/
|
|
7
10
|
date: Date
|
|
11
|
+
/**
|
|
12
|
+
* Accumulated log lines for this event.
|
|
13
|
+
*/
|
|
8
14
|
logs: string[]
|
|
15
|
+
/**
|
|
16
|
+
* Optional override for the output filename inside `.kubb/`. When omitted, the filename is derived from `date`.
|
|
17
|
+
*/
|
|
9
18
|
fileName?: string
|
|
10
19
|
}
|
|
11
20
|
|
|
12
21
|
/**
|
|
13
22
|
* FileSystem logger that captures debug events and writes them to `.kubb` directory files.
|
|
14
|
-
*
|
|
23
|
+
*
|
|
24
|
+
* @note Logs are written on `kubb:lifecycle:end` or process exit. Cached logs may be lost if the process crashes before either event.
|
|
15
25
|
*/
|
|
16
26
|
export const fileSystemLogger = defineLogger({
|
|
17
27
|
name: 'filesystem',
|
|
@@ -42,13 +52,15 @@ export const fileSystemLogger = defineLogger({
|
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
if (log.logs.length > 0) {
|
|
45
|
-
const
|
|
46
|
-
|
|
55
|
+
const prefix = `[${log.date.toLocaleString()}] `
|
|
56
|
+
const indent = ' '.repeat(prefix.length)
|
|
57
|
+
const [first, ...rest] = log.logs
|
|
58
|
+
files[pathName].push([prefix + first, ...rest.map((line) => indent + line)].join('\n'))
|
|
47
59
|
}
|
|
48
60
|
}
|
|
49
61
|
|
|
50
62
|
for (const [fileName, logs] of Object.entries(files)) {
|
|
51
|
-
await write(fileName, logs.join('\n
|
|
63
|
+
await write(fileName, logs.join('\n'))
|
|
52
64
|
}
|
|
53
65
|
|
|
54
66
|
return Object.keys(files)
|
|
@@ -57,21 +69,21 @@ export const fileSystemLogger = defineLogger({
|
|
|
57
69
|
context.on('kubb:info', ({ message, info }) => {
|
|
58
70
|
state.cachedLogs.add({
|
|
59
71
|
date: new Date(),
|
|
60
|
-
logs: [`ℹ ${message
|
|
72
|
+
logs: [`ℹ ${[message, info].filter(Boolean).join(' ')}`],
|
|
61
73
|
})
|
|
62
74
|
})
|
|
63
75
|
|
|
64
76
|
context.on('kubb:success', ({ message, info }) => {
|
|
65
77
|
state.cachedLogs.add({
|
|
66
78
|
date: new Date(),
|
|
67
|
-
logs: [`✓ ${message
|
|
79
|
+
logs: [`✓ ${[message, info].filter(Boolean).join(' ')}`],
|
|
68
80
|
})
|
|
69
81
|
})
|
|
70
82
|
|
|
71
83
|
context.on('kubb:warn', ({ message, info }) => {
|
|
72
84
|
state.cachedLogs.add({
|
|
73
85
|
date: new Date(),
|
|
74
|
-
logs: [`⚠ ${message
|
|
86
|
+
logs: [`⚠ ${[message, info].filter(Boolean).join(' ')}`],
|
|
75
87
|
})
|
|
76
88
|
})
|
|
77
89
|
|
|
@@ -82,17 +94,18 @@ export const fileSystemLogger = defineLogger({
|
|
|
82
94
|
})
|
|
83
95
|
})
|
|
84
96
|
|
|
85
|
-
context.on('kubb:debug', (
|
|
97
|
+
context.on('kubb:debug', ({ date, fileName, logs }) => {
|
|
86
98
|
state.cachedLogs.add({
|
|
87
|
-
date
|
|
88
|
-
|
|
99
|
+
date,
|
|
100
|
+
fileName,
|
|
101
|
+
logs,
|
|
89
102
|
})
|
|
90
103
|
})
|
|
91
104
|
|
|
92
105
|
context.on('kubb:plugin:start', ({ plugin }) => {
|
|
93
106
|
state.cachedLogs.add({
|
|
94
107
|
date: new Date(),
|
|
95
|
-
logs: [
|
|
108
|
+
logs: [`► Generating ${plugin.name}`],
|
|
96
109
|
})
|
|
97
110
|
})
|
|
98
111
|
|
|
@@ -101,14 +114,14 @@ export const fileSystemLogger = defineLogger({
|
|
|
101
114
|
|
|
102
115
|
state.cachedLogs.add({
|
|
103
116
|
date: new Date(),
|
|
104
|
-
logs: [success ?
|
|
117
|
+
logs: [success ? `✓ ${plugin.name} completed in ${durationStr}` : `✗ ${plugin.name} failed in ${durationStr}`],
|
|
105
118
|
})
|
|
106
119
|
})
|
|
107
120
|
|
|
108
121
|
context.on('kubb:files:processing:start', ({ files }) => {
|
|
109
122
|
state.cachedLogs.add({
|
|
110
123
|
date: new Date(),
|
|
111
|
-
logs: [
|
|
124
|
+
logs: [`► Writing ${files.length} files`, ...files.map((file) => ` ${file.path}`)],
|
|
112
125
|
})
|
|
113
126
|
})
|
|
114
127
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { styleText } from 'node:util'
|
|
2
2
|
import { formatHrtime, formatMs, formatMsWithColor, toCause } from '@internals/utils'
|
|
3
3
|
import { type Config, defineLogger, logLevel as logLevelMap } from '@kubb/core'
|
|
4
|
-
import { runHook } from '../utils/runHook.ts'
|
|
5
4
|
import { buildProgressLine, formatCommandWithArgs, formatMessage } from './utils.ts'
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -307,34 +306,18 @@ export const githubActionsLogger = defineLogger({
|
|
|
307
306
|
}
|
|
308
307
|
})
|
|
309
308
|
|
|
310
|
-
context.on('kubb:hook:start',
|
|
309
|
+
context.on('kubb:hook:start', ({ command, args }) => {
|
|
310
|
+
if (logLevel <= logLevelMap.silent) {
|
|
311
|
+
return
|
|
312
|
+
}
|
|
313
|
+
|
|
311
314
|
const commandWithArgs = formatCommandWithArgs(command, args)
|
|
312
315
|
const text = getMessage(`Hook ${styleText('dim', commandWithArgs)} started`)
|
|
313
316
|
|
|
314
|
-
if (
|
|
315
|
-
|
|
316
|
-
openGroup(`Hook ${commandWithArgs}`)
|
|
317
|
-
}
|
|
318
|
-
console.log(text)
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// Skip hook execution if no id is provided (e.g., during benchmarks or tests)
|
|
322
|
-
if (!id) {
|
|
323
|
-
return
|
|
317
|
+
if (state.currentConfigs.length === 1) {
|
|
318
|
+
openGroup(`Hook ${commandWithArgs}`)
|
|
324
319
|
}
|
|
325
|
-
|
|
326
|
-
await runHook({
|
|
327
|
-
id,
|
|
328
|
-
command,
|
|
329
|
-
args,
|
|
330
|
-
commandWithArgs,
|
|
331
|
-
context,
|
|
332
|
-
sink: {
|
|
333
|
-
// GHA formats errors with the ::error:: annotation
|
|
334
|
-
onStdout: logLevel > logLevelMap.silent ? (s) => console.log(s) : undefined,
|
|
335
|
-
onStderr: logLevel > logLevelMap.silent ? (s) => console.error(`::error::${s}`) : undefined,
|
|
336
|
-
},
|
|
337
|
-
})
|
|
320
|
+
console.log(text)
|
|
338
321
|
})
|
|
339
322
|
|
|
340
323
|
context.on('kubb:hook:end', ({ command, args }) => {
|
|
@@ -375,5 +358,10 @@ export const githubActionsLogger = defineLogger({
|
|
|
375
358
|
context.on('kubb:lifecycle:end', () => {
|
|
376
359
|
reset()
|
|
377
360
|
})
|
|
361
|
+
|
|
362
|
+
return (_commandWithArgs: string) => ({
|
|
363
|
+
onStdout: logLevel > logLevelMap.silent ? (s: string) => console.log(s) : undefined,
|
|
364
|
+
onStderr: logLevel > logLevelMap.silent ? (s: string) => console.error(`::error::${s}`) : undefined,
|
|
365
|
+
})
|
|
378
366
|
},
|
|
379
367
|
})
|