Skip to content

Commit 1c1db1f

Browse files
committed
chore: report http status
1 parent 081c015 commit 1c1db1f

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

packages/cli/bin/view/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const render = require('./render')
88

99
module.exports = ({ total, emitter, logspeed, ...opts }) => {
1010
const state = {
11+
status: {},
1112
count: 0,
1213
end: false,
1314
fetchingUrl: '',
@@ -27,6 +28,10 @@ module.exports = ({ total, emitter, logspeed, ...opts }) => {
2728
++state.count
2829
})
2930

31+
emitter.on('fetched', ({ targetUrl, statusCode }) => {
32+
state.status[targetUrl] = statusCode
33+
})
34+
3035
emitter.on('rule', ({ status }) => {
3136
if (!hasErrors && status === 'error') {
3237
hasErrors = true

packages/cli/bin/view/render.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const spinner = require('ora')({ text: '', color: 'gray' })
44
const indentString = require('indent-string')
55
const humanizeUrl = require('humanize-url')
6+
const httpStatus = require('http-status')
67
const logSymbols = require('log-symbols')
78
const prettyMs = require('pretty-ms')
89
const { EOL } = require('os')
@@ -21,7 +22,9 @@ const renderProgress = ({ fetchingUrl, count, total, startTimestamp }) => {
2122
const renderResume = state => {
2223
return Object.keys(state.data).reduce((acc, url) => {
2324
const allRules = state.data[url]
24-
let str = `${humanizeUrl(url)}${EOL}`
25+
const statusCode = state.status[url]
26+
const humanStatusCode = gray(`${statusCode} ${httpStatus[statusCode]}`)
27+
let str = `${humanizeUrl(url)} ${humanStatusCode} ${EOL}`
2528
Object.keys(allRules).forEach(ruleName => {
2629
const rules = allRules[ruleName]
2730
str += `${EOL}${indentString(`${ruleName}`, 2)}${EOL}${EOL}`

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"ci-env": "~1.16.0",
3838
"cosmiconfig": "~7.0.0",
3939
"github-build": "~1.2.2",
40+
"http-status": "~1.5.0",
4041
"humanize-url": "~2.1.1",
4142
"indent-string": "~4.0.0",
4243
"lodash": "~4.17.21",

packages/core/src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ const validate = async (html, emitter) => {
5050

5151
const validateUrl = async ({ acc, url, emitter, ...opts }) => {
5252
emitter.emit('fetching', { url })
53-
const { html } = await getHTML(url, opts)
53+
const data = await getHTML(url, opts)
54+
emitter.emit('fetched', { ...data, targetUrl: url })
5455

55-
const report = await validate(html, emitter)
56+
const report = await validate(data.html, emitter)
5657
emitter.emit('report', report)
5758

5859
acc[url] = report

0 commit comments

Comments
 (0)