Skip to content

Commit

Permalink
chore: Merge develop in
Browse files Browse the repository at this point in the history
  • Loading branch information
nprail committed Oct 22, 2020
2 parents c6aa399 + fb93074 commit b962e7c
Show file tree
Hide file tree
Showing 7 changed files with 1,383 additions and 3,433 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ script:
notifications:
email: false
after_success:
- npm run travis-deploy-once "npm run semantic-release"
- npm run semantic-release
branches:
except:
- /^v\d+\.\d+\.\d+$/
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ You can also fully customize the generated report by providing `--template` opti
npm audit --json | npm-audit-html --template ./my-awesome-template.hbs
```

If you'd like the generator to exit with non-zero exit code when vulnerabilities are found, you can add the `--fatal-exit-code` option:
```bash
npm audit --json | npm-audit-html --fatal-exit-code
```

## ✍️ Authors <a name = "authors"></a>

- [@nprail](https://github.com/nprail) - Maintainer
Expand Down
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ program
'template theme `dark` or `light` (defaults to `light`)'
)
.option('-t, --template [handlebars file]', 'handlebars template file')
.option('-f, --fatal-exit-code', 'exit with code 1 if vulnerabilities were found')
.action(async (cmd, env) => {
try {
let data
Expand All @@ -35,7 +36,7 @@ program
return process.exit(1)
}

await genReport(data, cmd.output, cmd.template, cmd.theme, cmd.open)
await genReport(data, cmd.output, cmd.template, cmd.theme, cmd.open, cmd.fatalExitCode)
} catch (err) {
console.error('Failed to parse NPM Audit JSON!')
return process.exit(1)
Expand All @@ -47,17 +48,22 @@ const genReport = async (
output = 'npm-audit.html',
template,
theme = 'light',
openBrowser = false
openBrowser = false,
fatalExitCode = false
) => {
try {
if (!data) {
console.log('No JSON')
return process.exit(1)
}

const templateFile = template || `${__dirname}/templates/template.hbs`
const templateFile = template || path.join(__dirname, '/templates/template.hbs')

await reporter(data, templateFile, output, theme)
const modifiedData = await reporter(data, templateFile, output, theme)

if (modifiedData.metadata.vulnerabilities.total > 0 && fatalExitCode) {
process.exitCode = 1
}

console.log(`Vulnerability snapshot saved at ${output}`)

Expand Down
1 change: 1 addition & 0 deletions lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ module.exports = async (data, templateFile, outputFile, theme) => {
modifiedData.theme = theme
const report = await generateTemplate(modifiedData, templateFile)
await writeReport(report, outputFile)
return modifiedData
} catch (err) {
console.log(err)
}
Expand Down
Loading

0 comments on commit b962e7c

Please sign in to comment.