@kubb/cli 5.0.0-alpha.7 → 5.0.0-alpha.71

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 (138) hide show
  1. package/README.md +4 -2
  2. package/bin/kubb.js +6 -0
  3. package/dist/agent-CouS-H2S.js +112 -0
  4. package/dist/agent-CouS-H2S.js.map +1 -0
  5. package/dist/{agent-Cc-0-A8t.cjs → agent-D5OIwM0z.cjs} +5 -5
  6. package/dist/agent-D5OIwM0z.cjs.map +1 -0
  7. package/dist/{agent-CjXjyuPe.js → agent-DypvJBwO.js} +5 -5
  8. package/dist/agent-DypvJBwO.js.map +1 -0
  9. package/dist/agent-Zo8CQwxZ.cjs +116 -0
  10. package/dist/agent-Zo8CQwxZ.cjs.map +1 -0
  11. package/dist/{constants-BTUap0zs.cjs → constants-BgLUQ1nx.cjs} +50 -9
  12. package/dist/constants-BgLUQ1nx.cjs.map +1 -0
  13. package/dist/{constants-CM3dJzjK.js → constants-mIdg9ls2.js} +39 -10
  14. package/dist/constants-mIdg9ls2.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-BP0WpC20.cjs → generate-BW0J1wvg.cjs} +3 -3
  24. package/dist/generate-BW0J1wvg.cjs.map +1 -0
  25. package/dist/{generate-yOyKmo19.cjs → generate-CLYhWYY1.cjs} +553 -251
  26. package/dist/generate-CLYhWYY1.cjs.map +1 -0
  27. package/dist/{generate-BX6LmxKo.js → generate-Cy11Ra5n.js} +3 -3
  28. package/dist/generate-Cy11Ra5n.js.map +1 -0
  29. package/dist/{generate-BYqhZfbq.js → generate-DfhKa1mG.js} +546 -244
  30. package/dist/generate-DfhKa1mG.js.map +1 -0
  31. package/dist/index.cjs +49 -21
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.ts +1 -1
  34. package/dist/index.js +49 -21
  35. package/dist/index.js.map +1 -1
  36. package/dist/{init-DkwG4Gbs.cjs → init-C_EgqqO4.cjs} +4 -4
  37. package/dist/init-C_EgqqO4.cjs.map +1 -0
  38. package/dist/{init-BqkRvRTM.js → init-CaQZcAvy.js} +4 -4
  39. package/dist/init-CaQZcAvy.js.map +1 -0
  40. package/dist/{init-hmolV6B4.cjs → init-CmrUd26x.cjs} +31 -21
  41. package/dist/init-CmrUd26x.cjs.map +1 -0
  42. package/dist/{init-C-InrmSY.js → init-DEC1gCsk.js} +27 -17
  43. package/dist/init-DEC1gCsk.js.map +1 -0
  44. package/dist/{mcp-Cqn_PHUg.js → mcp-7rBVhoQz.js} +4 -4
  45. package/dist/{mcp-Cqn_PHUg.js.map → mcp-7rBVhoQz.js.map} +1 -1
  46. package/dist/{mcp-BnEafD5r.cjs → mcp-CmXrXzDF.cjs} +4 -4
  47. package/dist/{mcp-BnEafD5r.cjs.map → mcp-CmXrXzDF.cjs.map} +1 -1
  48. package/dist/{mcp-D2SHEg_d.js → mcp-nlFo36z0.js} +4 -5
  49. package/dist/mcp-nlFo36z0.js.map +1 -0
  50. package/dist/{mcp-ChHFPRzD.cjs → mcp-vi8t2Rkb.cjs} +5 -6
  51. package/dist/mcp-vi8t2Rkb.cjs.map +1 -0
  52. package/dist/package-BD90dOVc.js +6 -0
  53. package/dist/package-BD90dOVc.js.map +1 -0
  54. package/dist/{package-DZb6I8FQ.cjs → package-DsKVMEXO.cjs} +2 -2
  55. package/dist/package-DsKVMEXO.cjs.map +1 -0
  56. package/dist/{shell-7HPrTCJ5.cjs → shell-475fQKaX.cjs} +8 -3
  57. package/dist/shell-475fQKaX.cjs.map +1 -0
  58. package/dist/{shell-DqqWsHCD.js → shell-DLzN4fRo.js} +8 -3
  59. package/dist/shell-DLzN4fRo.js.map +1 -0
  60. package/dist/{telemetry-DxiR7clS.js → telemetry-CS5ZE0cN.js} +48 -6
  61. package/dist/telemetry-CS5ZE0cN.js.map +1 -0
  62. package/dist/{telemetry-Cn9X1I5B.cjs → telemetry-kmnc5OAT.cjs} +50 -8
  63. package/dist/telemetry-kmnc5OAT.cjs.map +1 -0
  64. package/dist/{validate-l8vLmwKA.js → validate-BR_0eveE.js} +5 -13
  65. package/dist/validate-BR_0eveE.js.map +1 -0
  66. package/dist/{validate-9FoHgtvi.cjs → validate-BZKRjT0Y.cjs} +4 -4
  67. package/dist/validate-BZKRjT0Y.cjs.map +1 -0
  68. package/dist/{validate-Bbrn3Q-A.cjs → validate-Db7vfaU9.cjs} +6 -14
  69. package/dist/validate-Db7vfaU9.cjs.map +1 -0
  70. package/dist/{validate-Bgqwmhir.js → validate-RG85Fqjh.js} +4 -4
  71. package/dist/validate-RG85Fqjh.js.map +1 -0
  72. package/package.json +47 -46
  73. package/src/commands/agent/start.ts +20 -4
  74. package/src/commands/generate.ts +35 -6
  75. package/src/commands/init.ts +6 -1
  76. package/src/commands/validate.ts +6 -1
  77. package/src/constants.ts +40 -11
  78. package/src/index.ts +10 -12
  79. package/src/loggers/clackLogger.ts +54 -46
  80. package/src/loggers/fileSystemLogger.ts +13 -11
  81. package/src/loggers/githubActionsLogger.ts +22 -22
  82. package/src/loggers/plainLogger.ts +21 -21
  83. package/src/runners/agent.ts +81 -34
  84. package/src/runners/generate.ts +90 -100
  85. package/src/runners/init.ts +9 -9
  86. package/src/runners/mcp.ts +17 -4
  87. package/src/runners/validate.ts +19 -15
  88. package/src/types.ts +11 -0
  89. package/src/utils/executeHooks.ts +15 -15
  90. package/src/utils/flags.ts +10 -0
  91. package/src/utils/getConfig.ts +10 -0
  92. package/src/utils/getCosmiConfig.ts +21 -12
  93. package/src/utils/getSummary.ts +1 -1
  94. package/src/utils/runHook.ts +28 -10
  95. package/src/utils/telemetry.ts +16 -3
  96. package/bin/kubb.cjs +0 -18
  97. package/dist/agent-C6o_6GSJ.cjs +0 -92
  98. package/dist/agent-C6o_6GSJ.cjs.map +0 -1
  99. package/dist/agent-Cc-0-A8t.cjs.map +0 -1
  100. package/dist/agent-CjXjyuPe.js.map +0 -1
  101. package/dist/agent-L50VNhXv.js +0 -88
  102. package/dist/agent-L50VNhXv.js.map +0 -1
  103. package/dist/constants-BTUap0zs.cjs.map +0 -1
  104. package/dist/constants-CM3dJzjK.js.map +0 -1
  105. package/dist/define--M_JMcDC.js +0 -25
  106. package/dist/define--M_JMcDC.js.map +0 -1
  107. package/dist/define-D6Kfm7-Z.cjs +0 -36
  108. package/dist/define-D6Kfm7-Z.cjs.map +0 -1
  109. package/dist/errors-6mF_WKxg.js +0 -27
  110. package/dist/errors-6mF_WKxg.js.map +0 -1
  111. package/dist/errors-DBW0N9w4.cjs.map +0 -1
  112. package/dist/generate-BP0WpC20.cjs.map +0 -1
  113. package/dist/generate-BX6LmxKo.js.map +0 -1
  114. package/dist/generate-BYqhZfbq.js.map +0 -1
  115. package/dist/generate-yOyKmo19.cjs.map +0 -1
  116. package/dist/init-BqkRvRTM.js.map +0 -1
  117. package/dist/init-C-InrmSY.js.map +0 -1
  118. package/dist/init-DkwG4Gbs.cjs.map +0 -1
  119. package/dist/init-hmolV6B4.cjs.map +0 -1
  120. package/dist/jiti-Cd3S0xwr.cjs +0 -16
  121. package/dist/jiti-Cd3S0xwr.cjs.map +0 -1
  122. package/dist/jiti-e08mD2Ph.js +0 -11
  123. package/dist/jiti-e08mD2Ph.js.map +0 -1
  124. package/dist/mcp-ChHFPRzD.cjs.map +0 -1
  125. package/dist/mcp-D2SHEg_d.js.map +0 -1
  126. package/dist/package-DLd3fZNd.js +0 -6
  127. package/dist/package-DLd3fZNd.js.map +0 -1
  128. package/dist/package-DZb6I8FQ.cjs.map +0 -1
  129. package/dist/shell-7HPrTCJ5.cjs.map +0 -1
  130. package/dist/shell-DqqWsHCD.js.map +0 -1
  131. package/dist/telemetry-Cn9X1I5B.cjs.map +0 -1
  132. package/dist/telemetry-DxiR7clS.js.map +0 -1
  133. package/dist/validate-9FoHgtvi.cjs.map +0 -1
  134. package/dist/validate-Bbrn3Q-A.cjs.map +0 -1
  135. package/dist/validate-Bgqwmhir.js.map +0 -1
  136. package/dist/validate-l8vLmwKA.js.map +0 -1
  137. package/src/utils/getIntro.ts +0 -1
  138. package/src/utils/jiti.ts +0 -9
