@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/src/runners/agent.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import net from 'node:net'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import * as process from 'node:process'
|
|
4
|
-
import { fileURLToPath } from 'node:url'
|
|
5
|
-
import { styleText } from 'node:util'
|
|
6
|
-
import * as clack from '@clack/prompts'
|
|
7
|
-
import { spawnAsync } from '@internals/utils'
|
|
8
|
-
import { agentDefaults } from '../constants.ts'
|
|
9
|
-
import { buildTelemetryEvent, sendTelemetry } from '../utils/telemetry.ts'
|
|
10
|
-
|
|
11
|
-
type AgentStartOptions = {
|
|
12
|
-
port: string | undefined
|
|
13
|
-
host: string
|
|
14
|
-
configPath: string | undefined
|
|
15
|
-
allowWrite: boolean
|
|
16
|
-
allowAll: boolean
|
|
17
|
-
version: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
type ResolvedAgentStartEnvironment = {
|
|
21
|
-
port: string
|
|
22
|
-
host: string
|
|
23
|
-
allowWrite: boolean
|
|
24
|
-
allowAll: boolean
|
|
25
|
-
agentConfigPath: string
|
|
26
|
-
env: NodeJS.ProcessEnv
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Resolves the environment passed to the detached agent process using CLI values first, then environment values, then CLI defaults.
|
|
31
|
-
*/
|
|
32
|
-
function resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }: Omit<AgentStartOptions, 'version'>): ResolvedAgentStartEnvironment {
|
|
33
|
-
const resolvedPort = port ?? process.env.PORT ?? agentDefaults.port
|
|
34
|
-
const resolvedHost = host !== agentDefaults.host ? host : (process.env.HOST ?? agentDefaults.host)
|
|
35
|
-
const resolvedAllowAll = allowAll || process.env.KUBB_AGENT_ALLOW_ALL === 'true'
|
|
36
|
-
const resolvedAllowWrite = resolvedAllowAll || allowWrite || process.env.KUBB_AGENT_ALLOW_WRITE === 'true'
|
|
37
|
-
const agentRoot = process.env.KUBB_AGENT_ROOT ?? process.cwd()
|
|
38
|
-
const agentConfigPath = path.resolve(process.cwd(), configPath || process.env.KUBB_AGENT_CONFIG || agentDefaults.configFile)
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
port: resolvedPort,
|
|
42
|
-
host: resolvedHost,
|
|
43
|
-
allowWrite: resolvedAllowWrite,
|
|
44
|
-
allowAll: resolvedAllowAll,
|
|
45
|
-
agentConfigPath,
|
|
46
|
-
env: {
|
|
47
|
-
...process.env,
|
|
48
|
-
PORT: resolvedPort,
|
|
49
|
-
HOST: resolvedHost,
|
|
50
|
-
KUBB_AGENT_ROOT: agentRoot,
|
|
51
|
-
KUBB_AGENT_CONFIG: agentConfigPath,
|
|
52
|
-
KUBB_AGENT_ALLOW_WRITE: String(resolvedAllowWrite),
|
|
53
|
-
KUBB_AGENT_ALLOW_ALL: String(resolvedAllowAll),
|
|
54
|
-
KUBB_AGENT_TOKEN: process.env.KUBB_AGENT_TOKEN,
|
|
55
|
-
KUBB_AGENT_RETRY_TIMEOUT: process.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout,
|
|
56
|
-
KUBB_STUDIO_URL: process.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl,
|
|
57
|
-
},
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function isPortAvailable(port: number, host: string): Promise<boolean> {
|
|
62
|
-
return new Promise((resolve) => {
|
|
63
|
-
const server = net.createServer()
|
|
64
|
-
server.once('error', () => resolve(false))
|
|
65
|
-
server.once('listening', () => {
|
|
66
|
-
server.close()
|
|
67
|
-
resolve(true)
|
|
68
|
-
})
|
|
69
|
-
server.listen(port, host)
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export async function runAgentStart({ port, host, configPath, allowWrite, allowAll, version }: AgentStartOptions): Promise<void> {
|
|
74
|
-
const hrStart = process.hrtime()
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
// Load .env file into process.env using Node.js built-in (v20.12.0+)
|
|
78
|
-
try {
|
|
79
|
-
process.loadEnvFile()
|
|
80
|
-
} catch {
|
|
81
|
-
// .env file may not exist; ignore
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Resolve the @kubb/agent package path
|
|
85
|
-
let agentPkgUrl: string
|
|
86
|
-
try {
|
|
87
|
-
agentPkgUrl = import.meta.resolve('@kubb/agent/package.json')
|
|
88
|
-
} catch (_e) {
|
|
89
|
-
console.error(`Import of '@kubb/agent' is required to start the Agent server`)
|
|
90
|
-
process.exit(1)
|
|
91
|
-
}
|
|
92
|
-
const agentPkgPath = fileURLToPath(agentPkgUrl)
|
|
93
|
-
const agentDir = path.dirname(agentPkgPath)
|
|
94
|
-
const serverPath = path.join(agentDir, agentDefaults.serverEntryPath)
|
|
95
|
-
|
|
96
|
-
const resolvedEnv = resolveAgentStartEnvironment({
|
|
97
|
-
port,
|
|
98
|
-
host,
|
|
99
|
-
configPath,
|
|
100
|
-
allowWrite,
|
|
101
|
-
allowAll,
|
|
102
|
-
})
|
|
103
|
-
const numericPort = Number(resolvedEnv.port)
|
|
104
|
-
|
|
105
|
-
if (!Number.isInteger(numericPort) || numericPort <= 0) {
|
|
106
|
-
throw new Error(`Invalid port "${resolvedEnv.port}". Provide a positive integer with --port or PORT.`)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
clack.log.step(styleText('cyan', 'Starting agent server...'))
|
|
110
|
-
clack.log.info(styleText('dim', `Config: ${resolvedEnv.agentConfigPath}`))
|
|
111
|
-
clack.log.info(styleText('dim', `Host: ${resolvedEnv.host}`))
|
|
112
|
-
clack.log.info(styleText('dim', `Port: ${resolvedEnv.port}`))
|
|
113
|
-
if (!resolvedEnv.allowWrite && !resolvedEnv.allowAll) {
|
|
114
|
-
clack.log.warn(styleText('yellow', 'Filesystem writes disabled. Use --allow-write or --allow-all to enable.'))
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (!(await isPortAvailable(numericPort, resolvedEnv.host))) {
|
|
118
|
-
clack.log.error(styleText('red', `Port ${resolvedEnv.port} is already in use. Stop the existing process or choose a different port with --port.`))
|
|
119
|
-
process.exit(1)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Spawns the server as a detached background process so the CLI can exit independently.
|
|
123
|
-
await spawnAsync('node', [serverPath], {
|
|
124
|
-
env: resolvedEnv.env,
|
|
125
|
-
cwd: process.cwd(),
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
await sendTelemetry(
|
|
129
|
-
buildTelemetryEvent({
|
|
130
|
-
command: 'agent',
|
|
131
|
-
kubbVersion: version,
|
|
132
|
-
hrStart,
|
|
133
|
-
status: 'success',
|
|
134
|
-
}),
|
|
135
|
-
)
|
|
136
|
-
} catch (error) {
|
|
137
|
-
await sendTelemetry(
|
|
138
|
-
buildTelemetryEvent({
|
|
139
|
-
command: 'agent',
|
|
140
|
-
kubbVersion: version,
|
|
141
|
-
hrStart,
|
|
142
|
-
status: 'failed',
|
|
143
|
-
}),
|
|
144
|
-
)
|
|
145
|
-
clack.log.error(styleText('red', 'Failed to start agent server'))
|
|
146
|
-
console.error(error)
|
|
147
|
-
process.exit(1)
|
|
148
|
-
}
|
|
149
|
-
}
|
package/src/runners/generate.ts
DELETED
|
@@ -1,333 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import process from 'node:process'
|
|
4
|
-
import { styleText } from 'node:util'
|
|
5
|
-
import * as clack from '@clack/prompts'
|
|
6
|
-
import type { AsyncEventEmitter } from '@internals/utils'
|
|
7
|
-
import { AsyncEventEmitter as AsyncEventEmitterClass, detectFormatter, detectLinter, executeIfOnline, formatters, linters, toError } from '@internals/utils'
|
|
8
|
-
import { type CLIOptions, type Config, createKubb, isInputPath, type KubbHooks, logLevel as logLevelMap } from '@kubb/core'
|
|
9
|
-
import { version } from '../../package.json'
|
|
10
|
-
import { KUBB_NPM_PACKAGE_URL } from '../constants.ts'
|
|
11
|
-
import { setupLogger } from '../loggers/utils.ts'
|
|
12
|
-
import { executeHooks } from '../utils/executeHooks.ts'
|
|
13
|
-
import { getConfigs } from '../utils/getConfig.ts'
|
|
14
|
-
import { getCosmiConfig } from '../utils/getCosmiConfig.ts'
|
|
15
|
-
import { buildTelemetryEvent, sendTelemetry } from '../utils/telemetry.ts'
|
|
16
|
-
import { startWatcher } from '../utils/watcher.ts'
|
|
17
|
-
|
|
18
|
-
type GenerateProps = {
|
|
19
|
-
input?: string
|
|
20
|
-
config: Config
|
|
21
|
-
hooks: AsyncEventEmitter<KubbHooks>
|
|
22
|
-
logLevel: number
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
type ToolMap = typeof formatters | typeof linters
|
|
26
|
-
|
|
27
|
-
type RunToolPassOptions = {
|
|
28
|
-
toolValue: string
|
|
29
|
-
detect: () => Promise<string | null>
|
|
30
|
-
toolMap: ToolMap
|
|
31
|
-
/** Short noun used in "Auto-detected <toolLabel>:" message, e.g. "formatter" or "linter". */
|
|
32
|
-
toolLabel: string
|
|
33
|
-
/** Verb prefix for the success message, e.g. "Formatting" or "Linting". */
|
|
34
|
-
successPrefix: string
|
|
35
|
-
noToolMessage: string
|
|
36
|
-
configName: string | undefined
|
|
37
|
-
outputPath: string
|
|
38
|
-
logLevel: number
|
|
39
|
-
hooks: AsyncEventEmitter<KubbHooks>
|
|
40
|
-
onStart: () => Promise<void>
|
|
41
|
-
onEnd: () => Promise<void>
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function runToolPass({
|
|
45
|
-
toolValue,
|
|
46
|
-
detect,
|
|
47
|
-
toolMap,
|
|
48
|
-
toolLabel,
|
|
49
|
-
successPrefix,
|
|
50
|
-
noToolMessage,
|
|
51
|
-
configName,
|
|
52
|
-
outputPath,
|
|
53
|
-
logLevel,
|
|
54
|
-
hooks,
|
|
55
|
-
onStart,
|
|
56
|
-
onEnd,
|
|
57
|
-
}: RunToolPassOptions) {
|
|
58
|
-
await onStart()
|
|
59
|
-
|
|
60
|
-
let resolvedTool = toolValue
|
|
61
|
-
if (resolvedTool === 'auto') {
|
|
62
|
-
const detected = await detect()
|
|
63
|
-
if (!detected) {
|
|
64
|
-
await hooks.emit('kubb:warn', { message: noToolMessage })
|
|
65
|
-
} else {
|
|
66
|
-
resolvedTool = detected
|
|
67
|
-
await hooks.emit('kubb:info', { message: `Auto-detected ${toolLabel}: ${styleText('dim', resolvedTool)}` })
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
let toolError: Error | undefined
|
|
72
|
-
|
|
73
|
-
if (resolvedTool && resolvedTool !== 'auto' && resolvedTool in toolMap) {
|
|
74
|
-
const toolConfig = toolMap[resolvedTool as keyof ToolMap]
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
const hookId = createHash('sha256').update([configName, resolvedTool].filter(Boolean).join('-')).digest('hex')
|
|
78
|
-
|
|
79
|
-
// Wire up the hook:end listener BEFORE emitting hook:start to avoid the race condition
|
|
80
|
-
// where hook:end fires synchronously inside emit('kubb:hook:start') before the listener is registered.
|
|
81
|
-
const hookEndPromise = new Promise<void>((resolve, reject) => {
|
|
82
|
-
const handler = (ctx: { id?: string; command: string; args?: readonly string[]; success: boolean; error: Error | null }) => {
|
|
83
|
-
if (ctx.id !== hookId) return
|
|
84
|
-
hooks.off('kubb:hook:end', handler)
|
|
85
|
-
if (!ctx.success) {
|
|
86
|
-
reject(ctx.error ?? new Error(`${toolConfig.errorMessage}`))
|
|
87
|
-
return
|
|
88
|
-
}
|
|
89
|
-
hooks
|
|
90
|
-
.emit('kubb:success', {
|
|
91
|
-
message: [
|
|
92
|
-
`${successPrefix} with ${styleText('dim', resolvedTool)}`,
|
|
93
|
-
logLevel >= logLevelMap.info ? `on ${styleText('dim', outputPath)}` : undefined,
|
|
94
|
-
'successfully',
|
|
95
|
-
]
|
|
96
|
-
.filter(Boolean)
|
|
97
|
-
.join(' '),
|
|
98
|
-
})
|
|
99
|
-
.then(resolve)
|
|
100
|
-
.catch(reject)
|
|
101
|
-
}
|
|
102
|
-
hooks.on('kubb:hook:end', handler)
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
await hooks.emit('kubb:hook:start', {
|
|
106
|
-
id: hookId,
|
|
107
|
-
command: toolConfig.command,
|
|
108
|
-
args: toolConfig.args(outputPath),
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
await hookEndPromise
|
|
112
|
-
} catch (caughtError) {
|
|
113
|
-
// Use the actual error from the hook. toolConfig.errorMessage (e.g. "Oxlint not found")
|
|
114
|
-
// is misleading when the binary was found and ran but exited with a non-zero code.
|
|
115
|
-
// runHook already emitted kubb:error for binary-not-found cases; here we surface the
|
|
116
|
-
// real reason (e.g. "Hook execute failed: oxlint --fix …") for non-zero exits.
|
|
117
|
-
const err = toError(caughtError)
|
|
118
|
-
await hooks.emit('kubb:error', { error: err })
|
|
119
|
-
toolError = err
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
await onEnd()
|
|
124
|
-
|
|
125
|
-
if (toolError) {
|
|
126
|
-
throw toolError
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
async function generate(options: GenerateProps): Promise<void> {
|
|
131
|
-
const { input, hooks, logLevel } = options
|
|
132
|
-
|
|
133
|
-
const hrStart = process.hrtime()
|
|
134
|
-
const inputPath = input ?? ('path' in options.config.input ? options.config.input.path : undefined)
|
|
135
|
-
|
|
136
|
-
const config: Config = {
|
|
137
|
-
...options.config,
|
|
138
|
-
input: inputPath
|
|
139
|
-
? {
|
|
140
|
-
...options.config.input,
|
|
141
|
-
path: inputPath,
|
|
142
|
-
}
|
|
143
|
-
: options.config.input,
|
|
144
|
-
...options.config.output,
|
|
145
|
-
} satisfies Config
|
|
146
|
-
|
|
147
|
-
const kubb = createKubb(config, { hooks })
|
|
148
|
-
await kubb.setup()
|
|
149
|
-
|
|
150
|
-
await hooks.emit('kubb:generation:start', { config })
|
|
151
|
-
|
|
152
|
-
await hooks.emit('kubb:info', { message: config.name ? `Setup generation ${styleText('bold', config.name)}` : 'Setup generation', info: inputPath })
|
|
153
|
-
|
|
154
|
-
await hooks.emit('kubb:info', { message: config.name ? `Build generation ${styleText('bold', config.name)}` : 'Build generation', info: inputPath })
|
|
155
|
-
|
|
156
|
-
const { files, failedPlugins, pluginTimings, error, driver } = await kubb.safeBuild()
|
|
157
|
-
|
|
158
|
-
await hooks.emit('kubb:info', { message: 'Load summary' })
|
|
159
|
-
|
|
160
|
-
// Handle build failures (either from failed plugins or general errors)
|
|
161
|
-
|
|
162
|
-
const hasFailures = failedPlugins.size > 0 || error
|
|
163
|
-
if (hasFailures) {
|
|
164
|
-
// Collect all errors from failed plugins and general error
|
|
165
|
-
const allErrors: Error[] = [
|
|
166
|
-
error,
|
|
167
|
-
...Array.from(failedPlugins)
|
|
168
|
-
.filter((it) => it.error)
|
|
169
|
-
.map((it) => it.error),
|
|
170
|
-
].filter(Boolean)
|
|
171
|
-
|
|
172
|
-
for (const err of allErrors) {
|
|
173
|
-
await hooks.emit('kubb:error', { error: err })
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
await hooks.emit('kubb:generation:end', { config, files, sources: kubb.sources })
|
|
177
|
-
|
|
178
|
-
await hooks.emit('kubb:generation:summary', {
|
|
179
|
-
config,
|
|
180
|
-
failedPlugins,
|
|
181
|
-
filesCreated: files.length,
|
|
182
|
-
status: 'failed',
|
|
183
|
-
hrStart,
|
|
184
|
-
pluginTimings: logLevel >= logLevelMap.verbose ? pluginTimings : undefined,
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
await sendTelemetry(
|
|
188
|
-
buildTelemetryEvent({
|
|
189
|
-
command: 'generate',
|
|
190
|
-
kubbVersion: version,
|
|
191
|
-
plugins: Array.from(driver.plugins.values(), (p) => ({
|
|
192
|
-
name: p.name,
|
|
193
|
-
options: p.options as Record<string, unknown>,
|
|
194
|
-
})),
|
|
195
|
-
hrStart,
|
|
196
|
-
filesCreated: files.length,
|
|
197
|
-
status: 'failed',
|
|
198
|
-
}),
|
|
199
|
-
)
|
|
200
|
-
|
|
201
|
-
process.exit(1)
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
await hooks.emit('kubb:success', { message: 'Generation successfully', info: inputPath })
|
|
205
|
-
await hooks.emit('kubb:generation:end', { config, files, sources: kubb.sources })
|
|
206
|
-
|
|
207
|
-
const outputPath = path.resolve(config.root, config.output.path)
|
|
208
|
-
|
|
209
|
-
if (config.output.format) {
|
|
210
|
-
await runToolPass({
|
|
211
|
-
toolValue: config.output.format,
|
|
212
|
-
detect: detectFormatter,
|
|
213
|
-
toolMap: formatters,
|
|
214
|
-
toolLabel: 'formatter',
|
|
215
|
-
successPrefix: 'Formatting',
|
|
216
|
-
noToolMessage: 'No formatter found (oxfmt, biome, or prettier). Skipping formatting.',
|
|
217
|
-
configName: config.name,
|
|
218
|
-
outputPath,
|
|
219
|
-
logLevel,
|
|
220
|
-
hooks,
|
|
221
|
-
onStart: () => hooks.emit('kubb:format:start'),
|
|
222
|
-
onEnd: () => hooks.emit('kubb:format:end'),
|
|
223
|
-
})
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (config.output.lint) {
|
|
227
|
-
await runToolPass({
|
|
228
|
-
toolValue: config.output.lint,
|
|
229
|
-
detect: detectLinter,
|
|
230
|
-
toolMap: linters,
|
|
231
|
-
toolLabel: 'linter',
|
|
232
|
-
successPrefix: 'Linting',
|
|
233
|
-
noToolMessage: 'No linter found (oxlint, biome, or eslint). Skipping linting.',
|
|
234
|
-
configName: config.name,
|
|
235
|
-
outputPath,
|
|
236
|
-
logLevel,
|
|
237
|
-
hooks,
|
|
238
|
-
onStart: () => hooks.emit('kubb:lint:start'),
|
|
239
|
-
onEnd: () => hooks.emit('kubb:lint:end'),
|
|
240
|
-
})
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (config.hooks) {
|
|
244
|
-
await hooks.emit('kubb:hooks:start')
|
|
245
|
-
await executeHooks({ configHooks: config.hooks, hooks })
|
|
246
|
-
|
|
247
|
-
await hooks.emit('kubb:hooks:end')
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// Only reached when there are no failures (process.exit(1) is called above otherwise)
|
|
251
|
-
await hooks.emit('kubb:generation:summary', {
|
|
252
|
-
config,
|
|
253
|
-
failedPlugins,
|
|
254
|
-
filesCreated: files.length,
|
|
255
|
-
status: 'success',
|
|
256
|
-
hrStart,
|
|
257
|
-
pluginTimings,
|
|
258
|
-
})
|
|
259
|
-
|
|
260
|
-
const telemetryEvent = buildTelemetryEvent({
|
|
261
|
-
command: 'generate',
|
|
262
|
-
kubbVersion: version,
|
|
263
|
-
plugins: Array.from(driver.plugins.values(), (p) => ({
|
|
264
|
-
name: p.name,
|
|
265
|
-
options: p.options as Record<string, unknown>,
|
|
266
|
-
})),
|
|
267
|
-
hrStart,
|
|
268
|
-
filesCreated: files.length,
|
|
269
|
-
status: 'success',
|
|
270
|
-
})
|
|
271
|
-
|
|
272
|
-
await sendTelemetry(telemetryEvent)
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
type GenerateCommandOptions = {
|
|
276
|
-
input?: string
|
|
277
|
-
configPath?: string
|
|
278
|
-
logLevel: string
|
|
279
|
-
watch: boolean
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export async function runGenerateCommand({ input, configPath, logLevel: logLevelKey, watch }: GenerateCommandOptions): Promise<void> {
|
|
283
|
-
const logLevel = logLevelMap[logLevelKey as keyof typeof logLevelMap] ?? logLevelMap.info
|
|
284
|
-
const hooks = new AsyncEventEmitterClass<KubbHooks>()
|
|
285
|
-
|
|
286
|
-
await setupLogger(hooks, { logLevel })
|
|
287
|
-
|
|
288
|
-
await executeIfOnline(async () => {
|
|
289
|
-
try {
|
|
290
|
-
const res = await fetch(KUBB_NPM_PACKAGE_URL)
|
|
291
|
-
const data = (await res.json()) as { version: string }
|
|
292
|
-
const latestVersion = data.version
|
|
293
|
-
|
|
294
|
-
if (latestVersion && version < latestVersion) {
|
|
295
|
-
await hooks.emit('kubb:version:new', { currentVersion: version, latestVersion })
|
|
296
|
-
}
|
|
297
|
-
} catch {
|
|
298
|
-
// Ignore network errors for version check
|
|
299
|
-
}
|
|
300
|
-
})
|
|
301
|
-
|
|
302
|
-
try {
|
|
303
|
-
const result = await getCosmiConfig('kubb', configPath)
|
|
304
|
-
const configs = await getConfigs(result.config, { input } as CLIOptions)
|
|
305
|
-
|
|
306
|
-
await hooks.emit('kubb:config:start')
|
|
307
|
-
await hooks.emit('kubb:info', { message: 'Config loaded', info: path.relative(process.cwd(), result.filepath) })
|
|
308
|
-
await hooks.emit('kubb:success', { message: 'Config loaded successfully', info: path.relative(process.cwd(), result.filepath) })
|
|
309
|
-
await hooks.emit('kubb:config:end', { configs })
|
|
310
|
-
|
|
311
|
-
await hooks.emit('kubb:lifecycle:start', { version })
|
|
312
|
-
|
|
313
|
-
for (const config of configs) {
|
|
314
|
-
if (isInputPath(config) && watch) {
|
|
315
|
-
await startWatcher([input || config.input.path], async (paths) => {
|
|
316
|
-
// remove to avoid duplicate listeners after each change
|
|
317
|
-
hooks.removeAll()
|
|
318
|
-
|
|
319
|
-
await generate({ input, config, logLevel, hooks })
|
|
320
|
-
|
|
321
|
-
clack.log.step(styleText('yellow', `Watching for changes in ${paths.join(' and ')}`))
|
|
322
|
-
})
|
|
323
|
-
} else {
|
|
324
|
-
await generate({ input, config, logLevel, hooks })
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
await hooks.emit('kubb:lifecycle:end')
|
|
329
|
-
} catch (error) {
|
|
330
|
-
await hooks.emit('kubb:error', { error: toError(error) })
|
|
331
|
-
process.exit(1)
|
|
332
|
-
}
|
|
333
|
-
}
|