Skip to content

Commit e754eeb

Browse files
committed
feat(printer): 添加文件生成警告信息
- 在打印输出中添加了生成文件的警告信息,提示用户不要手动编辑 - 新增了 #printAlert 方法来生成警告信息 - 在 Printer 类的构造方法中添加了 hideAlert 参数,用于控制是否显示警告信息 - 在 printer/types.ts 中添加了 hideAlert 的类型定义
1 parent e297b53 commit e754eeb

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/printer/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { OpenAPILatest } from '../types/openapi';
22
import type { OpenApiLatest_Media, OpenApiLatest_Operation, OpenApiLatest_Parameter, OpenApiLatest_PathItem, OpenApiLatest_Request, OpenApiLatest_Response, OpenApiLatest_Schema } from './helpers';
33
import type { PrinterConfigs, PrinterOptions } from './types';
4+
import { pkgName, pkgVersion } from '../const';
45
import { OpenAPIVersion } from '../types/openapi';
56
import { toImportPath } from '../utils/path';
67
import { isString, isUndefined } from '../utils/type-is';
@@ -272,6 +273,7 @@ export class Printer {
272273
hideHeaders,
273274
hideHelpers,
274275
hideFooters,
276+
hideAlert,
275277
hideInfo,
276278
hideComponents,
277279
hideImports,
@@ -282,6 +284,7 @@ export class Printer {
282284

283285
return [
284286
!hideHeaders && header,
287+
!hideAlert && this.#printAlert(),
285288
!hideInfo && this.#printInfo(),
286289
!hideImports && this.#printImports(),
287290
!hideHelpers && Printer.helpersCode,
@@ -293,6 +296,20 @@ export class Printer {
293296
.join('\n\n');
294297
}
295298

299+
#printAlert() {
300+
return [
301+
`/**`,
302+
` * This file is generated by ${pkgName}@${pkgVersion}.`,
303+
` * Please do not edit it manually.`,
304+
` * If you use the following tools, you can refer to the corresponding documentation`,
305+
` * and ignore the check of this file.`,
306+
` * - [ESLint](https://eslint.org/docs/latest/use/configure/ignore)`,
307+
` * - [Prettier](https://prettier.io/docs/en/ignore.html)`,
308+
` * - [Biome](https://biomejs.dev/guides/configure-biome/#ignore-files)`,
309+
` */`,
310+
].join(`\n`);
311+
}
312+
296313
#printInfo() {
297314
const {
298315
contact,

src/printer/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export interface PrinterConfigs {
131131
hideHeaders?: boolean;
132132
hideHelpers?: boolean;
133133
hideFooters?: boolean;
134+
hideAlert?: boolean;
134135
hideInfo?: boolean;
135136
hideImports?: boolean;
136137
hideComponents?: boolean;

0 commit comments

Comments
 (0)