Skip to content

Commit

Permalink
fix(reporter): Handle incorrect being piped to the cli
Browse files Browse the repository at this point in the history
  • Loading branch information
nprail committed Dec 15, 2018
1 parent b382e7d commit cf47e25
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 16 deletions.
26 changes: 26 additions & 0 deletions lib/reporter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const terminalLink = require('terminal-link')
const Handlebars = require('handlebars')
const moment = require('moment')
const marked = require('marked')
const fse = require('fs-extra')
const chalk = require('chalk')
const fs = require('fs')
const { promisify } = require('util')

Expand Down Expand Up @@ -54,6 +56,30 @@ const modifyData = async data => {

module.exports = async (data, templateFile, outputFile) => {
try {
if (!data.metadata) {
if (data.updated) {
console.log(
chalk.red(
`Sorry! You can't use ${chalk.underline(
'npm audit fix'
)} with npm-audit-html.\n\nSee ${terminalLink(
'issue #3',
'https://github.com/Filiosoft/npm-audit-html/issues/3'
)}`
)
)
} else {
console.log(
chalk.red(
`The provided data doesn't seem to be correct. Did you run with ${chalk.underline(
'npm audit --json'
)}?`
)
)
}
process.exit(1)
}

const modifiedData = await modifyData(data)
const report = await generateTemplate(modifiedData, templateFile)
await writeReport(report, outputFile)
Expand Down
62 changes: 47 additions & 15 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@
"travis-deploy-once": "^5.0.0"
},
"dependencies": {
"chalk": "^2.4.1",
"commander": "^2.15.1",
"fs-extra": "^7.0.1",
"handlebars": "^4.0.11",
"marked": "^0.4.0",
"moment": "^2.22.2"
"moment": "^2.22.2",
"terminal-link": "^1.1.0"
},
"config": {
"commitizen": {
Expand Down

0 comments on commit cf47e25

Please sign in to comment.