Skip to content

Commit 101fe88

Browse files
committed
feat: 支持根据env动态配置
1 parent bc0d0c2 commit 101fe88

File tree

6 files changed

+147
-48
lines changed

6 files changed

+147
-48
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,30 @@ export const fooClient = new OpenapiClientFoo(adapter1);
9494
export const barClient = new OpenapiClientBar(adapter2);
9595
```
9696

97+
# 环境变量
98+
99+
不同运行环境下,可能需要使用不同的服务端,比如开发一套服务,生产一套服务。因此执行指令时可以传入`-env`参数
100+
101+
```bash
102+
npx foca-openapi --env development
103+
npx foca-openapi --env production
104+
```
105+
106+
配置文件使用回调函数的形式接收环境变量,并返回配置
107+
108+
```typescript
109+
import { defineConfig } from 'foca-openapi';
110+
111+
export default defineConfig((env) => {
112+
return {
113+
path:
114+
env === 'production'
115+
? 'https://api.com/openapi.json'
116+
: 'http://localhost:3000/openapi.json',
117+
};
118+
});
119+
```
120+
97121
# 参数
98122

99123
### path

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,14 @@
8080
"dependencies": {
8181
"listr2": "^8.2.3",
8282
"lodash-es": "^4.17.21",
83+
"minimist": "^1.2.8",
8384
"object-to-formdata": "^4.5.1",
8485
"openapi-types": "^12.1.3",
8586
"prettier": "^3.2.5",
8687
"query-string": "^9.0.0",
8788
"tsx": "^4.16.2",
88-
"yaml": "^2.4.5"
89+
"yaml": "^2.4.5",
90+
"yoctocolors": "^2.1.1"
8991
},
9092
"devDependencies": {
9193
"@aomex/console": "^2.0.2",
@@ -98,6 +100,7 @@
98100
"@release-it/conventional-changelog": "^8.0.1",
99101
"@tarojs/taro": "^3.6.34",
100102
"@types/lodash-es": "^4.17.12",
103+
"@types/minimist": "^1.2.5",
101104
"@types/node": "^20.14.10",
102105
"@types/qs": "^6.9.15",
103106
"@vitest/coverage-v8": "^2.0.3",

0 commit comments

Comments
 (0)