Skip to content

Commit cf9cb71

Browse files
committed
feat(writer): 新增 axiosImport 选项
1 parent 134da4e commit cf9cb71

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/writers/BaseWriter.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { TypeAlias, TypeDocument, TypeItem } from '../readers/types';
2+
import { joinSlices } from '../utils/string';
23
import { StrictWriterOptions, WriterOptions } from './types';
34
import prettier from 'prettier';
45

56
export class BaseWriter {
6-
static defaults: WriterOptions = {
7+
static defaults: StrictWriterOptions = {
8+
axiosImport: `import { Axios } from 'axios';
9+
const axios = new Axios();`,
710
prettier: {
811
singleQuote: true,
912
},
@@ -16,6 +19,11 @@ export class BaseWriter {
1619
options: StrictWriterOptions;
1720
constructor(readonly document: TypeDocument, options?: WriterOptions) {
1821
this.options = Object.assign({}, BaseWriter.defaults, options) as StrictWriterOptions;
22+
this.init();
23+
}
24+
25+
init() {
26+
//
1927
}
2028

2129
protected isTypeAlias(type: TypeItem): type is TypeAlias {
@@ -28,4 +36,25 @@ export class BaseWriter {
2836
parser: 'typescript',
2937
});
3038
}
39+
40+
// 头部声明
41+
statements: string[] = [];
42+
43+
// 头部导入
44+
imports: string[] = [];
45+
46+
// 帮助类型
47+
helpers: string[] = [];
48+
49+
writeStatements() {
50+
return joinSlices(this.statements);
51+
}
52+
53+
writeImports() {
54+
return this.format(joinSlices(this.imports));
55+
}
56+
57+
writeHelpers() {
58+
return this.format(joinSlices(this.helpers));
59+
}
3160
}

0 commit comments

Comments
 (0)