Skip to content

Commit 7df0331

Browse files
committed
Update index.js to import functions from new libs
Details: - Get functions from `lib/categoriesHandlers.js` - Get function from `lib/commanndHandlers.js`
1 parent 8369622 commit 7df0331

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

index.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { exec } from 'child_process'
33
import { readFileSync, writeFileSync, existsSync, mkdirSync, copyFileSync } from 'fs'
44
if (!existsSync('./src/urlList.js')) copyFileSync('./src/urlList.example', './src/urlList.js')
55
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'
68

79
Object.prototype.isEmpty = (obj) => {
810
for (const prop in obj)
@@ -17,19 +19,17 @@ Array.prototype.isEmpty = (arr) => {
1719
}
1820

1921
const execResult = (err = null, out, outerr = null) => {
20-
const isOptionsCategories = (!Array.isEmpty(options?.categories) ?? false) ? `--only-categories=${lighthouseCategories(options?.categories ?? "accessibility")} ` : ""
21-
2222
let accessibilityScores = (!existsSync('./out/scores.json')) ? readFileSync('./src/scores.json') : readFileSync('./out/scores.json')
2323

2424
const data = JSON.parse(out)
2525

26-
const commandToRun = `lighthouse ${data.requestedUrl} ${isOptionsCategories}--output json`
26+
const commandToRun = makeCommandFromURL(data?.requestedUrl, options)
2727
console.log(`command stopped: ${commandToRun}`)
2828

2929
const accessibilityScoresJSON = JSON.parse(accessibilityScores)
3030
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)
3333

3434
optionCategories.forEach(category => {
3535
let categoryScore = data?.categories[category].score
@@ -54,8 +54,7 @@ const execResult = (err = null, out, outerr = null) => {
5454
}
5555

5656
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)
5958

6059
console.log(`running command: ${commandToRun}`)
6160

@@ -66,9 +65,4 @@ const testURL = (urlToCheck, options = {}) => {
6665
])
6766
}
6867

69-
const lighthouseCategories = (categories = []) => {
70-
if (typeof categories == "string") return categories
71-
return categories.join(',')
72-
}
73-
7468
urlList.forEach(url => testURL(url, options))

0 commit comments

Comments
 (0)