Skip to content
This repository has been archived by the owner on Feb 15, 2019. It is now read-only.

Commit

Permalink
use fs instead of babel-register
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelly Selden committed Jun 14, 2016
1 parent 34b3afc commit 9186d70
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
8 changes: 2 additions & 6 deletions lib/to-csv.js
Expand Up @@ -4,10 +4,7 @@ import csvStringify from 'csv-stringify';
import eol from 'eol';
import denodeify from 'denodeify';
import map from 'lodash/map';

// this is needed to `require` the js locale files
// instead of using fs.read
import 'babel-register';
import parseJsonFromJsFile from './utils/parse-json-from-js-file';

const readdir = denodeify(fs.readdir);
const stat = denodeify(fs.stat);
Expand Down Expand Up @@ -73,8 +70,7 @@ export default function(localesPath, csvPath, { onlyMissing } = {}) {
for (let columnIndex in filePaths) {
let filePath = filePaths[columnIndex];

// this is why we need `babel-register` above
let json = require(filePath).default;
let json = parseJsonFromJsFile(filePath);

recurse(json, columnIndex, 0, '');
}
Expand Down
3 changes: 2 additions & 1 deletion lib/to-js.js
Expand Up @@ -4,6 +4,7 @@ import csvParse from 'csv-parse';
import eol from 'eol';
import denodeify from 'denodeify';
import Promise from 'promise';
import parseJsonFromJsFile from './utils/parse-json-from-js-file';

const readFile = denodeify(fs.readFile);
const writeFile = denodeify(fs.writeFile);
Expand All @@ -22,7 +23,7 @@ export default function(csvPath, localesPath, { ignoreJshint, merge } = {}) {
if (merge) {
let filePath = path.resolve(localesPath, locales[i], 'translations.js');
if (fs.existsSync(filePath)) {
obj = require(filePath).default;
obj = parseJsonFromJsFile(filePath);
}
}
objs.push(obj);
Expand Down
8 changes: 8 additions & 0 deletions lib/utils/parse-json-from-js-file.js
@@ -0,0 +1,8 @@
import fs from 'fs';

export default filePath => {
let js = fs.readFileSync(filePath, 'utf8');
let jsonString = js.substring(js.indexOf('{'), js.lastIndexOf('}') + 1);
let json = JSON.parse(jsonString);
return json;
};
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -28,7 +28,6 @@
},
"homepage": "https://github.com/kellyselden/ember-i18n-csv#readme",
"dependencies": {
"babel-register": "^6.0.0",
"csv-parse": "^1.0.0",
"csv-stringify": "^1.0.0",
"denodeify": "^1.0.0",
Expand All @@ -41,6 +40,7 @@
"babel-cli": "^6.0.0",
"babel-preset-es2015": "^6.0.0",
"babel-preset-stage-2": "^6.0.0",
"babel-register": "^6.0.0",
"chai": "^3.0.0",
"coveralls": "^2.0.0",
"eslint": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/locales-only-missing/nl-nl/translations.js
Expand Up @@ -14,7 +14,7 @@ export default {
"node2-2-1": "test",
"node2-2-2": "test"
}
},
}
};

/* jshint ignore:end */
2 changes: 1 addition & 1 deletion test/fixtures/locales-only-missing/pt-br/translations.js
Expand Up @@ -10,7 +10,7 @@ export default {
},
"node2": {
"node2-2": {
"node2-2-1": "test",
"node2-2-1": "test"
}
},
"weekday": {
Expand Down

0 comments on commit 9186d70

Please sign in to comment.