@kubb/cli 4.22.0 → 4.22.2

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.
Files changed (47) hide show
  1. package/dist/{generate-Bjj-OR20.js → generate-CBsaUUvV.js} +49 -674
  2. package/dist/generate-CBsaUUvV.js.map +1 -0
  3. package/dist/{generate-BJyvkuLI.cjs → generate-CLDVb4hB.cjs} +53 -678
  4. package/dist/generate-CLDVb4hB.cjs.map +1 -0
  5. package/dist/getCosmiConfig-Co29x0Wv.cjs +458 -0
  6. package/dist/getCosmiConfig-Co29x0Wv.cjs.map +1 -0
  7. package/dist/getCosmiConfig-y2n_oW_y.js +438 -0
  8. package/dist/getCosmiConfig-y2n_oW_y.js.map +1 -0
  9. package/dist/index.cjs +9 -7
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.js +9 -7
  12. package/dist/index.js.map +1 -1
  13. package/dist/{init-CxLDdq2k.cjs → init-Bs1GxKWV.cjs} +3 -3
  14. package/dist/{init-CxLDdq2k.cjs.map → init-Bs1GxKWV.cjs.map} +1 -1
  15. package/dist/{init-D37jPiGV.js → init-D3zCeqU-.js} +3 -3
  16. package/dist/{init-D37jPiGV.js.map → init-D3zCeqU-.js.map} +1 -1
  17. package/dist/{mcp-By2JUPa8.js → mcp-BdwwUv36.js} +1 -1
  18. package/dist/{mcp-By2JUPa8.js.map → mcp-BdwwUv36.js.map} +1 -1
  19. package/dist/{mcp-l-_Z-WU6.cjs → mcp-Hy_PYnFp.cjs} +1 -1
  20. package/dist/{mcp-l-_Z-WU6.cjs.map → mcp-Hy_PYnFp.cjs.map} +1 -1
  21. package/dist/package-BFidNEkS.js +6 -0
  22. package/dist/package-BFidNEkS.js.map +1 -0
  23. package/dist/{package-Cnl_fuIC.cjs → package-CiB5tqr0.cjs} +2 -2
  24. package/dist/package-CiB5tqr0.cjs.map +1 -0
  25. package/dist/start-BeoZd1fL.cjs +128 -0
  26. package/dist/start-BeoZd1fL.cjs.map +1 -0
  27. package/dist/start-Ohz4V8k2.js +125 -0
  28. package/dist/start-Ohz4V8k2.js.map +1 -0
  29. package/dist/{validate-DkHCd-Tl.cjs → validate-Cvb5aOEb.cjs} +1 -1
  30. package/dist/{validate-DkHCd-Tl.cjs.map → validate-Cvb5aOEb.cjs.map} +1 -1
  31. package/dist/{validate-0Qu8SxVA.js → validate-YI4YkVTl.js} +1 -1
  32. package/dist/{validate-0Qu8SxVA.js.map → validate-YI4YkVTl.js.map} +1 -1
  33. package/package.json +4 -4
  34. package/src/commands/generate.ts +0 -38
  35. package/src/commands/init.ts +3 -1
  36. package/src/commands/start.ts +149 -0
  37. package/src/index.ts +2 -1
  38. package/src/loggers/clackLogger.ts +32 -12
  39. package/src/loggers/githubActionsLogger.ts +21 -8
  40. package/src/loggers/plainLogger.ts +20 -8
  41. package/dist/generate-BJyvkuLI.cjs.map +0 -1
  42. package/dist/generate-Bjj-OR20.js.map +0 -1
  43. package/dist/package-Cnl_fuIC.cjs.map +0 -1
  44. package/dist/package-Qh9BQXK6.js +0 -6
  45. package/dist/package-Qh9BQXK6.js.map +0 -1
  46. package/src/loggers/streamLogger.ts +0 -93
  47. package/src/utils/streamServer.ts +0 -163
