Skip to content

Commit

Permalink
feat(cli): Add option to automatically open the report when done
Browse files Browse the repository at this point in the history
  • Loading branch information
nprail committed Oct 22, 2020
1 parent be8b56b commit c6aa399
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
14 changes: 11 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
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')
const pkg = require('./package.json')
Expand All @@ -15,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 @@ -32,7 +35,7 @@ program
return process.exit(1)
}

await genReport(data, cmd.output, cmd.template, cmd.theme)
await genReport(data, cmd.output, cmd.template, cmd.theme, cmd.open)
} catch (err) {
console.error('Failed to parse NPM Audit JSON!')
return process.exit(1)
Expand All @@ -43,7 +46,8 @@ const genReport = async (
data,
output = 'npm-audit.html',
template,
theme = 'light'
theme = 'light',
openBrowser = false
) => {
try {
if (!data) {
Expand All @@ -56,7 +60,11 @@ const genReport = async (
await reporter(data, templateFile, output, theme)

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

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 @@ -46,6 +46,7 @@
"marked": "^1.1.1",
"moment": "^2.27.0",
"numeral": "^2.0.6",
"open": "^7.3.0",
"terminal-link": "^2.1.1",
"update-notifier": "^4.1.0"
},
Expand Down

0 comments on commit c6aa399

Please sign in to comment.