Update extractLocals.js location

This commit is contained in:
Igor Gassmann 2017-12-20 12:37:19 -03:00
parent b0255f468a
commit 3b26f06210

View file

@ -1,20 +1,21 @@
const extract = require("i18n-extract"); const extract = require("i18n-extract");
const fs = require("fs"); const fs = require("fs");
const path = require("path");
const dir = `${__dirname}/../../static/locales`; const outputDir = `${__dirname}/../static/locales`;
const path = `${dir}/en.json`; const outputPath = `${outputDir}/en.json`;
if (!fs.existsSync(dir)) { if (!fs.existsSync(outputDir)) {
fs.mkdirSync(dir); fs.mkdirSync(outputDir);
} }
fs.writeFile(path, "{}", "utf8", err => { fs.writeFile(outputPath, "{}", "utf8", err => {
if (err) { if (err) {
return console.log(err); return console.log(err);
} }
const enLocale = require(path); const enLocale = require(outputPath);
const keys = extract.extractFromFiles(["js/**/*.{js,jsx}"], { const keys = extract.extractFromFiles("src/**/*.{js,jsx}", {
marker: "__", marker: "__",
}); });
@ -22,7 +23,7 @@ fs.writeFile(path, "{}", "utf8", err => {
reports = reports.concat(extract.findMissing(enLocale, keys)); reports = reports.concat(extract.findMissing(enLocale, keys));
if (reports.length > 0) { if (reports.length > 0) {
fs.readFile(path, "utf8", (err, data) => { fs.readFile(outputPath, "utf8", (err, data) => {
if (err) { if (err) {
console.log(err); console.log(err);
} else { } else {
@ -36,7 +37,7 @@ fs.writeFile(path, "{}", "utf8", err => {
} }
const json = JSON.stringify(localeObj, null, "\t"); // convert it back to json-string const json = JSON.stringify(localeObj, null, "\t"); // convert it back to json-string
fs.writeFile(path, json, "utf8", err => { fs.writeFile(outputPath, json, "utf8", err => {
if (err) { if (err) {
throw err; throw err;
} }