@kubb/cli 5.0.0-alpha.9 → 5.0.0-beta.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 (135) hide show
  1. package/README.md +4 -2
  2. package/bin/kubb.js +6 -0
  3. package/dist/{agent-BKphjOIF.cjs → agent-0Nk--lcr.cjs} +5 -5
  4. package/dist/agent-0Nk--lcr.cjs.map +1 -0
  5. package/dist/agent-B_pirbeB.cjs +116 -0
  6. package/dist/agent-B_pirbeB.cjs.map +1 -0
  7. package/dist/{agent-5mmp7QzF.js → agent-DKeVuiUC.js} +5 -5
  8. package/dist/agent-DKeVuiUC.js.map +1 -0
  9. package/dist/agent-Ev5hU5hH.js +112 -0
  10. package/dist/agent-Ev5hU5hH.js.map +1 -0
  11. package/dist/{constants-D0XHAHeZ.cjs → constants-CnDXa1R6.cjs} +30 -60
  12. package/dist/constants-CnDXa1R6.cjs.map +1 -0
  13. package/dist/{constants-DJM9zCXm.js → constants-aL3CP_Wq.js} +23 -59
  14. package/dist/constants-aL3CP_Wq.js.map +1 -0
  15. package/dist/define-Bdn8j5VM.cjs +54 -0
  16. package/dist/define-Bdn8j5VM.cjs.map +1 -0
  17. package/dist/define-Ctii4bel.js +43 -0
  18. package/dist/define-Ctii4bel.js.map +1 -0
  19. package/dist/{errors-DBW0N9w4.cjs → errors-CLCjoSg0.cjs} +22 -6
  20. package/dist/errors-CLCjoSg0.cjs.map +1 -0
  21. package/dist/errors-CjPmyZHy.js +43 -0
  22. package/dist/errors-CjPmyZHy.js.map +1 -0
  23. package/dist/{generate-Rly1EXBN.js → generate-B3PZ6Dp-.js} +3 -3
  24. package/dist/generate-B3PZ6Dp-.js.map +1 -0
  25. package/dist/{generate-Cq5RDTBL.cjs → generate-B3jl4ukb.cjs} +559 -265
  26. package/dist/generate-B3jl4ukb.cjs.map +1 -0
  27. package/dist/{generate-DU5zzc54.cjs → generate-DL_7a7Wd.cjs} +3 -3
  28. package/dist/generate-DL_7a7Wd.cjs.map +1 -0
  29. package/dist/{generate-BHNyeQXl.js → generate-Dt_r0ELY.js} +552 -258
  30. package/dist/generate-Dt_r0ELY.js.map +1 -0
  31. package/dist/index.cjs +40 -18
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.js +40 -18
  34. package/dist/index.js.map +1 -1
  35. package/dist/{init-iN7e1XwI.js → init-Bj94Nvt8.js} +4 -4
  36. package/dist/init-Bj94Nvt8.js.map +1 -0
  37. package/dist/{init-BK6inBTR.cjs → init-CZ5Xq2Hd.cjs} +45 -58
  38. package/dist/init-CZ5Xq2Hd.cjs.map +1 -0
  39. package/dist/{init-CN1JFyGX.cjs → init-CyN1oyTF.cjs} +4 -4
  40. package/dist/init-CyN1oyTF.cjs.map +1 -0
  41. package/dist/{init-BQ6zfsnw.js → init-eNRlotJK.js} +41 -54
  42. package/dist/init-eNRlotJK.js.map +1 -0
  43. package/dist/{mcp-eP1S40LZ.js → mcp-BzW703d7.js} +4 -4
  44. package/dist/{mcp-eP1S40LZ.js.map → mcp-BzW703d7.js.map} +1 -1
  45. package/dist/{mcp-CONmm_xT.cjs → mcp-CLcDV4Jm.cjs} +5 -6
  46. package/dist/mcp-CLcDV4Jm.cjs.map +1 -0
  47. package/dist/{mcp-BiGUvbWP.js → mcp-D7EIR9fR.js} +4 -5
  48. package/dist/mcp-D7EIR9fR.js.map +1 -0
  49. package/dist/{mcp-T7Q4nWbT.cjs → mcp-ZY-ONTOp.cjs} +4 -4
  50. package/dist/{mcp-T7Q4nWbT.cjs.map → mcp-ZY-ONTOp.cjs.map} +1 -1
  51. package/dist/{package-BJ6ionm6.cjs → package-D8wlStAg.cjs} +2 -2
  52. package/dist/package-D8wlStAg.cjs.map +1 -0
  53. package/dist/package-Yo-9_m5C.js +6 -0
  54. package/dist/package-Yo-9_m5C.js.map +1 -0
  55. package/dist/{shell-7HPrTCJ5.cjs → shell-475fQKaX.cjs} +8 -3
  56. package/dist/shell-475fQKaX.cjs.map +1 -0
  57. package/dist/{shell-DqqWsHCD.js → shell-DLzN4fRo.js} +8 -3
  58. package/dist/shell-DLzN4fRo.js.map +1 -0
  59. package/dist/{telemetry-DZ7IrLAU.cjs → telemetry-DN95_2pF.cjs} +50 -8
  60. package/dist/telemetry-DN95_2pF.cjs.map +1 -0
  61. package/dist/{telemetry-BF3SMlH6.js → telemetry-LgT_sdPe.js} +48 -6
  62. package/dist/telemetry-LgT_sdPe.js.map +1 -0
  63. package/dist/{validate-DAZdX_0i.js → validate-Dplr99xO.js} +4 -4
  64. package/dist/validate-Dplr99xO.js.map +1 -0
  65. package/dist/{validate-DucFMytl.cjs → validate-_8mBa63G.cjs} +4 -4
  66. package/dist/validate-_8mBa63G.cjs.map +1 -0
  67. package/dist/{validate-BImbbx1t.js → validate-kLJoT_hi.js} +5 -13
  68. package/dist/validate-kLJoT_hi.js.map +1 -0
  69. package/dist/{validate-ujLCYSWU.cjs → validate-yKKzqEZ5.cjs} +6 -14
  70. package/dist/validate-yKKzqEZ5.cjs.map +1 -0
  71. package/package.json +47 -46
  72. package/src/commands/agent/start.ts +20 -4
  73. package/src/commands/generate.ts +35 -6
  74. package/src/commands/init.ts +6 -1
  75. package/src/commands/validate.ts +6 -1
  76. package/src/constants.ts +19 -38
  77. package/src/index.ts +7 -10
  78. package/src/loggers/clackLogger.ts +54 -46
  79. package/src/loggers/fileSystemLogger.ts +15 -16
  80. package/src/loggers/githubActionsLogger.ts +23 -24
  81. package/src/loggers/plainLogger.ts +22 -23
  82. package/src/runners/agent.ts +81 -34
  83. package/src/runners/generate.ts +90 -100
  84. package/src/runners/init.ts +24 -51
  85. package/src/runners/mcp.ts +17 -4
  86. package/src/runners/validate.ts +19 -15
  87. package/src/utils/executeHooks.ts +15 -15
  88. package/src/utils/flags.ts +1 -2
  89. package/src/utils/getConfig.ts +10 -0
  90. package/src/utils/getCosmiConfig.ts +21 -12
  91. package/src/utils/getSummary.ts +1 -1
  92. package/src/utils/runHook.ts +29 -13
  93. package/src/utils/telemetry.ts +16 -3
  94. package/bin/kubb.cjs +0 -18
  95. package/dist/agent-5mmp7QzF.js.map +0 -1
  96. package/dist/agent-BKphjOIF.cjs.map +0 -1
  97. package/dist/agent-BapvKB4r.cjs +0 -92
  98. package/dist/agent-BapvKB4r.cjs.map +0 -1
  99. package/dist/agent-CBrpIMMU.js +0 -88
  100. package/dist/agent-CBrpIMMU.js.map +0 -1
  101. package/dist/constants-D0XHAHeZ.cjs.map +0 -1
  102. package/dist/constants-DJM9zCXm.js.map +0 -1
  103. package/dist/define--M_JMcDC.js +0 -25
  104. package/dist/define--M_JMcDC.js.map +0 -1
  105. package/dist/define-D6Kfm7-Z.cjs +0 -36
  106. package/dist/define-D6Kfm7-Z.cjs.map +0 -1
  107. package/dist/errors-6mF_WKxg.js +0 -27
  108. package/dist/errors-6mF_WKxg.js.map +0 -1
  109. package/dist/errors-DBW0N9w4.cjs.map +0 -1
  110. package/dist/generate-BHNyeQXl.js.map +0 -1
  111. package/dist/generate-Cq5RDTBL.cjs.map +0 -1
  112. package/dist/generate-DU5zzc54.cjs.map +0 -1
  113. package/dist/generate-Rly1EXBN.js.map +0 -1
  114. package/dist/init-BK6inBTR.cjs.map +0 -1
  115. package/dist/init-BQ6zfsnw.js.map +0 -1
  116. package/dist/init-CN1JFyGX.cjs.map +0 -1
  117. package/dist/init-iN7e1XwI.js.map +0 -1
  118. package/dist/jiti-Cd3S0xwr.cjs +0 -16
  119. package/dist/jiti-Cd3S0xwr.cjs.map +0 -1
  120. package/dist/jiti-e08mD2Ph.js +0 -11
  121. package/dist/jiti-e08mD2Ph.js.map +0 -1
  122. package/dist/mcp-BiGUvbWP.js.map +0 -1
  123. package/dist/mcp-CONmm_xT.cjs.map +0 -1
  124. package/dist/package-BJ6ionm6.cjs.map +0 -1
  125. package/dist/package-BKZ0H3Zf.js +0 -6
  126. package/dist/package-BKZ0H3Zf.js.map +0 -1
  127. package/dist/shell-7HPrTCJ5.cjs.map +0 -1
  128. package/dist/shell-DqqWsHCD.js.map +0 -1
  129. package/dist/telemetry-BF3SMlH6.js.map +0 -1
  130. package/dist/telemetry-DZ7IrLAU.cjs.map +0 -1
  131. package/dist/validate-BImbbx1t.js.map +0 -1
  132. package/dist/validate-DAZdX_0i.js.map +0 -1
  133. package/dist/validate-DucFMytl.cjs.map +0 -1
  134. package/dist/validate-ujLCYSWU.cjs.map +0 -1
  135. package/src/utils/jiti.ts +0 -9
