@kubb/cli 4.32.4 → 4.33.1

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 (133) hide show
  1. package/dist/agent-Bd1QdPVV.cjs +91 -0
  2. package/dist/agent-Bd1QdPVV.cjs.map +1 -0
  3. package/dist/agent-D83d9Pud.cjs +60 -0
  4. package/dist/agent-D83d9Pud.cjs.map +1 -0
  5. package/dist/agent-DgKQXSmR.js +57 -0
  6. package/dist/agent-DgKQXSmR.js.map +1 -0
  7. package/dist/agent-u_Ehwz6r.js +87 -0
  8. package/dist/agent-u_Ehwz6r.js.map +1 -0
  9. package/dist/constants-BTUap0zs.cjs +108 -0
  10. package/dist/constants-BTUap0zs.cjs.map +1 -0
  11. package/dist/constants-CM3dJzjK.js +67 -0
  12. package/dist/constants-CM3dJzjK.js.map +1 -0
  13. package/dist/define--M_JMcDC.js +25 -0
  14. package/dist/define--M_JMcDC.js.map +1 -0
  15. package/dist/define-D6Kfm7-Z.cjs +36 -0
  16. package/dist/define-D6Kfm7-Z.cjs.map +1 -0
  17. package/dist/errors-6mF_WKxg.js +27 -0
  18. package/dist/errors-6mF_WKxg.js.map +1 -0
  19. package/dist/errors-DBW0N9w4.cjs +44 -0
  20. package/dist/errors-DBW0N9w4.cjs.map +1 -0
  21. package/dist/generate-Bn8n4w1O.cjs +65 -0
  22. package/dist/generate-Bn8n4w1O.cjs.map +1 -0
  23. package/dist/{generate-CpWtSc45.js → generate-CAsV9wSx.js} +656 -689
  24. package/dist/generate-CAsV9wSx.js.map +1 -0
  25. package/dist/generate-D-59YK0L.js +66 -0
  26. package/dist/generate-D-59YK0L.js.map +1 -0
  27. package/dist/{generate-COj0aMS6.cjs → generate-JC65igQh.cjs} +662 -694
  28. package/dist/generate-JC65igQh.cjs.map +1 -0
  29. package/dist/index.cjs +226 -35
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.ts +1 -1
  32. package/dist/index.js +226 -35
  33. package/dist/index.js.map +1 -1
  34. package/dist/init-C-InrmSY.js +302 -0
  35. package/dist/init-C-InrmSY.js.map +1 -0
  36. package/dist/init-CXP8OfMe.js +25 -0
  37. package/dist/init-CXP8OfMe.js.map +1 -0
  38. package/dist/init-CbeE-L-0.cjs +25 -0
  39. package/dist/init-CbeE-L-0.cjs.map +1 -0
  40. package/dist/init-hmolV6B4.cjs +306 -0
  41. package/dist/init-hmolV6B4.cjs.map +1 -0
  42. package/dist/jiti-Cd3S0xwr.cjs +16 -0
  43. package/dist/jiti-Cd3S0xwr.cjs.map +1 -0
  44. package/dist/jiti-e08mD2Ph.js +11 -0
  45. package/dist/jiti-e08mD2Ph.js.map +1 -0
  46. package/dist/mcp-BDxg2oJm.cjs +16 -0
  47. package/dist/mcp-BDxg2oJm.cjs.map +1 -0
  48. package/dist/mcp-ChHFPRzD.cjs +42 -0
  49. package/dist/mcp-ChHFPRzD.cjs.map +1 -0
  50. package/dist/mcp-D2SHEg_d.js +41 -0
  51. package/dist/mcp-D2SHEg_d.js.map +1 -0
  52. package/dist/mcp-MSoE4vNA.js +16 -0
  53. package/dist/mcp-MSoE4vNA.js.map +1 -0
  54. package/dist/{package-aNQWvWbS.cjs → package-CUVyeIbt.cjs} +2 -2
  55. package/dist/package-CUVyeIbt.cjs.map +1 -0
  56. package/dist/package-Cbd8OC6q.js +6 -0
  57. package/dist/package-Cbd8OC6q.js.map +1 -0
  58. package/dist/shell-7HPrTCJ5.cjs +57 -0
  59. package/dist/shell-7HPrTCJ5.cjs.map +1 -0
  60. package/dist/shell-DqqWsHCD.js +46 -0
  61. package/dist/shell-DqqWsHCD.js.map +1 -0
  62. package/dist/{telemetry-BDSSqUiG.cjs → telemetry-Cn9X1I5B.cjs} +79 -9
  63. package/dist/telemetry-Cn9X1I5B.cjs.map +1 -0
  64. package/dist/{telemetry-DYWvlxqs.js → telemetry-DxiR7clS.js} +63 -11
  65. package/dist/telemetry-DxiR7clS.js.map +1 -0
  66. package/dist/validate-BG8A3aQS.cjs +25 -0
  67. package/dist/validate-BG8A3aQS.cjs.map +1 -0
  68. package/dist/validate-BZ1UFkwA.js +25 -0
  69. package/dist/validate-BZ1UFkwA.js.map +1 -0
  70. package/dist/validate-Bbrn3Q-A.cjs +42 -0
  71. package/dist/validate-Bbrn3Q-A.cjs.map +1 -0
  72. package/dist/validate-l8vLmwKA.js +41 -0
  73. package/dist/validate-l8vLmwKA.js.map +1 -0
  74. package/package.json +6 -6
  75. package/src/commands/agent/start.ts +27 -136
  76. package/src/commands/agent.ts +6 -25
  77. package/src/commands/generate.ts +26 -158
  78. package/src/commands/init.ts +9 -360
  79. package/src/commands/mcp.ts +7 -52
  80. package/src/commands/validate.ts +9 -60
  81. package/src/constants.ts +76 -0
  82. package/src/index.ts +36 -42
  83. package/src/loggers/clackLogger.ts +65 -165
  84. package/src/loggers/fileSystemLogger.ts +2 -14
  85. package/src/loggers/githubActionsLogger.ts +58 -125
  86. package/src/loggers/plainLogger.ts +44 -92
  87. package/src/loggers/utils.ts +67 -4
  88. package/src/runners/agent.ts +100 -0
  89. package/src/runners/generate.ts +223 -102
  90. package/src/runners/init.ts +323 -0
  91. package/src/runners/mcp.ts +32 -0
  92. package/src/runners/validate.ts +35 -0
  93. package/src/utils/Writables.ts +2 -2
  94. package/src/utils/executeHooks.ts +20 -8
  95. package/src/utils/getCosmiConfig.ts +10 -11
  96. package/src/utils/getIntro.ts +1 -81
  97. package/src/utils/getSummary.ts +12 -17
  98. package/src/utils/jiti.ts +9 -0
  99. package/src/utils/packageManager.ts +4 -4
  100. package/src/utils/runHook.ts +75 -0
  101. package/src/utils/telemetry.ts +8 -26
  102. package/src/utils/watcher.ts +2 -4
  103. package/dist/agent-6COck3B9.cjs +0 -20
  104. package/dist/agent-6COck3B9.cjs.map +0 -1
  105. package/dist/agent-DMm6c5Vg.js +0 -20
  106. package/dist/agent-DMm6c5Vg.js.map +0 -1
  107. package/dist/generate-COj0aMS6.cjs.map +0 -1
  108. package/dist/generate-CpWtSc45.js.map +0 -1
  109. package/dist/init-Bdn3_qir.js +0 -304
  110. package/dist/init-Bdn3_qir.js.map +0 -1
  111. package/dist/init-CFW2kWY8.cjs +0 -308
  112. package/dist/init-CFW2kWY8.cjs.map +0 -1
  113. package/dist/mcp-DkwtARfo.cjs +0 -57
  114. package/dist/mcp-DkwtARfo.cjs.map +0 -1
  115. package/dist/mcp-DrH93Vq4.js +0 -57
  116. package/dist/mcp-DrH93Vq4.js.map +0 -1
  117. package/dist/package-BnJbGmLm.js +0 -6
  118. package/dist/package-BnJbGmLm.js.map +0 -1
  119. package/dist/package-aNQWvWbS.cjs.map +0 -1
  120. package/dist/start-CqTUu14n.js +0 -131
  121. package/dist/start-CqTUu14n.js.map +0 -1
  122. package/dist/start-D-rsIJGo.cjs +0 -134
  123. package/dist/start-D-rsIJGo.cjs.map +0 -1
  124. package/dist/telemetry-BDSSqUiG.cjs.map +0 -1
  125. package/dist/telemetry-DYWvlxqs.js.map +0 -1
  126. package/dist/validate-BlV8L8gC.js +0 -66
  127. package/dist/validate-BlV8L8gC.js.map +0 -1
  128. package/dist/validate-COhZUXF8.cjs +0 -66
  129. package/dist/validate-COhZUXF8.cjs.map +0 -1
  130. package/src/loggers/envDetection.ts +0 -28
  131. package/src/loggers/index.ts +0 -5
  132. package/src/utils/formatMsWithColor.ts +0 -22
  133. package/src/utils/randomColor.ts +0 -23