@@ -1 +0,0 @@
1
- {"version":3,"file":"package-Cnl_fuIC.cjs","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
@@ -1,6 +0,0 @@
1
- //#region package.json
2
- var version = "4.22.0";
3
-
4
- //#endregion
5
- export { version as t };
6
- //# sourceMappingURL=package-Qh9BQXK6.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"package-Qh9BQXK6.js","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
@@ -1,93 +0,0 @@
1
- import type { ServerResponse } from 'node:http'
2
- import { relative } from 'node:path'
3
- import type { StreamEvents, StreamEventType } from '@kubb/core'
4
- import { defineLogger, LogLevel } from '@kubb/core'
5
-
6
- type StreamLoggerState = {
7
- res: ServerResponse
8
- }
9
-
10
- /**
11
- * Stream logger for SSE (Server-Sent Events) streaming
12
- * Sends Kubb events to HTTP client via SSE protocol
13
- */
14
- export function createStreamLogger(res: ServerResponse) {
15
- return defineLogger({
16
- name: 'stream',
17
- install(context, options) {
18
- const logLevel = options?.logLevel || LogLevel.info
19
- const state: StreamLoggerState = { res }
20
-
21
- // Helper to send SSE events
22
- function send<T extends StreamEventType>(type: T, ...data: StreamEvents[T]) {
23
- if (!state.res.destroyed) {
24
- state.res.write(`data: ${JSON.stringify({ type, data })}\n\n`)
25
- }
26
- }
27
-
28
- // Plugin events
29
- context.on('plugin:start', (plugin) => {
30
- send('plugin:start', { name: plugin.name })
31
- })
32
-
33
- context.on('plugin:end', (plugin, { duration, success }) => {
34
- send('plugin:end', { name: plugin.name }, { duration, success })
35
- })
36
-
37
- // File processing events
38
- context.on('files:processing:start', (files) => {
39
- send('files:processing:start', { total: files.length })
40
- })
41
-
42
- context.on('file:processing:update', ({ file, processed, total, percentage, config }) => {
43
- send('file:processing:update', {
44
- file: file.path ? relative(config.root, file.path) : file.baseName || 'unknown',
45
- processed,
46
- total,
47
- percentage,
48
- })
49
- })
50
-
51
- context.on('files:processing:end', (files) => {
52
- send('files:processing:end', { total: files.length })
53
- })
54
-
55
- // Info/Success events
56
- context.on('info', (message, info) => {
57
- if (logLevel <= LogLevel.silent) return
58
- send('info', message, info)
59
- })
60
-
61
- context.on('success', (message, info) => {
62
- if (logLevel <= LogLevel.silent) return
63
- send('success', message, info)
64
- })
65
-
66
- // Warning events
67
- context.on('warn', (message, info) => {
68
- if (logLevel < LogLevel.warn) return
69
- send('warn', message, info)
70
- })
71
-
72
- // Error events
73
- context.on('error', (error) => {
74
- send('error', {
75
- message: error.message,
76
- stack: logLevel >= LogLevel.debug ? error.stack : undefined,
77
- })
78
- })
79
-
80
- // Generation lifecycle
81
- context.on('generation:start', (config) => {
82
- send('generation:start', {
83
- name: config.name,
84
- plugins: config.plugins?.length || 0,
85
- })
86
- })
87
-
88
- context.on('generation:end', (config, files, sources) => {
89
- send('generation:end', config, files, Object.fromEntries(sources))
90
- })
91
- },
92
- })
93
- }
@@ -1,163 +0,0 @@
1
- import { readFileSync } from 'node:fs'
2
- import type { IncomingMessage, ServerResponse } from 'node:http'
3
- import { createServer } from 'node:http'
4
- import path from 'node:path'
5
- import process from 'node:process'
6
- import * as clack from '@clack/prompts'
7
- import type { Config, ConnectResponse, HealthResponse, KubbEvents, StreamEvent, StreamEvents, StreamEventType } from '@kubb/core'
8
- import { LogLevel } from '@kubb/core'
9
- import { AsyncEventEmitter, serializePluginOptions } from '@kubb/core/utils'
10
- import pc from 'picocolors'
11
- import { version } from '../../package.json'
12
- import type { Args } from '../commands/generate.ts'
13
- import { createStreamLogger } from '../loggers/streamLogger.ts'
14
- import { generate } from '../runners/generate.ts'
15
-
16
- type StartStreamServerOptions = {
17
- port: number
18
- host: string
19
- configPath: string
20
- config: Config
21
- input?: string
22
- args: Args
23
- }
24
-
25
- export async function startStreamServer({ port, host, configPath, config, input, args }: StartStreamServerOptions): Promise<void> {
26
- const server = createServer(async (req: IncomingMessage, res: ServerResponse) => {
27
- // CORS headers
28
- res.setHeader('Access-Control-Allow-Origin', '*')
29
- res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
30
- res.setHeader('Access-Control-Allow-Headers', 'Content-Type')
31
-
32
- if (req.method === 'OPTIONS') {
33
- res.writeHead(204)
34
- res.end()
35
- return
36
- }
37
-
38
- // Health check endpoint
39
- if (req.url === '/api/health' && req.method === 'GET') {
40
- res.writeHead(200, { 'Content-Type': 'application/json' })
41
- const body: HealthResponse = { status: 'ok', version, configPath: path.relative(process.cwd(), configPath) }
42
- res.end(JSON.stringify(body))
43
-
44
- return
45
- }
46
-
47
- // Connect endpoint - returns config metadata and OpenAPI spec
48
- if (req.url === '/api/info' && req.method === 'GET') {
49
- res.writeHead(200, { 'Content-Type': 'application/json' })
50
-
51
- // Read OpenAPI spec if available
52
- let specContent: string | undefined
53
- if (config && 'path' in config.input) {
54
- const specPath = path.resolve(process.cwd(), config.root, config.input.path)
55
- try {
56
- specContent = readFileSync(specPath, 'utf-8')
57
- } catch {
58
- // Spec file not found or unreadable
59
- }
60
- }
61
-
62
- const body: ConnectResponse = {
63
- version,
64
- configPath: path.relative(process.cwd(), configPath),
65
- spec: specContent,
66
- config: {
67
- name: config.name,
68
- root: config.root,
69
- input: {
70
- path: 'path' in config.input ? config.input.path : undefined,
71
- },
72
- output: {
73
- path: config.output.path,
74
- write: config.output.write,
75
- extension: config.output.extension,
76
- barrelType: config.output.barrelType,
77
- },
78
- plugins: config.plugins?.map((plugin) => ({
79
- name: `@kubb/${plugin.name}`,
80
- options: serializePluginOptions(plugin.options),
81
- })),
82
- },
83
- }
84
-
85
- res.end(JSON.stringify(body))
86
- return
87
- }
88
-
89
- // Stream endpoint
90
- if (req.url === '/api/stream' && req.method === 'POST') {
91
- await handleGenerate(res, config, input, args)
92
- return
93
- }
94
-
95
- // 404 for other routes
96
- res.writeHead(404, { 'Content-Type': 'application/json' })
97
- res.end(JSON.stringify({ error: 'Not found' }))
98
- })
99
-
100
- server.listen(port, host, () => {
101
- const address = server.address()
102
- const actualPort = typeof address === 'object' && address ? address.port : port
103
- const serverUrl = `http://${host}:${actualPort}`
104
- clack.log.success(pc.green(`Stream server started on ${pc.bold(serverUrl)}`))
105
- clack.log.info(pc.dim(`Config: ${path.relative(process.cwd(), configPath)}`))
106
- clack.log.info(pc.dim(`Connect: ${serverUrl}/api/info`))
107
- clack.log.info(pc.dim(`Stream: ${serverUrl}/api/stream`))
108
- clack.log.info(pc.dim(`Health: ${serverUrl}/api/health`))
109
- clack.log.step(pc.yellow('Waiting for requests... (Press Ctrl+C to stop)'))
110
- })
111
-
112
- // Graceful shutdown
113
- process.on('SIGINT', () => {
114
- clack.log.info('Shutting down stream server...')
115
- server.close(() => {
116
- clack.log.success('Server stopped')
117
- process.exit(0)
118
- })
119
- })
120
- }
121
-
122
- async function handleGenerate(res: ServerResponse, config: Config, input: string | undefined, args: Args): Promise<void> {
123
- // Create isolated event emitter for this request
124
- const events = new AsyncEventEmitter<KubbEvents>()
125
- const logLevel = LogLevel[args.logLevel as keyof typeof LogLevel] || 3
126
-
127
- // Set SSE headers
128
- res.writeHead(200, {
129
- 'Content-Type': 'text/event-stream',
130
- 'Cache-Control': 'no-cache',
131
- Connection: 'keep-alive',
132
- })
133
-
134
- // Helper to send SSE events
135
- function send<T extends StreamEventType>(type: T, ...data: StreamEvents[T]) {
136
- //todo add date here: timestamp: number
137
- const streamEvent: StreamEvent = { type, data }
138
-
139
- res.write(`data: ${JSON.stringify(streamEvent)}\n\n`)
140
- }
141
-
142
- // Install stream logger
143
- const streamLogger = createStreamLogger(res)
144
- await streamLogger.install(events, { logLevel })
145
-
146
- try {
147
- await generate({
148
- input,
149
- config,
150
- logLevel,
151
- events,
152
- })
153
-
154
- send('lifecycle:end')
155
- } catch (error) {
156
- send('error', {
157
- message: error instanceof Error ? error.message : 'Unknown error',
158
- stack: error instanceof Error ? error.stack : undefined,
159
- })
160
- } finally {
161
- res.end()
162
- }
163
- }