Skip to content

Commit 241f7ac

Browse files
committed
Fix foreign.js command implementation
1 parent 68eecdc commit 241f7ac

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/commands/foreign.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ const fs = require('fs');
1212
* @param {Hash} opts - All options
1313
*/
1414
module.exports = function(opts) {
15-
const file = path.resolve(opts.target, 'eo-foreign.json'),
16-
all = JSON.parse(fs.readFileSync(file, 'utf8'));
17-
console.info('There are %d objects in %s:', all.length, rel(file));
18-
all.forEach((obj) => {
19-
console.info(' %s', obj.id);
20-
});
15+
const file = path.resolve(opts.target, 'eo-foreign.json');
16+
try {
17+
let content = fs.readFileSync(file, "utf8");
18+
content = content.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
19+
const all = JSON.parse(content);
20+
console.info('There are %d objects in %s:', all.length, rel(file));
21+
all.forEach((obj) => {
22+
console.info(' %s', obj.id);
23+
});
24+
} catch (error) {
25+
throw new Error(`Parsing a document fails:`, error);
26+
}
2127
};

0 commit comments

Comments
 (0)