Skip to content

Instantly share code, notes, and snippets.

@Misterhex
Created November 20, 2017 13:25
Show Gist options
  • Save Misterhex/6cc90f039ea278f2f644934b21ccce3d to your computer and use it in GitHub Desktop.
Save Misterhex/6cc90f039ea278f2f644934b21ccce3d to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const cucumberJsonFolder = process.argv[2];
const outDir = process.argv[3];
const fs = require('fs');
if (!fs.existsSync(outDir)) {
fs.mkdirSync(outDir);
}
const dict = {};
fs.readdirSync(cucumberJsonFolder).forEach(file => {
console.log(`processing ${file}`);
try {
const jsonString = fs.readFileSync(`./${cucumberJsonFolder}/${file}`, 'utf8')
const cucumberJson = JSON.parse(jsonString);
const item = cucumberJson[0];
const id = item.id;
if (dict[id]) {
const itemElement = item.elements[0];
dict[id][0].elements.push(itemElement);
}
else {
dict[id] = cucumberJson;
}
}
catch (err) {
console.log(`error parsing json file ${file}`);
}
});
Object.entries(dict).forEach(([key, value]) => {
console.log(`writing consolidated feature ${key} file`);
fs.writeFileSync(`${outDir}/${key}.json`, JSON.stringify(value));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment