99
1010import { execSync } from 'child_process'
1111import program from 'commander'
12+ import fs from 'fs'
1213
1314// Set up supported linting check types and their corresponding commands.
1415const CHECK_COMMANDS = {
@@ -48,7 +49,7 @@ if (SUPPORTED_CHECK_TYPES.includes(specifiedCheckType)) {
4849function lintAndResetFiles ( checkType ) {
4950 console . log ( `Running ${ checkType } check...` )
5051
51- const log = `~ /docs-translation-${ checkType } -error.txt`
52+ const log = `${ process . env . HOME } /docs-translation-${ checkType } -error.txt`
5253 const cmd = `${ CHECK_COMMANDS [ checkType ] } > ${ log } `
5354
5455 // Lint the files based on the check type and output the errors to a log file.
@@ -58,10 +59,28 @@ function lintAndResetFiles(checkType) {
5859 console . log ( `There were new ${ checkType } errors! Check ${ log } for more details.` )
5960 }
6061
61- // Reset the files
62- execSync (
63- `cat ${ log } | egrep "^translations/.*/(.+.md|.+.yml)$" | uniq | xargs -L1 script/i18n/reset-translated-file.js --prefer-main`
64- )
62+ // return if file does not exist
63+ if ( ! fs . existsSync ( log ) ) {
64+ console . log ( `${ log } : no such file` )
65+ return
66+ }
67+
68+ const filesToReset = fs
69+ . readFileSync ( log )
70+ . toString ( )
71+ . split ( '\n' )
72+ . filter ( ( p ) => p . startsWith ( 'translations' ) && ( p . endsWith ( '.md' ) || p . endsWith ( '.yml' ) ) )
73+
74+ if ( filesToReset . length === 0 ) {
75+ console . log ( 'There are no violations' )
76+ return
77+ }
78+
79+ // We are not passing --prefer-main because we want to remove the file so we
80+ // reset it directly to the English source
81+ filesToReset . forEach ( ( file ) => {
82+ execSync ( `script/i18n/reset-translated-file.js ${ file } ` )
83+ } )
6584
6685 // Print a message with next steps
6786 console . log ( `Success!
0 commit comments