forked from aaronbriel/jsonjunit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (33 loc) · 1.15 KB
/
index.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
37
#!/usr/bin/env node
var program = require('commander'),
fs = require('fs'),
path = require('path'),
pkg = require('./package.json'),
jsonJunit = require('./lib/jsonjunit'),
fileName,
jsonFile,
junitFile;
program
.version(pkg.version)
.option('-ju, --json <json>', 'JSON report target path')
.option('-jx, --junit <junit>', 'JUnitXML report destination path')
//.option('-jt, --jsontype', 'Type of JSON report to convert')
.parse(process.argv);
if (!program.json || !program.junit) {
console.log('You must specify both JSON and JUNIT path!');
process.exit(1);
} else {
//create JUnitXML report dir if it doesn't exist
if (!fs.existsSync(program.junit)) {
fs.mkdirSync(program.junit);
}
var jsonFiles = fs.readdirSync(program.json);
for(var i in jsonFiles) {
if (jsonFiles[i].indexOf('.json')>-1) {
jsonFile = path.join(program.json, jsonFiles[i]);
fileName = jsonFiles[i].slice(0, jsonFiles[i].indexOf('.json'));
junitFile = path.join(program.junit, fileName + ".xml");
jsonJunit.convertJson(jsonFile, junitFile);
}
}
}