@@ -1,141 +1,32 @@
1
- import { spawn } from 'node:child_process'
2
1
  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 type { ArgsDef } from 'citty'
8
- import { defineCommand } from 'citty'
2
+ import { defineCommand } from '@internals/utils'
9
3
  import { version } from '../../../package.json'
10
- import { buildTelemetryEvent, sendTelemetry } from '../../utils/telemetry.ts'
11
-
12
- const args = {
13
- config: {
14
- type: 'string',
15
- description: 'Path to the Kubb config',
16
- alias: 'c',
17
- },
18
- port: {
19
- type: 'string',
20
- description: 'Port for the server. If not specified, an available port is automatically selected.',
21
- alias: 'p',
22
- },
23
- host: {
24
- type: 'string',
25
- description: 'Host for the server',
26
- default: 'localhost',
27
- },
28
- 'no-cache': {
29
- type: 'boolean',
30
- description: 'Disable session caching',
31
- default: false,
32
- },
33
- 'allow-write': {
34
- type: 'boolean',
35
- description: 'Allow writing generated files to the filesystem. When not set, no files are written and the config patch is not persisted.',
36
- default: false,
37
- },
38
- 'allow-all': {
39
- type: 'boolean',
40
- description: 'Grant all permissions (implies --allow-write).',
41
- default: false,
42
- },
43
- } as const satisfies ArgsDef
44
-
45
- type StartServerProps = {
46
- port: number
47
- host: string
48
- configPath: string
49
- allowWrite: boolean
50
- allowAll: boolean
51
- }
52
-
53
- async function startServer({ port, host, configPath, allowWrite, allowAll }: StartServerProps): Promise<void> {
54
- try {
55
- // Load .env file into process.env using Node.js built-in (v20.12.0+)
56
- try {
57
- process.loadEnvFile()
58
- } catch {
59
- // .env file may not exist; ignore
60
- }
61
-
62
- // Resolve the @kubb/agent package path
63
- const agentPkgUrl = import.meta.resolve('@kubb/agent/package.json')
64
- const agentPkgPath = fileURLToPath(agentPkgUrl)
65
- const agentDir = path.dirname(agentPkgPath)
66
- const serverPath = path.join(agentDir, '.output', 'server', 'index.mjs')
67
-
68
- // nitro env
69
- const PORT = process.env.PORT || (port === 0 ? '3000' : String(port))
70
- const HOST = process.env.HOST || host || '0.0.0.0'
71
-
72
- // kubb env
73
- const KUBB_AGENT_ROOT = process.env.KUBB_AGENT_ROOT || process.cwd()
74
- const KUBB_AGENT_CONFIG = process.env.KUBB_AGENT_CONFIG || configPath || 'kubb.config.ts'
75
- const KUBB_AGENT_ALLOW_WRITE = allowAll || allowWrite ? 'true' : (process.env.KUBB_AGENT_ALLOW_WRITE ?? 'false')
76
- const KUBB_AGENT_ALLOW_ALL = allowAll ? 'true' : (process.env.KUBB_AGENT_ALLOW_ALL ?? 'false')
77
- const KUBB_AGENT_TOKEN = process.env.KUBB_AGENT_TOKEN
78
- const KUBB_AGENT_RETRY_TIMEOUT = process.env.KUBB_AGENT_RETRY_TIMEOUT || '30000'
79
- const KUBB_STUDIO_URL = process.env.KUBB_STUDIO_URL || 'https://studio.kubb.dev'
80
-
81
- // Set environment variables
82
- const env = {
83
- PORT,
84
- HOST,
85
- KUBB_AGENT_ROOT,
86
- KUBB_AGENT_CONFIG,
87
- KUBB_AGENT_ALLOW_WRITE,
88
- KUBB_AGENT_ALLOW_ALL,
89
- KUBB_AGENT_TOKEN,
90
- KUBB_AGENT_RETRY_TIMEOUT,
91
- KUBB_STUDIO_URL,
92
- }
93
-
94
- clack.log.step(styleText('cyan', 'Starting agent server...'))
95
- clack.log.info(styleText('dim', `Config: ${KUBB_AGENT_CONFIG}`))
96
- clack.log.info(styleText('dim', `Host: ${HOST}`))
97
- clack.log.info(styleText('dim', `Port: ${PORT}`))
98
- if (!KUBB_AGENT_ALLOW_WRITE && !KUBB_AGENT_ALLOW_ALL) {
99
- clack.log.warn(styleText('yellow', 'Filesystem writes disabled. Use --allow-write or --allow-all to enable.'))
100
- }
101
-
102
- spawn('node', [serverPath], {
103
- env: { ...process.env, ...env },
104
- stdio: 'inherit',
105
- cwd: process.cwd(),
4
+ import { agentDefaults } from '../../constants.ts'
5
+
6
+ export const command = defineCommand({
7
+ name: 'start',
8
+ description: 'Start the Agent server',
9
+ options: {
10
+ config: { type: 'string', description: 'Path to the Kubb config', short: 'c' },
11
+ port: { type: 'string', description: `Port for the server (default: ${agentDefaults.port})`, short: 'p' },
12
+ host: { type: 'string', description: 'Host for the server', default: agentDefaults.host },
13
+ 'allow-write': {
14
+ type: 'boolean',
15
+ description: 'Allow writing generated files to the filesystem. When not set, no files are written and the config patch is not persisted.',
16
+ default: false,
17
+ },
18
+ 'allow-all': { type: 'boolean', description: 'Grant all permissions (implies --allow-write).', default: false },
19
+ },
20
+ async run({ values }) {
21
+ const { runAgentStart } = await import('../../runners/agent.ts')
22
+
23
+ await runAgentStart({
24
+ port: values.port !== undefined ? values.port : undefined,
25
+ host: values.host,
26
+ configPath: path.resolve(process.cwd(), values.config ?? agentDefaults.configFile),
27
+ allowWrite: values['allow-write'],
28
+ allowAll: values['allow-all'],
29
+ version,
106
30
  })
107
- } catch (error) {
108
- console.error('Failed to start agent server:', error)
109
- process.exit(1)
110
- }
111
- }
112
-
113
- const command = defineCommand({
114
- meta: {
115
- name: 'start',
116
- description: 'Start the Agent server',
117
- },
118
- args,
119
- async run(commandContext) {
120
- const { args } = commandContext
121
- const hrStart = process.hrtime()
122
-
123
- try {
124
- const configPath = path.resolve(process.cwd(), args.config || 'kubb.config.ts')
125
- const port = args.port ? Number.parseInt(args.port, 10) : 0
126
- const host = args.host
127
- const allowWrite = args['allow-write']
128
- const allowAll = args['allow-all']
129
-
130
- startServer({ port, host, configPath, allowWrite, allowAll })
131
- await sendTelemetry(buildTelemetryEvent({ command: 'agent', kubbVersion: version, hrStart, status: 'success' }))
132
- } catch (error) {
133
- await sendTelemetry(buildTelemetryEvent({ command: 'agent', kubbVersion: version, hrStart, status: 'failed' }))
134
- clack.log.error(styleText('red', 'Failed to start agent server'))
135
- console.error(error)
136
- process.exit(1)
137
- }
138
31
  },
139
32
  })
140
-
141
- export default command
@@ -1,27 +1,8 @@
1
- import type { ArgsDef } from 'citty'
2
- import { defineCommand, showUsage } from 'citty'
1
+ import { defineCommand } from '@internals/utils'
2
+ import { command as startCommand } from './agent/start.ts'
3
3
 
4
- const args = {
5
- help: {
6
- type: 'boolean',
7
- description: 'Show help',
8
- alias: 'h',
9
- default: false,
10
- },
11
- } as const satisfies ArgsDef
12
-
13
- const command = defineCommand({
14
- args,
15
- subCommands: {
16
- start: () => import('./agent/start.ts').then((m) => m.default),
17
- },
18
- async run(commandContext) {
19
- const { args } = commandContext
20
-
21
- if (args.help) {
22
- return showUsage(command)
23
- }
24
- },
4
+ export const command = defineCommand({
5
+ name: 'agent',
6
+ description: 'Manage the Kubb Agent server',
7
+ subCommands: [startCommand],
25
8
  })
26
-
27
- export default command
@@ -1,160 +1,28 @@
1
- import path from 'node:path'
2
- import * as process from 'node:process'
3
- import { styleText } from 'node:util'
4
- import * as clack from '@clack/prompts'
5
- import { type CLIOptions, isInputPath, type KubbEvents, LogLevel, PromiseManager } from '@kubb/core'
6
- import { AsyncEventEmitter, executeIfOnline, getConfigs } from '@kubb/core/utils'
7
- import type { ArgsDef, ParsedArgs } from 'citty'
8
- import { defineCommand, showUsage } from 'citty'
9
- import { version } from '../../package.json'
10
- import { setupLogger } from '../loggers/utils.ts'
11
- import { generate } from '../runners/generate.ts'
12
- import { getCosmiConfig } from '../utils/getCosmiConfig.ts'
13
- import { startWatcher } from '../utils/watcher.ts'
14
-
15
- const args = {
16
- config: {
17
- type: 'string',
18
- description: 'Path to the Kubb config',
19
- alias: 'c',
20
- },
21
- logLevel: {
22
- type: 'string',
23
- description: 'Info, silent, verbose or debug',
24
- alias: 'l',
25
- default: 'info',
26
- valueHint: 'silent|info|verbose|debug',
27
- },
28
- watch: {
29
- type: 'boolean',
30
- description: 'Watch mode based on the input file',
31
- alias: 'w',
32
- default: false,
33
- },
34
- debug: {
35
- type: 'boolean',
36
- description: 'Override logLevel to debug',
37
- alias: 'd',
38
- default: false,
39
- },
40
- verbose: {
41
- type: 'boolean',
42
- description: 'Override logLevel to verbose',
43
- alias: 'v',
44
- default: false,
45
- },
46
- silent: {
47
- type: 'boolean',
48
- description: 'Override logLevel to silent',
49
- alias: 's',
50
- default: false,
51
- },
52
- help: {
53
- type: 'boolean',
54
- description: 'Show help',
55
- alias: 'h',
56
- default: false,
57
- },
58
- } as const satisfies ArgsDef
59
-
60
- export type Args = ParsedArgs<typeof args>
61
-
62
- const command = defineCommand({
63
- meta: {
64
- name: 'generate',
65
- description: "[input] Generate files based on a 'kubb.config.ts' file",
66
- },
67
- args,
68
- async run(commandContext) {
69
- const { args } = commandContext
70
- const input = args._[0]
71
- const events = new AsyncEventEmitter<KubbEvents>()
72
- const promiseManager = new PromiseManager()
73
-
74
- if (args.help) {
75
- return showUsage(command)
76
- }
77
-
78
- if (args.debug) {
79
- args.logLevel = 'debug'
80
- }
81
-
82
- if (args.verbose) {
83
- args.logLevel = 'verbose'
84
- }
85
-
86
- if (args.silent) {
87
- args.logLevel = 'silent'
88
- }
89
-
90
- const logLevel = LogLevel[args.logLevel as keyof typeof LogLevel] || 3
91
-
92
- await setupLogger(events, { logLevel })
93
-
94
- await executeIfOnline(async () => {
95
- try {
96
- const res = await fetch('https://registry.npmjs.org/@kubb/cli/latest')
97
- const data = (await res.json()) as { version: string }
98
- const latestVersion = data.version
99
-
100
- if (latestVersion && version < latestVersion) {
101
- await events.emit('version:new', version, latestVersion)
102
- }
103
- } catch {
104
- // Ignore network errors for version check
105
- }
106
- })
107
-
108
- try {
109
- const result = await getCosmiConfig('kubb', args.config)
110
- const configs = await getConfigs(result.config, args as CLIOptions)
111
-
112
- await events.emit('config:start')
113
-
114
- await events.emit('info', 'Config loaded', path.relative(process.cwd(), result.filepath))
115
-
116
- await events.emit('success', 'Config loaded successfully', path.relative(process.cwd(), result.filepath))
117
- await events.emit('config:end', configs)
118
-
119
- await events.emit('lifecycle:start', version)
120
-
121
- const promises = configs.map((config) => {
122
- return async () => {
123
- if (isInputPath(config) && args.watch) {
124
- await startWatcher([input || config.input.path], async (paths) => {
125
- // remove to avoid duplicate listeners after each change
126
- events.removeAll()
127
-
128
- await generate({
129
- input,
130
- config,
131
- logLevel,
132
- events,
133
- })
134
-
135
- clack.log.step(styleText('yellow', `Watching for changes in ${paths.join(' and ')}`))
136
- })
137
-
138
- return
139
- }
140
-
141
- await generate({
142
- input,
143
- config,
144
- logLevel,
145
- events,
146
- })
147
- }
148
- })
149
-
150
- await promiseManager.run('seq', promises)
151
-
152
- await events.emit('lifecycle:end')
153
- } catch (error) {
154
- await events.emit('error', error as Error)
155
- process.exit(1)
156
- }
1
+ import { defineCommand } from '@internals/utils'
2
+
3
+ export const command = defineCommand({
4
+ name: 'generate',
5
+ description: "[input] Generate files based on a 'kubb.config.ts' file",
6
+ arguments: ['[input]'],
7
+ options: {
8
+ config: { type: 'string', description: 'Path to the Kubb config', short: 'c' },
9
+ logLevel: {
10
+ type: 'string',
11
+ description: 'Info, silent, verbose or debug',
12
+ short: 'l',
13
+ default: 'info',
14
+ hint: 'silent|info|verbose|debug',
15
+ enum: ['silent', 'info', 'verbose', 'debug'],
16
+ },
17
+ watch: { type: 'boolean', description: 'Watch mode based on the input file', short: 'w', default: false },
18
+ debug: { type: 'boolean', description: 'Override logLevel to debug', short: 'd', default: false },
19
+ verbose: { type: 'boolean', description: 'Override logLevel to verbose', short: 'v', default: false },
20
+ silent: { type: 'boolean', description: 'Override logLevel to silent', short: 's', default: false },
21
+ },
22
+ async run({ values, positionals }) {
23
+ const logLevel = values.debug ? 'debug' : values.verbose ? 'verbose' : values.silent ? 'silent' : values.logLevel
24
+ const { runGenerateCommand } = await import('../runners/generate.ts')
25
+
26
+ await runGenerateCommand({ input: positionals[0], configPath: values.config, logLevel, watch: values.watch })
157
27
  },
158
28
  })
159
-
160
- export default command