package/README.md CHANGED
@@ -4,12 +4,12 @@
4
4
  <img width="180" src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/logo.png" alt="Kubb logo">
5
5
  </a>
6
6
 
7
-
8
7
  [![npm version][npm-version-src]][npm-version-href]
9
8
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
10
9
  [![Coverage][coverage-src]][coverage-href]
11
10
  [![License][license-src]][license-href]
12
11
  [![Sponsors][sponsors-src]][sponsors-href]
12
+
13
13
  <h4>
14
14
  <a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a>
15
15
  <span> · </span>
@@ -38,11 +38,13 @@ npx kubb init -y
38
38
  ```
39
39
 
40
40
  Defaults when using `-y`:
41
+
41
42
  - Input path: `./openapi.yaml`
42
43
  - Output path: `./src/gen`
43
44
  - Plugins: OpenAPI Parser + TypeScript
44
45
 
45
46
  This command will:
47
+
46
48
  1. Detect or create a `package.json` if it doesn't exist
47
49
  2. Prompt you for your OpenAPI specification path (default: `./openapi.yaml`)
48
50
  3. Ask for the output directory for generated files (default: `./src/gen`)
@@ -59,6 +61,7 @@ npx kubb generate
59
61
  ```
60
62
 
61
63
  Options:
64
+
62
65
  - `-c, --config <path>` - Path to the Kubb config file
63
66
  - `-l, --logLevel <level>` - Set log level (silent, info, verbose, debug)
64
67
  - `-w, --watch` - Watch mode based on the input file
@@ -94,7 +97,6 @@ Kubb uses an MIT-licensed open source project with its ongoing development made
94
97
  </a>
95
98
  </p>
96
99
 
97
-
98
100
  <!-- Badges -->
99
101
 
100
102
  [npm-version-src]: https://img.shields.io/npm/v/@kubb/cli?flat&colorA=18181B&colorB=f58517
