Skip to content

Commit

Permalink
chore: Merge pull request #57 from eventOneHQ/develop
Browse files Browse the repository at this point in the history
1.5
  • Loading branch information
nprail authored Nov 11, 2020
2 parents 88287a7 + 6a5cbad commit 5e09db1
Show file tree
Hide file tree
Showing 10 changed files with 1,480 additions and 3,423 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Node CI

on: [pull_request, push]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
- run: npm ci
- run: npm run lint
test:
name: Node v${{ matrix.node-version }} on ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version: [8.x, 10.x, 12.x, 13.x, 14.x, 15.x]
os: [ubuntu-latest, macOS-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: install
run: npm ci
- name: run tests
run: npm run test-ci
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
24 changes: 19 additions & 5 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,11 +17,13 @@ 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`)'
)
.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 @@ -32,7 +36,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, cmd.fatalExitCode)
} catch (err) {
console.error('Failed to parse NPM Audit JSON!')
return process.exit(1)
Expand All @@ -43,20 +47,30 @@ const genReport = async (
data,
output = 'npm-audit.html',
template,
theme = 'light'
theme = 'light',
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}`)
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
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 5e09db1

Please sign in to comment.