@@ -6,58 +6,60 @@ import fs from 'fs/promises';
66
77const buildDataDir = path . resolve ( process . cwd ( ) , 'node_modules' , '@replexica/translations' ) ;
88const buildDataFilePath = path . resolve ( buildDataDir , '.replexica.json' ) ;
9- const spinner = Ora ( ) ;
109
1110export default new Command ( )
1211 . command ( 'i18n' )
1312 . description ( 'Process i18n with Replexica' )
1413 . helpOption ( '-h, --help' , 'Show help' )
1514 . action ( async ( ) => {
16- const env = getEnv ( ) ;
17- spinner . start ( 'Loading Replexica build data...' ) ;
15+ const initSpinner = Ora ( ) ;
16+ initSpinner . start ( 'Loading Replexica build data...' ) ;
1817 const buildData = await loadBuildData ( ) ;
1918 if ( ! buildData ) {
20- spinner . fail ( `Couldn't load Replexica build data. Did you forget to run 'replexica i18n'?` ) ;
19+ initSpinner . fail ( `Couldn't load Replexica build data. Did you forget to run 'replexica i18n'?` ) ;
2120 return process . exit ( 1 ) ;
2221 }
2322
2423 const localeSource = buildData . settings ?. locale ?. source ;
2524 if ( ! localeSource ) {
26- spinner . fail ( `No source locale found in Replexica build data. Please check your Replexica configuration and run 'replexica i18n' again.` ) ;
25+ initSpinner . fail ( `No source locale found in Replexica build data. Please check your Replexica configuration and run 'replexica i18n' again.` ) ;
2726 return process . exit ( 1 ) ;
2827 }
2928
3029 const localeTargets = buildData . settings ?. locale ?. targets || [ ] ;
3130 if ( ! localeTargets . length ) {
32- spinner . fail ( `No target locales found in Replexica build data. Please check your Replexica configuration and run 'replexica i18n' again.` ) ;
31+ initSpinner . fail ( `No target locales found in Replexica build data. Please check your Replexica configuration and run 'replexica i18n' again.` ) ;
3332 return process . exit ( 1 ) ;
3433 }
3534
3635 const localeSourceData = await loadLocaleData ( localeSource ) ;
3736 if ( ! localeSourceData ) {
38- spinner . fail ( `Couldn't load source locale data for source locale ${ localeSource } . Did you forget to run 'replexica i18n'?` ) ;
37+ initSpinner . fail ( `Couldn't load source locale data for source locale ${ localeSource } . Did you forget to run 'replexica i18n'?` ) ;
3938 return process . exit ( 1 ) ;
4039 }
4140
41+ initSpinner . succeed ( 'Replexica build data loaded!' ) ;
42+
4243 for ( const target of localeTargets ) {
43- spinner . start ( `Processing i18n for ${ target } ...` ) ;
44+ const targetSpinner = Ora ( ) ;
45+ targetSpinner . start ( `Processing i18n for ${ target } ...` ) ;
4446 const result = await processI18n (
4547 { source : localeSource , target } ,
4648 buildData . meta ,
4749 localeSourceData ,
4850 ) ;
49- spinner . succeed ( `i18n processed for ${ target } !` ) ;
51+ targetSpinner . succeed ( `i18n processed for ${ target } !` ) ;
5052
51- spinner . start ( `Saving full i18n data for ${ target } ...` ) ;
53+ targetSpinner . start ( `Saving full i18n data for ${ target } ...` ) ;
5254 await saveFullLocaleData ( target , result . data ) ;
53- spinner . succeed ( `Full i18n data saved for ${ target } !` ) ;
55+ targetSpinner . succeed ( `Full i18n data saved for ${ target } !` ) ;
5456
55- spinner . start ( `Saving client i18n data for ${ target } ...` ) ;
57+ targetSpinner . start ( `Saving client i18n data for ${ target } ...` ) ;
5658 await saveClientLocaleData ( target , result . data , buildData . meta ) ;
57- spinner . succeed ( `Client i18n data saved for ${ target } !` ) ;
59+ targetSpinner . succeed ( `Client i18n data saved for ${ target } !` ) ;
5860 }
5961
60- spinner . succeed ( 'All i18n processed !' ) ;
62+ initSpinner . succeed ( 'Replexica i18n processing complete !' ) ;
6163 } ) ;
6264
6365async function processI18n (
@@ -114,7 +116,6 @@ async function loadLocaleData(locale: string) {
114116
115117async function saveFullLocaleData ( locale : string , data : any ) {
116118 const localeFilePath = path . resolve ( buildDataDir , `${ locale } .json` ) ;
117- spinner . succeed ( `Saved full ${ locale } locale data to ${ localeFilePath } ` ) ;
118119 await fs . writeFile ( localeFilePath , JSON . stringify ( data , null , 2 ) ) ;
119120}
120121
@@ -132,6 +133,5 @@ async function saveClientLocaleData(locale: string, data: any, meta: any) {
132133 }
133134
134135 const localeFilePath = path . resolve ( buildDataDir , `${ locale } .client.json` ) ;
135- spinner . succeed ( `Saved client ${ locale } locale data to ${ localeFilePath } ` ) ;
136136 await fs . writeFile ( localeFilePath , JSON . stringify ( newData , null , 2 ) ) ;
137137}
0 commit comments