-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconcat_scenarios.js
36 lines (27 loc) · 1.19 KB
/
concat_scenarios.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
31
32
33
34
35
36
var fs = require('fs');
var _ = require('underscore');
var arrayOperations = require('./lib/array_operations');
var argv = require('yargs')
.alias('s', 'scenarios')
.describe('s', 'Directory containing scenarios')
.alias('o', 'output')
.describe('o', 'File to output concatenated files')
.demandOption(['s', 'o'])
.argv;
var scenarios = loadScenarios(argv.scenarios);
var flat_scenarios = _.flatten(scenarios, true);
assertNoDuplicates(flat_scenarios);
fs.writeFileSync(argv.output, JSON.stringify(flat_scenarios, null, 2));
function loadScenarios(scenarioDirectory) {
scenarioFilenames = fs.readdirSync(scenarioDirectory);
scenarioPaths = scenarioFilenames.map(fn => scenarioDirectory + '/' + fn);
return scenarioPaths.map(path => JSON.parse(fs.readFileSync(path)));
}
function assertNoDuplicates(scenarios) {
var duplicates = arrayOperations.getDuplicateElements(scenarios, (s1, s2) => s1.scenario === s2.scenario);
_.each(duplicates, (d) => console.log(`ERROR: Duplicate scenario: ${d.scenario}`));
if (duplicates.length > 0) {
console.log("Scenarios were not concatenated. Please fix scenarios and try again.");
process.exit(1);
}
}