Skip to content

Commit ada155a

Browse files
committed
Create clean.js, index.js, src/scores.js, and urlList.example
1 parent a438594 commit ada155a

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

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))

src/scores.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

src/urlList.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const _urlList = [
2+
// you can add more links in here, but keep in mind, the more links you add
3+
// the more resource it will use
4+
"https://www.emptywork.my.id"
5+
];
6+
7+
export { _urlList as urlList };

0 commit comments

Comments
 (0)