@@ -30,8 +30,14 @@ program
3030 '-m, --prefer-main' ,
3131 'Reset file to the translated file, try using the file from `main` branch first, if not found (usually due to renaming), fall back to English source.'
3232 )
33+ . option ( '-d, --dry-run' , 'Just pretend to reset files' )
34+ . option ( '-r, --reason <reason>' , 'A reason why the file is getting reset' )
3335 . parse ( process . argv )
3436
37+ const dryRun = program . opts ( ) . dryRun
38+ const reason = program . opts ( ) . reason
39+ const reasonMessage = reason ? `Reason: ${ reason } ` : ''
40+
3541const resetToEnglishSource = ( translationFilePath ) => {
3642 assert (
3743 translationFilePath . startsWith ( 'translations/' ) ,
@@ -45,15 +51,21 @@ const resetToEnglishSource = (translationFilePath) => {
4551 const relativePath = translationFilePath . split ( path . sep ) . slice ( 2 ) . join ( path . sep )
4652 const englishFile = path . join ( process . cwd ( ) , relativePath )
4753
48- if ( ! fs . existsSync ( englishFile ) ) {
54+ if ( ! dryRun && ! fs . existsSync ( englishFile ) ) {
4955 fs . unlinkSync ( translationFilePath )
5056 return
5157 }
5258
53- // replace file with English source
54- const englishContent = fs . readFileSync ( englishFile , 'utf8' )
55- fs . writeFileSync ( translationFilePath , englishContent )
56- console . log ( '-> reverted to English: %s' , path . relative ( process . cwd ( ) , translationFilePath ) )
59+ if ( ! dryRun ) {
60+ // replace file with English source
61+ const englishContent = fs . readFileSync ( englishFile , 'utf8' )
62+ fs . writeFileSync ( translationFilePath , englishContent )
63+ }
64+ console . log (
65+ '-> reverted to English: %s %s' ,
66+ path . relative ( process . cwd ( ) , translationFilePath ) ,
67+ reasonMessage
68+ )
5769}
5870
5971const [ pathArg ] = program . args
@@ -64,8 +76,10 @@ const relativePath = fs.existsSync(pathArg) ? path.relative(process.cwd(), pathA
6476
6577if ( program . opts ( ) . preferMain ) {
6678 try {
67- execSync ( `git checkout main -- ${ relativePath } ` , { stdio : 'pipe' } )
68- console . log ( '-> reverted to file from main branch: %s' , relativePath )
79+ if ( ! dryRun ) {
80+ execSync ( `git checkout main -- ${ relativePath } ` , { stdio : 'pipe' } )
81+ }
82+ console . log ( '-> reverted to file from main branch: %s %s' , relativePath , reasonMessage )
6983 } catch ( e ) {
7084 if ( e . message . includes ( 'pathspec' ) ) {
7185 console . warn (
0 commit comments