-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfilterBOM.js
43 lines (37 loc) · 1.26 KB
/
filterBOM.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
const fs = require('fs');
function uniqueRequiredComponents(components) {
seen = {};
for (const component of components) {
seen[component.purl] = {
...component,
scope: 'required'
// 'scope' is useful for downstream consumers of the SBOM.
// Given the assumptions of this project we have enough knowledge
// to set this value here.
// May be one of 'optional', 'required', 'excluded'.
// See: https://github.com/CycloneDX/specification/blob/master/schema/bom-1.2.xsd#L487-L510
};
}
return Object.values(seen);
}
async function run() {
const infile = process.argv[2];
if (!infile) {
console.error("Missing input file argument!");
process.exit(2);
}
const outfile = process.argv[3] || infile;
const data = JSON.parse(fs.readFileSync(infile, 'utf8'));
if (data !== undefined && data.components !== undefined) {
console.log('Before: ' + data.components.length + ' components.');
data.components = uniqueRequiredComponents(data.components);
console.log(' After: ' + data.components.length + ' components.');
} else {
console.log('data.components is empty');
}
fs.writeFileSync(outfile, JSON.stringify(data, null, 2));
}
run().catch(err => {
console.error(err);
process.exit(2);
});