-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmissing_bcd_paths.js
More file actions
50 lines (44 loc) · 1.14 KB
/
Copy pathmissing_bcd_paths.js
File metadata and controls
50 lines (44 loc) · 1.14 KB
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
"use strict";
const path = require('path');
const utils = require('./utils');
const nctFile = process.argv[2];
const bcdFile = process.argv[3];
if (! nctFile || ! bcdFile) {
const cmd = path.basename(process.argv[1]);
const usage =
`Usage:
node ${cmd} nct-file bcd-file
nct-file: path to NCT mapping file, e.g. nct.json
bcd-file: path to BCD mapping file, e.g. bcd.json
Example:
node ${cmd} nct.json bcd.json
Read data from nct.json and bcd.json, print bcd_path values in bcd.json without mapping in nct.json.`;
console.log(usage);
return;
}
const bcd = utils.readJsonSync(bcdFile);
const nct = utils.readJsonSync(nctFile);
// recursively iterate through version data nodes
function *leafs(tree) {
if (tree.bcd_path !== undefined) {
yield tree;
}
else {
for (const branch of Object.values(tree)) {
yield *leafs(branch);
}
}
}
for (const node of leafs(nct)) {
if (Array.isArray(node.bcd_path)) {
for (const bpath of node.bcd_path) {
delete bcd[bpath];
}
}
else if (node.bcd_path !== '') {
delete bcd[node.bcd_path];
}
}
for (const bpath of Object.keys(bcd)) {
console.log(bpath);
}