@@ -3,6 +3,7 @@ import fs from 'fs'
3
3
import path from 'path'
4
4
import { applyDiff } from 'deep-diff'
5
5
import glob from 'glob'
6
+ import { format as prettierFormat } from 'prettier'
6
7
7
8
import {
8
9
resolve ,
@@ -146,7 +147,7 @@ export const handler = async (args: Arguments<InfuseOptions>) => {
146
147
}
147
148
148
149
if ( ! args . dryRun && external ) {
149
- writeExternalLocaleMessages ( external )
150
+ writeExternalLocaleMessages ( external , prettierConfig )
150
151
}
151
152
}
152
153
@@ -280,11 +281,27 @@ async function writeSFC (sources: SFCFileInfo[], format: any, prettier: any, vue
280
281
}
281
282
}
282
283
283
- function writeExternalLocaleMessages ( meta : MetaExternalLocaleMessages [ ] ) {
284
- // TODO: async implementation
285
- meta . forEach ( ( { path, messages } ) => {
286
- fs . writeFileSync ( path , JSON . stringify ( messages , null , 2 ) )
287
- } )
284
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
285
+ function writeExternalLocaleMessages ( meta : MetaExternalLocaleMessages [ ] , prettierConfig : any ) {
286
+ const config = prettierConfig
287
+ ? Object . assign (
288
+ { } ,
289
+ prettierConfig ,
290
+ {
291
+ parser : 'json' ,
292
+ plugins : [ './node_modules/prettier-plugin-sort-json' ] ,
293
+ pluginSearchDirs : [ './node_modules' ] ,
294
+ jsonRecursiveSort : true
295
+ } )
296
+ : null
297
+ for ( const { path, messages } of meta ) {
298
+ let _messages = JSON . stringify ( messages , null , 2 )
299
+ if ( config ) {
300
+ _messages = prettierFormat ( _messages , config )
301
+ }
302
+ // TODO: async implementation
303
+ fs . writeFileSync ( path , _messages )
304
+ }
288
305
}
289
306
290
307
function loadFormat ( ) {
0 commit comments