@kubb/cli 5.0.0-beta.5 → 5.0.0-beta.51

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 (148) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +171 -51
  3. package/dist/Telemetry-BG80bcoQ.cjs +350 -0
  4. package/dist/Telemetry-BG80bcoQ.cjs.map +1 -0
  5. package/dist/Telemetry-CyBqvgcj.js +313 -0
  6. package/dist/Telemetry-CyBqvgcj.js.map +1 -0
  7. package/dist/{define-Bdn8j5VM.cjs → define-C4AB3POr.cjs} +2 -2
  8. package/dist/{define-Bdn8j5VM.cjs.map → define-C4AB3POr.cjs.map} +1 -1
  9. package/dist/{define-Ctii4bel.js → define-C63T4jp6.js} +2 -2
  10. package/dist/{define-Ctii4bel.js.map → define-C63T4jp6.js.map} +1 -1
  11. package/dist/{errors-CjPmyZHy.js → errors-BsemQCMn.js} +2 -2
  12. package/dist/{errors-CjPmyZHy.js.map → errors-BsemQCMn.js.map} +1 -1
  13. package/dist/{errors-CLCjoSg0.cjs → errors-DykI11xo.cjs} +2 -2
  14. package/dist/{errors-CLCjoSg0.cjs.map → errors-DykI11xo.cjs.map} +1 -1
  15. package/dist/generate-BRpukupe.cjs +82 -0
  16. package/dist/generate-BRpukupe.cjs.map +1 -0
  17. package/dist/generate-XeCSLYWp.js +83 -0
  18. package/dist/generate-XeCSLYWp.js.map +1 -0
  19. package/dist/index.cjs +22 -16
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.js +21 -15
  23. package/dist/index.js.map +1 -1
  24. package/dist/init-C156kkn3.cjs +53 -0
  25. package/dist/init-C156kkn3.cjs.map +1 -0
  26. package/dist/init-Djx-xXm2.js +53 -0
  27. package/dist/init-Djx-xXm2.js.map +1 -0
  28. package/dist/mcp--t_K4yMF.js +39 -0
  29. package/dist/mcp--t_K4yMF.js.map +1 -0
  30. package/dist/mcp-D4ZwcNDD.cjs +39 -0
  31. package/dist/mcp-D4ZwcNDD.cjs.map +1 -0
  32. package/dist/package-_PDiS5qW.js +6 -0
  33. package/dist/package-_PDiS5qW.js.map +1 -0
  34. package/dist/{package-BmYRU2hz.cjs → package-aN3cIOkh.cjs} +2 -2
  35. package/dist/package-aN3cIOkh.cjs.map +1 -0
  36. package/dist/run-7yQQ3lIR.js +51 -0
  37. package/dist/run-7yQQ3lIR.js.map +1 -0
  38. package/dist/{init-C5sZulT6.cjs → run-BtjzfTz3.cjs} +155 -85
  39. package/dist/run-BtjzfTz3.cjs.map +1 -0
  40. package/dist/{init-Cag3082g.js → run-C-omuksC.js} +147 -77
  41. package/dist/run-C-omuksC.js.map +1 -0
  42. package/dist/run-CDs_ebOt.cjs +1458 -0
  43. package/dist/run-CDs_ebOt.cjs.map +1 -0
  44. package/dist/run-CZEf3B3A.cjs +33 -0
  45. package/dist/run-CZEf3B3A.cjs.map +1 -0
  46. package/dist/run-CsBW0NRp.js +32 -0
  47. package/dist/run-CsBW0NRp.js.map +1 -0
  48. package/dist/run-YYlwMdeu.cjs +52 -0
  49. package/dist/run-YYlwMdeu.cjs.map +1 -0
  50. package/dist/run-aODbKkaY.js +1455 -0
  51. package/dist/run-aODbKkaY.js.map +1 -0
  52. package/dist/{shell-DLzN4fRo.js → shell-DsgkfUSW.js} +2 -2
  53. package/dist/{shell-DLzN4fRo.js.map → shell-DsgkfUSW.js.map} +1 -1
  54. package/dist/{shell-475fQKaX.cjs → shell-Lh-vLWwH.cjs} +2 -2
  55. package/dist/{shell-475fQKaX.cjs.map → shell-Lh-vLWwH.cjs.map} +1 -1
  56. package/dist/validate-DWdTJLGF.js +26 -0
  57. package/dist/validate-DWdTJLGF.js.map +1 -0
  58. package/dist/validate-sOD68Kma.cjs +26 -0
  59. package/dist/validate-sOD68Kma.cjs.map +1 -0
  60. package/package.json +14 -24
  61. package/src/Telemetry.ts +290 -0
  62. package/src/commands/generate.ts +27 -13
  63. package/src/commands/init.ts +34 -3
  64. package/src/commands/mcp.ts +28 -4
  65. package/src/commands/validate.ts +6 -4
  66. package/src/constants.ts +1 -81
  67. package/src/index.ts +7 -6
  68. package/src/loggers/clackLogger.ts +135 -201
  69. package/src/loggers/defineLogger.ts +59 -0
  70. package/src/loggers/plainLogger.ts +47 -102
  71. package/src/loggers/types.ts +6 -1
  72. package/src/loggers/utils.ts +164 -23
  73. package/src/runners/generate/run.ts +403 -0
  74. package/src/runners/generate/utils.ts +228 -0
  75. package/src/runners/init/run.ts +210 -0
  76. package/src/{utils/packageManager.ts → runners/init/utils.ts} +12 -2
  77. package/src/runners/mcp/run.ts +37 -0
  78. package/src/runners/validate/run.ts +63 -0
  79. package/dist/agent-BcUEl9yB.js +0 -56
  80. package/dist/agent-BcUEl9yB.js.map +0 -1
  81. package/dist/agent-CS45W0kL.cjs +0 -122
  82. package/dist/agent-CS45W0kL.cjs.map +0 -1
  83. package/dist/agent-CsMvXeqI.cjs +0 -58
  84. package/dist/agent-CsMvXeqI.cjs.map +0 -1
  85. package/dist/agent-IP0eLV3C.js +0 -118
  86. package/dist/agent-IP0eLV3C.js.map +0 -1
  87. package/dist/constants-B4iBDvCe.cjs +0 -148
  88. package/dist/constants-B4iBDvCe.cjs.map +0 -1
  89. package/dist/constants-DmPrkaz8.js +0 -95
  90. package/dist/constants-DmPrkaz8.js.map +0 -1
  91. package/dist/generate-7td_hs73.cjs +0 -65
  92. package/dist/generate-7td_hs73.cjs.map +0 -1
  93. package/dist/generate-BqeFFQGD.js +0 -66
  94. package/dist/generate-BqeFFQGD.js.map +0 -1
  95. package/dist/generate-CUd1dUY5.cjs +0 -1755
  96. package/dist/generate-CUd1dUY5.cjs.map +0 -1
  97. package/dist/generate-DVmGtwWe.js +0 -1752
  98. package/dist/generate-DVmGtwWe.js.map +0 -1
  99. package/dist/init-C5sZulT6.cjs.map +0 -1
  100. package/dist/init-Cag3082g.js.map +0 -1
  101. package/dist/init-CfAn19gC.js +0 -25
  102. package/dist/init-CfAn19gC.js.map +0 -1
  103. package/dist/init-CfsYoyGe.cjs +0 -25
  104. package/dist/init-CfsYoyGe.cjs.map +0 -1
  105. package/dist/mcp-BfORW-mY.cjs +0 -47
  106. package/dist/mcp-BfORW-mY.cjs.map +0 -1
  107. package/dist/mcp-BtOV6acy.js +0 -16
  108. package/dist/mcp-BtOV6acy.js.map +0 -1
  109. package/dist/mcp-CIbuLGMx.cjs +0 -16
  110. package/dist/mcp-CIbuLGMx.cjs.map +0 -1
  111. package/dist/mcp-DtQ5o0On.js +0 -46
  112. package/dist/mcp-DtQ5o0On.js.map +0 -1
  113. package/dist/package-BmYRU2hz.cjs.map +0 -1
  114. package/dist/package-DBU5ii-k.js +0 -6
  115. package/dist/package-DBU5ii-k.js.map +0 -1
  116. package/dist/telemetry-BU25EoI-.cjs +0 -282
  117. package/dist/telemetry-BU25EoI-.cjs.map +0 -1
  118. package/dist/telemetry-CaNU4-Bf.js +0 -245
  119. package/dist/telemetry-CaNU4-Bf.js.map +0 -1
  120. package/dist/validate-CQqM9siF.js +0 -25
  121. package/dist/validate-CQqM9siF.js.map +0 -1
  122. package/dist/validate-DBXLaLIn.cjs +0 -34
  123. package/dist/validate-DBXLaLIn.cjs.map +0 -1
  124. package/dist/validate-DI23zgmL.js +0 -33
  125. package/dist/validate-DI23zgmL.js.map +0 -1
  126. package/dist/validate-DwX4LzYq.cjs +0 -25
  127. package/dist/validate-DwX4LzYq.cjs.map +0 -1
  128. package/src/commands/agent/start.ts +0 -47
  129. package/src/commands/agent.ts +0 -8
  130. package/src/loggers/fileSystemLogger.ts +0 -138
  131. package/src/loggers/githubActionsLogger.ts +0 -379
  132. package/src/runners/agent.ts +0 -155
  133. package/src/runners/generate.ts +0 -333
  134. package/src/runners/init.ts +0 -296
  135. package/src/runners/mcp.ts +0 -51
  136. package/src/runners/validate.ts +0 -39
  137. package/src/types.ts +0 -11
  138. package/src/utils/Writables.ts +0 -17
  139. package/src/utils/executeHooks.ts +0 -45
  140. package/src/utils/flags.ts +0 -9
  141. package/src/utils/getConfig.ts +0 -10
  142. package/src/utils/getCosmiConfig.ts +0 -75
  143. package/src/utils/getSummary.ts +0 -68
  144. package/src/utils/runHook.ts +0 -91
  145. package/src/utils/telemetry.ts +0 -273
  146. package/src/utils/watcher.ts +0 -19
  147. /package/dist/{chunk-ByKO4r7w.cjs → chunk-Bx3C2hgW.cjs} +0 -0
  148. /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
package/LICENSE CHANGED
@@ -1,14 +1,21 @@
1
- Copyright (c) 2026 Stijn Van Hulle
2
-
3
- This repository contains software under two licenses:
1
+ MIT License
4
2
 
5
- 1. Most of the code in this repository is licensed under the
6
- MIT License — see licenses/LICENSE-MIT for the full license text.
3
+ Copyright (c) 2026 Stijn Van Hulle
7
4
 
8
- 2. The following components are licensed under the
9
- GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later)
10
- see licenses/LICENSE-AGPL-3.0 for the full license text:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
11
 
12
- - packages/agent (published as @kubb/agent)
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
13
14
 
14
- Each package's own LICENSE file or package.json specifies its applicable license.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,95 +1,215 @@
1
1
  <div align="center">
2
- <h1>Kubb Cli</h1>
3
2
  <a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
4
- <img width="180" src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/logo.png" alt="Kubb logo">
3
+ <img src="https://kubb.dev/og.png" alt="Kubb banner">
5
4
  </a>
6
5
 
7
6
  [![npm version][npm-version-src]][npm-version-href]
8
7
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
9
- [![Coverage][coverage-src]][coverage-href]
8
+ [![Stars][stars-src]][stars-href]
10
9
  [![License][license-src]][license-href]
