Skip to content

Commit 93b9b46

Browse files
authored
Merge pull request #4932 from jabrah/4930-fix-merge-i18n-script
Fix merge-i18n script
2 parents 43e358b + 6d47d3b commit 93b9b46

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

scripts/merge-i18n-files.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ parseCliInput();
1919
* This script uses the i18n files found in a source directory to override settings in files with the same
2020
* name in a destination directory. Only the i18n labels to be overridden need be in the source files.
2121
*
22-
* Execution (using custom theme):
22+
* Example execution (using custom theme):
2323
* ```
24-
* yarn merge-i18n -s src/themes/custom/assets/i18n
24+
* npm run merge-i18n -- -s src/themes/custom/assets/i18n
2525
* ```
2626
*
2727
* Input parameters:
@@ -42,21 +42,25 @@ function parseCliInput() {
4242
.usage('(-s <source-dir> [-d <output-dir>])')
4343
.parse(process.argv);
4444

45-
if (program.outputDir && program.sourceDir) {
46-
if (!fs.existsSync(program.outputDir) && !fs.lstatSync(program.outputDir).isDirectory() ) {
45+
const source = program.opts().sourceDir;
46+
const destination = program.opts().outputDir;
47+
48+
if (destination && source) {
49+
if (!fs.existsSync(destination) || !fs.lstatSync(destination).isDirectory() ) {
4750
console.error('Output does not exist or is not a directory.');
4851
console.log(program.outputHelp());
4952
process.exit(1);
5053
}
51-
if (!fs.existsSync(program.sourceDir) && !fs.lstatSync(program.sourceDir).isDirectory() ) {
54+
if (!fs.existsSync(source) || !fs.lstatSync(source).isDirectory() ) {
5255
console.error('Source does not exist or is not a directory.');
5356
console.log(program.outputHelp());
5457
process.exit(1);
5558
}
56-
fs.readdirSync(projectRoot(program.sourceDir)).forEach(file => {
57-
if (fs.existsSync(program.outputDir + '/' + file) ) {
58-
console.log('Merging: ' + program.outputDir + '/' + file + ' with ' + program.sourceDir + '/' + file);
59-
mergeFileWithSource(program.sourceDir + '/' + file, program.outputDir + '/' + file);
59+
60+
fs.readdirSync(projectRoot(source)).forEach(file => {
61+
if (fs.existsSync(destination + '/' + file) ) {
62+
console.log('Merging: ' + destination + '/' + file + ' with ' + source + '/' + file);
63+
mergeFileWithSource(source + '/' + file, destination + '/' + file);
6064
}
6165
});
6266
} else {

0 commit comments

Comments
 (0)