Skip to content

Commit edc699e

Browse files
antfukazupon
authored andcommitted
👕 refactor: remove unnecessary prettier dependency (#16) by @antfu
1 parent 51f222d commit edc699e

File tree

3 files changed

+6
-25
lines changed

3 files changed

+6
-25
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"glob": "^7.1.4",
1818
"js-yaml": "^3.13.1",
1919
"json5": "^2.1.0",
20-
"prettier": "^1.18.2",
2120
"vue-template-compiler": "^2.6.10",
2221
"yargs": "^13.3.0"
2322
},

src/infuser.ts

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { SFCDescriptor, SFCBlock } from 'vue-template-compiler'
22
import { Locale, MetaLocaleMessage, SFCI18nBlock, SFCFileInfo } from '../types'
33

4-
import { escape, reflectSFCDescriptor, parseContent, stringfyContent } from './utils'
5-
import prettier from 'prettier'
4+
import { escape, reflectSFCDescriptor, parseContent, stringifyContent } from './utils'
65

76
import { debug as Debug } from 'debug'
87
const debug = Debug('vue-i18n-locale-message:infuser')
@@ -30,7 +29,7 @@ function generate (meta: MetaLocaleMessage, descriptor: SFCDescriptor): string {
3029
debug(`build content:\n${content}`)
3130
debug(`content size: raw=${raw.length}, content=${content.length}`)
3231

33-
return format(content, 'vue')
32+
return content
3433
}
3534

3635
function getBlocks (descriptor: SFCDescriptor): SFCBlock[] {
@@ -68,7 +67,7 @@ function buildContent (i18nBlocks: SFCI18nBlock[], raw: string, blocks: SFCBlock
6867
}
6968

7069
contents = contents.concat(raw.slice(offset, block.start))
71-
const serialized = `\n${format(stringfyContent(messages, lang), lang)}`
70+
const serialized = `\n${stringifyContent(messages, lang), lang}`
7271
contents = contents.concat(serialized)
7372
offset = block.end as number
7473
i18nBlockCounter++
@@ -103,22 +102,5 @@ function buildI18nTag (i18nBlock: SFCI18nBlock): string {
103102

104103
return `\n
105104
${tag}
106-
${format(stringfyContent(locale ? messages[locale] : messages, lang), lang)}</i18n>`
107-
}
108-
109-
function format (source: string, lang: string): string {
110-
debug(`format: lang=${lang}, source=${source}`)
111-
112-
switch (lang) {
113-
case 'vue':
114-
return source
115-
case 'yaml':
116-
case 'yml':
117-
return prettier.format(source, { parser: 'yaml', tabWidth: 2 })
118-
case 'json5':
119-
return prettier.format(source, { parser: 'json5', tabWidth: 2 })
120-
case 'json':
121-
default:
122-
return prettier.format(source, { parser: 'json-stringify', tabWidth: 2 })
123-
}
105+
${stringifyContent(locale ? messages[locale] : messages, lang), lang}</i18n>`
124106
}

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ export function parseContent (content: string, lang: string): any {
7777
}
7878
}
7979

80-
export function stringfyContent (content: any, lang: string): string {
80+
export function stringifyContent (content: any, lang: string): string {
8181
switch (lang) {
8282
case 'yaml':
8383
case 'yml':
84-
return yaml.safeDump(content)
84+
return yaml.safeDump(content, { indent: 2 })
8585
case 'json5':
8686
return JSON5.stringify(content, null, 2)
8787
case 'json':

0 commit comments

Comments
 (0)