forked from Kitware/vtk-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xml2json-cli.js
executable file
·30 lines (26 loc) · 911 Bytes
/
xml2json-cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#! /usr/bin/env node
var fs = require('fs');
var { program } = require('commander');
var xml2js = require('xml2js');
program.version('1.0.0')
.option('-i, --input [file.xml]', 'Input file to convert')
.option('-o, --output [file.json]', 'Destination file\n')
.option('-p, --process [chemistry]', 'Name of post-processor to apply')
.parse(process.argv);
const options = program.opts();
var parser = new xml2js.Parser();
fs.readFile(options.input, function (err, data) {
parser.parseString(data, function (err, result) {
var dataToWrite = result;
if (options.process) {
var postProcessor = require('./' + options.process + '/post-process.js');
dataToWrite = postProcessor(result);
}
fs.writeFile(options.output, JSON.stringify(dataToWrite, null, 2), function(err) {
if(err) {
return console.log(err);
}
console.log("Success");
});
});
});