11
- [![Sponsors][sponsors-src]][sponsors-href]
10
+ [![Node][node-src]][node-href]
12
11
 
13
12
  <h4>
14
- <a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a>
15
- <span> · </span>
16
- <a href="https://kubb.dev/" target="_blank">Documentation</a>
17
- <span> · </span>
18
- <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
19
- <span> · </span>
20
- <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Request Feature</a>
21
- </h4>
13
+ <a href="https://kubb.dev" target="_blank">Documentation</a>
14
+ <span> · </span>
15
+ <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
16
+ <span> · </span>
17
+ <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Request Feature</a>
18
+ </h4>
22
19
  </div>
23
20
 
21
+ <br />
22
+
23
+ # @kubb/cli
24
+
25
+ ### The command-line interface for Kubb
26
+
27
+ Official CLI for Kubb. Run `kubb generate` to transform OpenAPI/Swagger specs into TypeScript types, API clients, hooks, validators, and mocks. Includes interactive project setup (`kubb init`), spec validation, watch mode, and an MCP server.
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ bun add -D @kubb/cli
33
+ # or
34
+ pnpm add -D @kubb/cli
35
+ # or
36
+ npm install -D @kubb/cli
37
+ ```
38
+
24
39
  ## Commands
25
40
 
41
+ - [`kubb init`](#kubb-init) — scaffold a new project
42
+ - [`kubb generate`](#kubb-generate) — run code generation
43
+ - [`kubb validate`](#kubb-validate) — validate an OpenAPI spec
44
+ - [`kubb mcp`](#kubb-mcp) — start the MCP server for AI assistants
45
+
46
+ ---
47
+
26
48
  ### `kubb init`
27
49
 
28
- Initialize a new Kubb project with an interactive setup wizard.
50
+ Scaffold a `kubb.config.ts` and install plugins for code generation from an OpenAPI spec. Run without flags for an interactive setup wizard, or pass flags to skip the prompts.
29
51
 
30
52
  ```bash
31
53
  npx kubb init
