Created
November 20, 2017 13:25
-
-
Save Misterhex/6cc90f039ea278f2f644934b21ccce3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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