|
| 1 | +const diffSBOMs = require('./src/sbom-diff/differ.js'); |
| 2 | +const formatTemplate = require('./src/sbom-diff/format-handlebars-template.js'); |
| 3 | +const fs = require('fs'); |
| 4 | + |
| 5 | +const readFile = function(path) { |
| 6 | + return fs.readFileSync(path, 'utf8') |
| 7 | +} |
| 8 | + |
| 9 | +const writeFile = function(path, content) { |
| 10 | + fs.writeFileSync(path, content); // default encoding is utf8 |
| 11 | +} |
| 12 | + |
| 13 | +var args = process.argv.slice(2); // first two arguments are the executable and the JS file |
| 14 | + |
| 15 | +if (args.length != 3) { |
| 16 | + throw new Error('Requires three arguments: <path to base SBOM> <path to comparing SBOM> <path to output file>'); |
| 17 | +} |
| 18 | + |
| 19 | +const baseSbomPath = args[0]; |
| 20 | +const headSbomPath = args[1]; |
| 21 | +const outPath = args[2]; |
| 22 | + |
| 23 | +const baseSbom = readFile(baseSbomPath); |
| 24 | +const headSbom = readFile(headSbomPath); |
| 25 | + |
| 26 | +const licenseList = readFile('../java-dependency-check/licenses.json'); |
| 27 | + |
| 28 | +const commentTemplate = readFile('../java-dependency-check/diff.hbs'); |
| 29 | + |
| 30 | +const partialPaths = [ |
| 31 | + 'componentDetails:../java-dependency-check/component-details.hbs', |
| 32 | + 'componentDiff:../java-dependency-check/component-diff.hbs', |
| 33 | + 'componentTree:../java-dependency-check/component-tree.hbs', |
| 34 | + 'componentVersion:../java-dependency-check/component-version.hbs' |
| 35 | +]; |
| 36 | + |
| 37 | +const partials = partialPaths.reduce( |
| 38 | + (result, input) => { |
| 39 | + [ partialId, partialPath ] = input.split(':'); |
| 40 | + result[partialId.trim()] = readFile(partialPath.trim()); |
| 41 | + return result; |
| 42 | + }, |
| 43 | + {} |
| 44 | +); |
| 45 | + |
| 46 | +diffSBOMs(baseSbom, headSbom, '^org\\.camunda', licenseList) |
| 47 | + .then(rootComponentDiff => formatTemplate(rootComponentDiff, commentTemplate, partials) |
| 48 | + .then(diff => writeFile(outPath, diff.fullDiff))); |
| 49 | + |
| 50 | + |
0 commit comments