1
- import { series } from 'async' ;
2
- import { exec } from 'child_process' ;
3
- import { readFileSync , writeFileSync , existsSync , mkdirSync , copyFileSync } from 'fs' ;
1
+ import { series } from 'async'
2
+ import { exec } from 'child_process'
3
+ import { readFileSync , writeFileSync , existsSync , mkdirSync , copyFileSync , write , writeFile } from 'fs'
4
4
if ( ! existsSync ( './src/urlList.js' ) ) copyFileSync ( './src/urlList.example' , './src/urlList.js' )
5
- import { urlList } from './src/urlList.js' ;
5
+ import { urlList } from './src/urlList.js'
6
6
7
7
const execResult = ( err = null , out , outerr = null ) => {
8
8
let accessibilityScores = ( ! existsSync ( './out/scores.json' ) ) ? readFileSync ( './src/scores.json' ) : readFileSync ( './out/scores.json' )
9
9
10
- const data = JSON . parse ( out ) ;
10
+ const data = JSON . parse ( out )
11
11
const accessibilityScoresJSON = JSON . parse ( accessibilityScores )
12
12
const URLaccessibilityScoreResult = data ?. categories ?. accessibility ?. score
13
+
13
14
accessibilityScoresJSON [ data . requestedUrl ] = URLaccessibilityScoreResult
15
+
14
16
const newAccessibilityJSON = JSON . stringify ( accessibilityScoresJSON )
17
+
15
18
if ( ! existsSync ( './out/' ) ) mkdirSync ( './out/' )
19
+
20
+ if ( ! existsSync ( './out/logs' ) ) mkdirSync ( './out/logs' )
21
+ const rawOutputFilename = `./out/logs/${ data . requestedUrl . split ( '.' ) [ 1 ] } _${ Date . now ( ) } .json`
22
+
23
+ writeFileSync ( rawOutputFilename , JSON . stringify ( data ) , { flag : 'w' } )
16
24
return writeFileSync ( './out/scores.json' , newAccessibilityJSON , { flag : 'w' } )
17
25
}
18
26
19
- const testURL = ( urlToCheck ) => {
20
- const commandToRun = `lighthouse ${ urlToCheck } --only-categories=accessibility --output json`
21
-
27
+ const testURL = ( urlToCheck , options = { } ) => {
28
+ const commandToRun = `lighthouse ${ urlToCheck } --only-categories=${ lighthouseCategories ( options ?. categories ?? " accessibility" ) } --output json`
29
+ console . log ( `running command: ${ commandToRun } ` )
22
30
series ( [
23
31
( ) => exec ( commandToRun , execResult )
24
32
] )
25
33
}
26
34
27
- urlList . forEach ( url => testURL ( url ) )
35
+ const lighthouseCategories = ( categories = [ ] ) => {
36
+ if ( typeof categories == "string" ) return categories
37
+ return categories . join ( ',' )
38
+ }
39
+
40
+ urlList . forEach ( url => testURL ( url ,
41
+ {
42
+ "categories" : [
43
+ "accessibility" ,
44
+ "performance"
45
+ ]
46
+ } )
47
+ )
0 commit comments