package/bin/kubb.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ process.setSourceMapsEnabled?.(true)
3
+
4
+ const { run } = await import('../dist/index.js')
5
+ process.title = 'Kubb'
6
+ run(process.argv)
@@ -0,0 +1,112 @@
1
+ import "./chunk--u3MIqq1.js";
2
+ import { r as sendTelemetry, t as buildTelemetryEvent } from "./telemetry-CS5ZE0cN.js";
3
+ import { t as spawnAsync } from "./shell-DLzN4fRo.js";
4
+ import { s as agentDefaults } from "./constants-mIdg9ls2.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
+ /**
13
+ * Resolves the environment passed to the detached agent process using CLI values first, then environment values, then CLI defaults.
14
+ */
15
+ function resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }) {
16
+ const resolvedPort = port ?? process$1.env.PORT ?? agentDefaults.port;
17
+ const resolvedHost = host !== agentDefaults.host ? host : process$1.env.HOST ?? agentDefaults.host;
18
+ const resolvedAllowAll = allowAll || process$1.env.KUBB_AGENT_ALLOW_ALL === "true";
19
+ const resolvedAllowWrite = resolvedAllowAll || allowWrite || process$1.env.KUBB_AGENT_ALLOW_WRITE === "true";
20
+ const agentRoot = process$1.env.KUBB_AGENT_ROOT ?? process$1.cwd();
21
+ const agentConfigPath = path.resolve(process$1.cwd(), configPath || process$1.env.KUBB_AGENT_CONFIG || agentDefaults.configFile);
22
+ return {
23
+ port: resolvedPort,
24
+ host: resolvedHost,
25
+ allowWrite: resolvedAllowWrite,
26
+ allowAll: resolvedAllowAll,
27
+ agentConfigPath,
28
+ env: {
29
+ ...process$1.env,
30
+ PORT: resolvedPort,
31
+ HOST: resolvedHost,
32
+ KUBB_AGENT_ROOT: agentRoot,
33
+ KUBB_AGENT_CONFIG: agentConfigPath,
34
+ KUBB_AGENT_ALLOW_WRITE: String(resolvedAllowWrite),
35
+ KUBB_AGENT_ALLOW_ALL: String(resolvedAllowAll),
36
+ KUBB_AGENT_TOKEN: process$1.env.KUBB_AGENT_TOKEN,
37
+ KUBB_AGENT_RETRY_TIMEOUT: process$1.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout,
38
+ KUBB_STUDIO_URL: process$1.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl
39
+ }
40
+ };
41
+ }
42
+ function isPortAvailable(port, host) {
43
+ return new Promise((resolve) => {
44
+ const server = net.createServer();
45
+ server.once("error", () => resolve(false));
46
+ server.once("listening", () => {
47
+ server.close();
48
+ resolve(true);
49
+ });
50
+ server.listen(port, host);
51
+ });
52
+ }
53
+ async function runAgentStart({ port, host, configPath, allowWrite, allowAll, version }) {
54
+ const hrStart = process$1.hrtime();
55
+ try {
56
+ try {
57
+ process$1.loadEnvFile();
58
+ } catch {}
59
+ let agentPkgUrl;
60
+ try {
61
+ agentPkgUrl = import.meta.resolve("@kubb/agent/package.json");
62
+ } catch (_e) {
63
+ console.error(`Import of '@kubb/agent' is required to start the Agent server`);
64
+ process$1.exit(1);
65
+ }
66
+ const agentPkgPath = fileURLToPath(agentPkgUrl);
67
+ const agentDir = path.dirname(agentPkgPath);
68
+ const serverPath = path.join(agentDir, agentDefaults.serverEntryPath);
69
+ const resolvedEnv = resolveAgentStartEnvironment({
70
+ port,
71
+ host,
72
+ configPath,
73
+ allowWrite,
74
+ allowAll
75
+ });
76
+ const numericPort = Number(resolvedEnv.port);
77
+ if (!Number.isInteger(numericPort) || numericPort <= 0) throw new Error(`Invalid port "${resolvedEnv.port}". Provide a positive integer with --port or PORT.`);
78
+ clack.log.step(styleText("cyan", "Starting agent server..."));
79
+ clack.log.info(styleText("dim", `Config: ${resolvedEnv.agentConfigPath}`));
80
+ clack.log.info(styleText("dim", `Host: ${resolvedEnv.host}`));
81
+ clack.log.info(styleText("dim", `Port: ${resolvedEnv.port}`));
82
+ if (!resolvedEnv.allowWrite && !resolvedEnv.allowAll) clack.log.warn(styleText("yellow", "Filesystem writes disabled. Use --allow-write or --allow-all to enable."));
83
+ if (!await isPortAvailable(numericPort, resolvedEnv.host)) {
84
+ clack.log.error(styleText("red", `Port ${resolvedEnv.port} is already in use. Stop the existing process or choose a different port with --port.`));
85
+ process$1.exit(1);
86
+ }
87
+ await spawnAsync("node", [serverPath], {
88
+ env: resolvedEnv.env,
89
+ cwd: process$1.cwd()
90
+ });
91
+ await sendTelemetry(buildTelemetryEvent({
92
+ command: "agent",
93
+ kubbVersion: version,
94
+ hrStart,
95
+ status: "success"
96
+ }));
97
+ } catch (error) {
98
+ await sendTelemetry(buildTelemetryEvent({
99
+ command: "agent",
100
+ kubbVersion: version,
101
+ hrStart,
102
+ status: "failed"
103
+ }));
104
+ clack.log.error(styleText("red", "Failed to start agent server"));
105
+ console.error(error);
106
+ process$1.exit(1);
107
+ }
108
+ }
109
+ //#endregion
110
+ export { runAgentStart };
111
+
112
+ //# sourceMappingURL=agent-CouS-H2S.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-CouS-H2S.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\ntype ResolvedAgentStartEnvironment = {\n port: string\n host: string\n allowWrite: boolean\n allowAll: boolean\n agentConfigPath: string\n env: NodeJS.ProcessEnv\n}\n\n/**\n * Resolves the environment passed to the detached agent process using CLI values first, then environment values, then CLI defaults.\n */\nfunction resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }: Omit<AgentStartOptions, 'version'>): ResolvedAgentStartEnvironment {\n const resolvedPort = port ?? process.env.PORT ?? agentDefaults.port\n const resolvedHost = host !== agentDefaults.host ? host : (process.env.HOST ?? agentDefaults.host)\n const resolvedAllowAll = allowAll || process.env.KUBB_AGENT_ALLOW_ALL === 'true'\n const resolvedAllowWrite = resolvedAllowAll || allowWrite || process.env.KUBB_AGENT_ALLOW_WRITE === 'true'\n const agentRoot = process.env.KUBB_AGENT_ROOT ?? process.cwd()\n const agentConfigPath = path.resolve(process.cwd(), configPath || process.env.KUBB_AGENT_CONFIG || agentDefaults.configFile)\n\n return {\n port: resolvedPort,\n host: resolvedHost,\n allowWrite: resolvedAllowWrite,\n allowAll: resolvedAllowAll,\n agentConfigPath,\n env: {\n ...process.env,\n PORT: resolvedPort,\n HOST: resolvedHost,\n KUBB_AGENT_ROOT: agentRoot,\n KUBB_AGENT_CONFIG: agentConfigPath,\n KUBB_AGENT_ALLOW_WRITE: String(resolvedAllowWrite),\n KUBB_AGENT_ALLOW_ALL: String(resolvedAllowAll),\n KUBB_AGENT_TOKEN: process.env.KUBB_AGENT_TOKEN,\n KUBB_AGENT_RETRY_TIMEOUT: process.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout,\n KUBB_STUDIO_URL: process.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl,\n },\n }\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 let agentPkgUrl: string\n try {\n agentPkgUrl = import.meta.resolve('@kubb/agent/package.json')\n } catch (_e) {\n console.error(`Import of '@kubb/agent' is required to start the Agent server`)\n process.exit(1)\n }\n const agentPkgPath = fileURLToPath(agentPkgUrl)\n const agentDir = path.dirname(agentPkgPath)\n const serverPath = path.join(agentDir, agentDefaults.serverEntryPath)\n\n const resolvedEnv = resolveAgentStartEnvironment({\n port,\n host,\n configPath,\n allowWrite,\n allowAll,\n })\n const numericPort = Number(resolvedEnv.port)\n\n if (!Number.isInteger(numericPort) || numericPort <= 0) {\n throw new Error(`Invalid port \"${resolvedEnv.port}\". Provide a positive integer with --port or PORT.`)\n }\n\n clack.log.step(styleText('cyan', 'Starting agent server...'))\n clack.log.info(styleText('dim', `Config: ${resolvedEnv.agentConfigPath}`))\n clack.log.info(styleText('dim', `Host: ${resolvedEnv.host}`))\n clack.log.info(styleText('dim', `Port: ${resolvedEnv.port}`))\n if (!resolvedEnv.allowWrite && !resolvedEnv.allowAll) {\n clack.log.warn(styleText('yellow', 'Filesystem writes disabled. Use --allow-write or --allow-all to enable.'))\n }\n\n if (!(await isPortAvailable(numericPort, resolvedEnv.host))) {\n clack.log.error(styleText('red', `Port ${resolvedEnv.port} is already in use. Stop the existing process or choose a different port with --port.`))\n process.exit(1)\n }\n\n // Spawns the server as a detached background process so the CLI can exit independently.\n await spawnAsync('node', [serverPath], {\n env: resolvedEnv.env,\n cwd: process.cwd(),\n })\n\n await sendTelemetry(\n buildTelemetryEvent({\n command: 'agent',\n kubbVersion: version,\n hrStart,\n status: 'success',\n }),\n )\n } catch (error) {\n await sendTelemetry(\n buildTelemetryEvent({\n command: 'agent',\n kubbVersion: version,\n hrStart,\n status: 'failed',\n }),\n )\n clack.log.error(styleText('red', 'Failed to start agent server'))\n console.error(error)\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA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Q,KAAK,EAAE"}
@@ -1,7 +1,7 @@
1
1
  require("./chunk-ByKO4r7w.cjs");
