@devup-api/rsbuild-plugin 0.1.1 → 0.1.3

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 CHANGED
@@ -1,24 +1,128 @@
1
1
  # @devup-api/rsbuild-plugin
2
2
 
3
- devup API plugin for Rsbuild
3
+ Rsbuild plugin for devup-api that generates TypeScript types from OpenAPI schemas.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @devup-api/rsbuild-plugin
8
+ npm install @devup-api/rsbuild-plugin @devup-api/fetch
9
9
  ```
10
10
 
11
11
  ## Usage
12
12
 
13
- ```typescript
14
- import devupApiRsbuildPlugin from '@devup-api/rsbuild-plugin';
15
- import { defineConfig } from '@rsbuild/core';
13
+ ### Basic Setup
14
+
15
+ Add the plugin to your `rsbuild.config.ts`:
16
+
17
+ ```ts
18
+ import { defineConfig } from '@rsbuild/core'
19
+ import { devupApiRsbuildPlugin } from '@devup-api/rsbuild-plugin'
20
+
21
+ export default defineConfig({
22
+ plugins: [devupApiRsbuildPlugin()],
23
+ })
24
+ ```
25
+
26
+ ### With Options
27
+
28
+ ```ts
29
+ import { defineConfig } from '@rsbuild/core'
30
+ import { devupApiRsbuildPlugin } from '@devup-api/rsbuild-plugin'
16
31
 
17
32
  export default defineConfig({
18
33
  plugins: [
19
34
  devupApiRsbuildPlugin({
20
- // options
21
- }),
35
+ openapiFile: './api/openapi.json',
36
+ convertCase: 'camel',
37
+ tempDir: 'temp'
38
+ })
22
39
  ],
23
- });
40
+ })
24
41
  ```
42
+
43
+ ## Options
44
+
45
+ ```ts
46
+ interface DevupApiOptions {
47
+ /**
48
+ * OpenAPI file path
49
+ * @default 'openapi.json'
50
+ */
51
+ openapiFile?: string
52
+
53
+ /**
54
+ * Temporary directory for storing generated files
55
+ * @default 'df'
56
+ */
57
+ tempDir?: string
58
+
59
+ /**
60
+ * Case conversion type for API endpoint names and parameters
61
+ * @default 'camel'
62
+ */
63
+ convertCase?: 'snake' | 'camel' | 'pascal' | 'maintain'
64
+
65
+ /**
66
+ * Whether to make all properties non-nullable by default
67
+ * @default false
68
+ */
69
+ requestDefaultNonNullable?: boolean
70
+
71
+ /**
72
+ * Whether to make all request properties non-nullable by default
73
+ * @default true
74
+ */
75
+ responseDefaultNonNullable?: boolean
76
+ }
77
+ ```
78
+
79
+ ## What It Does
80
+
81
+ 1. Reads your `openapi.json` file during build
82
+ 2. Generates TypeScript interface definitions (`api.d.ts`)
83
+ 3. Creates a URL map and injects it as `process.env.DEVUP_API_URL_MAP` via Rsbuild's define feature
84
+ 4. Makes types available for use with `@devup-api/fetch`
85
+
86
+ ## TypeScript Configuration
87
+
88
+ To use the generated types, add the generated type definitions to your `tsconfig.json`:
89
+
90
+ ```json
91
+ {
92
+ "compilerOptions": {
93
+ // ... your compiler options
94
+ },
95
+ "include": [
96
+ "src",
97
+ "df/**/*.d.ts"
98
+ ]
99
+ }
100
+ ```
101
+
102
+ > **Note:** If you've customized `tempDir` in plugin options, adjust the path accordingly (e.g., `"your-temp-dir/**/*.d.ts"`).
103
+
104
+ ## Using the Generated Types
105
+
106
+ After the plugin runs, you can use the generated types with `@devup-api/fetch`:
107
+
108
+ ```ts
109
+ import { createApi } from '@devup-api/fetch'
110
+
111
+ const api = createApi('https://api.example.com')
112
+
113
+ // Types are automatically available
114
+ const users = await api.get('getUsers', {})
115
+ ```
116
+
117
+ ## Cold Typing vs Bold Typing
118
+
119
+ devup-api uses a two-phase typing system:
120
+
121
+ - **Cold Typing**: Before the build runs, types are `any` to prevent type errors. Your code compiles and runs smoothly.
122
+ - **Bold Typing**: After the build runs and `api.d.ts` is generated, full type safety is enforced with strict type checking.
123
+
124
+ This ensures you can start coding immediately without waiting for the build, while still getting full type safety in production.
125
+
126
+ ## License
127
+
128
+ Apache 2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devup-api/rsbuild-plugin",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -20,9 +20,9 @@
20
20
  "access": "public"
21
21
  },
22
22
  "dependencies": {
23
- "@devup-api/utils": "0.1.1",
24
- "@devup-api/core": "0.1.1",
25
- "@devup-api/generator": "0.1.1"
23
+ "@devup-api/utils": "0.1.3",
24
+ "@devup-api/core": "0.1.3",
25
+ "@devup-api/generator": "0.1.3"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "@rsbuild/core": "*",
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/index.test.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=plugin.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/plugin.test.ts"],"names":[],"mappings":""}