Skip to content

Commit 8bd8ea9

Browse files
authored
Create Lighthouse Accessibility Thesis Program (#1)
Create `Lighthouse Accessibility Thesis Program`
2 parents a1cc8d8 + ada155a commit 8bd8ea9

File tree

7 files changed

+1719
-0
lines changed

7 files changed

+1719
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
3+
/out/
4+
/src/urlList.js

clean.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { existsSync, rmSync } from 'fs';
2+
3+
const cleanDirectory = () => {
4+
if (!existsSync('./out/')) return console.error(`failed: dir out not exist`)
5+
rmSync('./out/', { recursive: true })
6+
console.log(`complete: dir out has been deleted`)
7+
}
8+
9+
cleanDirectory()

index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { series } from 'async';
2+
import { exec } from 'child_process';
3+
import { readFileSync, writeFileSync, existsSync, mkdirSync, copyFileSync } from 'fs';
4+
if (!existsSync('./src/urlList.js')) copyFileSync('./src/urlList.example', './src/urlList.js')
5+
import { urlList } from './src/urlList.js';
6+
7+
const execResult = (err = null, out, outerr = null) => {
8+
let accessibilityScores = (!existsSync('./out/scores.json')) ? readFileSync('./src/scores.json') : readFileSync('./out/scores.json')
9+
10+
const data = JSON.parse(out);
11+
const accessibilityScoresJSON = JSON.parse(accessibilityScores)
12+
const URLaccessibilityScoreResult = data?.categories?.accessibility?.score
13+
accessibilityScoresJSON[data.requestedUrl] = URLaccessibilityScoreResult
14+
const newAccessibilityJSON = JSON.stringify(accessibilityScoresJSON)
15+
if (!existsSync('./out/')) mkdirSync('./out/')
16+
return writeFileSync('./out/scores.json', newAccessibilityJSON, { flag: 'w' })
17+
}
18+
19+
const testURL = (urlToCheck) => {
20+
const commandToRun = `lighthouse ${urlToCheck} --only-categories=accessibility --output json`
21+
22+
series([
23+
() => exec(commandToRun, execResult)
24+
])
25+
}
26+
27+
urlList.forEach(url => testURL(url))

0 commit comments

Comments
 (0)