@@ -22,6 +22,8 @@ export const command = 'diff'
22
22
export const aliases = 'df'
23
23
export const describe = 'Diff locale messages between local and localization service'
24
24
25
+ class DiffError extends Error { }
26
+
25
27
export const builder = ( args : Argv ) : Argv < DiffOptions > => {
26
28
return args
27
29
. option ( 'provider' , {
@@ -60,6 +62,19 @@ export const builder = (args: Argv): Argv<DiffOptions> => {
60
62
alias : 'n' ,
61
63
describe : 'option for the locale messages structure, you can specify the option, if you hope to normalize for the provider.'
62
64
} )
65
+ . fail ( ( msg , err ) => {
66
+ if ( msg ) {
67
+ console . error ( msg )
68
+ process . exit ( 1 )
69
+ } else {
70
+ if ( err instanceof DiffError ) {
71
+ console . warn ( err . message )
72
+ process . exit ( 1 )
73
+ } else {
74
+ if ( err ) throw err
75
+ }
76
+ }
77
+ } )
63
78
}
64
79
65
80
export const handler = async ( args : Arguments < DiffOptions > ) : Promise < unknown > => {
@@ -90,15 +105,15 @@ export const handler = async (args: Arguments<DiffOptions>): Promise<unknown> =>
90
105
return
91
106
}
92
107
93
- try {
94
- const provider = ProviderFactory ( conf )
95
- const locales = Object . keys ( localeMessages ) as Locale [ ]
96
- const serviceMessages = await provider . pull ( { locales , dryRun : false , normalize , format } )
97
- console . log ( diffString ( localeMessages , serviceMessages ) )
98
- } catch ( e ) {
99
- // TODO: should refactor console message
100
- console . error ( 'diff fail' , e )
101
- }
108
+ const provider = ProviderFactory ( conf )
109
+ const locales = Object . keys ( localeMessages ) as Locale [ ]
110
+ const serviceMessages = await provider . pull ( { locales , dryRun : false , normalize , format } )
111
+ const ret = diffString ( localeMessages , serviceMessages )
112
+ console . log ( ret )
113
+
114
+ return ! ret
115
+ ? Promise . reject ( new DiffError ( 'There are differences!' ) )
116
+ : Promise . resolve ( 'No difference!' )
102
117
}
103
118
104
119
export default {
0 commit comments