@@ -3,6 +3,7 @@ import fs from 'fs'
33import path from 'path'
44import { applyDiff } from 'deep-diff'
55import glob from 'glob'
6+ import { format as prettierFormat } from 'prettier'
67
78import {
89 resolve ,
@@ -146,7 +147,7 @@ export const handler = async (args: Arguments<InfuseOptions>) => {
146147 }
147148
148149 if ( ! args . dryRun && external ) {
149- writeExternalLocaleMessages ( external )
150+ writeExternalLocaleMessages ( external , prettierConfig )
150151 }
151152}
152153
@@ -280,11 +281,27 @@ async function writeSFC (sources: SFCFileInfo[], format: any, prettier: any, vue
280281 }
281282}
282283
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+ }
288305}
289306
290307function loadFormat ( ) {
0 commit comments