mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-29 05:00:43 +10:00
Wrap file writing to a Promise
This commit is contained in:
parent
aa75f56e62
commit
1eeccb9153
1 changed files with 24 additions and 7 deletions
31
translations
31
translations
|
|
@ -151,13 +151,10 @@ const run = () => {
|
|||
const sorted = sort(target);
|
||||
const data = JSON.stringify(sorted, null, 2);
|
||||
|
||||
fs.writeFile(filePath(targetLang), data, err => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
console.log(chalk.bold('The translation file is updated'));
|
||||
run();
|
||||
});
|
||||
return updateTranslationsFile(data, targetLang);
|
||||
})
|
||||
.then(() => {
|
||||
run();
|
||||
})
|
||||
.catch(err => {
|
||||
if (err instanceof BreakSignal) {
|
||||
|
|
@ -257,4 +254,24 @@ const confirmTranslation = (targetLang, key, translation) => {
|
|||
]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update translations file.
|
||||
*
|
||||
* @param {String} data String data to be written to file
|
||||
* @param {String} targetLang Language code of the translation file
|
||||
*
|
||||
* @return a Promise that resolves when file is written
|
||||
*/
|
||||
const updateTranslationsFile = (data, targetLang) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.writeFile(filePath(targetLang), data, err => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
console.log(chalk.bold('The translation file is updated'));
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
run();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue