Skip to content

Instantly share code, notes, and snippets.

@b-coimbra
Last active November 8, 2019 17:57
Show Gist options
  • Save b-coimbra/1d1631e550874abbae13880d0a179a69 to your computer and use it in GitHub Desktop.
Save b-coimbra/1d1631e550874abbae13880d0a179a69 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const { execSync } = require('child_process');
var parser = null;
const filename = process.argv[2];
const outputFile = filename.split('.')[0] + '.txt';
const filters = [
"MD5"
];
const install_pkg = async () => {
try {
parser = require('xml2json');
} catch (error) {
execSync("npm install xml2json", (err, stdout, stderr) => console.log(stdout));
parser = require('xml2json');
}
};
const output = (line) =>
fs.appendFileSync(`./${outputFile}`, line + "\n", (err) => err && console.warn(err));
install_pkg().then(() => {
fs.readFile(filename, (err, data) => {
const json = JSON.parse(parser.toJson(data)).steps.step;
for (let step of json) {
if (filters.length)
filters.forEach(f => delete step[f]);
output(Object.values(step).join(' '));
}
});
console.log("DONE");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment