diff --git a/index.js b/index.js index a21fe7f..b38643c 100644 --- a/index.js +++ b/index.js @@ -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') @@ -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`)' @@ -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) @@ -46,6 +48,7 @@ const genReport = async ( output = 'npm-audit.html', template, theme = 'light', + openBrowser = false, fatalExitCode = false ) => { try { @@ -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) diff --git a/package-lock.json b/package-lock.json index 99a6d21..08951af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4029,6 +4029,11 @@ } } }, + "is-docker": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.1.1.tgz", + "integrity": "sha512-ZOoqiXfEwtGknTiuDEy8pN2CfE3TxMHprvNer1mXiqwkOT77Rw3YVrUQ52EqAOU3QAWDQ+bQdx7HJzrv7LS2Hw==" + }, "is-extendable": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/is-extendable/-/is-extendable-0.1.1.tgz", @@ -4193,6 +4198,14 @@ "integrity": "sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==", "dev": true }, + "is-wsl": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", + "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", + "requires": { + "is-docker": "^2.0.0" + } + }, "is-yarn-global": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/is-yarn-global/-/is-yarn-global-0.3.0.tgz", @@ -9043,6 +9056,15 @@ "mimic-fn": "^1.0.0" } }, + "open": { + "version": "7.3.0", + "resolved": "https://registry.npmjs.org/open/-/open-7.3.0.tgz", + "integrity": "sha512-mgLwQIx2F/ye9SmbrUkurZCnkoXyXyu9EbHtJZrICjVAJfyMArdHp3KkixGdZx1ZHFPNIwl0DDM1dFFqXbTLZw==", + "requires": { + "is-docker": "^2.0.0", + "is-wsl": "^2.1.1" + } + }, "opencollective-postinstall": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz", diff --git a/package.json b/package.json index 9282c75..b553a01 100644 --- a/package.json +++ b/package.json @@ -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" },