@@ -5,6 +5,7 @@ const path = require('path');
55const chalk = require ( 'chalk' ) ;
66const globby = require ( 'globby' ) ;
77const { promises : fs } = require ( 'fs' ) ;
8+ const originFs = require ( 'fs' ) ;
89const { sync : mkdirp } = require ( 'mkdirp' ) ;
910
1011const defaultOptions = {
@@ -70,14 +71,13 @@ class EasyI18n {
7071 this . infoLog ( 'output file: %s' , options . distFile ) ;
7172 }
7273
73- async resolveDir ( ) {
74+ resolveDirSync ( ) {
7475 const { options } = this ;
7576 mkdirp ( options . distDir ) ;
76- const list = globby
77+ return globby
7778 . sync ( options . srcDirs , { cwd : options . cwd } )
7879 . map ( filePath => path . resolve ( options . cwd , filePath ) )
79- . map ( filePath => this . resolveFile ( filePath ) ) ;
80- await Promise . all ( list ) ;
80+ . map ( filePath => this . resolveFileSync ( filePath ) ) ;
8181 }
8282
8383 sortKey ( data ) {
@@ -131,23 +131,25 @@ class EasyI18n {
131131 return res ;
132132 }
133133
134- async resolveFile ( filePath ) {
135- const content = await fs . readFile ( filePath , 'utf-8' ) ;
134+ resolveFileSync ( filePath ) {
135+ const content = originFs . readFileSync ( filePath , 'utf-8' ) ;
136136 const res = this . getI18nTokens ( content ) ;
137+
137138 this . currentData = {
138139 ...this . currentData ,
139140 ...res ,
140141 } ;
141142 }
142143
143- async initData ( ) {
144+ initData ( ) {
144145 const { distFile } = this . options ;
145146 try {
146147 const data = require ( distFile ) ;
147148 this . existedData = data . default || data ;
148149 } catch ( e ) {
149150 console . error ( e ) ;
150151 }
152+ this . resolveDirSync ( ) ;
151153 }
152154
153155 async run ( options = { } ) {
@@ -156,8 +158,7 @@ class EasyI18n {
156158 ...options ,
157159 } ;
158160 this . debugLog ( 'options:\n%s\n' , JSON . stringify ( this . options , null , 2 ) ) ;
159- await this . initData ( ) ;
160- await this . resolveDir ( ) ;
161+ this . initData ( ) ;
161162 await this . output ( ) ;
162163 }
163164
0 commit comments