2
- const require_define = require("./define-D6Kfm7-Z.cjs");
3
- const require_package = require("./package-DZb6I8FQ.cjs");
4
- const require_constants = require("./constants-BTUap0zs.cjs");
2
+ const require_define = require("./define-Bdn8j5VM.cjs");
3
+ const require_package = require("./package-DsKVMEXO.cjs");
4
+ const require_constants = require("./constants-BgLUQ1nx.cjs");
5
5
  //#region src/commands/agent/start.ts
6
6
  const command$1 = require_define.defineCommand({
7
7
  name: "start",
@@ -34,7 +34,7 @@ const command$1 = require_define.defineCommand({
34
34
  }
35
35
  },
36
36
  async run({ values }) {
37
- const { runAgentStart } = await Promise.resolve().then(() => require("./agent-C6o_6GSJ.cjs"));
37
+ const { runAgentStart } = await Promise.resolve().then(() => require("./agent-Zo8CQwxZ.cjs"));
38
38
  await runAgentStart({
39
39
  port: values.port !== void 0 ? values.port : void 0,
40
40
  host: values.host,
@@ -55,4 +55,4 @@ const command = require_define.defineCommand({
55
55
  //#endregion
56
56
  exports.command = command;
57
57
 
58
- //# sourceMappingURL=agent-Cc-0-A8t.cjs.map
58
+ //# sourceMappingURL=agent-D5OIwM0z.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-D5OIwM0z.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: {\n type: 'string',\n description: 'Path to the Kubb config',\n short: 'c',\n },\n port: {\n type: 'string',\n description: `Port for the server (default: ${agentDefaults.port})`,\n short: 'p',\n },\n host: {\n type: 'string',\n description: 'Host for the server',\n default: agentDefaults.host,\n },\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': {\n type: 'boolean',\n description: 'Grant all permissions (implies --allow-write).',\n default: false,\n },\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;GACN,MAAM;GACN,aAAa;GACb,OAAO;GACR;EACD,MAAM;GACJ,MAAM;GACN,aAAa,iCAAiCC,kBAAAA,cAAc,KAAK;GACjE,OAAO;GACR;EACD,MAAM;GACJ,MAAM;GACN,aAAa;GACb,SAASA,kBAAAA,cAAc;GACxB;EACD,eAAe;GACb,MAAM;GACN,aAAa;GACb,SAAS;GACV;EACD,aAAa;GACX,MAAM;GACN,aAAa;GACb,SAAS;GACV;EACF;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;;;AC3CF,MAAa,UAAUC,eAAAA,cAAc;CACnC,MAAM;CACN,aAAa;CACb,aAAa,CAACC,UAAa;CAC5B,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import "./chunk--u3MIqq1.js";
2
- import { n as defineCommand } from "./define--M_JMcDC.js";
3
- import { t as version } from "./package-DLd3fZNd.js";
4
- import { a as agentDefaults } from "./constants-CM3dJzjK.js";
2
+ import { n as defineCommand } from "./define-Ctii4bel.js";
3
+ import { t as version } from "./package-BD90dOVc.js";
4
+ import { s as agentDefaults } from "./constants-mIdg9ls2.js";
5
5
  //#endregion
6
6
  //#region src/commands/agent.ts
7
7
  const command = defineCommand({
@@ -38,7 +38,7 @@ const command = defineCommand({
38
38
  }
39
39
  },
40
40
  async run({ values }) {
41
- const { runAgentStart } = await import("./agent-L50VNhXv.js");
41
+ const { runAgentStart } = await import("./agent-CouS-H2S.js");
42
42
  await runAgentStart({
43
43
  port: values.port !== void 0 ? values.port : void 0,
44
44
  host: values.host,
@@ -53,4 +53,4 @@ const command = defineCommand({
53
53
  //#endregion
54
54
  export { command };
55
55
 
56
- //# sourceMappingURL=agent-CjXjyuPe.js.map
56
+ //# sourceMappingURL=agent-DypvJBwO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-DypvJBwO.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: {\n type: 'string',\n description: 'Path to the Kubb config',\n short: 'c',\n },\n port: {\n type: 'string',\n description: `Port for the server (default: ${agentDefaults.port})`,\n short: 'p',\n },\n host: {\n type: 'string',\n description: 'Host for the server',\n default: agentDefaults.host,\n },\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': {\n type: 'boolean',\n description: 'Grant all permissions (implies --allow-write).',\n default: false,\n },\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;IACN,MAAM;IACN,aAAa;IACb,OAAO;IACR;GACD,MAAM;IACJ,MAAM;IACN,aAAa,iCAAiC,cAAc,KAAK;IACjE,OAAO;IACR;GACD,MAAM;IACJ,MAAM;IACN,aAAa;IACb,SAAS,cAAc;IACxB;GACD,eAAe;IACb,MAAM;IACN,aAAa;IACb,SAAS;IACV;GACD,aAAa;IACX,MAAM;IACN,aAAa;IACb,SAAS;IACV;GACF;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,CCxCeC,CAAa;CAC5B,CAAC"}
@@ -0,0 +1,116 @@
1
+ const require_chunk = require("./chunk-ByKO4r7w.cjs");
2
+ const require_telemetry = require("./telemetry-kmnc5OAT.cjs");
3
+ const require_shell = require("./shell-475fQKaX.cjs");
4
+ const require_constants = require("./constants-BgLUQ1nx.cjs");
5
+ let node_util = require("node:util");
6
+ let node_path = require("node:path");
7
+ node_path = require_chunk.__toESM(node_path, 1);
8
+ let node_process = require("node:process");
9
+ node_process = require_chunk.__toESM(node_process, 1);
10
+ let node_net = require("node:net");
11
+ node_net = require_chunk.__toESM(node_net, 1);
12
+ let node_url = require("node:url");
13
+ let _clack_prompts = require("@clack/prompts");
14
+ _clack_prompts = require_chunk.__toESM(_clack_prompts, 1);
15
+ //#region src/runners/agent.ts
16
+ /**
17
+ * Resolves the environment passed to the detached agent process using CLI values first, then environment values, then CLI defaults.
18
+ */
19
+ function resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }) {
20
+ const resolvedPort = port ?? node_process.env.PORT ?? require_constants.agentDefaults.port;
21
+ const resolvedHost = host !== require_constants.agentDefaults.host ? host : node_process.env.HOST ?? require_constants.agentDefaults.host;
22
+ const resolvedAllowAll = allowAll || node_process.env.KUBB_AGENT_ALLOW_ALL === "true";
23
+ const resolvedAllowWrite = resolvedAllowAll || allowWrite || node_process.env.KUBB_AGENT_ALLOW_WRITE === "true";
24
+ const agentRoot = node_process.env.KUBB_AGENT_ROOT ?? node_process.cwd();
25
+ const agentConfigPath = node_path.default.resolve(node_process.cwd(), configPath || node_process.env.KUBB_AGENT_CONFIG || require_constants.agentDefaults.configFile);
26
+ return {
27
+ port: resolvedPort,
28
+ host: resolvedHost,
29
+ allowWrite: resolvedAllowWrite,
30
+ allowAll: resolvedAllowAll,
31
+ agentConfigPath,
32
+ env: {
33
+ ...node_process.env,
34
+ PORT: resolvedPort,
35
+ HOST: resolvedHost,
36
+ KUBB_AGENT_ROOT: agentRoot,
37
+ KUBB_AGENT_CONFIG: agentConfigPath,
38
+ KUBB_AGENT_ALLOW_WRITE: String(resolvedAllowWrite),
39
+ KUBB_AGENT_ALLOW_ALL: String(resolvedAllowAll),
40
+ KUBB_AGENT_TOKEN: node_process.env.KUBB_AGENT_TOKEN,
41
+ KUBB_AGENT_RETRY_TIMEOUT: node_process.env.KUBB_AGENT_RETRY_TIMEOUT ?? require_constants.agentDefaults.retryTimeout,
42
+ KUBB_STUDIO_URL: node_process.env.KUBB_STUDIO_URL ?? require_constants.agentDefaults.studioUrl
43
+ }
44
+ };
45
+ }
46
+ function isPortAvailable(port, host) {
47
+ return new Promise((resolve) => {
48
+ const server = node_net.default.createServer();
49
+ server.once("error", () => resolve(false));
50
+ server.once("listening", () => {
51
+ server.close();
52
+ resolve(true);
53
+ });
54
+ server.listen(port, host);
55
+ });
56
+ }
57
+ async function runAgentStart({ port, host, configPath, allowWrite, allowAll, version }) {
58
+ const hrStart = node_process.hrtime();
59
+ try {
60
+ try {
61
+ node_process.loadEnvFile();
62
+ } catch {}
63
+ let agentPkgUrl;
64
+ try {
65
+ agentPkgUrl = {}.resolve("@kubb/agent/package.json");
66
+ } catch (_e) {
67
+ console.error(`Import of '@kubb/agent' is required to start the Agent server`);
68
+ node_process.exit(1);
69
+ }
70
+ const agentPkgPath = (0, node_url.fileURLToPath)(agentPkgUrl);
71
+ const agentDir = node_path.default.dirname(agentPkgPath);
72
+ const serverPath = node_path.default.join(agentDir, require_constants.agentDefaults.serverEntryPath);
73
+ const resolvedEnv = resolveAgentStartEnvironment({
74
+ port,
75
+ host,
76
+ configPath,
77
+ allowWrite,
78
+ allowAll
79
+ });
80
+ const numericPort = Number(resolvedEnv.port);
81
+ if (!Number.isInteger(numericPort) || numericPort <= 0) throw new Error(`Invalid port "${resolvedEnv.port}". Provide a positive integer with --port or PORT.`);
82
+ _clack_prompts.log.step((0, node_util.styleText)("cyan", "Starting agent server..."));
83
+ _clack_prompts.log.info((0, node_util.styleText)("dim", `Config: ${resolvedEnv.agentConfigPath}`));
84
+ _clack_prompts.log.info((0, node_util.styleText)("dim", `Host: ${resolvedEnv.host}`));
85
+ _clack_prompts.log.info((0, node_util.styleText)("dim", `Port: ${resolvedEnv.port}`));
86
+ if (!resolvedEnv.allowWrite && !resolvedEnv.allowAll) _clack_prompts.log.warn((0, node_util.styleText)("yellow", "Filesystem writes disabled. Use --allow-write or --allow-all to enable."));
87
+ if (!await isPortAvailable(numericPort, resolvedEnv.host)) {
88
+ _clack_prompts.log.error((0, node_util.styleText)("red", `Port ${resolvedEnv.port} is already in use. Stop the existing process or choose a different port with --port.`));
89
+ node_process.exit(1);
90
+ }
91
+ await require_shell.spawnAsync("node", [serverPath], {
92
+ env: resolvedEnv.env,
93
+ cwd: node_process.cwd()
94
+ });
95
+ await require_telemetry.sendTelemetry(require_telemetry.buildTelemetryEvent({
96
+ command: "agent",
97
+ kubbVersion: version,
98
+ hrStart,
99
+ status: "success"
100
+ }));
101
+ } catch (error) {
102
+ await require_telemetry.sendTelemetry(require_telemetry.buildTelemetryEvent({
103
+ command: "agent",
104
+ kubbVersion: version,
105
+ hrStart,
106
+ status: "failed"
107
+ }));
108
+ _clack_prompts.log.error((0, node_util.styleText)("red", "Failed to start agent server"));
109
+ console.error(error);
110
+ node_process.exit(1);
111
+ }
112
+ }
113
+ //#endregion
114
+ exports.runAgentStart = runAgentStart;
115
+
116
+ //# sourceMappingURL=agent-Zo8CQwxZ.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-Zo8CQwxZ.cjs","names":["process","agentDefaults","path","net","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\ntype ResolvedAgentStartEnvironment = {\n port: string\n host: string\n allowWrite: boolean\n allowAll: boolean\n agentConfigPath: string\n env: NodeJS.ProcessEnv\n}\n\n/**\n * Resolves the environment passed to the detached agent process using CLI values first, then environment values, then CLI defaults.\n */\nfunction resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }: Omit<AgentStartOptions, 'version'>): ResolvedAgentStartEnvironment {\n const resolvedPort = port ?? process.env.PORT ?? agentDefaults.port\n const resolvedHost = host !== agentDefaults.host ? host : (process.env.HOST ?? agentDefaults.host)\n const resolvedAllowAll = allowAll || process.env.KUBB_AGENT_ALLOW_ALL === 'true'\n const resolvedAllowWrite = resolvedAllowAll || allowWrite || process.env.KUBB_AGENT_ALLOW_WRITE === 'true'\n const agentRoot = process.env.KUBB_AGENT_ROOT ?? process.cwd()\n const agentConfigPath = path.resolve(process.cwd(), configPath || process.env.KUBB_AGENT_CONFIG || agentDefaults.configFile)\n\n return {\n port: resolvedPort,\n host: resolvedHost,\n allowWrite: resolvedAllowWrite,\n allowAll: resolvedAllowAll,\n agentConfigPath,\n env: {\n ...process.env,\n PORT: resolvedPort,\n HOST: resolvedHost,\n KUBB_AGENT_ROOT: agentRoot,\n KUBB_AGENT_CONFIG: agentConfigPath,\n KUBB_AGENT_ALLOW_WRITE: String(resolvedAllowWrite),\n KUBB_AGENT_ALLOW_ALL: String(resolvedAllowAll),\n KUBB_AGENT_TOKEN: process.env.KUBB_AGENT_TOKEN,\n KUBB_AGENT_RETRY_TIMEOUT: process.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout,\n KUBB_STUDIO_URL: process.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl,\n },\n }\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 let agentPkgUrl: string\n try {\n agentPkgUrl = import.meta.resolve('@kubb/agent/package.json')\n } catch (_e) {\n console.error(`Import of '@kubb/agent' is required to start the Agent server`)\n process.exit(1)\n }\n const agentPkgPath = fileURLToPath(agentPkgUrl)\n const agentDir = path.dirname(agentPkgPath)\n const serverPath = path.join(agentDir, agentDefaults.serverEntryPath)\n\n const resolvedEnv = resolveAgentStartEnvironment({\n port,\n host,\n configPath,\n allowWrite,\n allowAll,\n })\n const numericPort = Number(resolvedEnv.port)\n\n if (!Number.isInteger(numericPort) || numericPort <= 0) {\n throw new Error(`Invalid port \"${resolvedEnv.port}\". Provide a positive integer with --port or PORT.`)\n }\n\n clack.log.step(styleText('cyan', 'Starting agent server...'))\n clack.log.info(styleText('dim', `Config: ${resolvedEnv.agentConfigPath}`))\n clack.log.info(styleText('dim', `Host: ${resolvedEnv.host}`))\n clack.log.info(styleText('dim', `Port: ${resolvedEnv.port}`))\n if (!resolvedEnv.allowWrite && !resolvedEnv.allowAll) {\n clack.log.warn(styleText('yellow', 'Filesystem writes disabled. Use --allow-write or --allow-all to enable.'))\n }\n\n if (!(await isPortAvailable(numericPort, resolvedEnv.host))) {\n clack.log.error(styleText('red', `Port ${resolvedEnv.port} is already in use. Stop the existing process or choose a different port with --port.`))\n process.exit(1)\n }\n\n // Spawns the server as a detached background process so the CLI can exit independently.\n await spawnAsync('node', [serverPath], {\n env: resolvedEnv.env,\n cwd: process.cwd(),\n })\n\n await sendTelemetry(\n buildTelemetryEvent({\n command: 'agent',\n kubbVersion: version,\n hrStart,\n status: 'success',\n }),\n )\n } catch (error) {\n await sendTelemetry(\n buildTelemetryEvent({\n command: 'agent',\n kubbVersion: version,\n hrStart,\n status: 'failed',\n }),\n )\n clack.log.error(styleText('red', 'Failed to start agent server'))\n console.error(error)\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA+BA,SAAS,6BAA6B,EAAE,MAAM,MAAM,YAAY,YAAY,YAA+E;CACzJ,MAAM,eAAe,QAAQA,aAAQ,IAAI,QAAQC,kBAAAA,cAAc;CAC/D,MAAM,eAAe,SAASA,kBAAAA,cAAc,OAAO,OAAQD,aAAQ,IAAI,QAAQC,kBAAAA,cAAc;CAC7F,MAAM,mBAAmB,YAAYD,aAAQ,IAAI,yBAAyB;CAC1E,MAAM,qBAAqB,oBAAoB,cAA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@@
1
1
  //#region src/constants.ts
2
- /** NPM registry endpoint used to check for @kubb/cli updates. */
2
+ /**
3
+ * Default filename for the Kubb configuration file.
4
+ *
5
+ * Used by the `init` command when scaffolding new projects and by the `agent` default config.
6
+ */
7
+ const KUBB_CONFIG_FILENAME = "kubb.config.ts";
8
+ /**
9
+ * NPM registry endpoint used to check for @kubb/cli updates.
10
+ */
3
11
  const KUBB_NPM_PACKAGE_URL = "https://registry.npmjs.org/@kubb/cli/latest";
4
- /** OpenTelemetry ingestion endpoint for anonymous usage telemetry. */
12
+ /**
13
+ * OpenTelemetry ingestion endpoint for anonymous usage telemetry.
14
+ */
5
15
  const OTLP_ENDPOINT = "https://otlp.kubb.dev";
6
- /** Horizontal rule rendered above/below the plain-logger generation summary. */
16
+ /**
17
+ * Horizontal rule rendered above/below the plain-logger generation summary.
18
+ */
7
19
  const SUMMARY_SEPARATOR = "─".repeat(27);
8
- /** Glob pattern for paths the file watcher ignores. */
20
+ /**
21
+ * Glob pattern for paths the file watcher ignores.
22
+ */
9
23
  const WATCHER_IGNORED_PATHS = "**/{.git,node_modules}/**";
10
- /** Default runtime values for the `agent start` command. */
24
+ /**
25
+ * Flags that short-circuit execution (help/version) — no telemetry notice is shown.
26
+ */
27
+ const QUIET_FLAGS = new Set([
28
+ "--help",
29
+ "-h",
30
+ "--version",
31
+ "-v"
32
+ ]);
11
33
  const agentDefaults = {
12
34
  port: "3000",
13
35
  host: "localhost",
14
- configFile: "kubb.config.ts",
36
+ configFile: KUBB_CONFIG_FILENAME,
15
37
  retryTimeout: "30000",
16
38
  studioUrl: "https://studio.kubb.dev",
39
+ /**
40
+ * Relative path from the @kubb/agent package root to the server entry.
41
+ */
17
42
  serverEntryPath: ".output/server/index.mjs"
18
43
  };
19
- /** Default values used during interactive `init` scaffolding. */
44
+ /**
45
+ * Default values used during interactive `init` scaffolding.
46
+ */
20
47
  const initDefaults = {
21
48
  inputPath: "./openapi.yaml",
22
49
  outputPath: "./src/gen",
@@ -60,8 +87,16 @@ const pluginDefaultConfigs = {
60
87
  output: { path: 'msw' },
61
88
  })`
62
89
  };
63
- /** Color palette used by randomCliColor() for deterministic plugin name coloring. */
90
+ /**
91
+ * Color palette used by randomCliColor() for deterministic plugin name coloring.
92
+ */
64
93
  //#endregion
94
+ Object.defineProperty(exports, "KUBB_CONFIG_FILENAME", {
95
+ enumerable: true,
96
+ get: function() {
97
+ return KUBB_CONFIG_FILENAME;
98
+ }
99
+ });
65
100
  Object.defineProperty(exports, "KUBB_NPM_PACKAGE_URL", {
66
101
  enumerable: true,
67
102
  get: function() {
@@ -74,6 +109,12 @@ Object.defineProperty(exports, "OTLP_ENDPOINT", {
74
109
  return OTLP_ENDPOINT;
75
110
  }
76
111
  });
112
+ Object.defineProperty(exports, "QUIET_FLAGS", {
113
+ enumerable: true,
114
+ get: function() {
115
+ return QUIET_FLAGS;
116
+ }
117
+ });
77
118
  Object.defineProperty(exports, "SUMMARY_SEPARATOR", {
78
119
  enumerable: true,
79
120
  get: function() {
@@ -105,4 +146,4 @@ Object.defineProperty(exports, "pluginDefaultConfigs", {
105
146
  }
106
147
  });
107
148
 
108
- //# sourceMappingURL=constants-BTUap0zs.cjs.map
149
+ //# sourceMappingURL=constants-BgLUQ1nx.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants-BgLUQ1nx.cjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["/**\n * Default filename for the Kubb configuration file.\n *\n * Used by the `init` command when scaffolding new projects and by the `agent` default config.\n */\nexport const KUBB_CONFIG_FILENAME = 'kubb.config.ts' as const\n\n/**\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 QUIET_FLAGS = new Set(['--help', '-h', '--version', '-v'] as const)\n\nexport const agentDefaults = {\n port: '3000',\n host: 'localhost',\n configFile: KUBB_CONFIG_FILENAME,\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":";;;;;;AAKA,MAAa,uBAAuB;;;;AAKpC,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;AAEhF,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,22 +1,49 @@
1
1
  //#region src/constants.ts
2
- /** NPM registry endpoint used to check for @kubb/cli updates. */
2
+ /**
3
+ * Default filename for the Kubb configuration file.
4
+ *
5
+ * Used by the `init` command when scaffolding new projects and by the `agent` default config.
6
+ */
7
+ const KUBB_CONFIG_FILENAME = "kubb.config.ts";
8
+ /**
9
+ * NPM registry endpoint used to check for @kubb/cli updates.
10
+ */
3
11
  const KUBB_NPM_PACKAGE_URL = "https://registry.npmjs.org/@kubb/cli/latest";
4
- /** OpenTelemetry ingestion endpoint for anonymous usage telemetry. */
12
+ /**
13
+ * OpenTelemetry ingestion endpoint for anonymous usage telemetry.
14
+ */
5
15
  const OTLP_ENDPOINT = "https://otlp.kubb.dev";
6
- /** Horizontal rule rendered above/below the plain-logger generation summary. */
16
+ /**
17
+ * Horizontal rule rendered above/below the plain-logger generation summary.
18
+ */
7
19
  const SUMMARY_SEPARATOR = "─".repeat(27);
8
- /** Glob pattern for paths the file watcher ignores. */
20
+ /**
21
+ * Glob pattern for paths the file watcher ignores.
22
+ */
9
23
  const WATCHER_IGNORED_PATHS = "**/{.git,node_modules}/**";
10
- /** Default runtime values for the `agent start` command. */
24
+ /**
25
+ * Flags that short-circuit execution (help/version) — no telemetry notice is shown.
26
+ */
27
+ const QUIET_FLAGS = new Set([
28
+ "--help",
29
+ "-h",
30
+ "--version",
31
+ "-v"
32
+ ]);
11
33
  const agentDefaults = {
12
34
  port: "3000",
13
35
  host: "localhost",
14
- configFile: "kubb.config.ts",
36
+ configFile: KUBB_CONFIG_FILENAME,
15
37
  retryTimeout: "30000",
16
38
  studioUrl: "https://studio.kubb.dev",
39
+ /**
40
+ * Relative path from the @kubb/agent package root to the server entry.
41
+ */
17
42
  serverEntryPath: ".output/server/index.mjs"
18
43
  };
19
- /** Default values used during interactive `init` scaffolding. */
44
+ /**
45
+ * Default values used during interactive `init` scaffolding.
46
+ */
20
47
  const initDefaults = {
21
48
  inputPath: "./openapi.yaml",
22
49
  outputPath: "./src/gen",
@@ -60,8 +87,10 @@ const pluginDefaultConfigs = {
60
87
  output: { path: 'msw' },
61
88
  })`
62
89
  };
63
- /** Color palette used by randomCliColor() for deterministic plugin name coloring. */
90
+ /**
91
+ * Color palette used by randomCliColor() for deterministic plugin name coloring.
92
+ */
64
93
  //#endregion
65
- export { agentDefaults as a, WATCHER_IGNORED_PATHS as i, OTLP_ENDPOINT as n, initDefaults as o, SUMMARY_SEPARATOR as r, pluginDefaultConfigs as s, KUBB_NPM_PACKAGE_URL as t };
94
+ export { SUMMARY_SEPARATOR as a, initDefaults as c, QUIET_FLAGS as i, pluginDefaultConfigs as l, KUBB_NPM_PACKAGE_URL as n, WATCHER_IGNORED_PATHS as o, OTLP_ENDPOINT as r, agentDefaults as s, KUBB_CONFIG_FILENAME as t };
66
95
 
67
- //# sourceMappingURL=constants-CM3dJzjK.js.map
96
+ //# sourceMappingURL=constants-mIdg9ls2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants-mIdg9ls2.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["/**\n * Default filename for the Kubb configuration file.\n *\n * Used by the `init` command when scaffolding new projects and by the `agent` default config.\n */\nexport const KUBB_CONFIG_FILENAME = 'kubb.config.ts' as const\n\n/**\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 QUIET_FLAGS = new Set(['--help', '-h', '--version', '-v'] as const)\n\nexport const agentDefaults = {\n port: '3000',\n host: 'localhost',\n configFile: KUBB_CONFIG_FILENAME,\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":";;;;;;AAKA,MAAa,uBAAuB;;;;AAKpC,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;AAEhF,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"}
@@ -0,0 +1,54 @@
1
+ require("./chunk-ByKO4r7w.cjs");
2
+ //#region ../../internals/utils/src/cli/define.ts
3
+ /**
4
+ * Returns a `CLIAdapter` as-is with full type inference. Pass a custom adapter to `createCLI` to swap the CLI engine.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * const adapter = defineCLIAdapter({ run: myRun, renderHelp: myHelp })
9
+ * createCLI({ adapter }).run(commands, argv, opts)
10
+ * ```
11
+ */
12
+ function defineCLIAdapter(adapter) {
13
+ return adapter;
14
+ }
15
+ /**
16
+ * Returns a `CommandDefinition` with typed `values` in `run()`.
17
+ * The callback receives `values` inferred from the declared options — no casts needed.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const generate = defineCommand({
22
+ * name: 'generate',
23
+ * description: 'Generate client code',
24
+ * options: { config: { type: 'string', description: 'Config path' } },
25
+ * async run({ values }) { console.log(values.config) },
26
+ * })
27
+ * ```
28
+ */
29
+ function defineCommand(def) {
30
+ const { run, ...rest } = def;
31
+ if (!run) return rest;
32
+ return {
33
+ ...rest,
34
+ run: (args) => run({
35
+ values: args.values,
36
+ positionals: args.positionals
37
+ })
38
+ };
39
+ }
40
+ //#endregion
41
+ Object.defineProperty(exports, "defineCLIAdapter", {
42
+ enumerable: true,
43
+ get: function() {
44
+ return defineCLIAdapter;
45
+ }
46
+ });
47
+ Object.defineProperty(exports, "defineCommand", {
48
+ enumerable: true,
49
+ get: function() {
50
+ return defineCommand;
51
+ }
52
+ });
53
+
54
+ //# sourceMappingURL=define-Bdn8j5VM.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-Bdn8j5VM.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/**\n * Infers typed values from an options record. Options with a `default` or `required: true` are always defined.\n */\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/**\n * Returns a `CLIAdapter` as-is with full type inference. Pass a custom adapter to `createCLI` to swap the CLI engine.\n *\n * @example\n * ```ts\n * const adapter = defineCLIAdapter({ run: myRun, renderHelp: myHelp })\n * createCLI({ adapter }).run(commands, argv, opts)\n * ```\n */\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` inferred from the declared options — no casts needed.\n *\n * @example\n * ```ts\n * const generate = defineCommand({\n * name: 'generate',\n * description: 'Generate client code',\n * options: { config: { type: 'string', description: 'Config path' } },\n * async run({ values }) { console.log(values.config) },\n * })\n * ```\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) =>\n run({\n values: args.values as InferValues<O>,\n positionals: args.positionals,\n }),\n }\n}\n"],"mappings":";;;;;;;;;;;AAwBA,SAAgB,iBAAiB,SAAiC;AAChE,QAAO;;;;;;;;;;;;;;;;AAiBT,SAAgB,cAA0D,KAOpD;CACpB,MAAM,EAAE,KAAK,GAAG,SAAS;AACzB,KAAI,CAAC,IAAK,QAAO;AACjB,QAAO;EACL,GAAG;EACH,MAAM,SACJ,IAAI;GACF,QAAQ,KAAK;GACb,aAAa,KAAK;GACnB,CAAC;EACL"}