@kubb/renderer-jsx 5.0.0-beta.3 → 5.0.0-beta.30

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.
package/README.md ADDED
@@ -0,0 +1,124 @@
1
+ <div align="center">
2
+ <h1>@kubb/renderer-jsx</h1>
3
+ <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">
5
+ </a>
6
+
7
+ [![npm version][npm-version-src]][npm-version-href]
8
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
9
+ [![Coverage][coverage-src]][coverage-href]
10
+ [![License][license-src]][license-href]
11
+ [![Sponsors][sponsors-src]][sponsors-href]
12
+
13
+ <h4>
14
+ <a href="https://kubb.dev/" target="_blank">Documentation</a>
15
+ <span> · </span>
16
+ <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
17
+ <span> · </span>
18
+ <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Request Feature</a>
19
+ </h4>
20
+ </div>
21
+
22
+ JSX-based renderer for Kubb. Provides a custom React runtime, reconciler, and built-in components (`File`, `Function`, `Type`, `Const`) for component-based, type-safe code generation inside Kubb plugins.
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ bun add @kubb/renderer-jsx
28
+ # or
29
+ pnpm add @kubb/renderer-jsx
30
+ # or
31
+ npm install @kubb/renderer-jsx
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ Use the built-in components inside a Kubb plugin to emit generated files:
37
+
38
+ ```tsx
39
+ import { createRenderer } from '@kubb/renderer-jsx'
40
+ import { File, Function, Type } from '@kubb/renderer-jsx'
41
+
42
+ const renderer = createRenderer()
43
+
44
+ await renderer.render(
45
+ <File baseName="petStore.ts" path="src/gen/petStore.ts">
46
+ <File.Source>
47
+ <Type name="Pet">{'{ id: number; name: string }'}</Type>
48
+ <Function name="getPet" async>
49
+ {"return fetch('/pets')"}
50
+ </Function>
51
+ </File.Source>
52
+ </File>,
53
+ )
54
+
55
+ const files = renderer.files
56
+ renderer.unmount()
57
+ ```
58
+
59
+ ## Built-in Components
60
+
61
+ | Component | Description |
62
+ | --------------- | --------------------------------------------------------------------------- |
63
+ | `<File>` | Declares a generated output file with its path and optional imports/exports |
64
+ | `<File.Source>` | The source content block inside a `<File>` |
65
+ | `<Function>` | Generates a TypeScript function declaration |
66
+ | `<Type>` | Generates a TypeScript type alias |
67
+ | `<Const>` | Generates a `const` variable declaration |
68
+ | `<Jsx>` | Renders JSX expressions inside generated output |
69
+ | `<Root>` | Root container for the renderer tree |
70
+
71
+ ## API
72
+
73
+ ### `createRenderer(options?)`
74
+
75
+ Creates a new renderer instance.
76
+
77
+ ```typescript
78
+ const renderer = createRenderer({ debug: false })
79
+ await renderer.render(<MyComponent />)
80
+ const files = renderer.files // FileNode[]
81
+ renderer.unmount()
82
+ ```
83
+
84
+ ### `jsxRenderer`
85
+
86
+ Pre-built renderer instance for use directly in Kubb plugins as the `jsxRenderer` plugin option.
87
+
88
+ ## JSX Runtime
89
+
90
+ `@kubb/renderer-jsx` ships its own JSX runtime (`jsx-runtime` and `jsx-dev-runtime`). Configure your `tsconfig.json` to use it:
91
+
92
+ ```json
93
+ {
94
+ "compilerOptions": {
95
+ "jsx": "react-jsx",
96
+ "jsxImportSource": "@kubb/renderer-jsx"
97
+ }
98
+ }
99
+ ```
100
+
101
+ ## Supporting Kubb
102
+
103
+ Kubb is an 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:
104
+
105
+ - [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
106
+
107
+ <p align="center">
108
+ <a href="https://github.com/sponsors/stijnvanhulle">
109
+ <img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
110
+ </a>
111
+ </p>
112
+
113
+ <!-- Badges -->
114
+
115
+ [npm-version-src]: https://img.shields.io/npm/v/@kubb/renderer-jsx?flat&colorA=18181B&colorB=f58517
116
+ [npm-version-href]: https://npmjs.com/package/@kubb/renderer-jsx
117
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/renderer-jsx?flat&colorA=18181B&colorB=f58517
118
+ [npm-downloads-href]: https://npmjs.com/package/@kubb/renderer-jsx
119
+ [license-src]: https://img.shields.io/github/license/kubb-labs/kubb.svg?flat&colorA=18181B&colorB=f58517
120
+ [license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
121
+ [coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
122
+ [coverage-href]: https://www.npmjs.com/package/@kubb/renderer-jsx
123
+ [sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
124
+ [sponsors-href]: https://github.com/sponsors/stijnvanhulle/