32
54
  ```
33
55
 
34
- Use the `-y` / `--yes` flag to skip all prompts and accept the defaults:
56
+ #### Options
57
+
58
+ | Flag | Short | Type | Default | Description |
59
+ | ------------------ | ----- | ------- | ---------------- | ------------------------------------------ |
60
+ | `--yes` | `-y` | boolean | `false` | Skip all prompts and use defaults |
61
+ | `--input <path>` | `-i` | string | `./openapi.yaml` | Path to the OpenAPI specification |
62
+ | `--output <path>` | `-o` | string | `./src/gen` | Output directory for generated files |
63
+ | `--plugins <list>` | | string | | Comma-separated list of plugins to install |
64
+
65
+ Available plugin values for `--plugins`: `plugin-ts`, `plugin-client`, `plugin-react-query`, `plugin-vue-query`, `plugin-zod`, `plugin-faker`, `plugin-msw`, `plugin-cypress`, `plugin-mcp`, `plugin-redoc`.
66
+
67
+ #### Examples
35
68
 
36
69
  ```bash
37
- npx kubb init -y
38
- ```
70
+ # Interactive wizard
71
+ npx kubb init
39
72
 
40
- Defaults when using `-y`:
73
+ # Accept all defaults
74
+ npx kubb init --yes
41
75
 
42
- - Input path: `./openapi.yaml`
43
- - Output path: `./src/gen`
44
- - Plugins: OpenAPI Parser + TypeScript
76
+ # Fully non-interactive
77
+ npx kubb init --input ./openapi.yaml --output ./src/gen --plugins plugin-ts,plugin-zod
78
+
79
+ # Select specific plugins only
80
+ npx kubb init --plugins plugin-ts,plugin-client,plugin-react-query
81
+ ```
45
82
 
46
- This command will:
83
+ The wizard will:
47
84
 
48
- 1. Detect or create a `package.json` if it doesn't exist
49
- 2. Prompt you for your OpenAPI specification path (default: `./openapi.yaml`)
50
- 3. Ask for the output directory for generated files (default: `./src/gen`)
51
- 4. Let you select which Kubb plugins to use (default: OpenAPI Parser + TypeScript)
85
+ 1. Detect or create a `package.json` if one does not exist
86
+ 2. Prompt for your OpenAPI specification path (default: `./openapi.yaml`)
87
+ 3. Ask for the output directory (default: `./src/gen`)
88
+ 4. Let you choose which plugins to install
52
89
  5. Install the selected packages using your package manager (npm, pnpm, yarn, or bun)
53
- 6. Generate a `kubb.config.ts` file with your chosen configuration
90
+ 6. Generate a `kubb.config.ts` with your chosen configuration
91
+
92
+ ---
54
93
 
55
94
  ### `kubb generate`
56
95
 
57
- Generate files based on your `kubb.config.ts` configuration.
96
+ Generate TypeScript types, API clients, React Query hooks, Zod schemas, and more from an OpenAPI specification. Reads `kubb.config.ts` by default. Pass an OpenAPI file path as the first argument to override the input without editing the config.
58
97
 
59
98
  ```bash
60
99
  npx kubb generate
61
100
  ```
62
101
 
63
- Options:
102
+ #### Options
103
+
104
+ | Flag | Short | Type | Default | Description |
105
+ | -------------------- | ----- | ------- | ------- | --------------------------------------------------------------------------------------------------- |
106
+ | `[input]` | | string | | OpenAPI file path — overrides `input.path` in the config |
107
+ | `--config <path>` | `-c` | string | | Path to the Kubb config file |
108
+ | `--logLevel <level>` | `-l` | string | `info` | Log level: `silent`, `info`, or `verbose` |
109
+ | `--watch` | `-w` | boolean | `false` | Re-generate whenever the input file changes |
110
+ | `--verbose` | `-v` | boolean | `false` | Override log level to `verbose` |
111
+ | `--silent` | `-s` | boolean | `false` | Override log level to `silent` |
112
+ | `--reporter <names>` | | string | `cli` | Reporters that render the run, comma-separated: `cli`, `json`, `file`. Overrides `config.reporters` |
113
+ | `--no-cache` | | boolean | `false` | Disable the incremental build cache and regenerate everything |
114
+
115
+ #### Examples
116
+
117
+ ```bash
118
+ # Use kubb.config.ts in the current directory
119
+ npx kubb generate
120
+
121
+ # Override the input spec without editing the config
122
+ npx kubb generate ./openapi.yaml
123
+
124
+ # Point to a custom config file
125
+ npx kubb generate --config ./configs/kubb.config.ts
126
+
127
+ # Watch for changes and regenerate automatically
128
+ npx kubb generate --watch
64
129
 
65
- - `-c, --config <path>` - Path to the Kubb config file
66
- - `-l, --logLevel <level>` - Set log level (silent, info, verbose, debug)
67
- - `-w, --watch` - Watch mode based on the input file
68
- - `-d, --debug` - Enable debug mode
69
- - `-v, --verbose` - Enable verbose mode
70
- - `-s, --silent` - Enable silent mode
130
+ # Verbose output
131
+ npx kubb generate --verbose
132
+
133
+ # Write a JSON run report alongside the CLI output
134
+ npx kubb generate --reporter cli,json
135
+ ```
136
+
137
+ ---
71
138
 
