@@ -17,42 +17,52 @@ Array.prototype.isEmpty = (arr) => {
17
17
}
18
18
19
19
const execResult = ( err = null , out , outerr = null ) => {
20
+ const isOptionsCategories = ( ! Array . isEmpty ( options ?. categories ) ?? false ) ? `--only-categories=${ lighthouseCategories ( options ?. categories ?? "accessibility" ) } ` : ""
20
21
21
22
let accessibilityScores = ( ! existsSync ( './out/scores.json' ) ) ? readFileSync ( './src/scores.json' ) : readFileSync ( './out/scores.json' )
22
23
23
24
const data = JSON . parse ( out )
25
+
26
+ const commandToRun = `lighthouse ${ data . requestedUrl } ${ isOptionsCategories } --output json`
27
+ console . log ( `command stopped: ${ commandToRun } ` )
28
+
24
29
const accessibilityScoresJSON = JSON . parse ( accessibilityScores )
25
30
const categoriesScoresObject = { }
26
- const optionCategories = options . categories ?? [ "accessibility" , "pwa" , "best-practices" , "performance" , "seo" ] ;
31
+ const categories = ( ! Array . isEmpty ( options ?. categories ) ) ? options ?. categories : undefined
32
+ const optionCategories = categories ?? [ "accessibility" , "pwa" , "best-practices" , "performance" , "seo" ]
27
33
28
34
optionCategories . forEach ( category => {
29
35
let categoryScore = data ?. categories [ category ] . score
30
36
31
37
categoriesScoresObject [ category ] = categoryScore
32
38
} )
33
39
34
- accessibilityScoresJSON [ data . requestedUrl ] = categoriesScoresObject
40
+ accessibilityScoresJSON [ data ? .requestedUrl ] = categoriesScoresObject
35
41
36
42
const newAccessibilityJSON = JSON . stringify ( accessibilityScoresJSON )
37
43
38
44
if ( ! existsSync ( './out/' ) ) mkdirSync ( './out/' )
39
45
40
46
if ( ! existsSync ( './out/logs' ) ) mkdirSync ( './out/logs' )
41
- const rawOutputFilename = `./out/logs/${ data . requestedUrl . split ( '.' ) [ 1 ] } _${ Date . now ( ) } .json`
47
+
48
+ const logFileNameBasedOnUrl = data ?. requestedUrl . replace ( / ^ ( h t t p | h t t p s ) : \/ \/ ( w w w .| ) / g, '' ) . replaceAll ( "/" , "" ) . split ( '.' ) . reverse ( ) . join ( '.' )
49
+ const rawOutputFilename = `./out/logs/${ logFileNameBasedOnUrl } -${ optionCategories
50
+ . join ( '-' ) } -${ Date . now ( ) } .json`
42
51
43
52
writeFileSync ( rawOutputFilename , JSON . stringify ( data ) , { flag : 'w' } )
44
53
return writeFileSync ( './out/scores.json' , newAccessibilityJSON , { flag : 'w' } )
45
54
}
46
55
47
56
const testURL = ( urlToCheck , options = { } ) => {
48
- const isOptionsCategories = ( ! Object . isEmpty ( options . categories ) ?? false ) ? `--only-categories=${ lighthouseCategories ( options ?. categories ?? "accessibility" ) } ` : ""
49
- const commandToRun = `lighthouse ${ urlToCheck } ${ isOptionsCategories } --output json`
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 `
50
59
51
60
console . log ( `running command: ${ commandToRun } ` )
52
61
53
62
series ( [
54
- ( ) => exec ( commandToRun , execResult ) ,
63
+ ( ) => exec ( commandToRun , execOptions , execResult ) ,
55
64
// () => exec("lighthouse https://emptywork.my.id --output json >> dump", (err, stdout, stderr) => console.log(stdout))
65
+ // () => exec("lighthouse --help", (err, stdout, stderr) => console.log(stdout))
56
66
] )
57
67
}
58
68
0 commit comments