gen-api-types 1.0.12 → 1.0.14
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 +26 -0
- package/docs/images/image.png +0 -0
- package/package.json +2 -1
- package/src/cli/index.ts +2 -6
package/README.md
CHANGED
|
@@ -148,3 +148,29 @@ npx gen-api-types --isExported -o output_dir -O output_file_name ./api_dir1 ./ap
|
|
|
148
148
|
export type XXX = { name: string };
|
|
149
149
|
export type Response_TestApi_getWeather = {...}
|
|
150
150
|
```
|
|
151
|
+
|
|
152
|
+
#### VS Code 插件
|
|
153
|
+
|
|
154
|
+
如果你在 VS Code 中使用 `gen-api-types` ,可以安装配套插件 [gen-api-types-vsce](https://github.com/xuejiangping/gen-api-types-vsce),通过右键菜单生成 API 返回类型。
|
|
155
|
+

|
|
156
|
+
|
|
157
|
+
插件不会内置 CLI,它会调用当前业务项目本地安装的 `gen-api-types`:
|
|
158
|
+
|
|
159
|
+
安装插件后,在已标记装饰器的 `.ts` / `.tsx` 文件中右键选择 `生成 API 返回类型(gen-api-types)` 即可。插件会默认:
|
|
160
|
+
|
|
161
|
+
- 将当前 TypeScript 文件所在目录作为 `api_dirs` 参数
|
|
162
|
+
- 将类型文件生成到当前 TypeScript 文件同目录
|
|
163
|
+
- 使用 `api-types.d.ts` 作为默认输出文件名
|
|
164
|
+
- 输出文件已存在时弹出覆盖确认
|
|
165
|
+
|
|
166
|
+
插件支持在 VS Code 设置中配置 CLI 参数:
|
|
167
|
+
|
|
168
|
+
| 插件配置项 | 对应 CLI 参数 | 默认行为 |
|
|
169
|
+
| ---------------------------- | ---------------------- | --------------------------------- |
|
|
170
|
+
| `gen-api-types.projectRoot` | `-r, --project_root` | 当前 TS 文件所在 workspace 根目录 |
|
|
171
|
+
| `gen-api-types.outputFile` | `-O, --output_file` | `api-types.d.ts` |
|
|
172
|
+
| `gen-api-types.outputDir` | `-o, --output_dir` | 当前 TS 文件所在目录 |
|
|
173
|
+
| `gen-api-types.tsConfigPath` | `-t, --ts_config_path` | 不传,由 CLI 使用默认值 |
|
|
174
|
+
| `gen-api-types.isExported` | `--isExported` | `false` |
|
|
175
|
+
|
|
176
|
+
插件本质上是对 CLI 的 VS Code 入口封装,类型分析、接口执行和类型文件生成仍由 `gen-api-types` 完成。
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gen-api-types",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "一个自动生成请求接口返回类型的 cli 小工具",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"exports": {
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"files": [
|
|
31
31
|
"bin",
|
|
32
32
|
"src",
|
|
33
|
+
"docs",
|
|
33
34
|
"tsconfig.json",
|
|
34
35
|
"package.json"
|
|
35
36
|
],
|
package/src/cli/index.ts
CHANGED
|
@@ -118,12 +118,8 @@ async function executeApiMethods(apiMethodsInfo: ApiMethodInfo[]): Promise<Execu
|
|
|
118
118
|
try {
|
|
119
119
|
// console.log(`🔍 Calling ${fullMethodName} with args:`, args);
|
|
120
120
|
const result = apiMethod.apply(apiModule, args)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
// console.log(`${fullMethodName} result`)
|
|
124
|
-
return { data, typeName, fullMethodName }
|
|
125
|
-
}
|
|
126
|
-
return { error: 'not Promise method', fullMethodName, typeName }
|
|
121
|
+
const data = await Promise.resolve(result)
|
|
122
|
+
return { data, typeName, fullMethodName }
|
|
127
123
|
} catch (error) {
|
|
128
124
|
console.error(`❌ ${fullMethodName} execute error:`, error)
|
|
129
125
|
return { error, fullMethodName, typeName }
|