forked from smartsheet/smartsheet-sdk-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_mappings.js
34 lines (28 loc) · 1016 Bytes
/
gen_mappings.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
var fs = require('fs');
var _ = require('underscore');
var colors = require('colors/safe');
var scenarioMappings = require('./lib/scenario_mappings');
var argv = require('yargs')
.alias('s', 'scenarios')
.describe('s', 'Path of JSON scenarios file')
.alias('o', 'output_dir')
.describe('o', 'Directory to wiremock mapping files')
.demandOption(['scenarios', 'output_dir'])
.argv;
var scenarios = JSON.parse(fs.readFileSync(argv.scenarios));
var wiremockStubs = scenarioMappings.buildStubsFromScenarios(scenarios);
_.each(wiremockStubs, function(stub) {
fs.writeFile(argv.output_dir + stub.name + '.json', JSON.stringify(stub.mapping, null, 2), printResult(stub.name));
});
function printResult(name) {
return function(error, result) {
if (error) {
var cross = colors.red("✗");
console.log(cross + " " + name);
}
else {
var check = colors.green("✓");
console.log(check + " " + name);
}
};
}