From 024ff3cb50be184f080ab2ba1e4826f888a9939a Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Wed, 21 Jun 2017 08:23:21 -0400 Subject: [PATCH] create locales dir if it doesnt exist --- ui/extractLocals.js | 80 ++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/ui/extractLocals.js b/ui/extractLocals.js index f67d123e2..b36e3e9d4 100644 --- a/ui/extractLocals.js +++ b/ui/extractLocals.js @@ -1,48 +1,48 @@ -var extract = require('i18n-extract'); -const fs = require('fs'); +var extract = require("i18n-extract"); +const fs = require("fs"); -var path = '../app/dist/locales/en.json'; +var dir = __dirname + "/../app/dist/locales"; +var path = dir + "/en.json"; -fs.writeFile(path, '{}', 'utf8', function(err) { - if(err) { - return console.log(err); - } - var enLocale = require(path); +if (!fs.existsSync(dir)) { + fs.mkdirSync(dir); +} - const keys = extract.extractFromFiles(['js/**/*.{js,jsx}'], { - marker: '__', - }); +fs.writeFile(path, "{}", "utf8", function(err) { + if (err) { + return console.log(err); + } + var enLocale = require(path); - let reports = []; - reports = reports.concat(extract.findMissing(enLocale, keys)); + const keys = extract.extractFromFiles(["js/**/*.{js,jsx}"], { + marker: "__", + }); - if (reports.length > 0) { - fs.readFile(path, 'utf8', function readFileCallback(err, data){ - if (err){ - console.log(err); - } else { - localeObj = JSON.parse(data); + let reports = []; + reports = reports.concat(extract.findMissing(enLocale, keys)); - for (var i = 0; i < reports.length; i++) { - // no need to care for other types than MISSING because starting file will always be empty - if (reports[i].type === 'MISSING') { - localeObj[reports[i].key] = reports[i].key; - } - } + if (reports.length > 0) { + fs.readFile(path, "utf8", function readFileCallback(err, data) { + if (err) { + console.log(err); + } else { + localeObj = JSON.parse(data); - var json = JSON.stringify(localeObj, null, '\t'); //convert it back to json-string - fs.writeFile(path, json, 'utf8', function callback(err) { - if (err) throw err; - console.log('Extracted all strings!'); - }); - } + for (var i = 0; i < reports.length; i++) { + // no need to care for other types than MISSING because starting file will always be empty + if (reports[i].type === "MISSING") { + localeObj[reports[i].key] = reports[i].key; + } + } + + var json = JSON.stringify(localeObj, null, "\t"); //convert it back to json-string + fs.writeFile(path, json, "utf8", function callback(err) { + if (err) { + throw err; + } + console.log("Extracted all strings!"); }); - } -}); - - - - - - - + } + }); + } +});