Skip to content

Commit

Permalink
Merge pull request #620 from langpavel/feature/react-intl
Browse files Browse the repository at this point in the history
[feature/react-intl] Write newlines on message files EOF
  • Loading branch information
koistya committed Apr 25, 2016
2 parents 91b0982 + bd587c3 commit 03bcce4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/messages/_default.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
"src/components/Navigation/Navigation.js"
]
}
]
]
2 changes: 1 addition & 1 deletion src/messages/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
"src/components/Navigation/Navigation.js"
]
}
]
]
2 changes: 1 addition & 1 deletion src/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
"src/components/Navigation/Navigation.js"
]
}
]
]
8 changes: 6 additions & 2 deletions tools/extractMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const GLOB_PATTERN = 'src/**/*.{js,jsx}';
const fileToMessages = {};
let messages = {};

async function writeMessages(fileName, messages) {
await fs.writeFile(fileName, JSON.stringify(messages, null, 2) + '\n');
}

// merge messages to source files
async function mergeToFile(locale, toBuild) {
const fileName = `src/messages/${locale}.json`;
Expand Down Expand Up @@ -56,14 +60,14 @@ async function mergeToFile(locale, toBuild) {
.map(key => originalMessages[key])
.filter(msg => msg.files || msg.message);

await fs.writeFile(fileName, JSON.stringify(result, null, 2));
await writeMessages(fileName, result);

console.log(`Messages updated: ${fileName}`);

if (toBuild && locale !== '_default') {
const buildFileName = `build/messages/${locale}.json`;
try {
await fs.writeFile(buildFileName, JSON.stringify(result, null, 2));
await writeMessages(buildFileName, result);
console.log(`Build messages updated: ${buildFileName}`);
} catch (err) {
console.error(`Failed to update ${buildFileName}`);
Expand Down

0 comments on commit 03bcce4

Please sign in to comment.