Skip to content

Commit

Permalink
Create Lighthouse Accessibility Thesis Program (#1)
Browse files Browse the repository at this point in the history
Create `Lighthouse Accessibility Thesis Program`
  • Loading branch information
EmptyWork authored Jun 8, 2023
2 parents a1cc8d8 + ada155a commit 8bd8ea9
Show file tree
Hide file tree
Showing 7 changed files with 1,719 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/

/out/
/src/urlList.js
9 changes: 9 additions & 0 deletions clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { existsSync, rmSync } from 'fs';

const cleanDirectory = () => {
if (!existsSync('./out/')) return console.error(`failed: dir out not exist`)
rmSync('./out/', { recursive: true })
console.log(`complete: dir out has been deleted`)
}

cleanDirectory()
27 changes: 27 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { series } from 'async';
import { exec } from 'child_process';
import { readFileSync, writeFileSync, existsSync, mkdirSync, copyFileSync } from 'fs';
if (!existsSync('./src/urlList.js')) copyFileSync('./src/urlList.example', './src/urlList.js')
import { urlList } from './src/urlList.js';

const execResult = (err = null, out, outerr = null) => {
let accessibilityScores = (!existsSync('./out/scores.json')) ? readFileSync('./src/scores.json') : readFileSync('./out/scores.json')

const data = JSON.parse(out);
const accessibilityScoresJSON = JSON.parse(accessibilityScores)
const URLaccessibilityScoreResult = data?.categories?.accessibility?.score
accessibilityScoresJSON[data.requestedUrl] = URLaccessibilityScoreResult
const newAccessibilityJSON = JSON.stringify(accessibilityScoresJSON)
if (!existsSync('./out/')) mkdirSync('./out/')
return writeFileSync('./out/scores.json', newAccessibilityJSON, { flag: 'w' })
}

const testURL = (urlToCheck) => {
const commandToRun = `lighthouse ${urlToCheck} --only-categories=accessibility --output json`

series([
() => exec(commandToRun, execResult)
])
}

urlList.forEach(url => testURL(url))
Loading

0 comments on commit 8bd8ea9

Please sign in to comment.