@@ -2,15 +2,15 @@ import { createHash } from 'node:crypto'
2
2
  import { styleText } from 'node:util'
3
3
  import type { AsyncEventEmitter } from '@internals/utils'
4
4
  import { tokenize } from '@internals/utils'
5
- import type { Config, KubbEvents } from '@kubb/core'
5
+ import type { Config, KubbHookEndContext, KubbHooks } from '@kubb/core'
6
6
 
7
7
  type ExecutingHooksProps = {
8
- hooks: NonNullable<Config['hooks']>
9
- events: AsyncEventEmitter<KubbEvents>
8
+ configHooks: NonNullable<Config['hooks']>
9
+ hooks: AsyncEventEmitter<KubbHooks>
10
10
  }
11
11
 
12
- export async function executeHooks({ hooks, events }: ExecutingHooksProps): Promise<void> {
13
- const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done].filter(Boolean)
12
+ export async function executeHooks({ configHooks, hooks }: ExecutingHooksProps): Promise<void> {
13
+ const commands = Array.isArray(configHooks.done) ? configHooks.done : [configHooks.done].filter(Boolean)
14
14
 
15
15
  for (const command of commands) {
16
16
  const [cmd, ...args] = tokenize(command)
@@ -22,24 +22,24 @@ export async function executeHooks({ hooks, events }: ExecutingHooksProps): Prom
22
22
  const hookId = createHash('sha256').update(command).digest('hex')
23
23
 
24
24
  // Wire up the hook:end listener BEFORE emitting hook:start to avoid the race condition
25
- // where hook:end fires synchronously inside emit('hook:start') before the listener is registered.
25
+ // where hook:end fires synchronously inside emit('kubb:hook:start') before the listener is registered.
26
26
  const hookEndPromise = new Promise<void>((resolve, reject) => {
27
- const handler = ({ id, success, error }: { id?: string; command: string; args?: readonly string[]; success: boolean; error: Error | null }) => {
28
- if (id !== hookId) return
29
- events.off('hook:end', handler)
30
- if (!success) {
31
- reject(error ?? new Error(`Hook failed: ${command}`))
27
+ const handler = (ctx: KubbHookEndContext) => {
28
+ if (ctx.id !== hookId) return
29
+ hooks.off('kubb:hook:end', handler)
30
+ if (!ctx.success) {
31
+ reject(ctx.error ?? new Error(`Hook failed: ${command}`))
32
32
  return
33
33
  }
34
- events
35
- .emit('success', `${styleText('dim', command)} successfully executed`)
34
+ hooks
35
+ .emit('kubb:success', { message: `${styleText('dim', command)} successfully executed` })
36
36
  .then(resolve)
37
37
  .catch(reject)
38
38
  }
39
- events.on('hook:end', handler)
39
+ hooks.on('kubb:hook:end', handler)
40
40
  })
41
41
 
42
- await events.emit('hook:start', { id: hookId, command: cmd, args })
42
+ await hooks.emit('kubb:hook:start', { id: hookId, command: cmd, args })
43
43
  await hookEndPromise
44
44
  }
45
45
  }
@@ -1,6 +1,5 @@
1
1
  /**
2
- * Type guard that checks whether a raw string is a member of a typed flag set.
3
- * Avoids the need for type assertions when working with `Set<T extends string>`.
2
+ * Type guard that confirms `value` is a member of `set`. Avoids type assertions with `Set<T extends string>`.
4
3
  */
5
4
  export function isFlag<T extends string>(set: ReadonlySet<T>, value: string): value is T {
6
5
  for (const flag of set) {
@@ -0,0 +1,10 @@
1
+ import type { CLIOptions, Config, PossibleConfig } from '@kubb/core'
2
+
3
+ type ConfigInput = PossibleConfig<CLIOptions>
4
+
5
+ export async function getConfigs(config: ConfigInput, args: CLIOptions): Promise<Array<Config>> {
6
+ const resolved = await (typeof config === 'function' ? config(args as CLIOptions) : config)
7
+ const userConfigs = Array.isArray(resolved) ? resolved : [resolved]
8
+
9
+ return userConfigs.map((item) => ({ ...item, plugins: item.plugins ?? [] }) as Config)
10
+ }
@@ -1,25 +1,28 @@
1
- import type { defineConfig, UserConfig } from '@kubb/core'
1
+ import type { Config } from '@kubb/core'
2
2
  import { cosmiconfig } from 'cosmiconfig'
3
- import { createJiti } from 'jiti'
3
+ import { unrun } from 'unrun'
4
4
 
5
5
  type CosmiconfigResult = {
6
6
  filepath: string
7
7
  isEmpty?: boolean
8
- config: ReturnType<typeof defineConfig> | UserConfig
8
+ config: Config
9
9
  }
10
10
 
11
- const jiti = createJiti(import.meta.url, {
12
- jsx: {
13
- runtime: 'automatic',
14
- importSource: '@kubb/react-fabric',
11
+ const unrunInputOptions = {
12
+ transform: {
13
+ jsx: {
14
+ runtime: 'automatic' as const,
15
+ importSource: '@kubb/renderer-jsx',
16
+ },
15
17
  },
16
- sourceMaps: true,
17
- interopDefault: true,
18
- })
18
+ }
19
19
 
20
20
  const tsLoader = async (configFile: string) => {
21
- const mod = await jiti.import(configFile, { default: true })
22
- return mod
21
+ const { module } = await unrun({
22
+ path: configFile,
23
+ inputOptions: unrunInputOptions,
24
+ })
25
+ return module
23
26
  }
24
27
 
25
28
  export async function getCosmiConfig(moduleName: string, config?: string): Promise<CosmiconfigResult> {
@@ -32,11 +35,15 @@ export async function getCosmiConfig(moduleName: string, config?: string): Promi
32
35
  `.${moduleName}rc.yml`,
33
36
 
34
37
  `.${moduleName}rc.ts`,
38
+ `.${moduleName}rc.mts`,
39
+ `.${moduleName}rc.cts`,
35
40
  `.${moduleName}rc.js`,
36
41
  `.${moduleName}rc.mjs`,
37
42
  `.${moduleName}rc.cjs`,
38
43
 
39
44
  `${moduleName}.config.ts`,
45
+ `${moduleName}.config.mts`,
46
+ `${moduleName}.config.cts`,
40
47
  `${moduleName}.config.js`,
41
48
  `${moduleName}.config.mjs`,
42
49
  `${moduleName}.config.cjs`,
@@ -54,6 +61,8 @@ export async function getCosmiConfig(moduleName: string, config?: string): Promi
54
61
  ],
55
62
  loaders: {
56
63
  '.ts': tsLoader,
64
+ '.mts': tsLoader,
65
+ '.cts': tsLoader,
57
66
  },
58
67
  })
59
68
 
@@ -27,7 +27,7 @@ export function getSummary({ failedPlugins, filesCreated, status, hrStart, confi
27
27
  pluginsFailed: status === 'failed' ? [...failedPlugins].map(({ plugin }) => randomCliColor(plugin.name)).join(', ') : undefined,
28
28
  filesCreated,
29
29
  time: styleText('green', duration),
30
- output: path.isAbsolute(config.root) ? path.resolve(config.root, config.output.path) : config.root,
30
+ output: path.resolve(config.root, config.output.path),
31
31
  } as const
32
32
 
33
33
  const labels = {
@@ -1,6 +1,6 @@
1
1
  import type { AsyncEventEmitter } from '@internals/utils'
2
2
  import { toError } from '@internals/utils'
3
- import type { KubbEvents } from '@kubb/core'
3
+ import type { KubbHooks } from '@kubb/core'
4
4
  import { NonZeroExitError, x } from 'tinyexec'
5
5
 
6
6
  type HookOutputSink = {
@@ -17,21 +17,19 @@ type RunHookOptions = {
17
17
  command: string
18
18
  args?: readonly string[]
19
19
  commandWithArgs: string
20
- context: AsyncEventEmitter<KubbEvents>
20
+ context: AsyncEventEmitter<KubbHooks>
21
21
  /** When true the process output is streamed line-by-line via onLine. */
22
22
  stream?: boolean
23
23
  sink?: HookOutputSink
24
24
  }
25
25
 
26
26
  /**
27
- * Execute a hook command, emit debug/hook:end events, and forward output to
28
- * an optional HookOutputSink. All three logger adapters share this function
29
- * so the process-spawning logic lives in exactly one place.
27
+ * Executes a hook command, emits debug and completion events, and forwards output to an optional sink.
30
28
  */
31
29
  export async function runHook({ id, command, args, commandWithArgs, context, stream = false, sink }: RunHookOptions): Promise<void> {
32
30
  try {
33
31
  const proc = x(command, [...(args ?? [])], {
34
- nodeOptions: { detached: true },
32
+ nodeOptions: { detached: process.platform !== 'win32' },
35
33
  throwOnError: true,
36
34
  })
37
35
 
@@ -43,23 +41,35 @@ export async function runHook({ id, command, args, commandWithArgs, context, str
43
41
 
44
42
  const result = await proc
45
43
 
46
- await context.emit('debug', {
44
+ await context.emit('kubb:debug', {
47
45
  date: new Date(),
48
46
  logs: [result.stdout.trimEnd()],
49
47
  })
50
48
 
51
- await context.emit('hook:end', { command, args, id, success: true, error: null })
49
+ await context.emit('kubb:hook:end', {
50
+ command,
51
+ args,
52
+ id,
53
+ success: true,
54
+ error: null,
55
+ })
52
56
  } catch (err) {
53
57
  if (!(err instanceof NonZeroExitError)) {
54
- await context.emit('hook:end', { command, args, id, success: false, error: toError(err) })
55
- await context.emit('error', toError(err))
58
+ await context.emit('kubb:hook:end', {
59
+ command,
60
+ args,
61
+ id,
62
+ success: false,
63
+ error: toError(err),
64
+ })
65
+ await context.emit('kubb:error', { error: toError(err) })
56
66
  return
57
67
  }
58
68
 
59
69
  const stderr = err.output?.stderr ?? ''
60
70
  const stdout = err.output?.stdout ?? ''
61
71
 
62
- await context.emit('debug', {
72
+ await context.emit('kubb:debug', {
63
73
  date: new Date(),
64
74
  logs: [stdout, stderr].filter(Boolean),
65
75
  })
@@ -69,7 +79,13 @@ export async function runHook({ id, command, args, commandWithArgs, context, str
69
79
 
70
80
  const errorMessage = new Error(`Hook execute failed: ${commandWithArgs}`)
71
81
 
72
- await context.emit('hook:end', { command, args, id, success: false, error: errorMessage })
73
- await context.emit('error', errorMessage)
82
+ await context.emit('kubb:hook:end', {
83
+ command,
84
+ args,
85
+ id,
86
+ success: false,
87
+ error: errorMessage,
88
+ })
89
+ await context.emit('kubb:error', { error: errorMessage })
74
90
  }
75
91
  }
@@ -161,7 +161,15 @@ export function buildOtlpPayload(event: TelemetryEvent): OtlpExportTraceServiceR
161
161
  kvlistValue: {
162
162
  values: [
163
163
  { key: 'name', value: { stringValue: p.name } },
164
- { key: 'options', value: { stringValue: JSON.stringify({ ...p.options, usedEnumNames: undefined }) } },
164
+ {
165
+ key: 'options',
166
+ value: {
167
+ stringValue: JSON.stringify({
168
+ ...p.options,
169
+ usedEnumNames: undefined,
170
+ }),
171
+ },
172
+ },
165
173
  ],
166
174
  },
167
175
  }),
@@ -177,7 +185,10 @@ export function buildOtlpPayload(event: TelemetryEvent): OtlpExportTraceServiceR
177
185
  resource: {
178
186
  attributes: [
179
187
  { key: 'service.name', value: { stringValue: 'kubb-cli' } },
180
- { key: 'service.version', value: { stringValue: event.kubbVersion } },
188
+ {
189
+ key: 'service.version',
190
+ value: { stringValue: event.kubbVersion },
191
+ },
181
192
  { key: 'telemetry.sdk.language', value: { stringValue: 'nodejs' } },
182
193
  ],
183
194
  },
@@ -193,7 +204,9 @@ export function buildOtlpPayload(event: TelemetryEvent): OtlpExportTraceServiceR
193
204
  startTimeUnixNano: String(startTimeNs),
194
205
  endTimeUnixNano: String(endTimeNs),
195
206
  attributes,
196
- status: { code: (event.status === 'success' ? 1 : 2) satisfies OtlpStatusCode },
207
+ status: {
208
+ code: (event.status === 'success' ? 1 : 2) satisfies OtlpStatusCode,
209
+ },
197
210
  },
198
211
  ],
199
212
  },
package/bin/kubb.cjs DELETED
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env node
2
- try {
3
- const cachedSourceMaps = new Map()
4
-
5
- require('source-map-support').install({
6
- retrieveSourceMap(source) {
7
- if (cachedSourceMaps.has(source)) {
8
- return cachedSourceMaps.get(source)
9
- }
10
- return null
11
- },
12
- })
13
- } catch (_err) {}
14
-
15
- import('../dist/index.js').then(({ run }) => {
16
- process.title = 'Kubb'
17
- run(process.argv)
18
- })
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent-5mmp7QzF.js","names":["command","startCommand"],"sources":["../src/commands/agent/start.ts","../src/commands/agent.ts"],"sourcesContent":["import { defineCommand } from '@internals/utils'\nimport { version } from '../../../package.json'\nimport { agentDefaults } from '../../constants.ts'\n\nexport const command = defineCommand({\n name: 'start',\n description: 'Start the Agent server',\n options: {\n config: { type: 'string', description: 'Path to the Kubb config', short: 'c' },\n port: { type: 'string', description: `Port for the server (default: ${agentDefaults.port})`, short: 'p' },\n host: { type: 'string', description: 'Host for the server', default: agentDefaults.host },\n 'allow-write': {\n type: 'boolean',\n description: 'Allow writing generated files to the filesystem. When not set, no files are written and the config patch is not persisted.',\n default: false,\n },\n 'allow-all': { type: 'boolean', description: 'Grant all permissions (implies --allow-write).', default: false },\n },\n async run({ values }) {\n const { runAgentStart } = await import('../../runners/agent.ts')\n\n await runAgentStart({\n port: values.port !== undefined ? values.port : undefined,\n host: values.host,\n configPath: values.config,\n allowWrite: values['allow-write'],\n allowAll: values['allow-all'],\n version,\n })\n },\n})\n","import { defineCommand } from '@internals/utils'\nimport { command as startCommand } from './agent/start.ts'\n\nexport const command = defineCommand({\n name: 'agent',\n description: 'Manage the Kubb Agent server',\n subCommands: [startCommand],\n})\n"],"mappings":";;;;;;ACGA,MAAa,UAAU,cAAc;CACnC,MAAM;CACN,aAAa;CACb,aAAa,CDFQ,cAAc;EACnC,MAAM;EACN,aAAa;EACb,SAAS;GACP,QAAQ;IAAE,MAAM;IAAU,aAAa;IAA2B,OAAO;IAAK;GAC9E,MAAM;IAAE,MAAM;IAAU,aAAa,iCAAiC,cAAc,KAAK;IAAI,OAAO;IAAK;GACzG,MAAM;IAAE,MAAM;IAAU,aAAa;IAAuB,SAAS,cAAc;IAAM;GACzF,eAAe;IACb,MAAM;IACN,aAAa;IACb,SAAS;IACV;GACD,aAAa;IAAE,MAAM;IAAW,aAAa;IAAkD,SAAS;IAAO;GAChH;EACD,MAAM,IAAI,EAAE,UAAU;GACpB,MAAM,EAAE,kBAAkB,MAAM,OAAO;AAEvC,SAAM,cAAc;IAClB,MAAM,OAAO,SAAS,KAAA,IAAY,OAAO,OAAO,KAAA;IAChD,MAAM,OAAO;IACb,YAAY,OAAO;IACnB,YAAY,OAAO;IACnB,UAAU,OAAO;IACjB;IACD,CAAC;;EAEL,CAAC,CCxB2B;CAC5B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent-BKphjOIF.cjs","names":["command","defineCommand","agentDefaults","defineCommand","startCommand"],"sources":["../src/commands/agent/start.ts","../src/commands/agent.ts"],"sourcesContent":["import { defineCommand } from '@internals/utils'\nimport { version } from '../../../package.json'\nimport { agentDefaults } from '../../constants.ts'\n\nexport const command = defineCommand({\n name: 'start',\n description: 'Start the Agent server',\n options: {\n config: { type: 'string', description: 'Path to the Kubb config', short: 'c' },\n port: { type: 'string', description: `Port for the server (default: ${agentDefaults.port})`, short: 'p' },\n host: { type: 'string', description: 'Host for the server', default: agentDefaults.host },\n 'allow-write': {\n type: 'boolean',\n description: 'Allow writing generated files to the filesystem. When not set, no files are written and the config patch is not persisted.',\n default: false,\n },\n 'allow-all': { type: 'boolean', description: 'Grant all permissions (implies --allow-write).', default: false },\n },\n async run({ values }) {\n const { runAgentStart } = await import('../../runners/agent.ts')\n\n await runAgentStart({\n port: values.port !== undefined ? values.port : undefined,\n host: values.host,\n configPath: values.config,\n allowWrite: values['allow-write'],\n allowAll: values['allow-all'],\n version,\n })\n },\n})\n","import { defineCommand } from '@internals/utils'\nimport { command as startCommand } from './agent/start.ts'\n\nexport const command = defineCommand({\n name: 'agent',\n description: 'Manage the Kubb Agent server',\n subCommands: [startCommand],\n})\n"],"mappings":";;;;;AAIA,MAAaA,YAAUC,eAAAA,cAAc;CACnC,MAAM;CACN,aAAa;CACb,SAAS;EACP,QAAQ;GAAE,MAAM;GAAU,aAAa;GAA2B,OAAO;GAAK;EAC9E,MAAM;GAAE,MAAM;GAAU,aAAa,iCAAiCC,kBAAAA,cAAc,KAAK;GAAI,OAAO;GAAK;EACzG,MAAM;GAAE,MAAM;GAAU,aAAa;GAAuB,SAASA,kBAAAA,cAAc;GAAM;EACzF,eAAe;GACb,MAAM;GACN,aAAa;GACb,SAAS;GACV;EACD,aAAa;GAAE,MAAM;GAAW,aAAa;GAAkD,SAAS;GAAO;EAChH;CACD,MAAM,IAAI,EAAE,UAAU;EACpB,MAAM,EAAE,kBAAkB,MAAA,QAAA,SAAA,CAAA,WAAA,QAAM,uBAAA,CAAA;AAEhC,QAAM,cAAc;GAClB,MAAM,OAAO,SAAS,KAAA,IAAY,OAAO,OAAO,KAAA;GAChD,MAAM,OAAO;GACb,YAAY,OAAO;GACnB,YAAY,OAAO;GACnB,UAAU,OAAO;GACjB,SAAA,gBAAA;GACD,CAAC;;CAEL,CAAC;;;AC3BF,MAAa,UAAUC,eAAAA,cAAc;CACnC,MAAM;CACN,aAAa;CACb,aAAa,CAACC,UAAa;CAC5B,CAAC"}
@@ -1,92 +0,0 @@
1
- const require_chunk = require("./chunk-ByKO4r7w.cjs");
2
- const require_telemetry = require("./telemetry-DZ7IrLAU.cjs");
3
- const require_shell = require("./shell-7HPrTCJ5.cjs");
4
- const require_constants = require("./constants-D0XHAHeZ.cjs");
5
- let node_util = require("node:util");
6
- let node_path = require("node:path");
7
- node_path = require_chunk.__toESM(node_path);
8
- let node_process = require("node:process");
9
- node_process = require_chunk.__toESM(node_process);
10
- let node_net = require("node:net");
11
- node_net = require_chunk.__toESM(node_net);
12
- let node_url = require("node:url");
13
- let _clack_prompts = require("@clack/prompts");
14
- _clack_prompts = require_chunk.__toESM(_clack_prompts);
15
- //#region src/runners/agent.ts
16
- function isPortAvailable(port, host) {
17
- return new Promise((resolve) => {
18
- const server = node_net.default.createServer();
19
- server.once("error", () => resolve(false));
20
- server.once("listening", () => {
21
- server.close();
22
- resolve(true);
23
- });
24
- server.listen(port, host);
25
- });
26
- }
27
- async function runAgentStart({ port, host, configPath, allowWrite, allowAll, version }) {
28
- const hrStart = node_process.hrtime();
29
- try {
30
- try {
31
- node_process.loadEnvFile();
32
- } catch {}
33
- const agentPkgPath = (0, node_url.fileURLToPath)({}.resolve("@kubb/agent/package.json"));
34
- const agentDir = node_path.default.dirname(agentPkgPath);
35
- const serverPath = node_path.default.join(agentDir, require_constants.agentDefaults.serverEntryPath);
36
- const PORT = port !== void 0 ? port : node_process.env.PORT ?? require_constants.agentDefaults.port;
37
- const HOST = host !== require_constants.agentDefaults.host ? host : node_process.env.HOST ?? require_constants.agentDefaults.host;
38
- const KUBB_AGENT_ROOT = node_process.env.KUBB_AGENT_ROOT ?? node_process.cwd();
39
- const KUBB_AGENT_CONFIG = node_path.default.resolve(node_process.cwd(), configPath || node_process.env.KUBB_AGENT_CONFIG || require_constants.agentDefaults.configFile);
40
- const KUBB_AGENT_ALLOW_WRITE = allowAll || allowWrite ? "true" : node_process.env.KUBB_AGENT_ALLOW_WRITE ?? "false";
41
- const KUBB_AGENT_ALLOW_ALL = allowAll ? "true" : node_process.env.KUBB_AGENT_ALLOW_ALL ?? "false";
42
- const KUBB_AGENT_TOKEN = node_process.env.KUBB_AGENT_TOKEN;
43
- const KUBB_AGENT_RETRY_TIMEOUT = node_process.env.KUBB_AGENT_RETRY_TIMEOUT ?? require_constants.agentDefaults.retryTimeout;
44
- const KUBB_STUDIO_URL = node_process.env.KUBB_STUDIO_URL ?? require_constants.agentDefaults.studioUrl;
45
- const env = {
46
- ...node_process.env,
47
- PORT,
48
- HOST,
49
- KUBB_AGENT_ROOT,
50
- KUBB_AGENT_CONFIG,
51
- KUBB_AGENT_ALLOW_WRITE,
52
- KUBB_AGENT_ALLOW_ALL,
53
- KUBB_AGENT_TOKEN,
54
- KUBB_AGENT_RETRY_TIMEOUT,
55
- KUBB_STUDIO_URL
56
- };
57
- _clack_prompts.log.step((0, node_util.styleText)("cyan", "Starting agent server..."));
58
- _clack_prompts.log.info((0, node_util.styleText)("dim", `Config: ${KUBB_AGENT_CONFIG}`));
59
- _clack_prompts.log.info((0, node_util.styleText)("dim", `Host: ${HOST}`));
60
- _clack_prompts.log.info((0, node_util.styleText)("dim", `Port: ${PORT}`));
61
- if (!KUBB_AGENT_ALLOW_WRITE && !KUBB_AGENT_ALLOW_ALL) _clack_prompts.log.warn((0, node_util.styleText)("yellow", "Filesystem writes disabled. Use --allow-write or --allow-all to enable."));
62
- if (!await isPortAvailable(Number(PORT), HOST)) {
63
- _clack_prompts.log.error((0, node_util.styleText)("red", `Port ${PORT} is already in use. Stop the existing process or choose a different port with --port.`));
64
- node_process.exit(1);
65
- }
66
- console.log(env);
67
- await require_shell.spawnAsync("node", [serverPath], {
68
- env,
69
- cwd: node_process.cwd()
70
- });
71
- await require_telemetry.sendTelemetry(require_telemetry.buildTelemetryEvent({
72
- command: "agent",
73
- kubbVersion: version,
74
- hrStart,
75
- status: "success"
76
- }));
77
- } catch (error) {
78
- await require_telemetry.sendTelemetry(require_telemetry.buildTelemetryEvent({
79
- command: "agent",
80
- kubbVersion: version,
81
- hrStart,
82
- status: "failed"
83
- }));
84
- _clack_prompts.log.error((0, node_util.styleText)("red", "Failed to start agent server"));
85
- console.error(error);
86
- node_process.exit(1);
87
- }
88
- }
89
- //#endregion
90
- exports.runAgentStart = runAgentStart;
91
-
92
- //# sourceMappingURL=agent-BapvKB4r.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent-BapvKB4r.cjs","names":["net","process","path","agentDefaults","spawnAsync","sendTelemetry","buildTelemetryEvent"],"sources":["../src/runners/agent.ts"],"sourcesContent":["import net from 'node:net'\nimport path from 'node:path'\nimport * as process from 'node:process'\nimport { fileURLToPath } from 'node:url'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { spawnAsync } from '@internals/utils'\nimport { agentDefaults } from '../constants.ts'\nimport { buildTelemetryEvent, sendTelemetry } from '../utils/telemetry.ts'\n\ntype AgentStartOptions = {\n port: string | undefined\n host: string\n configPath: string | undefined\n allowWrite: boolean\n allowAll: boolean\n version: string\n}\n\nfunction isPortAvailable(port: number, host: string): Promise<boolean> {\n return new Promise((resolve) => {\n const server = net.createServer()\n server.once('error', () => resolve(false))\n server.once('listening', () => {\n server.close()\n resolve(true)\n })\n server.listen(port, host)\n })\n}\n\nexport async function runAgentStart({ port, host, configPath, allowWrite, allowAll, version }: AgentStartOptions): Promise<void> {\n const hrStart = process.hrtime()\n\n try {\n // Load .env file into process.env using Node.js built-in (v20.12.0+)\n try {\n process.loadEnvFile()\n } catch {\n // .env file may not exist; ignore\n }\n\n // Resolve the @kubb/agent package path\n const agentPkgUrl = import.meta.resolve('@kubb/agent/package.json')\n const agentPkgPath = fileURLToPath(agentPkgUrl)\n const agentDir = path.dirname(agentPkgPath)\n const serverPath = path.join(agentDir, agentDefaults.serverEntryPath)\n\n // CLI params take priority over process.env; process.env fills in what the CLI didn't specify;\n // agentDefaults are the last resort. Build env as: defaults ← process.env ← CLI.\n const PORT = port !== undefined ? port : (process.env.PORT ?? agentDefaults.port)\n const HOST = host !== agentDefaults.host ? host : (process.env.HOST ?? agentDefaults.host)\n const KUBB_AGENT_ROOT = process.env.KUBB_AGENT_ROOT ?? process.cwd()\n const KUBB_AGENT_CONFIG = path.resolve(process.cwd(), configPath || process.env.KUBB_AGENT_CONFIG || agentDefaults.configFile)\n const KUBB_AGENT_ALLOW_WRITE = allowAll || allowWrite ? 'true' : (process.env.KUBB_AGENT_ALLOW_WRITE ?? 'false')\n const KUBB_AGENT_ALLOW_ALL = allowAll ? 'true' : (process.env.KUBB_AGENT_ALLOW_ALL ?? 'false')\n const KUBB_AGENT_TOKEN = process.env.KUBB_AGENT_TOKEN\n const KUBB_AGENT_RETRY_TIMEOUT = process.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout\n const KUBB_STUDIO_URL = process.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl\n\n const env = {\n ...process.env,\n PORT,\n HOST,\n KUBB_AGENT_ROOT,\n KUBB_AGENT_CONFIG,\n KUBB_AGENT_ALLOW_WRITE,\n KUBB_AGENT_ALLOW_ALL,\n KUBB_AGENT_TOKEN,\n KUBB_AGENT_RETRY_TIMEOUT,\n KUBB_STUDIO_URL,\n }\n\n clack.log.step(styleText('cyan', 'Starting agent server...'))\n clack.log.info(styleText('dim', `Config: ${KUBB_AGENT_CONFIG}`))\n clack.log.info(styleText('dim', `Host: ${HOST}`))\n clack.log.info(styleText('dim', `Port: ${PORT}`))\n if (!KUBB_AGENT_ALLOW_WRITE && !KUBB_AGENT_ALLOW_ALL) {\n clack.log.warn(styleText('yellow', 'Filesystem writes disabled. Use --allow-write or --allow-all to enable.'))\n }\n\n if (!(await isPortAvailable(Number(PORT), HOST))) {\n clack.log.error(styleText('red', `Port ${PORT} is already in use. Stop the existing process or choose a different port with --port.`))\n process.exit(1)\n }\n\n console.log(env)\n\n // Spawns the server as a detached background process so the CLI can exit independently.\n await spawnAsync('node', [serverPath], {\n env,\n cwd: process.cwd(),\n })\n\n await sendTelemetry(buildTelemetryEvent({ command: 'agent', kubbVersion: version, hrStart, status: 'success' }))\n } catch (error) {\n await sendTelemetry(buildTelemetryEvent({ command: 'agent', kubbVersion: version, hrStart, status: 'failed' }))\n clack.log.error(styleText('red', 'Failed to start agent server'))\n console.error(error)\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,SAAS,gBAAgB,MAAc,MAAgC;AACrE,QAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,SAASA,SAAAA,QAAI,cAAc;AACjC,SAAO,KAAK,eAAe,QAAQ,MAAM,CAAC;AAC1C,SAAO,KAAK,mBAAmB;AAC7B,UAAO,OAAO;AACd,WAAQ,KAAK;IACb;AACF,SAAO,OAAO,MAAM,KAAK;GACzB;;AAGJ,eAAsB,cAAc,EAAE,MAAM,MAAM,YAAY,YAAY,UAAU,WAA6C;CAC/H,MAAM,UAAUC,aAAQ,QAAQ;AAEhC,KAAI;AAEF,MAAI;AACF,gBAAQ,aAAa;UACf;EAMR,MAAM,gBAAA,GAAA,SAAA,eAAA,EAAA,CAD0B,QAAQ,2BAA2B,CACpB;EAC/C,MAAM,WAAWC,UAAAA,QAAK,QAAQ,aAAa;EAC3C,MAAM,aAAaA,UAAAA,QAAK,KAAK,UAAUC,kBAAAA,cAAc,gBAAgB;EAIrE,MAAM,OAAO,SAAS,KAAA,IAAY,OAAQF,aAAQ,IAAI,QAAQE,kBAAAA,cAAc;EAC5E,MAAM,OAAO,SAASA,kBAAAA,cAAc,OAAO,OAAQF,aAAQ,IAAI,QAAQE,kBAAAA,cAAc;EACrF,MAAM,kBAAkBF,aAAQ,IAAI,mBAAmBA,aAAQ,KAAK;EACpE,MAAM,oBAAoBC,UAAAA,QAAK,QAAQD,aAAQ,KAAK,EAAE,cAAcA,aAAQ,IAAI,qBAAqBE,kBAAAA,cAAc,WAAW;EAC9H,MAAM,yBAAyB,YAAY,aAAa,SAAUF,aAAQ,IAAI,0BAA0B;EACxG,MAAM,uBAAuB,WAAW,SAAUA,aAAQ,IAAI,wBAAwB;EACtF,MAAM,mBAAmBA,aAAQ,IAAI;EACrC,MAAM,2BAA2BA,aAAQ,IAAI,4BAA4BE,kBAAAA,cAAc;EACvF,MAAM,kBAAkBF,aAAQ,IAAI,mBAAmBE,kBAAAA,cAAc;EAErE,MAAM,MAAM;GACV,GAAGF,aAAQ;GACX;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACD;AAED,iBAAM,IAAI,MAAA,GAAA,UAAA,WAAe,QAAQ,2BAA2B,CAAC;AAC7D,iBAAM,IAAI,MAAA,GAAA,UAAA,WAAe,OAAO,WAAW,oBAAoB,CAAC;AAChE,iBAAM,IAAI,MAAA,GAAA,UAAA,WAAe,OAAO,SAAS,OAAO,CAAC;AACjD,iBAAM,IAAI,MAAA,GAAA,UAAA,WAAe,OAAO,SAAS,OAAO,CAAC;AACjD,MAAI,CAAC,0BAA0B,CAAC,qBAC9B,gBAAM,IAAI,MAAA,GAAA,UAAA,WAAe,UAAU,0EAA0E,CAAC;AAGhH,MAAI,CAAE,MAAM,gBAAgB,OAAO,KAAK,EAAE,KAAK,EAAG;AAChD,kBAAM,IAAI,OAAA,GAAA,UAAA,WAAgB,OAAO,QAAQ,KAAK,uFAAuF,CAAC;AACtI,gBAAQ,KAAK,EAAE;;AAGjB,UAAQ,IAAI,IAAI;AAGhB,QAAMG,cAAAA,WAAW,QAAQ,CAAC,WAAW,EAAE;GACrC;GACA,KAAKH,aAAQ,KAAK;GACnB,CAAC;AAEF,QAAMI,kBAAAA,cAAcC,kBAAAA,oBAAoB;GAAE,SAAS;GAAS,aAAa;GAAS;GAAS,QAAQ;GAAW,CAAC,CAAC;UACzG,OAAO;AACd,QAAMD,kBAAAA,cAAcC,kBAAAA,oBAAoB;GAAE,SAAS;GAAS,aAAa;GAAS;GAAS,QAAQ;GAAU,CAAC,CAAC;AAC/G,iBAAM,IAAI,OAAA,GAAA,UAAA,WAAgB,OAAO,+BAA+B,CAAC;AACjE,UAAQ,MAAM,MAAM;AACpB,eAAQ,KAAK,EAAE"}
@@ -1,88 +0,0 @@
1
- import "./chunk--u3MIqq1.js";
2
- import { r as sendTelemetry, t as buildTelemetryEvent } from "./telemetry-BF3SMlH6.js";
3
- import { t as spawnAsync } from "./shell-DqqWsHCD.js";
4
- import { o as agentDefaults } from "./constants-DJM9zCXm.js";
5
- import { styleText } from "node:util";
6
- import path from "node:path";
7
- import * as process$1 from "node:process";
8
- import net from "node:net";
9
- import { fileURLToPath } from "node:url";
10
- import * as clack from "@clack/prompts";
11
- //#region src/runners/agent.ts
12
- function isPortAvailable(port, host) {
13
- return new Promise((resolve) => {
14
- const server = net.createServer();
15
- server.once("error", () => resolve(false));
16
- server.once("listening", () => {
17
- server.close();
18
- resolve(true);
19
- });
20
- server.listen(port, host);
21
- });
22
- }
23
- async function runAgentStart({ port, host, configPath, allowWrite, allowAll, version }) {
24
- const hrStart = process$1.hrtime();
25
- try {
26
- try {
27
- process$1.loadEnvFile();
28
- } catch {}
29
- const agentPkgPath = fileURLToPath(import.meta.resolve("@kubb/agent/package.json"));
30
- const agentDir = path.dirname(agentPkgPath);
31
- const serverPath = path.join(agentDir, agentDefaults.serverEntryPath);
32
- const PORT = port !== void 0 ? port : process$1.env.PORT ?? agentDefaults.port;
33
- const HOST = host !== agentDefaults.host ? host : process$1.env.HOST ?? agentDefaults.host;
34
- const KUBB_AGENT_ROOT = process$1.env.KUBB_AGENT_ROOT ?? process$1.cwd();
35
- const KUBB_AGENT_CONFIG = path.resolve(process$1.cwd(), configPath || process$1.env.KUBB_AGENT_CONFIG || agentDefaults.configFile);
36
- const KUBB_AGENT_ALLOW_WRITE = allowAll || allowWrite ? "true" : process$1.env.KUBB_AGENT_ALLOW_WRITE ?? "false";
37
- const KUBB_AGENT_ALLOW_ALL = allowAll ? "true" : process$1.env.KUBB_AGENT_ALLOW_ALL ?? "false";
38
- const KUBB_AGENT_TOKEN = process$1.env.KUBB_AGENT_TOKEN;
39
- const KUBB_AGENT_RETRY_TIMEOUT = process$1.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout;
40
- const KUBB_STUDIO_URL = process$1.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl;
41
- const env = {
42
- ...process$1.env,
43
- PORT,
44
- HOST,
45
- KUBB_AGENT_ROOT,
46
- KUBB_AGENT_CONFIG,
47
- KUBB_AGENT_ALLOW_WRITE,
48
- KUBB_AGENT_ALLOW_ALL,
49
- KUBB_AGENT_TOKEN,
50
- KUBB_AGENT_RETRY_TIMEOUT,
51
- KUBB_STUDIO_URL
52
- };
53
- clack.log.step(styleText("cyan", "Starting agent server..."));
54
- clack.log.info(styleText("dim", `Config: ${KUBB_AGENT_CONFIG}`));
55
- clack.log.info(styleText("dim", `Host: ${HOST}`));
56
- clack.log.info(styleText("dim", `Port: ${PORT}`));
57
- if (!KUBB_AGENT_ALLOW_WRITE && !KUBB_AGENT_ALLOW_ALL) clack.log.warn(styleText("yellow", "Filesystem writes disabled. Use --allow-write or --allow-all to enable."));
58
- if (!await isPortAvailable(Number(PORT), HOST)) {
59
- clack.log.error(styleText("red", `Port ${PORT} is already in use. Stop the existing process or choose a different port with --port.`));
60
- process$1.exit(1);
61
- }
62
- console.log(env);
63
- await spawnAsync("node", [serverPath], {
64
- env,
65
- cwd: process$1.cwd()
66
- });
67
- await sendTelemetry(buildTelemetryEvent({
68
- command: "agent",
69
- kubbVersion: version,
70
- hrStart,
71
- status: "success"
72
- }));
73
- } catch (error) {
74
- await sendTelemetry(buildTelemetryEvent({
75
- command: "agent",
76
- kubbVersion: version,
77
- hrStart,
78
- status: "failed"
79
- }));
80
- clack.log.error(styleText("red", "Failed to start agent server"));
81
- console.error(error);
82
- process$1.exit(1);
83
- }
84
- }
85
- //#endregion
86
- export { runAgentStart };
87
-
88
- //# sourceMappingURL=agent-CBrpIMMU.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent-CBrpIMMU.js","names":["process"],"sources":["../src/runners/agent.ts"],"sourcesContent":["import net from 'node:net'\nimport path from 'node:path'\nimport * as process from 'node:process'\nimport { fileURLToPath } from 'node:url'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { spawnAsync } from '@internals/utils'\nimport { agentDefaults } from '../constants.ts'\nimport { buildTelemetryEvent, sendTelemetry } from '../utils/telemetry.ts'\n\ntype AgentStartOptions = {\n port: string | undefined\n host: string\n configPath: string | undefined\n allowWrite: boolean\n allowAll: boolean\n version: string\n}\n\nfunction isPortAvailable(port: number, host: string): Promise<boolean> {\n return new Promise((resolve) => {\n const server = net.createServer()\n server.once('error', () => resolve(false))\n server.once('listening', () => {\n server.close()\n resolve(true)\n })\n server.listen(port, host)\n })\n}\n\nexport async function runAgentStart({ port, host, configPath, allowWrite, allowAll, version }: AgentStartOptions): Promise<void> {\n const hrStart = process.hrtime()\n\n try {\n // Load .env file into process.env using Node.js built-in (v20.12.0+)\n try {\n process.loadEnvFile()\n } catch {\n // .env file may not exist; ignore\n }\n\n // Resolve the @kubb/agent package path\n const agentPkgUrl = import.meta.resolve('@kubb/agent/package.json')\n const agentPkgPath = fileURLToPath(agentPkgUrl)\n const agentDir = path.dirname(agentPkgPath)\n const serverPath = path.join(agentDir, agentDefaults.serverEntryPath)\n\n // CLI params take priority over process.env; process.env fills in what the CLI didn't specify;\n // agentDefaults are the last resort. Build env as: defaults ← process.env ← CLI.\n const PORT = port !== undefined ? port : (process.env.PORT ?? agentDefaults.port)\n const HOST = host !== agentDefaults.host ? host : (process.env.HOST ?? agentDefaults.host)\n const KUBB_AGENT_ROOT = process.env.KUBB_AGENT_ROOT ?? process.cwd()\n const KUBB_AGENT_CONFIG = path.resolve(process.cwd(), configPath || process.env.KUBB_AGENT_CONFIG || agentDefaults.configFile)\n const KUBB_AGENT_ALLOW_WRITE = allowAll || allowWrite ? 'true' : (process.env.KUBB_AGENT_ALLOW_WRITE ?? 'false')\n const KUBB_AGENT_ALLOW_ALL = allowAll ? 'true' : (process.env.KUBB_AGENT_ALLOW_ALL ?? 'false')\n const KUBB_AGENT_TOKEN = process.env.KUBB_AGENT_TOKEN\n const KUBB_AGENT_RETRY_TIMEOUT = process.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout\n const KUBB_STUDIO_URL = process.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl\n\n const env = {\n ...process.env,\n PORT,\n HOST,\n KUBB_AGENT_ROOT,\n KUBB_AGENT_CONFIG,\n KUBB_AGENT_ALLOW_WRITE,\n KUBB_AGENT_ALLOW_ALL,\n KUBB_AGENT_TOKEN,\n KUBB_AGENT_RETRY_TIMEOUT,\n KUBB_STUDIO_URL,\n }\n\n clack.log.step(styleText('cyan', 'Starting agent server...'))\n clack.log.info(styleText('dim', `Config: ${KUBB_AGENT_CONFIG}`))\n clack.log.info(styleText('dim', `Host: ${HOST}`))\n clack.log.info(styleText('dim', `Port: ${PORT}`))\n if (!KUBB_AGENT_ALLOW_WRITE && !KUBB_AGENT_ALLOW_ALL) {\n clack.log.warn(styleText('yellow', 'Filesystem writes disabled. Use --allow-write or --allow-all to enable.'))\n }\n\n if (!(await isPortAvailable(Number(PORT), HOST))) {\n clack.log.error(styleText('red', `Port ${PORT} is already in use. Stop the existing process or choose a different port with --port.`))\n process.exit(1)\n }\n\n console.log(env)\n\n // Spawns the server as a detached background process so the CLI can exit independently.\n await spawnAsync('node', [serverPath], {\n env,\n cwd: process.cwd(),\n })\n\n await sendTelemetry(buildTelemetryEvent({ command: 'agent', kubbVersion: version, hrStart, status: 'success' }))\n } catch (error) {\n await sendTelemetry(buildTelemetryEvent({ command: 'agent', kubbVersion: version, hrStart, status: 'failed' }))\n clack.log.error(styleText('red', 'Failed to start agent server'))\n console.error(error)\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;AAmBA,SAAS,gBAAgB,MAAc,MAAgC;AACrE,QAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,SAAS,IAAI,cAAc;AACjC,SAAO,KAAK,eAAe,QAAQ,MAAM,CAAC;AAC1C,SAAO,KAAK,mBAAmB;AAC7B,UAAO,OAAO;AACd,WAAQ,KAAK;IACb;AACF,SAAO,OAAO,MAAM,KAAK;GACzB;;AAGJ,eAAsB,cAAc,EAAE,MAAM,MAAM,YAAY,YAAY,UAAU,WAA6C;CAC/H,MAAM,UAAUA,UAAQ,QAAQ;AAEhC,KAAI;AAEF,MAAI;AACF,aAAQ,aAAa;UACf;EAMR,MAAM,eAAe,cADD,OAAO,KAAK,QAAQ,2BAA2B,CACpB;EAC/C,MAAM,WAAW,KAAK,QAAQ,aAAa;EAC3C,MAAM,aAAa,KAAK,KAAK,UAAU,cAAc,gBAAgB;EAIrE,MAAM,OAAO,SAAS,KAAA,IAAY,OAAQA,UAAQ,IAAI,QAAQ,cAAc;EAC5E,MAAM,OAAO,SAAS,cAAc,OAAO,OAAQA,UAAQ,IAAI,QAAQ,cAAc;EACrF,MAAM,kBAAkBA,UAAQ,IAAI,mBAAmBA,UAAQ,KAAK;EACpE,MAAM,oBAAoB,KAAK,QAAQA,UAAQ,KAAK,EAAE,cAAcA,UAAQ,IAAI,qBAAqB,cAAc,WAAW;EAC9H,MAAM,yBAAyB,YAAY,aAAa,SAAUA,UAAQ,IAAI,0BAA0B;EACxG,MAAM,uBAAuB,WAAW,SAAUA,UAAQ,IAAI,wBAAwB;EACtF,MAAM,mBAAmBA,UAAQ,IAAI;EACrC,MAAM,2BAA2BA,UAAQ,IAAI,4BAA4B,cAAc;EACvF,MAAM,kBAAkBA,UAAQ,IAAI,mBAAmB,cAAc;EAErE,MAAM,MAAM;GACV,GAAGA,UAAQ;GACX;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACD;AAED,QAAM,IAAI,KAAK,UAAU,QAAQ,2BAA2B,CAAC;AAC7D,QAAM,IAAI,KAAK,UAAU,OAAO,WAAW,oBAAoB,CAAC;AAChE,QAAM,IAAI,KAAK,UAAU,OAAO,SAAS,OAAO,CAAC;AACjD,QAAM,IAAI,KAAK,UAAU,OAAO,SAAS,OAAO,CAAC;AACjD,MAAI,CAAC,0BAA0B,CAAC,qBAC9B,OAAM,IAAI,KAAK,UAAU,UAAU,0EAA0E,CAAC;AAGhH,MAAI,CAAE,MAAM,gBAAgB,OAAO,KAAK,EAAE,KAAK,EAAG;AAChD,SAAM,IAAI,MAAM,UAAU,OAAO,QAAQ,KAAK,uFAAuF,CAAC;AACtI,aAAQ,KAAK,EAAE;;AAGjB,UAAQ,IAAI,IAAI;AAGhB,QAAM,WAAW,QAAQ,CAAC,WAAW,EAAE;GACrC;GACA,KAAKA,UAAQ,KAAK;GACnB,CAAC;AAEF,QAAM,cAAc,oBAAoB;GAAE,SAAS;GAAS,aAAa;GAAS;GAAS,QAAQ;GAAW,CAAC,CAAC;UACzG,OAAO;AACd,QAAM,cAAc,oBAAoB;GAAE,SAAS;GAAS,aAAa;GAAS;GAAS,QAAQ;GAAU,CAAC,CAAC;AAC/G,QAAM,IAAI,MAAM,UAAU,OAAO,+BAA+B,CAAC;AACjE,UAAQ,MAAM,MAAM;AACpB,YAAQ,KAAK,EAAE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants-D0XHAHeZ.cjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["/**\n * NPM registry endpoint used to check for @kubb/cli updates.\n */\nexport const KUBB_NPM_PACKAGE_URL = 'https://registry.npmjs.org/@kubb/cli/latest' as const\n\n/**\n * OpenTelemetry ingestion endpoint for anonymous usage telemetry.\n */\nexport const OTLP_ENDPOINT = 'https://otlp.kubb.dev' as const\n\n/**\n * Horizontal rule rendered above/below the plain-logger generation summary.\n */\nexport const SUMMARY_SEPARATOR = '─'.repeat(27)\n\n/**\n * Maximum number of █ characters in a plugin timing bar.\n */\nexport const SUMMARY_MAX_BAR_LENGTH = 10 as const\n\n/**\n * Divides elapsed milliseconds into bar-length units (1 block per 100 ms).\n */\nexport const SUMMARY_TIME_SCALE_DIVISOR = 100 as const\n\n/**\n * Glob pattern for paths the file watcher ignores.\n */\nexport const WATCHER_IGNORED_PATHS = '**/{.git,node_modules}/**' as const\n\n/**\n * Flags that short-circuit execution (help/version) — no telemetry notice is shown.\n */\nexport const QUITE_FLAGS = new Set(['--help', '-h', '--version', '-v'] as const)\n\n/**\n * Flags accepted by the `generate` command.\n */\nexport const GENERATE_FLAGS = new Set(['--config', '-c', '--log-level', '-l', '--watch', '-w', '--debug', '-d', '--verbose', '-v', '--silent', '-s'] as const)\n\n/**\n * Flags accepted by the `validate` command.\n */\nexport const VALIDATE_FLAGS = new Set(['--input', '-i'] as const)\n\n/**\n * Flags accepted by the `init` command.\n */\nexport const INIT_FLAGS = new Set(['--yes', '-y'] as const)\n\n/**\n * Flags accepted by the `agent start` command.\n */\nexport const AGENT_START_FLAGS = new Set(['--config', '-c', '--port', '-p', '--host', '--allow-write', '--allow-all'] as const)\n\n/**\n * All known CLI flags across every command.\n */\nexport const ARGS = new Set([...QUITE_FLAGS, ...GENERATE_FLAGS, ...VALIDATE_FLAGS, ...INIT_FLAGS, ...AGENT_START_FLAGS] as const)\n\nexport const agentDefaults = {\n port: '3000',\n host: 'localhost',\n configFile: 'kubb.config.ts',\n retryTimeout: '30000',\n studioUrl: 'https://studio.kubb.dev',\n /**\n * Relative path from the @kubb/agent package root to the server entry.\n */\n serverEntryPath: '.output/server/index.mjs',\n} as const\n\n/**\n * Default values used during interactive `init` scaffolding.\n */\nexport const initDefaults = {\n inputPath: './openapi.yaml',\n outputPath: './src/gen',\n plugins: ['plugin-oas', 'plugin-ts'],\n} as const\n\n/**\n * Maps each plugin value to the default config snippet inserted by `init`.\n * The `satisfies` constraint ensures all values remain plain strings while\n * `as const` keeps the object deeply immutable.\n */\nexport const pluginDefaultConfigs = {\n 'plugin-oas': 'pluginOas()',\n 'plugin-ts': `pluginTs({\n output: { path: 'models' },\n })`,\n 'plugin-client': `pluginClient({\n output: { path: 'clients' },\n })`,\n 'plugin-react-query': `pluginReactQuery({\n output: { path: 'hooks' },\n })`,\n 'plugin-solid-query': `pluginSolidQuery({\n output: { path: 'hooks' },\n })`,\n 'plugin-svelte-query': `pluginSvelteQuery({\n output: { path: 'hooks' },\n })`,\n 'plugin-vue-query': `pluginVueQuery({\n output: { path: 'hooks' },\n })`,\n 'plugin-swr': `pluginSwr({\n output: { path: 'hooks' },\n })`,\n 'plugin-zod': `pluginZod({\n output: { path: 'zod' },\n })`,\n 'plugin-faker': `pluginFaker({\n output: { path: 'mocks' },\n })`,\n 'plugin-msw': `pluginMsw({\n output: { path: 'msw' },\n })`,\n} as const satisfies Record<string, string>\n\n/**\n * Color palette used by randomCliColor() for deterministic plugin name coloring.\n */\n"],"mappings":";;;;AAGA,MAAa,uBAAuB;;;;AAKpC,MAAa,gBAAgB;;;;AAK7B,MAAa,oBAAoB,IAAI,OAAO,GAAG;;;;AAe/C,MAAa,wBAAwB;;;;AAKrC,MAAa,cAAc,IAAI,IAAI;CAAC;CAAU;CAAM;CAAa;CAAK,CAAU;;;;AAKhF,MAAa,iBAAiB,IAAI,IAAI;CAAC;CAAY;CAAM;CAAe;CAAM;CAAW;CAAM;CAAW;CAAM;CAAa;CAAM;CAAY;CAAK,CAAU;;;;AAK9J,MAAa,iBAAiB,IAAI,IAAI,CAAC,WAAW,KAAK,CAAU;;;;AAKjE,MAAa,aAAa,IAAI,IAAI,CAAC,SAAS,KAAK,CAAU;;;;AAK3D,MAAa,oBAAoB,IAAI,IAAI;CAAC;CAAY;CAAM;CAAU;CAAM;CAAU;CAAiB;CAAc,CAAU;AAK3G,IAAI,IAAI;CAAC,GAAG;CAAa,GAAG;CAAgB,GAAG;CAAgB,GAAG;CAAY,GAAG;CAAkB,CAAU;AAEjI,MAAa,gBAAgB;CAC3B,MAAM;CACN,MAAM;CACN,YAAY;CACZ,cAAc;CACd,WAAW;CAIX,iBAAiB;CAClB;;;;AAKD,MAAa,eAAe;CAC1B,WAAW;CACX,YAAY;CACZ,SAAS,CAAC,cAAc,YAAY;CACrC;;;;;;AAOD,MAAa,uBAAuB;CAClC,cAAc;CACd,aAAa;;;CAGb,iBAAiB;;;CAGjB,sBAAsB;;;CAGtB,sBAAsB;;;CAGtB,uBAAuB;;;CAGvB,oBAAoB;;;CAGpB,cAAc;;;CAGd,cAAc;;;CAGd,gBAAgB;;;CAGhB,cAAc;;;CAGf"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants-DJM9zCXm.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["/**\n * NPM registry endpoint used to check for @kubb/cli updates.\n */\nexport const KUBB_NPM_PACKAGE_URL = 'https://registry.npmjs.org/@kubb/cli/latest' as const\n\n/**\n * OpenTelemetry ingestion endpoint for anonymous usage telemetry.\n */\nexport const OTLP_ENDPOINT = 'https://otlp.kubb.dev' as const\n\n/**\n * Horizontal rule rendered above/below the plain-logger generation summary.\n */\nexport const SUMMARY_SEPARATOR = '─'.repeat(27)\n\n/**\n * Maximum number of █ characters in a plugin timing bar.\n */\nexport const SUMMARY_MAX_BAR_LENGTH = 10 as const\n\n/**\n * Divides elapsed milliseconds into bar-length units (1 block per 100 ms).\n */\nexport const SUMMARY_TIME_SCALE_DIVISOR = 100 as const\n\n/**\n * Glob pattern for paths the file watcher ignores.\n */\nexport const WATCHER_IGNORED_PATHS = '**/{.git,node_modules}/**' as const\n\n/**\n * Flags that short-circuit execution (help/version) — no telemetry notice is shown.\n */\nexport const QUITE_FLAGS = new Set(['--help', '-h', '--version', '-v'] as const)\n\n/**\n * Flags accepted by the `generate` command.\n */\nexport const GENERATE_FLAGS = new Set(['--config', '-c', '--log-level', '-l', '--watch', '-w', '--debug', '-d', '--verbose', '-v', '--silent', '-s'] as const)\n\n/**\n * Flags accepted by the `validate` command.\n */\nexport const VALIDATE_FLAGS = new Set(['--input', '-i'] as const)\n\n/**\n * Flags accepted by the `init` command.\n */\nexport const INIT_FLAGS = new Set(['--yes', '-y'] as const)\n\n/**\n * Flags accepted by the `agent start` command.\n */\nexport const AGENT_START_FLAGS = new Set(['--config', '-c', '--port', '-p', '--host', '--allow-write', '--allow-all'] as const)\n\n/**\n * All known CLI flags across every command.\n */\nexport const ARGS = new Set([...QUITE_FLAGS, ...GENERATE_FLAGS, ...VALIDATE_FLAGS, ...INIT_FLAGS, ...AGENT_START_FLAGS] as const)\n\nexport const agentDefaults = {\n port: '3000',\n host: 'localhost',\n configFile: 'kubb.config.ts',\n retryTimeout: '30000',\n studioUrl: 'https://studio.kubb.dev',\n /**\n * Relative path from the @kubb/agent package root to the server entry.\n */\n serverEntryPath: '.output/server/index.mjs',\n} as const\n\n/**\n * Default values used during interactive `init` scaffolding.\n */\nexport const initDefaults = {\n inputPath: './openapi.yaml',\n outputPath: './src/gen',\n plugins: ['plugin-oas', 'plugin-ts'],\n} as const\n\n/**\n * Maps each plugin value to the default config snippet inserted by `init`.\n * The `satisfies` constraint ensures all values remain plain strings while\n * `as const` keeps the object deeply immutable.\n */\nexport const pluginDefaultConfigs = {\n 'plugin-oas': 'pluginOas()',\n 'plugin-ts': `pluginTs({\n output: { path: 'models' },\n })`,\n 'plugin-client': `pluginClient({\n output: { path: 'clients' },\n })`,\n 'plugin-react-query': `pluginReactQuery({\n output: { path: 'hooks' },\n })`,\n 'plugin-solid-query': `pluginSolidQuery({\n output: { path: 'hooks' },\n })`,\n 'plugin-svelte-query': `pluginSvelteQuery({\n output: { path: 'hooks' },\n })`,\n 'plugin-vue-query': `pluginVueQuery({\n output: { path: 'hooks' },\n })`,\n 'plugin-swr': `pluginSwr({\n output: { path: 'hooks' },\n })`,\n 'plugin-zod': `pluginZod({\n output: { path: 'zod' },\n })`,\n 'plugin-faker': `pluginFaker({\n output: { path: 'mocks' },\n })`,\n 'plugin-msw': `pluginMsw({\n output: { path: 'msw' },\n })`,\n} as const satisfies Record<string, string>\n\n/**\n * Color palette used by randomCliColor() for deterministic plugin name coloring.\n */\n"],"mappings":";;;;AAGA,MAAa,uBAAuB;;;;AAKpC,MAAa,gBAAgB;;;;AAK7B,MAAa,oBAAoB,IAAI,OAAO,GAAG;;;;AAe/C,MAAa,wBAAwB;;;;AAKrC,MAAa,cAAc,IAAI,IAAI;CAAC;CAAU;CAAM;CAAa;CAAK,CAAU;;;;AAKhF,MAAa,iBAAiB,IAAI,IAAI;CAAC;CAAY;CAAM;CAAe;CAAM;CAAW;CAAM;CAAW;CAAM;CAAa;CAAM;CAAY;CAAK,CAAU;;;;AAK9J,MAAa,iBAAiB,IAAI,IAAI,CAAC,WAAW,KAAK,CAAU;;;;AAKjE,MAAa,aAAa,IAAI,IAAI,CAAC,SAAS,KAAK,CAAU;;;;AAK3D,MAAa,oBAAoB,IAAI,IAAI;CAAC;CAAY;CAAM;CAAU;CAAM;CAAU;CAAiB;CAAc,CAAU;AAK3G,IAAI,IAAI;CAAC,GAAG;CAAa,GAAG;CAAgB,GAAG;CAAgB,GAAG;CAAY,GAAG;CAAkB,CAAU;AAEjI,MAAa,gBAAgB;CAC3B,MAAM;CACN,MAAM;CACN,YAAY;CACZ,cAAc;CACd,WAAW;CAIX,iBAAiB;CAClB;;;;AAKD,MAAa,eAAe;CAC1B,WAAW;CACX,YAAY;CACZ,SAAS,CAAC,cAAc,YAAY;CACrC;;;;;;AAOD,MAAa,uBAAuB;CAClC,cAAc;CACd,aAAa;;;CAGb,iBAAiB;;;CAGjB,sBAAsB;;;CAGtB,sBAAsB;;;CAGtB,uBAAuB;;;CAGvB,oBAAoB;;;CAGpB,cAAc;;;CAGd,cAAc;;;CAGd,gBAAgB;;;CAGhB,cAAc;;;CAGf"}
@@ -1,25 +0,0 @@
1
- import "./chunk--u3MIqq1.js";
2
- //#region ../../internals/utils/src/cli/define.ts
3
- /** Returns a `CLIAdapter` with type inference. Pass a different adapter to `createCLI` to swap the CLI engine. */
4
- function defineCLIAdapter(adapter) {
5
- return adapter;
6
- }
7
- /**
8
- * Returns a `CommandDefinition` with typed `values` in `run()`.
9
- * The callback receives `values` typed from the declared options — no casts needed.
10
- */
11
- function defineCommand(def) {
12
- const { run, ...rest } = def;
13
- if (!run) return rest;
14
- return {
15
- ...rest,
16
- run: (args) => run({
17
- values: args.values,
18
- positionals: args.positionals
19
- })
20
- };
21
- }
22
- //#endregion
23
- export { defineCommand as n, defineCLIAdapter as t };
24
-
25
- //# sourceMappingURL=define--M_JMcDC.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"define--M_JMcDC.js","names":[],"sources":["../../../internals/utils/src/cli/define.ts"],"sourcesContent":["import type { CLIAdapter, CommandDefinition, OptionDefinition } from './types.ts'\n\ntype OptionTypeMap = { string: string; boolean: boolean }\n\ntype IsRequired<O extends OptionDefinition> = O['default'] extends string | boolean ? true : O['required'] extends true ? true : false\n\n/** Infers typed values from an options record. Options with a `default` or `required: true` are always defined. */\ntype InferValues<O extends Record<string, OptionDefinition>> = {\n [K in keyof O as IsRequired<O[K]> extends true ? K : never]: OptionTypeMap[O[K]['type']]\n} & {\n [K in keyof O as IsRequired<O[K]> extends true ? never : K]?: OptionTypeMap[O[K]['type']]\n}\n\n/** Returns a `CLIAdapter` with type inference. Pass a different adapter to `createCLI` to swap the CLI engine. */\nexport function defineCLIAdapter(adapter: CLIAdapter): CLIAdapter {\n return adapter\n}\n\n/**\n * Returns a `CommandDefinition` with typed `values` in `run()`.\n * The callback receives `values` typed from the declared options — no casts needed.\n */\nexport function defineCommand<O extends Record<string, OptionDefinition>>(def: {\n name: string\n description: string\n arguments?: string[]\n options?: O\n subCommands?: CommandDefinition[]\n run?: (args: { values: InferValues<O>; positionals: string[] }) => Promise<void>\n}): CommandDefinition {\n const { run, ...rest } = def\n if (!run) return rest\n return {\n ...rest,\n run: (args) => run({ values: args.values as InferValues<O>, positionals: args.positionals }),\n }\n}\n"],"mappings":";;;AAcA,SAAgB,iBAAiB,SAAiC;AAChE,QAAO;;;;;;AAOT,SAAgB,cAA0D,KAOpD;CACpB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,KAAI,CAAC,IAAK,QAAO;AACjB,QAAO;EACL,GAAG;EACH,MAAM,SAAS,IAAI;GAAE,QAAQ,KAAK;GAA0B,aAAa,KAAK;GAAa,CAAC;EAC7F"}
@@ -1,36 +0,0 @@
1
- require("./chunk-ByKO4r7w.cjs");
2
- //#region ../../internals/utils/src/cli/define.ts
3
- /** Returns a `CLIAdapter` with type inference. Pass a different adapter to `createCLI` to swap the CLI engine. */
4
- function defineCLIAdapter(adapter) {
5
- return adapter;
6
- }
7
- /**
8
- * Returns a `CommandDefinition` with typed `values` in `run()`.
9
- * The callback receives `values` typed from the declared options — no casts needed.
10
- */
11
- function defineCommand(def) {
12
- const { run, ...rest } = def;
13
- if (!run) return rest;
14
- return {
15
- ...rest,
16
- run: (args) => run({
17
- values: args.values,
18
- positionals: args.positionals
19
- })
20
- };
21
- }
22
- //#endregion
23
- Object.defineProperty(exports, "defineCLIAdapter", {
24
- enumerable: true,
25
- get: function() {
26
- return defineCLIAdapter;
27
- }
28
- });
29
- Object.defineProperty(exports, "defineCommand", {
30
- enumerable: true,
31
- get: function() {
32
- return defineCommand;
33
- }
34
- });
35
-
36
- //# sourceMappingURL=define-D6Kfm7-Z.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"define-D6Kfm7-Z.cjs","names":[],"sources":["../../../internals/utils/src/cli/define.ts"],"sourcesContent":["import type { CLIAdapter, CommandDefinition, OptionDefinition } from './types.ts'\n\ntype OptionTypeMap = { string: string; boolean: boolean }\n\ntype IsRequired<O extends OptionDefinition> = O['default'] extends string | boolean ? true : O['required'] extends true ? true : false\n\n/** Infers typed values from an options record. Options with a `default` or `required: true` are always defined. */\ntype InferValues<O extends Record<string, OptionDefinition>> = {\n [K in keyof O as IsRequired<O[K]> extends true ? K : never]: OptionTypeMap[O[K]['type']]\n} & {\n [K in keyof O as IsRequired<O[K]> extends true ? never : K]?: OptionTypeMap[O[K]['type']]\n}\n\n/** Returns a `CLIAdapter` with type inference. Pass a different adapter to `createCLI` to swap the CLI engine. */\nexport function defineCLIAdapter(adapter: CLIAdapter): CLIAdapter {\n return adapter\n}\n\n/**\n * Returns a `CommandDefinition` with typed `values` in `run()`.\n * The callback receives `values` typed from the declared options — no casts needed.\n */\nexport function defineCommand<O extends Record<string, OptionDefinition>>(def: {\n name: string\n description: string\n arguments?: string[]\n options?: O\n subCommands?: CommandDefinition[]\n run?: (args: { values: InferValues<O>; positionals: string[] }) => Promise<void>\n}): CommandDefinition {\n const { run, ...rest } = def\n if (!run) return rest\n return {\n ...rest,\n run: (args) => run({ values: args.values as InferValues<O>, positionals: args.positionals }),\n }\n}\n"],"mappings":";;;AAcA,SAAgB,iBAAiB,SAAiC;AAChE,QAAO;;;;;;AAOT,SAAgB,cAA0D,KAOpD;CACpB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,KAAI,CAAC,IAAK,QAAO;AACjB,QAAO;EACL,GAAG;EACH,MAAM,SAAS,IAAI;GAAE,QAAQ,KAAK;GAA0B,aAAa,KAAK;GAAa,CAAC;EAC7F"}