forked from engrchachi/official_devices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_tester.js
34 lines (32 loc) · 986 Bytes
/
json_tester.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
let glob = require('glob'),
fs = require('fs');
function arrayRemove(originalArray, regex) {
var j = 0;
while (j < originalArray.length) {
if (regex.test(originalArray[j]))
originalArray.splice(j, 1);
else
j++;
}
return originalArray;
}
var files = glob.sync("**/*.json", { cwd: "." });
var result = arrayRemove(files, new RegExp("package-lock.json"));
result = arrayRemove(result, new RegExp("node_modules"));
result = arrayRemove(result, new RegExp("builds/example.json"));
result.forEach(function (item, index) {
try {
console.log("Linting "+item);
let data = fs.readFileSync(item);
let _json = JSON.parse(data);
let new_json = JSON.stringify(_json, null, 3);
fs.writeFileSync(item, new_json);
} catch (e) {
console.log("Lint Failure as "+item+" has improper json format!")
fs.writeFileSync("/tmp/failedfile",item)
process.exit(1);
}
finally {
console.log("Lint Success!")
}
});