@acrool/rtk-query-codegen-openapi 1.2.0-alpha.0 → 1.2.0-alpha.1
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/lib/bin/cli.mjs +50 -37
- package/lib/bin/cli.mjs.map +1 -1
- package/lib/index.js +56 -4
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +56 -4
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/generators/rtk-query-generator.ts +10 -3
- package/src/generators/tag-types-generator.ts +30 -0
- package/src/services/api-code-generator.ts +9 -0
- package/src/services/unified-code-generator.ts +30 -1
- package/src/types.ts +1 -0
|
@@ -11,6 +11,7 @@ import { generateDoNotModifyFile } from '../generators/do-not-modify-generator';
|
|
|
11
11
|
import type { GenerationOptions, CommonOptions } from '../types';
|
|
12
12
|
import { ApiCodeGenerator } from './api-code-generator';
|
|
13
13
|
import { generateUtilsFile } from '../generators/utils-generator';
|
|
14
|
+
import { generateTagTypesFile } from '../generators/tag-types-generator';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* 統一代碼生成器選項
|
|
@@ -68,14 +69,19 @@ export class UnifiedCodeGenerator {
|
|
|
68
69
|
componentSchema: string;
|
|
69
70
|
doNotModify: string;
|
|
70
71
|
utils: string;
|
|
72
|
+
tagTypes: string;
|
|
71
73
|
} = {
|
|
72
74
|
groups: [],
|
|
73
75
|
commonTypes: '',
|
|
74
76
|
componentSchema: '',
|
|
75
77
|
doNotModify: '',
|
|
76
|
-
utils: ''
|
|
78
|
+
utils: '',
|
|
79
|
+
tagTypes: ''
|
|
77
80
|
};
|
|
78
81
|
|
|
82
|
+
// 收集所有 tags
|
|
83
|
+
private allTags: Set<string> = new Set();
|
|
84
|
+
|
|
79
85
|
|
|
80
86
|
constructor(options: UnifiedGenerationOptions) {
|
|
81
87
|
this._options = options;
|
|
@@ -98,6 +104,7 @@ export class UnifiedCodeGenerator {
|
|
|
98
104
|
this.generateSchemaContent()
|
|
99
105
|
this.generateUtilsContent()
|
|
100
106
|
this.generateDoNotModifyContent()
|
|
107
|
+
this.generateTagTypesContent()
|
|
101
108
|
|
|
102
109
|
return await this.release();
|
|
103
110
|
}
|
|
@@ -176,6 +183,11 @@ export class UnifiedCodeGenerator {
|
|
|
176
183
|
outputPath: groupInfo.outputPath,
|
|
177
184
|
content: groupContent
|
|
178
185
|
});
|
|
186
|
+
|
|
187
|
+
// 收集此群組的所有 tags
|
|
188
|
+
if (groupContent.tags && Array.isArray(groupContent.tags)) {
|
|
189
|
+
groupContent.tags.forEach((tag: string) => this.allTags.add(tag));
|
|
190
|
+
}
|
|
179
191
|
}
|
|
180
192
|
// 如果沒有任何 endpoint,則跳過此群組,不創建資料夾
|
|
181
193
|
} catch (error) {
|
|
@@ -217,6 +229,14 @@ export class UnifiedCodeGenerator {
|
|
|
217
229
|
this.generatedContent.utils = generateUtilsFile();
|
|
218
230
|
}
|
|
219
231
|
|
|
232
|
+
/**
|
|
233
|
+
* 生成 Tag Types
|
|
234
|
+
*/
|
|
235
|
+
private async generateTagTypesContent(): Promise<void> {
|
|
236
|
+
const tagsArray = Array.from(this.allTags);
|
|
237
|
+
this.generatedContent.tagTypes = generateTagTypesFile(tagsArray);
|
|
238
|
+
}
|
|
239
|
+
|
|
220
240
|
|
|
221
241
|
|
|
222
242
|
|
|
@@ -273,6 +293,15 @@ export class UnifiedCodeGenerator {
|
|
|
273
293
|
results.push(...sharedResults);
|
|
274
294
|
}
|
|
275
295
|
|
|
296
|
+
// 寫入 tagTypes.ts
|
|
297
|
+
if (this.generatedContent.tagTypes) {
|
|
298
|
+
const tagTypesResult = await this.fileWriterService.writeFile(
|
|
299
|
+
path.join(outputDir, 'tagTypes.ts'),
|
|
300
|
+
this.generatedContent.tagTypes
|
|
301
|
+
);
|
|
302
|
+
results.push(tagTypesResult);
|
|
303
|
+
}
|
|
304
|
+
|
|
276
305
|
// 寫入 component schema
|
|
277
306
|
if (this.generatedContent.componentSchema) {
|
|
278
307
|
const schemaResults = await this.fileWriterService.writeSchemaFile(
|