Skip to content

Commit e8c3264

Browse files
committed
Update application.class.js migrate from console.log to Logger
1 parent 8f195af commit e8c3264

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/lib/application.class.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { series } from "async"
22
import { exec } from 'child_process'
33
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs'
44
import { getCategoriesFlags, getCategoriesFromCategoriesFlags, getCurrentCategories } from "./categoriesHandlers.class.js"
5+
import { Logger, LoggerType } from "./utilities.class.js"
56
import Command from "./commandHandlers.class.js"
67

78
export default class ThesisLighthouse {
@@ -20,9 +21,10 @@ export default class ThesisLighthouse {
2021
this.#currentCategories = getCurrentCategories(categories)
2122
}
2223

23-
testURL = (urlToCheck, options = {}) => {
24+
testURL = (urlToCheck, options = {}, currentIndex) => {
2425
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)
2628

2729
series([
2830
() => exec(commandToRun, this.execOptions, this.execResult.bind(this))
@@ -36,7 +38,7 @@ export default class ThesisLighthouse {
3638
)
3739

3840
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)
4042

4143
const newAccessibilityJSON = this.#produceNewJSON(data, accessibilityScores)
4244

@@ -80,19 +82,24 @@ export default class ThesisLighthouse {
8082
}
8183

8284
#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)
8591
}
8692

8793
start = () => {
88-
if (this.options?.consoleLog) console.log(this.options)
8994

9095
const isOptionsCategories = getCategoriesFlags(this.options?.categories)
9196
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"`
9297

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`)
95102

96-
this.urlList.forEach((url, index) => { this.testURL(url, this.options) })
103+
this.urlList.forEach((url, index) => { this.testURL(url, this.options, index) })
97104
}
98105
}

0 commit comments

Comments
 (0)