@@ -5,6 +5,7 @@ if (!existsSync('./src/urlList.js')) copyFileSync('./src/urlList.example', './sr
5
5
import { urlList , options , execOptions } from './src/urlList.js'
6
6
import { makeCommandFromURL } from './src/lib/commandHandlers.js'
7
7
import { getCategoriesFromCategoriesFlags , getCurrentCategories } from './src/lib/categoriesHandlers.js'
8
+ import { getCategoriesFlags } from "./src/lib/categoriesHandlers.js"
8
9
9
10
Object . prototype . isEmpty = ( obj ) => {
10
11
for ( const prop in obj )
@@ -14,17 +15,16 @@ Object.prototype.isEmpty = (obj) => {
14
15
}
15
16
16
17
Array . prototype . isEmpty = ( arr ) => {
17
- if ( arr === undefined || arr . length === 0 ) return false
18
- return true
18
+ return ( arr === undefined || arr . length === 0 ) ? false : true
19
19
}
20
20
21
21
const execResult = ( err = null , out , outerr = null ) => {
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 = makeCommandFromURL ( data ?. requestedUrl , options )
27
- console . log ( `command stopped: ${ commandToRun } ` )
26
+ const { commandToRun } = makeCommandFromURL ( data ?. requestedUrl , options )
27
+ if ( options ?. consoleLog ?? true ) console . log ( `Stopped Test on ${ data ?. requestedUrl } ` )
28
28
29
29
const accessibilityScoresJSON = JSON . parse ( accessibilityScores )
30
30
const categoriesScoresObject = { }
@@ -45,7 +45,9 @@ const execResult = (err = null, out, outerr = null) => {
45
45
46
46
if ( ! existsSync ( './out/logs' ) ) mkdirSync ( './out/logs' )
47
47
48
- const logFileNameBasedOnUrl = data ?. requestedUrl . replace ( / ^ ( h t t p | h t t p s ) : \/ \/ ( w w w .| ) / g, '' ) . replaceAll ( "/" , "" ) . split ( '.' ) . reverse ( ) . join ( '.' )
48
+ const REGEX_HTTPS_HTTP = / ^ ( h t t p | h t t p s ) : \/ \/ ( w w w .| ) / g
49
+
50
+ const logFileNameBasedOnUrl = data ?. requestedUrl . replace ( REGEX_HTTPS_HTTP , '' ) . replaceAll ( "/" , "" ) . split ( '.' ) . reverse ( ) . join ( '.' )
49
51
const rawOutputFilename = `./out/logs/${ logFileNameBasedOnUrl } -${ optionCategories
50
52
. join ( '-' ) } -${ Date . now ( ) } .json`
51
53
@@ -54,9 +56,8 @@ const execResult = (err = null, out, outerr = null) => {
54
56
}
55
57
56
58
const testURL = ( urlToCheck , options = { } ) => {
57
- const commandToRun = makeCommandFromURL ( urlToCheck , options )
58
-
59
- console . log ( `running command: ${ commandToRun } ` )
59
+ const { commandToRun } = makeCommandFromURL ( urlToCheck , options )
60
+ if ( options ?. consoleLog ?? true ) console . log ( `Running Test on ${ urlToCheck } ` )
60
61
61
62
series ( [
62
63
( ) => exec ( commandToRun , execOptions , execResult ) ,
@@ -65,4 +66,14 @@ const testURL = (urlToCheck, options = {}) => {
65
66
] )
66
67
}
67
68
68
- urlList . forEach ( url => testURL ( url , options ) )
69
+ const main = ( urlList , options ) => {
70
+ const isOptionsCategories = getCategoriesFlags ( options ?. categories )
71
+ const currentFlags = `${ isOptionsCategories } --output json --disable-full-page-screenshot --chrome-flags="--no-sandbox --headless --disable-gpu"`
72
+
73
+ console . log ( `TLighthouse ${ process . env . npm_package_version } - Thesis Example Code` )
74
+ console . log ( `Running with these Flags: ${ currentFlags } \n` )
75
+
76
+ urlList . forEach ( ( url , index ) => { testURL ( url , options ) } )
77
+ }
78
+
79
+ main ( urlList , options )
0 commit comments