@@ -5,7 +5,7 @@ const prettier = require('prettier');
55
66main ( ) ;
77
8- function main ( ) {
8+ async function main ( ) {
99 const flagFile = path . resolve ( __dirname , '../platforms/android/.flag_done' ) ;
1010 if ( fs . existsSync ( flagFile ) ) {
1111 return ;
@@ -52,7 +52,7 @@ function main() {
5252 'android.view.inputmethod.InputConnection' ,
5353 'android.view.inputmethod.EditorInfo' ,
5454 ] ,
55- 'feilds ' : [
55+ 'fields ' : [
5656 {
5757 type : 'int' ,
5858 name : 'type' ,
@@ -128,7 +128,7 @@ function main() {
128128 }
129129 ]
130130 }
131- }
131+ } ;
132132
133133 const fileContent = { } ;
134134
@@ -139,10 +139,8 @@ function main() {
139139 for ( let file in contentToAdd ) {
140140 const content = fileContent [ file ] ;
141141 const contentToAddTo = contentToAdd [ file ] ;
142- let newContent = prettier . format ( removeComments ( content ) , {
143- parser : 'java' ,
144- printWidth : Infinity
145- } ) ;
142+ const text = removeComments ( content ) ;
143+ let newContent = await format ( text ) ;
146144 if ( contentToAddTo . import ) {
147145 const imports = contentToAddTo . import . map ( importStr => {
148146 return `import ${ importStr } ;` ;
@@ -153,13 +151,13 @@ function main() {
153151 `$1${ imports } \n$2`
154152 ) ;
155153 }
156- if ( contentToAddTo . feilds ) {
157- const feilds = contentToAddTo . feilds . map ( feild => {
158- return getFeildString ( feild ) ;
154+ if ( contentToAddTo . fields ) {
155+ const fields = contentToAddTo . fields . map ( field => {
156+ return getFieldString ( field ) ;
159157 } ) . join ( '\n' ) ;
160158 newContent = newContent . replace (
161159 / ^ ( \s * ) ( \w + \s + \w + \s * ; ) / m,
162- `$1${ feilds } \n$2`
160+ `$1${ fields } \n$2`
163161 ) ;
164162 }
165163 if ( contentToAddTo . methods ) {
@@ -190,11 +188,7 @@ function main() {
190188 }
191189 }
192190
193- newContent = prettier . format ( newContent , {
194- parser : 'java' ,
195- tabWidth : 2 ,
196- printWidth : Infinity ,
197- } ) ;
191+ newContent = await format ( newContent ) ;
198192 fs . writeFile ( files [ file ] , newContent , err => {
199193 if ( err ) {
200194 console . log ( err ) ;
@@ -214,6 +208,15 @@ function main() {
214208 console . log ( `${ flagFile } updated` ) ;
215209 } ) ;
216210
211+ async function format ( content ) {
212+ return prettier . format ( content , {
213+ plugins : [ 'prettier-plugin-java' ] ,
214+ parser : 'java' ,
215+ tabWidth : 2 ,
216+ printWidth : Infinity
217+ } ) ;
218+ }
219+
217220 function getMethodString ( method ) {
218221 const params = method . params . map ( param => {
219222 return `${ param . type } ${ param . name } ` ;
@@ -229,8 +232,8 @@ function main() {
229232 return str + ';' ;
230233 }
231234
232- function getFeildString ( feild ) {
233- return `${ feild . modifier } ${ feild . type } ${ feild . name } ${ feild . value ? ` = ${ feild . value } ` : '' } ;` ;
235+ function getFieldString ( field ) {
236+ return `${ field . modifier } ${ field . type } ${ field . name } ${ field . value ? ` = ${ field . value } ` : '' } ;` ;
234237 }
235238
236239 function isInterface ( filename , content ) {
0 commit comments