Skip to content

Commit 4fb00e3

Browse files
authored
Improve logging (#50)
* Install picocolors * Log final output even when no a11y issues
1 parent b9907c1 commit 4fb00e3

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

package-lock.json

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"dependencies": {
1111
"pa11y": "^6.1.0",
1212
"path-type": "^4.0.0",
13+
"picocolors": "^1.0.0",
1314
"readdirp": "^3.6.0"
1415
},
1516
"scripts": {

src/index.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const { getConfiguration } = require('./config')
44
const pluginCore = require('./pluginCore')
5+
const pico = require('picocolors')
56

67
module.exports = {
78
async onPostBuild({ constants, inputs, utils: { build } }) {
@@ -22,17 +23,23 @@ module.exports = {
2223
htmlFilePaths,
2324
pa11yOpts,
2425
})
25-
if (issueCount > 0) {
26-
const postRunMsg = `Pa11y found ${issueCount} accessibility violations on your site! Check the logs above for more information.`
27-
console.log(report)
28-
if (failWithIssues) {
29-
build.failBuild(postRunMsg)
30-
} else {
31-
console.warn(postRunMsg)
32-
}
33-
}
26+
const log = issueCount === 0 ? console.log : failWithIssues ? build.failBuild : console.warn
27+
log(generatePostrunMessage(issueCount, report))
3428
} catch (err) {
3529
build.failBuild(err.message)
3630
}
3731
},
3832
}
33+
34+
/**
35+
* Generates the message sent to the build log after a11y checks have been peformed.
36+
* @param {number} issueCount
37+
* @param {string} report
38+
*/
39+
function generatePostrunMessage(issueCount, report) {
40+
const humanReadableCount = issueCount === 0 ? 'No' : issueCount
41+
const summary = `${humanReadableCount} accessibility violations found! ${
42+
issueCount > 0 ? 'Check the logs above for more information.' : ''
43+
}`
44+
return report + '\n' + pico.magenta(summary)
45+
}

0 commit comments

Comments
 (0)