72
139
  ### `kubb validate`
73
140
 
74
- Validate a Swagger/OpenAPI file.
141
+ Parse and validate an OpenAPI/Swagger file for structural correctness. Reports schema errors, missing required fields, and malformed references. Use this before running `generate` to catch spec issues early.
75
142
 
76
143
  ```bash
77
- npx kubb validate <path-to-openapi>
144
+ npx kubb validate --input <path-or-url>
78
145
  ```
79
146
 
147
+ #### Options
148
+
149
+ | Flag | Short | Type | Required | Description |
150
+ | ---------------- | ----- | ------ | -------- | --------------------------------------------------- |
151
+ | `--input <path>` | `-i` | string | ✅ | Path or URL to the OpenAPI/Swagger file to validate |
152
+
153
+ #### Examples
154
+
155
+ ```bash
156
+ # Validate a local file
157
+ npx kubb validate --input ./openapi.yaml
158
+
159
+ # Validate a remote spec
160
+ npx kubb validate --input https://petstore3.swagger.io/api/v3/openapi.json
161
+ ```
162
+
163
+ ---
164
+
80
165
  ### `kubb mcp`
81
166
 
82
- Start the MCP server to enable the MCP client to interact with the LLM.
167
+ Start a Model Context Protocol (MCP) server that exposes Kubb code generation as a tool for AI assistants. Once running, configure your AI client (Claude, Cursor, Windsurf, etc.) to connect the assistant can then call `kubb generate` directly without leaving the chat.
168
+
169
+ Runs over **stdio** by default (compatible with all MCP clients). Pass `--port` to expose an HTTP server instead.
170
+
171
+ ```bash
172
+ npx kubb mcp
173
+ ```
174
+
175
+ #### Options
176
+
177
+ | Flag | Short | Type | Default | Description |
178
+ | ------------------- | ----- | ------ | ----------- | ----------------------------------------- |
179
+ | `--port <number>` | `-p` | string | | Port for HTTP MCP server (omit for stdio) |
180
+ | `--host <hostname>` | | string | `localhost` | Hostname to bind to (HTTP mode only) |
181
+
182
+ #### Examples
83
183
 
