@@ -3,6 +3,8 @@ import { exec } from 'child_process'
3
3
import { readFileSync , writeFileSync , existsSync , mkdirSync , copyFileSync } from 'fs'
4
4
if ( ! existsSync ( './src/urlList.js' ) ) copyFileSync ( './src/urlList.example' , './src/urlList.js' )
5
5
import { urlList , options , execOptions } from './src/urlList.js'
6
+ import { makeCommandFromURL } from './src/lib/commandHandlers.js'
7
+ import { getCategoriesFromCategoriesFlags , getCurrentCategories } from './src/lib/categoriesHandlers.js'
6
8
7
9
Object . prototype . isEmpty = ( obj ) => {
8
10
for ( const prop in obj )
@@ -17,19 +19,17 @@ Array.prototype.isEmpty = (arr) => {
17
19
}
18
20
19
21
const execResult = ( err = null , out , outerr = null ) => {
20
- const isOptionsCategories = ( ! Array . isEmpty ( options ?. categories ) ?? false ) ? `--only-categories=${ lighthouseCategories ( options ?. categories ?? "accessibility" ) } ` : ""
21
-
22
22
let accessibilityScores = ( ! existsSync ( './out/scores.json' ) ) ? readFileSync ( './src/scores.json' ) : readFileSync ( './out/scores.json' )
23
23
24
24
const data = JSON . parse ( out )
25
25
26
- const commandToRun = `lighthouse ${ data . requestedUrl } ${ isOptionsCategories } --output json`
26
+ const commandToRun = makeCommandFromURL ( data ? .requestedUrl , options )
27
27
console . log ( `command stopped: ${ commandToRun } ` )
28
28
29
29
const accessibilityScoresJSON = JSON . parse ( accessibilityScores )
30
30
const categoriesScoresObject = { }
31
- const categories = ( ! Array . isEmpty ( options ?. categories ) ) ? options ?. categories : undefined
32
- const optionCategories = categories ?? [ "accessibility" , "pwa" , "best-practices" , "performance" , "seo" ]
31
+ const categories = getCategoriesFromCategoriesFlags ( options ?. categories )
32
+ const optionCategories = getCurrentCategories ( categories )
33
33
34
34
optionCategories . forEach ( category => {
35
35
let categoryScore = data ?. categories [ category ] . score
@@ -54,8 +54,7 @@ const execResult = (err = null, out, outerr = null) => {
54
54
}
55
55
56
56
const testURL = ( urlToCheck , options = { } ) => {
57
- const isOptionsCategories = ( ! Array . isEmpty ( options ?. categories ) ?? false ) ? `--only-categories=${ lighthouseCategories ( options ?. categories ?? "accessibility" ) } ` : ""
58
- const commandToRun = `lighthouse ${ urlToCheck } ${ isOptionsCategories } --output json --disable-full-page-screenshot`
57
+ const commandToRun = makeCommandFromURL ( urlToCheck , options )
59
58
60
59
console . log ( `running command: ${ commandToRun } ` )
61
60
@@ -66,9 +65,4 @@ const testURL = (urlToCheck, options = {}) => {
66
65
] )
67
66
}
68
67
69
- const lighthouseCategories = ( categories = [ ] ) => {
70
- if ( typeof categories == "string" ) return categories
71
- return categories . join ( ',' )
72
- }
73
-
74
68
urlList . forEach ( url => testURL ( url , options ) )
0 commit comments