Skip to content

Commit

Permalink
chore: Merge pull request #55 from eventOneHQ/45-open-report
Browse files Browse the repository at this point in the history
#45 - Add option to automatically open report
  • Loading branch information
nprail authored Oct 30, 2020
2 parents fb93074 + b962e7c commit 0ec8a67
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const program = require('commander')
const updateNotifier = require('update-notifier')
const fs = require('fs-extra')
const open = require('open')
const path = require('path')

const reporter = require('./lib/reporter')
Expand All @@ -16,6 +17,7 @@ program
.version(pkg.version)
.option('-o, --output [output]', 'output file')
.option('-i, --input [input]', 'input file')
.option('-O, --open', 'open report in default browser automatically')
.option(
'-c, --theme [theme name]',
'template theme `dark` or `light` (defaults to `light`)'
Expand All @@ -34,7 +36,7 @@ program
return process.exit(1)
}

await genReport(data, cmd.output, cmd.template, cmd.theme, cmd.fatalExitCode)
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 @@ -46,6 +48,7 @@ const genReport = async (
output = 'npm-audit.html',
template,
theme = 'light',
openBrowser = false,
fatalExitCode = false
) => {
try {
Expand All @@ -63,6 +66,11 @@ const genReport = async (
}

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

if (openBrowser) {
console.log('Opening report in default browser...')
await open(path.resolve(output))
}
} catch (err) {
console.log('An error occurred!')
console.log(err)
Expand Down
22 changes: 22 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"marked": "^1.2.2",
"moment": "^2.29.1",
"numeral": "^2.0.6",
"open": "^7.3.0",
"terminal-link": "^2.1.1",
"update-notifier": "^4.1.3"
},
Expand Down

0 comments on commit 0ec8a67

Please sign in to comment.