84
184
  ```bash
185
+ # stdio mode (recommended for Claude Desktop, Cursor, etc.)
85
186
  npx kubb mcp
187
+
188
+ # HTTP mode
189
+ npx kubb mcp --port 3001
190
+ ```
191
+
192
+ #### MCP client configuration
193
+
194
+ Add the following to your MCP client config (e.g. Claude Desktop's `claude_desktop_config.json`):
195
+
196
+ ```json
197
+ {
198
+ "mcpServers": {
199
+ "kubb": {
200
+ "command": "npx",
201
+ "args": ["kubb", "mcp"]
202
+ }
203
+ }
204
+ }
86
205
  ```
87
206
 
88
207
  ## Supporting Kubb
89
208
 
90
- Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
209
+ Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:
91
210
 
92
211
  - [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
212
+ - [See sponsorship tiers and our sponsors](https://kubb.dev/sponsors)
93
213
 
94
214
  <p align="center">
95
215
  <a href="https://github.com/sponsors/stijnvanhulle">
@@ -97,19 +217,19 @@ Kubb uses an MIT-licensed open source project with its ongoing development made
97
217
  </a>
98
218
  </p>
99
219
 
220
+ ## License
221
+
222
+ [MIT](https://github.com/kubb-labs/kubb/blob/main/licenses/LICENSE-MIT)
223
+
100
224
  <!-- Badges -->
101
225
 
102
- [npm-version-src]: https://img.shields.io/npm/v/@kubb/cli?flat&colorA=18181B&colorB=f58517
103
- [npm-version-href]: https://npmjs.com/package/@kubb/cli
104
- [npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/cli?flat&colorA=18181B&colorB=f58517
105
- [npm-downloads-href]: https://npmjs.com/package/@kubb/cli
106
- [license-src]: https://img.shields.io/github/license/kubb-labs/kubb.svg?flat&colorA=18181B&colorB=f58517
226
+ [npm-version-src]: https://shieldcn.dev/npm/v/@kubb/cli.svg?variant=secondary&size=xs&theme=zinc&mode=dark
227
+ [npm-version-href]: https://npmx.dev/package/@kubb/cli
228
+ [npm-downloads-src]: https://shieldcn.dev/npm/dm/@kubb/cli.svg?variant=secondary&size=xs&theme=zinc&mode=dark
229
+ [npm-downloads-href]: https://npmx.dev/package/@kubb/cli
230
+ [stars-src]: https://shieldcn.dev/github/stars/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
231
+ [stars-href]: https://github.com/kubb-labs/kubb
232
+ [license-src]: https://shieldcn.dev/npm/license/@kubb/cli.svg?variant=secondary&size=xs&theme=zinc
107
233
  [license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
108
- [build-src]: https://img.shields.io/github/actions/workflow/status/kubb-labs/kubb/ci.yaml?style=flat&colorA=18181B&colorB=f58517
109
- [build-href]: https://www.npmjs.com/package/@kubb/cli
110
- [minified-src]: https://img.shields.io/bundlephobia/min/@kubb/cli?style=flat&colorA=18181B&colorB=f58517
111
- [minified-href]: https://www.npmjs.com/package/@kubb/cli
112
- [coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
113
- [coverage-href]: https://www.npmjs.com/package/@kubb/cli
114
- [sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
115
- [sponsors-href]: https://github.com/sponsors/stijnvanhulle/
234
+ [node-src]: https://shieldcn.dev/npm/node/@kubb/cli.svg?variant=secondary&size=xs&theme=zinc&mode=dark
235
+ [node-href]: https://npmx.dev/package/@kubb/cli
@@ -0,0 +1,350 @@
1
+ const require_chunk = require("./chunk-Bx3C2hgW.cjs");
2
+ let node_crypto = require("node:crypto");
3
+ let node_dns = require("node:dns");
4
+ let node_os = require("node:os");
5
+ node_os = require_chunk.__toESM(node_os, 1);
6
+ let node_process = require("node:process");
7
+ node_process = require_chunk.__toESM(node_process, 1);
8
+ //#region ../../internals/utils/src/env.ts
9
+ /**
10
+ * Returns `true` when the process is running in a CI environment.
11
+ * Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,
12
+ * TeamCity, Buildkite, and Azure Pipelines.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * if (isCIEnvironment()) {
17
+ * logger.level = 'error'
18
+ * }
19
+ * ```
20
+ */
21
+ function isCIEnvironment() {
22
+ return !!(process.env.CI || process.env.GITHUB_ACTIONS || process.env.GITLAB_CI || process.env.BITBUCKET_BUILD_NUMBER || process.env.JENKINS_URL || process.env.CIRCLECI || process.env.TRAVIS || process.env.TEAMCITY_VERSION || process.env.BUILDKITE || process.env.TF_BUILD);
23
+ }
24
+ /**
25
+ * Returns `true` when the process has an interactive TTY with a valid terminal
26
+ * width and is not running in CI.
27
+ *
28
+ * Some IDE-embedded terminals report `isTTY = true` but set `columns` to `0`,
29
+ * which breaks clack's box-drawing helpers (they call `String.prototype.repeat`
30
+ * with a negative count and throw a `RangeError`). We therefore require a
31
+ * positive column count before declaring the TTY usable.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * if (canUseTTY()) {
36
+ * renderProgressBar()
37
+ * }
38
+ * ```
39
+ */
40
+ function canUseTTY() {
41
+ return !!process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment();
42
+ }
43
+ //#endregion
44
+ //#region ../../internals/utils/src/network.ts
45
+ /**
46
+ * Well-known stable domains used as DNS probes to check internet connectivity.
47
+ */
48
+ const TEST_DOMAINS = [
49
+ "dns.google.com",
50
+ "cloudflare.com",
51
+ "one.one.one.one"
52
+ ];
53
+ /**
54
+ * Returns `true` when the system has internet connectivity.
55
+ * Probes DNS resolution against well-known stable domains.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * if (await isOnline()) {
60
+ * await fetchLatestVersion()
61
+ * }
62
+ * ```
63
+ */
64
+ async function isOnline() {
65
+ for (const domain of TEST_DOMAINS) try {
66
+ await node_dns.promises.resolve(domain);
67
+ return true;
68
+ } catch {}
69
+ return false;
70
+ }
71
+ /**
72
+ * Executes `fn` only when the system is online. Returns `null` when offline or on error.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * const version = await executeIfOnline(() => fetchLatestVersion('kubb'))
77
+ * // null when offline
78
+ * ```
79
+ */
80
+ async function executeIfOnline(fn) {
81
+ if (!await isOnline()) return null;
82
+ try {
83
+ return await fn();
84
+ } catch {
85
+ return null;
86
+ }
87
+ }
88
+ //#endregion
89
+ //#region ../../internals/utils/src/runtime.ts
90
+ /**
91
+ * Returns `true` when the current process is running under Bun.
92
+ *
93
+ * Detection keys off the global `Bun` object rather than `process.versions`,
94
+ * because Bun polyfills `process.versions.node` for Node compatibility and would
95
+ * otherwise look like Node.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * if (isBun()) {
100
+ * await Bun.write(path, data)
101
+ * }
102
+ * ```
103
+ */
104
+ function isBun() {
105
+ return typeof Bun !== "undefined";
106
+ }
107
+ /**
108
+ * Returns `true` when the current process is running under Deno.
109
+ */
110
+ function isDeno() {
111
+ return typeof globalThis.Deno !== "undefined";
112
+ }
113
+ /**
114
+ * Returns the name of the runtime executing the current process.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * getRuntimeName() // 'bun' when run with `bun kubb`, 'node' otherwise
119
+ * ```
120
+ */
121
+ function getRuntimeName() {
122
+ if (isBun()) return "bun";
123
+ if (isDeno()) return "deno";
124
+ return "node";
125
+ }
126
+ /**
127
+ * Returns the version of the active runtime, or an empty string when it cannot be read.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * getRuntimeVersion() // '1.3.11' under Bun, '22.22.2' under Node
132
+ * ```
133
+ */
134
+ function getRuntimeVersion() {
135
+ if (isBun()) return process.versions.bun ?? "";
136
+ if (isDeno()) return globalThis.Deno?.version?.deno ?? "";
137
+ return process.versions?.node ?? "";
138
+ }
139
+ //#endregion
140
+ //#region src/constants.ts
141
+ /**
142
+ * NPM registry endpoint used to check for @kubb/cli updates.
143
+ */
144
+ const KUBB_NPM_PACKAGE_URL = "https://registry.npmjs.org/@kubb/cli/latest";
145
+ /**
146
+ * OpenTelemetry ingestion endpoint for anonymous usage telemetry.
147
+ */
148
+ const OTLP_ENDPOINT = "https://otlp.kubb.dev";
149
+ "─".repeat(27);
150
+ /**
151
+ * Glob pattern for paths the file watcher ignores.
152
+ */
153
+ const WATCHER_IGNORED_PATHS = "**/{.git,node_modules}/**";
154
+ /**
155
+ * Flags that short-circuit execution (help/version), no telemetry notice is shown.
156
+ */
157
+ const QUIET_FLAGS = new Set([
158
+ "--help",
159
+ "-h",
160
+ "--version",
161
+ "-v"
162
+ ]);
163
+ //#endregion
164
+ //#region src/Telemetry.ts
165
+ /**
166
+ * Anonymous OTLP usage telemetry for the Kubb run. All methods are static, so call them as
167
+ * `Telemetry.build(...)`, `Telemetry.send(...)`, and `Telemetry.isDisabled()`. No file paths,
168
+ * OpenAPI specs, or secrets are ever included, and sending fails silently to never break a run.
169
+ */
170
+ var Telemetry = class Telemetry {
171
+ /**
172
+ * Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.
173
+ */
174
+ static isDisabled() {
175
+ return node_process.default.env["DO_NOT_TRACK"] === "1" || node_process.default.env["DO_NOT_TRACK"] === "true" || node_process.default.env["KUBB_DISABLE_TELEMETRY"] === "1" || node_process.default.env["KUBB_DISABLE_TELEMETRY"] === "true";
176
+ }
177
+ /**
178
+ * Build an anonymous telemetry payload from a completed generation run.
179
+ */
180
+ static build(options) {
181
+ const [seconds, nanoseconds] = node_process.default.hrtime(options.hrStart);
182
+ const duration = Math.round(seconds * 1e3 + nanoseconds / 1e6);
183
+ return {
184
+ command: options.command,
185
+ kubbVersion: options.kubbVersion,
186
+ nodeVersion: node_process.default.versions.node.split(".")[0],
187
+ runtime: getRuntimeName(),
188
+ runtimeVersion: getRuntimeVersion().split(".")[0],
189
+ platform: node_os.default.platform(),
190
+ ci: isCIEnvironment(),
191
+ plugins: options.plugins ?? [],
192
+ duration,
193
+ filesCreated: options.filesCreated ?? 0,
194
+ status: options.status
195
+ };
196
+ }
197
+ /**
198
+ * Convert a {@link TelemetryEvent} into an OTLP-compatible JSON trace payload.
199
+ * See https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/
200
+ */
201
+ static buildOtlpPayload(event) {
202
+ const traceId = (0, node_crypto.randomBytes)(16).toString("hex");
203
+ const spanId = (0, node_crypto.randomBytes)(8).toString("hex");
204
+ const endTimeNs = BigInt(Date.now()) * 1000000n;
205
+ const startTimeNs = endTimeNs - BigInt(event.duration) * 1000000n;
206
+ const attributes = [
207
+ {
208
+ key: "kubb.command",
209
+ value: { stringValue: event.command }
210
+ },
211
+ {
212
+ key: "kubb.version",
213
+ value: { stringValue: event.kubbVersion }
214
+ },
215
+ {
216
+ key: "kubb.node_version",
217
+ value: { stringValue: event.nodeVersion }
218
+ },
219
+ {
220
+ key: "kubb.runtime",
221
+ value: { stringValue: event.runtime }
222
+ },
223
+ {
224
+ key: "kubb.runtime_version",
225
+ value: { stringValue: event.runtimeVersion }
226
+ },
227
+ {
228
+ key: "kubb.platform",
229
+ value: { stringValue: event.platform }
230
+ },
231
+ {
232
+ key: "kubb.ci",
233
+ value: { boolValue: event.ci }
234
+ },
235
+ {
236
+ key: "kubb.files_created",
237
+ value: { intValue: event.filesCreated }
238
+ },
239
+ {
240
+ key: "kubb.status",
241
+ value: { stringValue: event.status }
242
+ },
243
+ {
244
+ key: "kubb.plugins",
245
+ value: { arrayValue: { values: event.plugins.map((p) => ({ kvlistValue: { values: [{
246
+ key: "name",
247
+ value: { stringValue: p.name }
248
+ }, {
249
+ key: "options",
250
+ value: { stringValue: JSON.stringify({
251
+ ...p.options,
252
+ usedEnumNames: void 0
253
+ }) }
254
+ }] } })) } }
255
+ }
256
+ ];
257
+ return { resourceSpans: [{
258
+ resource: { attributes: [
259
+ {
260
+ key: "service.name",
261
+ value: { stringValue: "kubb-core" }
262
+ },
263
+ {
264
+ key: "service.version",
265
+ value: { stringValue: event.kubbVersion }
266
+ },
267
+ {
268
+ key: "telemetry.sdk.language",
269
+ value: { stringValue: "nodejs" }
270
+ }
271
+ ] },
272
+ scopeSpans: [{
273
+ scope: {
274
+ name: "kubb-core",
275
+ version: event.kubbVersion
276
+ },
277
+ spans: [{
278
+ traceId,
279
+ spanId,
280
+ name: event.command,
281
+ kind: 1,
282
+ startTimeUnixNano: String(startTimeNs),
283
+ endTimeUnixNano: String(endTimeNs),
284
+ attributes,
285
+ status: { code: event.status === "success" ? 1 : 2 }
286
+ }]
287
+ }]
288
+ }] };
289
+ }
290
+ /**
291
+ * Send an anonymous telemetry event to the Kubb OTLP endpoint. Respects `DO_NOT_TRACK` and
292
+ * `KUBB_DISABLE_TELEMETRY`, and fails silently so telemetry never interrupts a run.
293
+ */
294
+ static async send(event) {
295
+ if (Telemetry.isDisabled()) return;
296
+ await executeIfOnline(async () => {
297
+ try {
298
+ await fetch(`${OTLP_ENDPOINT}/v1/traces`, {
299
+ method: "POST",
300
+ headers: {
301
+ "Content-Type": "application/json",
302
+ "Kubb-Telemetry-Version": "1",
303
+ "Kubb-Telemetry-Source": "kubb-core"
304
+ },
305
+ body: JSON.stringify(Telemetry.buildOtlpPayload(event)),
306
+ signal: AbortSignal.timeout(5e3)
307
+ });
308
+ } catch (_e) {}
309
+ });
310
+ }
311
+ };
312
+ //#endregion
313
+ Object.defineProperty(exports, "KUBB_NPM_PACKAGE_URL", {
314
+ enumerable: true,
315
+ get: function() {
316
+ return KUBB_NPM_PACKAGE_URL;
317
+ }
318
+ });
319
+ Object.defineProperty(exports, "QUIET_FLAGS", {
320
+ enumerable: true,
321
+ get: function() {
322
+ return QUIET_FLAGS;
323
+ }
324
+ });
325
+ Object.defineProperty(exports, "Telemetry", {
326
+ enumerable: true,
327
+ get: function() {
328
+ return Telemetry;
329
+ }
330
+ });
331
+ Object.defineProperty(exports, "WATCHER_IGNORED_PATHS", {
332
+ enumerable: true,
333
+ get: function() {
334
+ return WATCHER_IGNORED_PATHS;
335
+ }
336
+ });
337
+ Object.defineProperty(exports, "canUseTTY", {
338
+ enumerable: true,
339
+ get: function() {
340
+ return canUseTTY;
341
+ }
342
+ });
343
+ Object.defineProperty(exports, "executeIfOnline", {
344
+ enumerable: true,
345
+ get: function() {
346
+ return executeIfOnline;
347
+ }
348
+ });
349
+
350
+ //# sourceMappingURL=Telemetry-BG80bcoQ.cjs.map