@devup-api/webpack-plugin 0.1.2 → 0.1.4

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,141 @@
1
1
  # @devup-api/webpack-plugin
2
2
 
3
- devup API plugin for Webpack
3
+ Webpack 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/webpack-plugin
8
+ npm install @devup-api/webpack-plugin @devup-api/fetch
9
9
  ```
10
10
 
11
11
  ## Usage
12
12
 
13
- ```typescript
14
- import devupApiWebpackPlugin from '@devup-api/webpack-plugin';
15
- import webpack from 'webpack';
13
+ ### Basic Setup
16
14
 
17
- const config: webpack.Configuration = {
15
+ Add the plugin to your `webpack.config.js`:
16
+
17
+ ```js
18
+ const { devupApiWebpackPlugin } = require('@devup-api/webpack-plugin')
19
+
20
+ module.exports = {
21
+ plugins: [new devupApiWebpackPlugin()],
22
+ }
23
+ ```
24
+
25
+ ### With Options
26
+
27
+ ```js
28
+ const { devupApiWebpackPlugin } = require('@devup-api/webpack-plugin')
29
+
30
+ module.exports = {
18
31
  plugins: [
19
32
  new devupApiWebpackPlugin({
20
- // options
21
- }),
33
+ openapiFile: './api/openapi.json',
34
+ convertCase: 'camel',
35
+ tempDir: 'temp'
36
+ })
22
37
  ],
23
- };
38
+ }
39
+ ```
40
+
41
+ ### TypeScript Configuration
42
+
43
+ If using TypeScript, you can use:
44
+
45
+ ```ts
46
+ import { devupApiWebpackPlugin } from '@devup-api/webpack-plugin'
47
+ import type { Configuration } from 'webpack'
48
+
49
+ const config: Configuration = {
50
+ plugins: [new devupApiWebpackPlugin()],
51
+ }
52
+
53
+ export default config
54
+ ```
55
+
56
+ ## Options
57
+
58
+ ```ts
59
+ interface DevupApiOptions {
60
+ /**
61
+ * OpenAPI file path
62
+ * @default 'openapi.json'
63
+ */
64
+ openapiFile?: string
65
+
66
+ /**
67
+ * Temporary directory for storing generated files
68
+ * @default 'df'
69
+ */
70
+ tempDir?: string
71
+
72
+ /**
73
+ * Case conversion type for API endpoint names and parameters
74
+ * @default 'camel'
75
+ */
76
+ convertCase?: 'snake' | 'camel' | 'pascal' | 'maintain'
77
+
78
+ /**
79
+ * Whether to make all properties non-nullable by default
80
+ * @default false
81
+ */
82
+ requestDefaultNonNullable?: boolean
83
+
84
+ /**
85
+ * Whether to make all request properties non-nullable by default
86
+ * @default true
87
+ */
88
+ responseDefaultNonNullable?: boolean
89
+ }
24
90
  ```
91
+
92
+ ## What It Does
93
+
94
+ 1. Reads your `openapi.json` file during build (before compilation)
95
+ 2. Generates TypeScript interface definitions (`api.d.ts`)
96
+ 3. Creates a URL map and injects it as `process.env.DEVUP_API_URL_MAP` via webpack DefinePlugin
97
+ 4. Makes types available for use with `@devup-api/fetch`
98
+
99
+ ## TypeScript Configuration
100
+
101
+ To use the generated types, add the generated type definitions to your `tsconfig.json`:
102
+
103
+ ```json
104
+ {
105
+ "compilerOptions": {
106
+ // ... your compiler options
107
+ },
108
+ "include": [
109
+ "src",
110
+ "df/**/*.d.ts"
111
+ ]
112
+ }
113
+ ```
114
+
115
+ > **Note:** If you've customized `tempDir` in plugin options, adjust the path accordingly (e.g., `"your-temp-dir/**/*.d.ts"`).
116
+
117
+ ## Using the Generated Types
118
+
119
+ After the plugin runs, you can use the generated types with `@devup-api/fetch`:
120
+
121
+ ```ts
122
+ import { createApi } from '@devup-api/fetch'
123
+
124
+ const api = createApi('https://api.example.com')
125
+
126
+ // Types are automatically available
127
+ const users = await api.get('getUsers', {})
128
+ ```
129
+
130
+ ## Cold Typing vs Bold Typing
131
+
132
+ devup-api uses a two-phase typing system:
133
+
134
+ - **Cold Typing**: Before the build runs, types are `any` to prevent type errors. Your code compiles and runs smoothly.
135
+ - **Bold Typing**: After the build runs and `api.d.ts` is generated, full type safety is enforced with strict type checking.
136
+
137
+ This ensures you can start coding immediately without waiting for the build, while still getting full type safety in production.
138
+
139
+ ## License
140
+
141
+ Apache 2.0
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- var{defineProperty:F,getOwnPropertyNames:Q,getOwnPropertyDescriptor:R}=Object,S=Object.prototype.hasOwnProperty;var K=new WeakMap,V=(x)=>{var W=K.get(x),q;if(W)return W;if(W=F({},"__esModule",{value:!0}),x&&typeof x==="object"||typeof x==="function")Q(x).map((z)=>!S.call(W,z)&&F(W,z,{get:()=>x[z],enumerable:!(q=R(x,z))||q.enumerable}));return K.set(x,W),W};var X=(x,W)=>{for(var q in W)F(x,q,{get:W[q],enumerable:!0,configurable:!0,set:(z)=>W[q]=()=>z})};var Y={};X(Y,{devupApiWebpackPlugin:()=>G,default:()=>G});module.exports=V(Y);var L=require("node:path"),C=require("@devup-api/generator"),B=require("@devup-api/utils"),N=require("webpack");class G{options;initialized=!1;constructor(x){this.options=x||{}}apply(x){x.hooks.beforeCompile.tapAsync("devup-api",async(W,q)=>{if(this.initialized){q();return}try{this.initialized=!0;let z=await B.createTmpDirAsync(this.options?.tempDir),H=await B.readOpenapiAsync(this.options?.openapiFile);await B.writeInterfaceAsync(L.join(z,"api.d.ts"),C.generateInterface(H,this.options));let J=C.createUrlMap(H,this.options),E={};if(J)E["process.env.DEVUP_API_URL_MAP"]=JSON.stringify(JSON.stringify(J));if(Object.keys(E).length>0)new N.DefinePlugin(E).apply(x);q()}catch(z){this.initialized=!1,q(z)}})}}
1
+ var{defineProperty:J,getOwnPropertyNames:R,getOwnPropertyDescriptor:S}=Object,V=Object.prototype.hasOwnProperty;var N=new WeakMap,X=(x)=>{var W=N.get(x),q;if(W)return W;if(W=J({},"__esModule",{value:!0}),x&&typeof x==="object"||typeof x==="function")R(x).map((B)=>!V.call(W,B)&&J(W,B,{get:()=>x[B],enumerable:!(q=S(x,B))||q.enumerable}));return N.set(x,W),W};var Y=(x,W)=>{for(var q in W)J(x,q,{get:W[q],enumerable:!0,configurable:!0,set:(B)=>W[q]=()=>B})};var Z={};Y(Z,{devupApiWebpackPlugin:()=>K,default:()=>K});module.exports=X(Z);var P=require("node:path"),E=require("@devup-api/generator"),C=require("@devup-api/utils");class K{options;initialized=!1;constructor(x){this.options=x||{}}apply(x){x.hooks.beforeCompile.tapAsync("devup-api",async(W,q)=>{if(this.initialized){q();return}try{this.initialized=!0;let B=await C.createTmpDirAsync(this.options?.tempDir),Q=C.normalizeOpenapiFiles(this.options?.openapiFiles),L=await C.readOpenapiAsync(Q);await C.writeInterfaceAsync(P.join(B,"api.d.ts"),E.generateInterface(L,this.options));let G=E.createUrlMap(L,this.options),H={};if(G&&Object.keys(G).length>0)H["process.env.DEVUP_API_URL_MAP"]=JSON.stringify(JSON.stringify(G));if(Object.keys(H).length>0)new x.webpack.DefinePlugin(H).apply(x);q()}catch(B){this.initialized=!1,q(B)}})}}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{join as F}from"node:path";import{createUrlMap as G,generateInterface as H}from"@devup-api/generator";import{createTmpDirAsync as J,readOpenapiAsync as K,writeInterfaceAsync as L}from"@devup-api/utils";import{DefinePlugin as N}from"webpack";class E{options;initialized=!1;constructor(x){this.options=x||{}}apply(x){x.hooks.beforeCompile.tapAsync("devup-api",async(Q,W)=>{if(this.initialized){W();return}try{this.initialized=!0;let q=await J(this.options?.tempDir),B=await K(this.options?.openapiFile);await L(F(q,"api.d.ts"),H(B,this.options));let C=G(B,this.options),z={};if(C)z["process.env.DEVUP_API_URL_MAP"]=JSON.stringify(JSON.stringify(C));if(Object.keys(z).length>0)new N(z).apply(x);W()}catch(q){this.initialized=!1,W(q)}})}}export{E as devupApiWebpackPlugin,E as default};
1
+ import{join as J}from"node:path";import{createUrlMap as K,generateInterface as L}from"@devup-api/generator";import{createTmpDirAsync as N,normalizeOpenapiFiles as P,readOpenapiAsync as Q,writeInterfaceAsync as R}from"@devup-api/utils";class G{options;initialized=!1;constructor(x){this.options=x||{}}apply(x){x.hooks.beforeCompile.tapAsync("devup-api",async(S,W)=>{if(this.initialized){W();return}try{this.initialized=!0;let q=await N(this.options?.tempDir),H=P(this.options?.openapiFiles),E=await Q(H);await R(J(q,"api.d.ts"),L(E,this.options));let B=K(E,this.options),C={};if(B&&Object.keys(B).length>0)C["process.env.DEVUP_API_URL_MAP"]=JSON.stringify(JSON.stringify(B));if(Object.keys(C).length>0)new x.webpack.DefinePlugin(C).apply(x);W()}catch(q){this.initialized=!1,W(q)}})}}export{G as devupApiWebpackPlugin,G as default};
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAOtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAGvC,qBAAa,qBAAqB;IAChC,OAAO,EAAE,eAAe,CAAA;IACxB,WAAW,UAAQ;gBAEP,OAAO,CAAC,EAAE,eAAe;IAIrC,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;CA6ChC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAQtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC,qBAAa,qBAAqB;IAChC,OAAO,EAAE,eAAe,CAAA;IACxB,WAAW,UAAQ;gBAEP,OAAO,CAAC,EAAE,eAAe;IAIrC,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;CA8ChC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devup-api/webpack-plugin",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -20,12 +20,11 @@
20
20
  "access": "public"
21
21
  },
22
22
  "dependencies": {
23
- "@devup-api/utils": "0.1.2",
24
- "@devup-api/core": "0.1.2",
25
- "@devup-api/generator": "0.1.2"
23
+ "@devup-api/utils": "0.1.4",
24
+ "@devup-api/core": "0.1.4",
25
+ "@devup-api/generator": "0.1.4"
26
26
  },
27
27
  "peerDependencies": {
28
- "webpack": "*",
29
28
  "@devup-api/core": "*"
30
29
  },
31
30
  "devDependencies": {