Skip to content

Commit 1aa7317

Browse files
committed
rm pretty printer
1 parent 333d8db commit 1aa7317

File tree

3 files changed

+18
-70
lines changed

3 files changed

+18
-70
lines changed

src/TsTypes.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { camelCase, upperFirst } from 'lodash'
33
const COMMENT_START = '/**'
44
const COMMENT_INDENT = ' * '
55
const COMMENT_END = ' */'
6-
const INDENT_STRING = ' '
6+
const INDENT_STRING = ' '
77

88
export namespace TsType {
99

@@ -124,7 +124,7 @@ export namespace TsType {
124124
toDeclaration(){
125125
// if there is a value associated with the identifier, declare as identifier=value
126126
// else declare as identifier
127-
return `${this.identifier}${this.value ? ('=' + this.value) : ''}`
127+
return `${this.identifier}${this.value ? (' = ' + this.value) : ''}`
128128
}
129129

130130
toString(){
@@ -144,9 +144,13 @@ export namespace TsType {
144144
return `${this.toType(settings)}`
145145
}
146146
toDeclaration(settings: TsTypeSettings): string {
147-
return `${this.toBlockComment(settings)}export ${settings.useConstEnums ? 'const ' : ''}enum ${this.safeId()}{
148-
${this.enumValues.map(_ => _.toDeclaration()).join(',\n')}
149-
}`
147+
return this.toBlockComment(settings)
148+
+ `export ${settings.useConstEnums ? 'const ' : ''}enum ${this.safeId()} {`
149+
+ '\n'
150+
+ INDENT_STRING
151+
+ this.enumValues.map(_ => _.toDeclaration()).join(`,\n${INDENT_STRING}`)
152+
+ '\n'
153+
+ '}'
150154
}
151155
}
152156

@@ -166,7 +170,7 @@ export namespace TsType {
166170
return this.data
167171
.filter(_ => !(_ instanceof Null))
168172
.map(_ => _.toSafeType(settings))
169-
.join('&')
173+
.join(' & ')
170174
}
171175
toSafeType(settings: TsTypeSettings) {
172176
return `${this.toType(settings)}`
@@ -177,7 +181,7 @@ export namespace TsType {
177181
_type(settings: TsTypeSettings) {
178182
return this.data
179183
.map(_ => _.toSafeType(settings))
180-
.join('|')
184+
.join(' | ')
181185
}
182186
}
183187

@@ -196,9 +200,11 @@ export namespace TsType {
196200
`${INDENT_STRING}${_.type.description
197201
? this.generateComment(_.type.description).join(`\n${INDENT_STRING}`) + `\n${INDENT_STRING}`
198202
: ''
199-
}${_.name}${_.required ? '' : '?'}: ${_.type.toType(settings)}${
200-
settings.endPropertyWithSemicolon ? ';' : ''
201-
}`
203+
}${_.name}${_.required ? '' : '?'}: ${
204+
_.type.toType(settings).replace(/\n/g, '\n' + INDENT_STRING)
205+
}${
206+
settings.endPropertyWithSemicolon ? ';' : ''
207+
}`
202208
).join('\n')}
203209
}`
204210
}

src/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { EnumJSONSchema, JSONSchema, NamedEnumJSONSchema } from './JSONSchema'
2-
import { format } from './prettyPrinter'
32
import { TsType } from './TsTypes'
43
import { readFile, readFileSync } from 'fs'
54
import { isPlainObject, last, map, merge, zip } from 'lodash'
@@ -37,14 +36,13 @@ class Compiler {
3736
}
3837

3938
toString(): string {
40-
return format(
41-
[
39+
return [
4240
...Array.from(this.namedEnums.values()),
4341
...Array.from(this.declarations.values())
4442
]
4543
.map(_ => _.toDeclaration(this.settings))
4644
.join('\n')
47-
)
45+
4846
}
4947

5048
private settings: TsType.TsTypeSettings

src/prettyPrinter.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)