gen-api-types 1.0.10 → 1.0.12
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.en.md +4 -4
- package/README.md +4 -4
- package/package.json +2 -6
- package/src/argv/index.ts +13 -2
package/README.en.md
CHANGED
|
@@ -104,26 +104,26 @@ Request results:
|
|
|
104
104
|
|
|
105
105
|
##### 3. Using the types
|
|
106
106
|
|
|
107
|
-
By default, a type definition file
|
|
107
|
+
By default, a type definition file api-types.d.ts is generated, and the type declarations are not exported:
|
|
108
108
|
|
|
109
109
|
```ts
|
|
110
110
|
type XXX = { name: string };
|
|
111
111
|
type Response_TestApi_getWeather = {...}
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
You can configure `include` in tsconfig.json to reference
|
|
114
|
+
You can configure `include` in tsconfig.json to reference it:
|
|
115
115
|
|
|
116
116
|
```json
|
|
117
117
|
// tsconfig.json
|
|
118
118
|
{
|
|
119
|
-
"include": ["
|
|
119
|
+
"include": ["api-types.d.ts"]
|
|
120
120
|
}
|
|
121
121
|
```
|
|
122
122
|
|
|
123
123
|
Or reference it directly at the top of the interface module file:
|
|
124
124
|
|
|
125
125
|
```ts
|
|
126
|
-
/// <reference path="./
|
|
126
|
+
/// <reference path="./api-types.d.ts" />
|
|
127
127
|
export class TestApi {
|
|
128
128
|
@gen_type_m()
|
|
129
129
|
static getWeather(): Promise<Response_TestApi_getWeather> {
|
package/README.md
CHANGED
|
@@ -105,26 +105,26 @@ sourceFilesGlob [ 'src\\**\\*.ts' ]
|
|
|
105
105
|
|
|
106
106
|
##### 3. 使用类型
|
|
107
107
|
|
|
108
|
-
默认生成类型文件
|
|
108
|
+
默认生成类型文件 api-types.d.ts,且类型声明没有导出
|
|
109
109
|
|
|
110
110
|
```ts
|
|
111
111
|
type XXX = { name: string };
|
|
112
112
|
type Response_TestApi_getWeather = {...}
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
-
可在`tsconfig.json`中配置`include
|
|
115
|
+
可在`tsconfig.json`中配置`include`引用
|
|
116
116
|
|
|
117
117
|
```json
|
|
118
118
|
// tsconfig.json
|
|
119
119
|
{
|
|
120
|
-
"include": ["
|
|
120
|
+
"include": ["api-types.d.ts"]
|
|
121
121
|
}
|
|
122
122
|
```
|
|
123
123
|
|
|
124
124
|
或者直接在接口模块文件顶部通过 reference 引用:
|
|
125
125
|
|
|
126
126
|
```ts
|
|
127
|
-
/// <reference path="./
|
|
127
|
+
/// <reference path="./api-types.d.ts" />
|
|
128
128
|
export class TestApi {
|
|
129
129
|
@gen_type_m()
|
|
130
130
|
static getWeather(): Promise<Response_TestApi_getWeather> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gen-api-types",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "一个自动生成请求接口返回类型的 cli 小工具",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"exports": {
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"test": "vitest",
|
|
20
|
-
"build": "webpack",
|
|
21
20
|
"publish:patch": "npm version patch && git push --tags && npm publish",
|
|
22
21
|
"preinstall": "echo preinstall 。。。",
|
|
23
22
|
"postinstall": "echo postinstall 。。。"
|
|
@@ -43,9 +42,6 @@
|
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
44
|
"@types/node": "^24.3.1",
|
|
46
|
-
"
|
|
47
|
-
"vitest": "^3.2.4",
|
|
48
|
-
"webpack": "^5.101.0",
|
|
49
|
-
"webpack-cli": "^6.0.1"
|
|
45
|
+
"vitest": "^3.2.4"
|
|
50
46
|
}
|
|
51
47
|
}
|
package/src/argv/index.ts
CHANGED
|
@@ -4,15 +4,26 @@ import { parseArgs } from "util";
|
|
|
4
4
|
|
|
5
5
|
// 1. 配置
|
|
6
6
|
const PROJECT_ROOT = path.resolve();
|
|
7
|
-
const OUTPUT_FILE = '
|
|
7
|
+
const OUTPUT_FILE = 'api-types.d.ts';
|
|
8
8
|
const OUTPUT_DIR = PROJECT_ROOT
|
|
9
9
|
const TS_CONFIG_PATH = path.join(PROJECT_ROOT, 'tsconfig.json');
|
|
10
10
|
|
|
11
|
+
function normalizeArgv(args: string[]) {
|
|
12
|
+
return args.map(arg => {
|
|
13
|
+
const matched = arg.match(/^([\u2013\u2014]+)(.+)$/u)
|
|
14
|
+
if (!matched) return arg
|
|
15
|
+
|
|
16
|
+
const [, dashes, optionName] = matched
|
|
17
|
+
if (dashes.length > 1 || optionName.length > 1) return `--${optionName}`
|
|
18
|
+
return `-${optionName}`
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
11
22
|
|
|
12
23
|
|
|
13
24
|
const _arg = parseArgs({
|
|
14
25
|
allowPositionals: true,
|
|
15
|
-
args: process.argv.slice(2),
|
|
26
|
+
args: normalizeArgv(process.argv.slice(2)),
|
|
16
27
|
options: {
|
|
17
28
|
output_dir: {
|
|
18
29
|
type: 'string',
|