Skip to content

Commit

Permalink
Merge pull request #8 from Filiosoft/develop
Browse files Browse the repository at this point in the history
Bug Fixes and Findings List
  • Loading branch information
nprail authored Dec 15, 2018
2 parents 252c64d + cf47e25 commit ece4968
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 34 deletions.
30 changes: 29 additions & 1 deletion lib/reporter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const terminalLink = require('terminal-link')
const Handlebars = require('handlebars')
const moment = require('moment')
const marked = require('marked')
const fse = require('fs-extra')
const chalk = require('chalk')
const fs = require('fs')
const { promisify } = require('util')

Expand All @@ -24,14 +27,15 @@ const generateTemplate = async (data, template) => {
const writeReport = async (report, output) => {
try {
const writeFile = promisify(fs.writeFile)
await fse.ensureFile(output)
await writeFile(output, report)
} catch (err) {
throw err
}
}

const modifyData = async data => {
const vulnerabilities = data.metadata.vulnerabilities
const vulnerabilities = data.metadata.vulnerabilities || []

// for (const act in data.actions) {
// const action = data.actions[act]
Expand All @@ -52,6 +56,30 @@ const modifyData = async data => {

module.exports = async (data, templateFile, outputFile) => {
try {
if (!data.metadata) {
if (data.updated) {
console.log(
chalk.red(
`Sorry! You can't use ${chalk.underline(
'npm audit fix'
)} with npm-audit-html.\n\nSee ${terminalLink(
'issue #3',
'https://github.com/Filiosoft/npm-audit-html/issues/3'
)}`
)
)
} else {
console.log(
chalk.red(
`The provided data doesn't seem to be correct. Did you run with ${chalk.underline(
'npm audit --json'
)}?`
)
)
}
process.exit(1)
}

const modifiedData = await modifyData(data)
const report = await generateTemplate(modifiedData, templateFile)
await writeReport(report, outputFile)
Expand Down
112 changes: 80 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@
"travis-deploy-once": "^5.0.0"
},
"dependencies": {
"chalk": "^2.4.1",
"commander": "^2.15.1",
"fs-extra": "^7.0.1",
"handlebars": "^4.0.11",
"marked": "^0.4.0",
"moment": "^2.22.2"
"moment": "^2.22.2",
"terminal-link": "^1.1.0"
},
"config": {
"commitizen": {
Expand Down
9 changes: 9 additions & 0 deletions templates/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@
<h3>Overview</h3>
<p class="card-text">{{{markdown overview}}}</p>

<h3>Findings</h3>
{{#each findings}}
<ul>
{{#each paths}}
<li>{{this}} </li>
{{/each}}
</ul>
{{/each}}

{{#if recommendation}}
<h3>Remediation</h3>
<p class="card-text">{{{markdown recommendation}}}</p>
Expand Down

0 comments on commit ece4968

Please sign in to comment.