snyk-to-html
Advanced tools
Comparing version 1.5.4 to 1.6.0
#!/usr/bin/env node | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var fs = require("fs"); | ||
var minimist = require("minimist"); | ||
var path = require("path"); | ||
var snyk_to_html_1 = require("./lib/snyk-to-html"); | ||
var argv = minimist(process.argv.slice(2)); | ||
var template; | ||
var source; | ||
var output; | ||
const fs = require("fs"); | ||
const minimist = require("minimist"); | ||
const path = require("path"); | ||
const snyk_to_html_1 = require("./lib/snyk-to-html"); | ||
const argv = minimist(process.argv.slice(2)); | ||
let template; | ||
let source; | ||
let output; | ||
if (argv.t) { // template | ||
@@ -36,3 +36,3 @@ template = argv.t; // grab the next item | ||
if (output) { | ||
fs.writeFile(output, report, function (err) { | ||
fs.writeFile(output, report, err => { | ||
if (err) { | ||
@@ -39,0 +39,0 @@ return console.log(err); |
@@ -12,39 +12,12 @@ #!/usr/bin/env node | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var fs = require("fs"); | ||
var Handlebars = require("handlebars"); | ||
var marked = require("marked"); | ||
var moment = require("moment"); | ||
var path = require("path"); | ||
var severityMap = { low: 0, medium: 1, high: 2 }; | ||
const fs = require("fs"); | ||
const Handlebars = require("handlebars"); | ||
const marked = require("marked"); | ||
const moment = require("moment"); | ||
const path = require("path"); | ||
const severityMap = { low: 0, medium: 1, high: 2 }; | ||
function readFile(filePath, encoding) { | ||
return new Promise(function (resolve, reject) { | ||
fs.readFile(filePath, encoding, function (err, data) { | ||
return new Promise((resolve, reject) => { | ||
fs.readFile(filePath, encoding, (err, data) => { | ||
if (err) { | ||
@@ -57,6 +30,4 @@ reject(err); | ||
} | ||
var SnykToHtml = /** @class */ (function () { | ||
function SnykToHtml() { | ||
} | ||
SnykToHtml.run = function (dataSource, hbsTemplate, reportCallback) { | ||
class SnykToHtml { | ||
static run(dataSource, hbsTemplate, reportCallback) { | ||
SnykToHtml | ||
@@ -66,17 +37,13 @@ .runAsync(dataSource, hbsTemplate) | ||
.catch(console.log); | ||
}; | ||
SnykToHtml.runAsync = function (source, template) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var promisedString, report; | ||
return __generator(this, function (_a) { | ||
promisedString = source ? readFile(source, 'utf8') : readInputFromStdin(); | ||
report = promisedString | ||
.then(JSON.parse) | ||
.then(function (data) { return processData(data, template); }); | ||
return [2 /*return*/, report]; | ||
}); | ||
} | ||
static runAsync(source, template) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const promisedString = source ? readFile(source, 'utf8') : readInputFromStdin(); | ||
const report = promisedString | ||
.then(JSON.parse) | ||
.then(data => processData(data, template)); | ||
return report; | ||
}); | ||
}; | ||
return SnykToHtml; | ||
}()); | ||
} | ||
} | ||
exports.SnykToHtml = SnykToHtml; | ||
@@ -96,7 +63,7 @@ function metadataForVuln(vuln) { | ||
function groupVulns(vulns) { | ||
var result = {}; | ||
var uniqueCount = 0; | ||
var pathsCount = 0; | ||
const result = {}; | ||
let uniqueCount = 0; | ||
let pathsCount = 0; | ||
if (vulns && Array.isArray(vulns)) { | ||
vulns.map(function (vuln) { | ||
vulns.map(vuln => { | ||
if (!result[vuln.id]) { | ||
@@ -120,55 +87,32 @@ result[vuln.id] = { list: [vuln], metadata: metadataForVuln(vuln) }; | ||
function compileTemplate(fileName) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, readFile(fileName, 'utf8').then(Handlebars.compile)]; | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return readFile(fileName, 'utf8').then(Handlebars.compile); | ||
}); | ||
} | ||
function registerPeerPartial(templatePath, name) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var dir, file, template; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
dir = path.dirname(templatePath); | ||
file = path.join(dir, "test-report." + name + ".hbs"); | ||
return [4 /*yield*/, compileTemplate(file)]; | ||
case 1: | ||
template = _a.sent(); | ||
Handlebars.registerPartial(name, template); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const dir = path.dirname(templatePath); | ||
const file = path.join(dir, `test-report.${name}.hbs`); | ||
const template = yield compileTemplate(file); | ||
Handlebars.registerPartial(name, template); | ||
}); | ||
} | ||
function generateTemplate(data, template) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var vulnMetadata, htmlTemplate; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
vulnMetadata = groupVulns(data.vulnerabilities); | ||
data.vulnerabilities = vulnMetadata.vulnerabilities; | ||
data.uniqueCount = vulnMetadata.vulnerabilitiesUniqueCount; | ||
data.summary = vulnMetadata.vulnerabilitiesPathsCount + ' vulnerable dependency paths'; | ||
return [4 /*yield*/, registerPeerPartial(template, 'inline-css')]; | ||
case 1: | ||
_a.sent(); | ||
return [4 /*yield*/, registerPeerPartial(template, 'vuln-card')]; | ||
case 2: | ||
_a.sent(); | ||
return [4 /*yield*/, compileTemplate(template)]; | ||
case 3: | ||
htmlTemplate = _a.sent(); | ||
return [2 /*return*/, htmlTemplate(data)]; | ||
} | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const vulnMetadata = groupVulns(data.vulnerabilities); | ||
data.vulnerabilities = vulnMetadata.vulnerabilities; | ||
data.uniqueCount = vulnMetadata.vulnerabilitiesUniqueCount; | ||
data.summary = vulnMetadata.vulnerabilitiesPathsCount + ' vulnerable dependency paths'; | ||
yield registerPeerPartial(template, 'inline-css'); | ||
yield registerPeerPartial(template, 'vuln-card'); | ||
const htmlTemplate = yield compileTemplate(template); | ||
return htmlTemplate(data); | ||
}); | ||
} | ||
function mergeData(dataArray) { | ||
var vulnsArrays = dataArray.map(function (project) { return project.vulnerabilities || []; }); | ||
var aggregateVulnerabilities = [].concat.apply([], vulnsArrays); | ||
var totalUniqueCount = dataArray.reduce(function (acc, item) { return acc + item.vulnerabilities.length || 0; }, 0); | ||
var totalDepCount = dataArray.reduce(function (acc, item) { return acc + item.dependencyCount || 0; }, 0); | ||
var paths = dataArray.map(function (project) { return ({ path: project.path, packageManager: project.packageManager }); }); | ||
const vulnsArrays = dataArray.map(project => project.vulnerabilities || []); | ||
const aggregateVulnerabilities = [].concat(...vulnsArrays); | ||
const totalUniqueCount = dataArray.reduce((acc, item) => acc + item.vulnerabilities.length || 0, 0); | ||
const totalDepCount = dataArray.reduce((acc, item) => acc + item.dependencyCount || 0, 0); | ||
const paths = dataArray.map(project => ({ path: project.path, packageManager: project.packageManager })); | ||
return { | ||
@@ -179,29 +123,24 @@ vulnerabilities: aggregateVulnerabilities, | ||
dependencyCount: totalDepCount, | ||
paths: paths, | ||
paths, | ||
}; | ||
} | ||
function processData(data, template) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var mergedData; | ||
return __generator(this, function (_a) { | ||
mergedData = Array.isArray(data) ? mergeData(data) : data; | ||
return [2 /*return*/, generateTemplate(mergedData, template)]; | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const mergedData = Array.isArray(data) ? mergeData(data) : data; | ||
return generateTemplate(mergedData, template); | ||
}); | ||
} | ||
function readInputFromStdin() { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
var jsonString = ''; | ||
process.stdin.setEncoding('utf8'); | ||
process.stdin.on('readable', function () { | ||
var chunk = process.stdin.read(); | ||
if (chunk !== null) { | ||
jsonString += chunk; | ||
} | ||
}); | ||
process.stdin.on('error', reject); | ||
process.stdin.on('end', function () { return resolve(jsonString); }); | ||
})]; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return new Promise((resolve, reject) => { | ||
let jsonString = ''; | ||
process.stdin.setEncoding('utf8'); | ||
process.stdin.on('readable', () => { | ||
const chunk = process.stdin.read(); | ||
if (chunk !== null) { | ||
jsonString += chunk; | ||
} | ||
}); | ||
process.stdin.on('error', reject); | ||
process.stdin.on('end', () => resolve(jsonString)); | ||
}); | ||
@@ -211,7 +150,7 @@ }); | ||
// handlebar helpers | ||
var hh = { | ||
const hh = { | ||
markdown: marked, | ||
moment: function (date, format) { return moment.utc(date).format(format); }, | ||
count: function (data) { return data && data.length; }, | ||
dump: function (data, spacer) { return JSON.stringify(data, null, spacer || null); }, | ||
moment: (date, format) => moment.utc(date).format(format), | ||
count: data => data && data.length, | ||
dump: (data, spacer) => JSON.stringify(data, null, spacer || null), | ||
// block helpers | ||
@@ -226,12 +165,7 @@ /* tslint:disable:only-arrow-functions */ | ||
}, | ||
if_any: function (opts) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
return args.some(function (v) { return !!v; }) ? opts.fn(this) : opts.inverse(this); | ||
if_any: function (opts, ...args) { | ||
return args.some(v => !!v) ? opts.fn(this) : opts.inverse(this); | ||
}, | ||
ifCond: function (v1, operator, v2, options) { | ||
var _this = this; | ||
var choose = function (pred) { return pred ? options.fn(_this) : options.inverse(_this); }; | ||
const choose = (pred) => pred ? options.fn(this) : options.inverse(this); | ||
switch (operator) { | ||
@@ -251,3 +185,3 @@ // tslint:disable-next-line:triple-equals | ||
}; | ||
Object.keys(hh).forEach(function (k) { return Handlebars.registerHelper(k, hh[k]); }); | ||
Object.keys(hh).forEach(k => Handlebars.registerHelper(k, hh[k])); | ||
//# sourceMappingURL=snyk-to-html.js.map |
@@ -41,3 +41,3 @@ { | ||
"tslint": "^5.20.0", | ||
"typescript": "^3.6.4" | ||
"typescript": "^3.7.3" | ||
}, | ||
@@ -56,3 +56,3 @@ "repository": { | ||
}, | ||
"version": "1.5.4" | ||
"version": "1.6.0" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
34784
231