-
Notifications
You must be signed in to change notification settings - Fork 0
/
brand-spec-check.js
53 lines (48 loc) · 2.06 KB
/
brand-spec-check.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import fs from 'fs'
if (process.argv.length < 3) {
console.log("usage: node brand-spec-check.js <brand definition>");
process.exit(-1);
}
const brandDefinition = JSON.parse(fs.readFileSync(process.argv[2]+".json"));
// console.log(brandDefinition);
console.log("Analyzing brand definition \""+brandDefinition.brand+"\" against spec edition "+brandDefinition.edition+".");
console.log("- Found "+brandDefinition.requiredBoxSupport.length+" boxes in the given brand definition.");
let boxDefinitions = {};
for (let editionIndex = 1; editionIndex<=brandDefinition.edition; editionIndex++) {
console.log("Loading edition "+editionIndex);
let edition = JSON.parse(fs.readFileSync("edition"+editionIndex+".json"));
// console.log(edition);
console.log("Found "+Object.keys(edition.boxes).length+" boxes.");
const keys = Object.keys(edition.boxes);
for (const b in keys) {
const key = keys[b];
console.log("Processing definition of box \""+key+"\"");
if (boxDefinitions[key]) {
console.log("Box \""+key+"\" already exists in previous editions ("+JSON.stringify(boxDefinitions[key])+"), overriding with "+JSON.stringify(edition.boxes[key]));
}
boxDefinitions[key] = edition.boxes[key];
}
}
console.log("- Found "+Object.keys(boxDefinitions).length+" boxes defined in all needed editions.");
//console.log(boxDefinitions);
brandDefinition.requiredBoxSupport.forEach(function (b) {
if (!b.type) {
console.error("Box in brand does not have type:", JSON.stringify(b));
} else {
const boxDef = boxDefinitions[b.type];
if (!boxDef) {
console.error("Box of type \""+b.type+"\" does not exist in provided spec edition");
} else {
if (boxDef.versions) {
if (!b.versions || b.versions.length === 0) {
console.error("Box of type \""+b.type+"\" is defined with versions ["+boxDef.versions+"], but the brand definition does not indicate any");
}
}
if (boxDef.flags) {
if (!b.flags || b.flags.length === 0) {
console.error("Box of type \""+b.type+"\" is defined with flags ["+boxDef.flags+"], but the brand definition does not indicate any");
}
}
}
}
})