@@ -2,6 +2,7 @@ import { series } from "async"
2
2
import { exec } from 'child_process'
3
3
import { readFileSync , writeFileSync , existsSync , mkdirSync } from 'fs'
4
4
import { getCategoriesFlags , getCategoriesFromCategoriesFlags , getCurrentCategories } from "./categoriesHandlers.class.js"
5
+ import { Logger , LoggerType } from "./utilities.class.js"
5
6
import Command from "./commandHandlers.class.js"
6
7
7
8
export default class ThesisLighthouse {
@@ -20,9 +21,10 @@ export default class ThesisLighthouse {
20
21
this . #currentCategories = getCurrentCategories ( categories )
21
22
}
22
23
23
- testURL = ( urlToCheck , options = { } ) => {
24
+ testURL = ( urlToCheck , options = { } , currentIndex ) => {
24
25
const { commandToRun } = Command . make ( urlToCheck , options )
25
- if ( options ?. consoleLog ?? true ) console . log ( `Running Test on ${ urlToCheck } ` )
26
+
27
+ Logger ( `Running Test on ${ urlToCheck } ` , LoggerType . info , options . consoleLog )
26
28
27
29
series ( [
28
30
( ) => exec ( commandToRun , this . execOptions , this . execResult . bind ( this ) )
@@ -36,7 +38,7 @@ export default class ThesisLighthouse {
36
38
)
37
39
38
40
const data = JSON . parse ( out )
39
- if ( this . options ?. consoleLog ) console . log ( `Stopped Test on ${ data ?. requestedUrl } ` )
41
+ Logger ( `Stopped Test on ${ data ?. requestedUrl } ` , LoggerType . info , this . options ?. consoleLog )
40
42
41
43
const newAccessibilityJSON = this . #produceNewJSON( data , accessibilityScores )
42
44
@@ -80,19 +82,24 @@ export default class ThesisLighthouse {
80
82
}
81
83
82
84
#checkDir = ( ) => {
83
- if ( ! existsSync ( `${ this . #outputDir} ` ) ) mkdirSync ( `${ this . #outputDir} ` )
84
- if ( ! existsSync ( `${ this . #outputDir} logs` ) ) mkdirSync ( `${ this . #outputDir} logs` )
85
+ this . #makeDirIfNotExists( `${ this . #outputDir} ` )
86
+ this . #makeDirIfNotExists( `${ this . #outputDir} logs` )
87
+ }
88
+
89
+ #makeDirIfNotExists = ( location ) => {
90
+ if ( ! existsSync ( location ) ) mkdirSync ( location )
85
91
}
86
92
87
93
start = ( ) => {
88
- if ( this . options ?. consoleLog ) console . log ( this . options )
89
94
90
95
const isOptionsCategories = getCategoriesFlags ( this . options ?. categories )
91
96
const currentFlags = `${ isOptionsCategories } \n\t--output json \n\t--disable-full-page-screenshot \n\t--chrome-flags="\n\t\t--no-sandbox \n\t\t--headless \n\t\t--disable-gpu"`
92
97
93
- console . log ( `ThesisLighthouse ${ process . env . npm_package_version } - Thesis Example Code` )
94
- console . log ( `Running with these flags: ${ currentFlags } \n` )
98
+ Logger ( `Copyright (c) 2023 Stevarth` )
99
+ Logger ( `ThesisLighthouse ${ process . env . npm_package_version } - Thesis Example Code` )
100
+ Logger ( this . options , LoggerType . info , this . options ?. consoleLog )
101
+ Logger ( `Running with these flags: ${ currentFlags } \n` )
95
102
96
- this . urlList . forEach ( ( url , index ) => { this . testURL ( url , this . options ) } )
103
+ this . urlList . forEach ( ( url , index ) => { this . testURL ( url , this . options , index ) } )
97
104
}
98
105
}
0 commit comments