This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaxe-pro-earl
executable file
·65 lines (55 loc) · 1.84 KB
/
axe-pro-earl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const yargs = require('yargs')
const globby = require('globby')
const groupResultsByRule = require('./src/group-results-by-rule')
const toEarlReport = require('./src/to-earl-report')
const loadJson = require('./src/load-json')
const inputDefault = './axe-pro-exports/**/*.json'
const argv = yargs.usage('Usage: $0 -input reports/**.json --output earl-report.json')
.option('input', {
alias: 'i',
default: inputDefault,
array: true
})
.option('outDir', {
alias: 'o',
default: './reports/'
})
.option('testcases', {
alias: 't',
default: 'https://act-rules.github.io/testcases.json'
})
.help('help')
.alias('help', 'h')
.alias('version', 'v')
.argv;
// Little work-around so that the default shows up as a globby, instead of listing out
// each JSON file individually
if (argv.input.length === 1 && argv.input[0] === inputDefault) {
argv.input = globby.sync(inputDefault)
}
async function main ({ input, outDir, testcases }) {
const testCasesJson = await loadJson(testcases)
// Ensure the output dir exists
const resolvedOutDir = path.resolve(outDir)
if (!fs.existsSync(resolvedOutDir)) {
fs.mkdirSync(resolvedOutDir)
}
// Group results by rule, so that we can figure out what rules ran
const ruleResultSets = groupResultsByRule(input, testCasesJson)
// Loop over each rule
Object.entries(ruleResultSets).forEach(([ruleId, ruleResults]) => {
const earlReport = toEarlReport(ruleResults)
const reportPath = path.resolve(resolvedOutDir, `${ruleId}-earl-report.json`)
const reportString = JSON.stringify(earlReport, null, 2)
// Save the report
fs.writeFileSync(reportPath, reportString, 'utf8')
console.log(`Created '${reportPath}'`)
})
}
main(argv).catch(err => {
console.error(err)
process.exit(1)
})