Skip to content

Commit 97546c3

Browse files
committed
Implement plugins
1 parent be8a57b commit 97546c3

File tree

14 files changed

+138
-25
lines changed

14 files changed

+138
-25
lines changed

bun.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@
4747
"version": "0.1.0",
4848
"dependencies": {
4949
"@devup-api/core": "workspace:*",
50+
"@devup-api/generator": "workspace:*",
5051
"@devup-api/utils": "workspace:*",
52+
"@devup-api/webpack-plugin": "workspace:*",
5153
},
5254
"devDependencies": {
5355
"@types/node": "^24.10",
56+
"@types/webpack": "^5.28",
5457
"typescript": "^5.9",
5558
},
5659
"peerDependencies": {
@@ -63,6 +66,7 @@
6366
"version": "0.1.0",
6467
"dependencies": {
6568
"@devup-api/core": "workspace:*",
69+
"@devup-api/generator": "workspace:*",
6670
"@devup-api/utils": "workspace:*",
6771
},
6872
"devDependencies": {
@@ -105,6 +109,7 @@
105109
"version": "0.1.0",
106110
"dependencies": {
107111
"@devup-api/core": "workspace:*",
112+
"@devup-api/generator": "workspace:*",
108113
"@devup-api/utils": "workspace:*",
109114
},
110115
"devDependencies": {

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
},
1212
"scripts": {
13-
"build": "tsc && bun build --target node --outfile=dist/index.js src/index.ts --production && bun build --target node --outfile=dist/index.cjs --format=cjs src/index.ts --production"
13+
"build": "tsc && bun build --target node --outfile=dist/index.js src/index.ts --production --packages=external && bun build --target node --outfile=dist/index.cjs --format=cjs src/index.ts --production --packages=external"
1414
},
1515
"devDependencies": {
1616
"@types/node": "^24.10",

packages/fetch/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
},
1212
"scripts": {
13-
"build": "tsc && bun build --target node --outfile=dist/index.js src/index.ts --production && bun build --target node --outfile=dist/index.cjs --format=cjs src/index.ts --production"
13+
"build": "tsc && bun build --target node --outfile=dist/index.js src/index.ts --production --packages=external && bun build --target node --outfile=dist/index.cjs --format=cjs src/index.ts --production --packages=external"
1414
},
1515
"dependencies": {
1616
"@devup-api/core": "workspace:*"

packages/fetch/src/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class devupApi {
123123
path: T,
124124
options?: RequestInit & Additional<T, DevupApiStruct>,
125125
) {
126-
const [method, url] = getUrlWithMethod(path)
126+
const { method, url } = getUrlWithMethod(path)
127127
return fetch(`${this.baseUrl}${url}`, {
128128
method,
129129
...this.defaultOptions,

packages/generator/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
},
1212
"scripts": {
13-
"build": "tsc && bun build --target node --outfile=dist/index.js src/index.ts --production && bun build --target node --outfile=dist/index.cjs --format=cjs src/index.ts --production"
13+
"build": "tsc && bun build --target node --outfile=dist/index.js src/index.ts --production --packages=external && bun build --target node --outfile=dist/index.cjs --format=cjs src/index.ts --production --packages=external"
1414
},
1515
"dependencies": {
1616
"@devup-api/core": "workspace:*",

packages/next-plugin/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@
1010
}
1111
},
1212
"scripts": {
13-
"build": "tsc && bun build --target node --outfile=dist/index.js src/index.ts --production && bun build --target node --outfile=dist/index.cjs --format=cjs src/index.ts --production"
13+
"build": "tsc && bun build --target node --outfile=dist/index.js src/index.ts --production --packages=external && bun build --target node --outfile=dist/index.cjs --format=cjs src/index.ts --production --packages=external"
1414
},
1515
"dependencies": {
1616
"@devup-api/utils": "workspace:*",
17-
"@devup-api/core": "workspace:*"
17+
"@devup-api/core": "workspace:*",
18+
"@devup-api/generator": "workspace:*",
19+
"@devup-api/webpack-plugin": "workspace:*"
1820
},
1921
"peerDependencies": {
2022
"next": "*",
2123
"@devup-api/core": "*"
2224
},
2325
"devDependencies": {
2426
"@types/node": "^24.10",
27+
"@types/webpack": "^5.28",
2528
"typescript": "^5.9"
2629
}
2730
}

packages/next-plugin/src/index.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
1+
import { join } from 'node:path'
12
import type { DevupApiOptions } from '@devup-api/core'
3+
import { createUrlMap, generateInterface } from '@devup-api/generator'
4+
import { createTmpDir, readOpenapi, writeInterface } from '@devup-api/utils'
5+
import { devupApiWebpackPlugin } from '@devup-api/webpack-plugin'
26
import type { NextConfig } from 'next'
7+
export function DevupUI(
8+
config: NextConfig,
9+
options: DevupApiOptions = {},
10+
): NextConfig {
11+
const isTurbo =
12+
process.env.TURBOPACK === '1' || process.env.TURBOPACK === 'auto'
13+
if (isTurbo) {
14+
const tempDir = createTmpDir(options?.tempDir)
15+
const schema = readOpenapi(options?.openapiFile)
316

4-
export default function devupApiPlugin(_options?: DevupApiOptions) {
5-
return (nextConfig: NextConfig): NextConfig => {
6-
return {
7-
...nextConfig,
8-
// Extend Next.js configuration
9-
}
17+
writeInterface(
18+
join(tempDir, 'api.d.ts'),
19+
generateInterface(schema, options),
20+
)
21+
// Create urlMap and set environment variable
22+
const urlMap = createUrlMap(schema, options)
23+
config.env ??= {}
24+
Object.assign(config.env, {
25+
DEVUP_API_URL_MAP: JSON.stringify(urlMap),
26+
})
27+
return config
1028
}
29+
30+
const webpack = config.webpack
31+
config.webpack = (config, _options) => {
32+
config.plugins.push(new devupApiWebpackPlugin(options))
33+
if (typeof webpack === 'function') return webpack(config, _options)
34+
return config
35+
}
36+
return config
1137
}

packages/rsbuild-plugin/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
}
1111
},
1212
"scripts": {
13-
"build": "tsc && bun build --target node --outfile=dist/index.js src/index.ts --production && bun build --target node --outfile=dist/index.cjs --format=cjs src/index.ts --production"
13+
"build": "tsc && bun build --target node --outfile=dist/index.js src/index.ts --production --packages=external && bun build --target node --outfile=dist/index.cjs --format=cjs src/index.ts --production --packages=external"
1414
},
1515
"dependencies": {
1616
"@devup-api/utils": "workspace:*",
17-
"@devup-api/core": "workspace:*"
17+
"@devup-api/core": "workspace:*",
18+
"@devup-api/generator": "workspace:*"
1819
},
1920
"peerDependencies": {
2021
"@rsbuild/core": "*",
Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
1+
import { join } from 'node:path'
12
import type { DevupApiOptions } from '@devup-api/core'
3+
import { createUrlMap, generateInterface } from '@devup-api/generator'
4+
import {
5+
createTmpDirAsync,
6+
readOpenapiAsync,
7+
writeInterfaceAsync,
8+
} from '@devup-api/utils'
29
import type { RsbuildPlugin } from '@rsbuild/core'
310

411
export default function devupApiRsbuildPlugin(
5-
_options?: DevupApiOptions,
12+
options?: DevupApiOptions,
613
): RsbuildPlugin {
714
return {
815
name: 'devup-api',
9-
setup: () => {},
10-
// Rsbuild plugin implementation
16+
async setup(build) {
17+
const tempDir = await createTmpDirAsync(options?.tempDir)
18+
const schema = await readOpenapiAsync(options?.openapiFile)
19+
20+
// Generate interface file
21+
await writeInterfaceAsync(
22+
join(tempDir, 'api.d.ts'),
23+
generateInterface(schema, options),
24+
)
25+
26+
// Create urlMap and set environment variable
27+
const urlMap = createUrlMap(schema, options)
28+
29+
build.modifyRsbuildConfig((config) => {
30+
config.source ??= {}
31+
config.source.define ??= {}
32+
if (urlMap) {
33+
config.source.define['process.env.DEVUP_API_URL_MAP'] =
34+
JSON.stringify(urlMap)
35+
}
36+
return config
37+
})
38+
},
1139
}
1240
}

packages/utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
},
1212
"scripts": {
13-
"build": "tsc && bun build --target node --outfile=dist/index.js src/index.ts --production && bun build --target node --outfile=dist/index.cjs --format=cjs src/index.ts --production"
13+
"build": "tsc && bun build --target node --outfile=dist/index.js src/index.ts --production --packages=external && bun build --target node --outfile=dist/index.cjs --format=cjs src/index.ts --production --packages=external"
1414
},
1515
"devDependencies": {
1616
"@types/node": "^24.10",

0 commit comments

Comments
 (0)