@@ -7,17 +7,14 @@ import path from 'path';
77const pathToSrc = path . join ( __dirname , '../src' ) ;
88const srcGlob = path . join ( pathToSrc , '**/*.js' ) ;
99
10- let EXIT_CODE = 0 ;
1110const localizeRE = / ( ^ | [ \. ] ) ( _ | l o c a l i z e ) $ / ;
1211
1312findLocaleStrings ( ) ;
1413
1514function findLocaleStrings ( ) {
1615 glob ( srcGlob , ( err , files ) => {
1716 if ( err ) {
18- EXIT_CODE = 1 ;
19- console . log ( err ) ;
20- return ;
17+ throw new Error ( err ) ;
2118 }
2219
2320 const dict = { } ;
@@ -79,25 +76,23 @@ function findLocaleStrings() {
7976 } ) ;
8077
8178 if ( ! hasTranslation ) {
82- console . error ( 'Found no translations.' ) ;
83- EXIT_CODE = 1 ;
79+ throw new Error ( 'Found no translations.' ) ;
8480 }
8581
86- if ( ! EXIT_CODE ) {
87- const strings = Object . keys ( dict )
88- . sort ( )
89- . map ( k => k + spaces ( maxLen - k . length ) + ' // ' + dict [ k ] )
90- . join ( '\n' ) ;
91- const pathToTranslationKeys = path . join ( __dirname , 'translationKeys.txt' ) ;
92- fs . writeFile ( pathToTranslationKeys , strings ) ;
93- console . log ( 'ok find_locale_strings' ) ;
94- }
82+ const strings = Object . keys ( dict )
83+ . sort ( )
84+ . map ( k => k + spaces ( maxLen - k . length ) + ' // ' + dict [ k ] )
85+ . join ( '\n' ) ;
86+ const pathToTranslationKeys = path . join ( __dirname , 'translationKeys.txt' ) ;
87+ fs . writeFile ( pathToTranslationKeys , strings ) ;
88+ console . log ( `translation keys were written to: ${ pathToTranslationKeys } ` ) ;
9589 } ) ;
9690}
9791
9892function logError ( file , node , msg ) {
99- console . error ( file + ' [line ' + node . loc . start . line + '] ' + msg + '\n ' ) ;
100- EXIT_CODE = 1 ;
93+ throw new Error (
94+ file + ' [line ' + node . loc . start . line + '] ' + msg + '\n '
95+ ) ;
10196}
10297
10398function spaces ( len ) {
@@ -108,8 +103,8 @@ function spaces(len) {
108103 return out ;
109104}
110105
111- process . on ( 'exit' , function ( ) {
112- if ( EXIT_CODE ) {
113- throw new Error ( 'find_locale_strings failed.' ) ;
106+ process . on ( 'exit' , function ( code ) {
107+ if ( code === 1 ) {
108+ throw new Error ( 'findLocaleStrings failed.' ) ;
114109 }
115110} ) ;
0 commit comments