yapi-apifox-to-typescript 5.0.0 → 5.0.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/cjs/Generator.js +15 -21
- package/lib/esm/Generator.js +15 -21
- package/lib/esm/types.d.ts +5 -2
- package/package.json +1 -1
package/lib/cjs/Generator.js
CHANGED
|
@@ -69,7 +69,10 @@ var Generator = class {
|
|
|
69
69
|
async generate() {
|
|
70
70
|
const outputFileList = Object.create(null);
|
|
71
71
|
await Promise.all(this.config.map(async (serverConfig, serverIndex) => {
|
|
72
|
-
const projects = serverConfig.projects.
|
|
72
|
+
const projects = (serverConfig.projects?.length ? serverConfig.projects : serverConfig.serverType === "swagger" || serverConfig.serverType === "local" ? [{
|
|
73
|
+
token: "local",
|
|
74
|
+
categories: [{ id: 0 }]
|
|
75
|
+
}] : require_utils.throwError(`projects is required when serverType is ${serverConfig.serverType || "yapi"}`)).reduce((projects, project) => {
|
|
73
76
|
projects.push(...require_mini_ut.castArray(project.token).map((token) => ({
|
|
74
77
|
...project,
|
|
75
78
|
token
|
|
@@ -298,15 +301,10 @@ var Generator = class {
|
|
|
298
301
|
${content.join("\n\n").trim()}
|
|
299
302
|
`}
|
|
300
303
|
`;
|
|
301
|
-
const
|
|
304
|
+
const outputContent = `/* prettier-ignore-start */\n${await (await require_utils.getPrettier(this.options.cwd)).format(rawOutputContent, {
|
|
302
305
|
...await require_utils.getCachedPrettierOptions(),
|
|
303
306
|
filepath: outputFilePath
|
|
304
|
-
})
|
|
305
|
-
const outputContent = `${require_mini_ut.dedent`
|
|
306
|
-
/* prettier-ignore-start */
|
|
307
|
-
${prettyOutputContent}
|
|
308
|
-
/* prettier-ignore-end */
|
|
309
|
-
`}\n`;
|
|
307
|
+
})}\n/* prettier-ignore-end */\n`;
|
|
310
308
|
await fs_extra.default.outputFile(outputFilePath, outputContent);
|
|
311
309
|
if (syntheticalConfig.target === "javascript") {
|
|
312
310
|
await this.tsc(outputFilePath);
|
|
@@ -325,23 +323,19 @@ var Generator = class {
|
|
|
325
323
|
const modulesDir = path.default.join(path.default.dirname(barrelPath), "modules");
|
|
326
324
|
const moduleExports = Object.keys(outputFileList).filter((f) => f.startsWith(modulesDir)).map((f) => `./modules/${path.default.basename(f, path.default.extname(f))}`).sort();
|
|
327
325
|
if (moduleExports.length === 0) continue;
|
|
328
|
-
const rawBarrelContent =
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
326
|
+
const rawBarrelContent = [
|
|
327
|
+
"/* tslint:disable */",
|
|
328
|
+
"/* eslint-disable */",
|
|
329
|
+
"",
|
|
330
|
+
"/* 该文件由 yapi-apifox-to-typescript 自动生成,请勿直接修改!!! */",
|
|
331
|
+
"",
|
|
332
|
+
...moduleExports.map((m) => `export * from ${JSON.stringify(m)}`)
|
|
333
|
+
].join("\n");
|
|
336
334
|
const prettyBarrelContent = await prettier.format(rawBarrelContent, {
|
|
337
335
|
...await require_utils.getCachedPrettierOptions(),
|
|
338
336
|
filepath: barrelPath
|
|
339
337
|
});
|
|
340
|
-
await fs_extra.default.outputFile(barrelPath,
|
|
341
|
-
/* prettier-ignore-start */
|
|
342
|
-
${prettyBarrelContent}
|
|
343
|
-
/* prettier-ignore-end */
|
|
344
|
-
`}\n`);
|
|
338
|
+
await fs_extra.default.outputFile(barrelPath, `/* prettier-ignore-start */\n${prettyBarrelContent}\n/* prettier-ignore-end */\n`);
|
|
345
339
|
}
|
|
346
340
|
}
|
|
347
341
|
}
|
package/lib/esm/Generator.js
CHANGED
|
@@ -65,7 +65,10 @@ var Generator = class {
|
|
|
65
65
|
async generate() {
|
|
66
66
|
const outputFileList = Object.create(null);
|
|
67
67
|
await Promise.all(this.config.map(async (serverConfig, serverIndex) => {
|
|
68
|
-
const projects = serverConfig.projects.
|
|
68
|
+
const projects = (serverConfig.projects?.length ? serverConfig.projects : serverConfig.serverType === "swagger" || serverConfig.serverType === "local" ? [{
|
|
69
|
+
token: "local",
|
|
70
|
+
categories: [{ id: 0 }]
|
|
71
|
+
}] : throwError(`projects is required when serverType is ${serverConfig.serverType || "yapi"}`)).reduce((projects, project) => {
|
|
69
72
|
projects.push(...castArray(project.token).map((token) => ({
|
|
70
73
|
...project,
|
|
71
74
|
token
|
|
@@ -294,15 +297,10 @@ var Generator = class {
|
|
|
294
297
|
${content.join("\n\n").trim()}
|
|
295
298
|
`}
|
|
296
299
|
`;
|
|
297
|
-
const
|
|
300
|
+
const outputContent = `/* prettier-ignore-start */\n${await (await getPrettier(this.options.cwd)).format(rawOutputContent, {
|
|
298
301
|
...await getCachedPrettierOptions(),
|
|
299
302
|
filepath: outputFilePath
|
|
300
|
-
})
|
|
301
|
-
const outputContent = `${dedent`
|
|
302
|
-
/* prettier-ignore-start */
|
|
303
|
-
${prettyOutputContent}
|
|
304
|
-
/* prettier-ignore-end */
|
|
305
|
-
`}\n`;
|
|
303
|
+
})}\n/* prettier-ignore-end */\n`;
|
|
306
304
|
await fs.outputFile(outputFilePath, outputContent);
|
|
307
305
|
if (syntheticalConfig.target === "javascript") {
|
|
308
306
|
await this.tsc(outputFilePath);
|
|
@@ -321,23 +319,19 @@ var Generator = class {
|
|
|
321
319
|
const modulesDir = path.join(path.dirname(barrelPath), "modules");
|
|
322
320
|
const moduleExports = Object.keys(outputFileList).filter((f) => f.startsWith(modulesDir)).map((f) => `./modules/${path.basename(f, path.extname(f))}`).sort();
|
|
323
321
|
if (moduleExports.length === 0) continue;
|
|
324
|
-
const rawBarrelContent =
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
322
|
+
const rawBarrelContent = [
|
|
323
|
+
"/* tslint:disable */",
|
|
324
|
+
"/* eslint-disable */",
|
|
325
|
+
"",
|
|
326
|
+
"/* 该文件由 yapi-apifox-to-typescript 自动生成,请勿直接修改!!! */",
|
|
327
|
+
"",
|
|
328
|
+
...moduleExports.map((m) => `export * from ${JSON.stringify(m)}`)
|
|
329
|
+
].join("\n");
|
|
332
330
|
const prettyBarrelContent = await prettier.format(rawBarrelContent, {
|
|
333
331
|
...await getCachedPrettierOptions(),
|
|
334
332
|
filepath: barrelPath
|
|
335
333
|
});
|
|
336
|
-
await fs.outputFile(barrelPath,
|
|
337
|
-
/* prettier-ignore-start */
|
|
338
|
-
${prettyBarrelContent}
|
|
339
|
-
/* prettier-ignore-end */
|
|
340
|
-
`}\n`);
|
|
334
|
+
await fs.outputFile(barrelPath, `/* prettier-ignore-start */\n${prettyBarrelContent}\n/* prettier-ignore-end */\n`);
|
|
341
335
|
}
|
|
342
336
|
}
|
|
343
337
|
}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -599,11 +599,14 @@ export interface ServerConfig extends SharedConfig {
|
|
|
599
599
|
serverType?: 'yapi' | 'swagger' | 'apifox' | 'local';
|
|
600
600
|
/**
|
|
601
601
|
* 项目列表。
|
|
602
|
+
*
|
|
603
|
+
* 当 serverType 为 `swagger` 或 `local` 时可省略,
|
|
604
|
+
* 缺省时默认使用单个虚拟项目(token 不参与鉴权)并生成全部分类的接口。
|
|
602
605
|
*/
|
|
603
|
-
projects
|
|
606
|
+
projects?: ProjectConfig[];
|
|
604
607
|
}
|
|
605
608
|
/** 混合的配置。 */
|
|
606
|
-
export type SyntheticalConfig = Partial<ServerConfig &
|
|
609
|
+
export type SyntheticalConfig = Partial<ServerConfig & ProjectConfig & ProjectConfig['categories'][0] & {
|
|
607
610
|
mockUrl: string;
|
|
608
611
|
devUrl: string;
|
|
609
612
|
prodUrl: string;
|