Skip to content

Commit

Permalink
Feature Flags Options from commandHandlers.js (#6)
Browse files Browse the repository at this point in the history
Feature `Flags Options` from `commandHandlers.js`
  • Loading branch information
EmptyWork authored Aug 1, 2023
2 parents dadfd37 + 7b24a3c commit a9ac01a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
29 changes: 20 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ if (!existsSync('./src/urlList.js')) copyFileSync('./src/urlList.example', './sr
import { urlList, options, execOptions } from './src/urlList.js'
import { makeCommandFromURL } from './src/lib/commandHandlers.js'
import { getCategoriesFromCategoriesFlags, getCurrentCategories } from './src/lib/categoriesHandlers.js'
import { getCategoriesFlags } from "./src/lib/categoriesHandlers.js"

Object.prototype.isEmpty = (obj) => {
for (const prop in obj)
Expand All @@ -14,17 +15,16 @@ Object.prototype.isEmpty = (obj) => {
}

Array.prototype.isEmpty = (arr) => {
if (arr === undefined || arr.length === 0) return false
return true
return (arr === undefined || arr.length === 0) ? false : true
}

const execResult = (err = null, out, outerr = null) => {
let accessibilityScores = (!existsSync('./out/scores.json')) ? readFileSync('./src/scores.json') : readFileSync('./out/scores.json')

const data = JSON.parse(out)

const commandToRun = makeCommandFromURL(data?.requestedUrl, options)
console.log(`command stopped: ${commandToRun}`)
const { commandToRun } = makeCommandFromURL(data?.requestedUrl, options)
if (options?.consoleLog ?? true) console.log(`Stopped Test on ${data?.requestedUrl}`)

const accessibilityScoresJSON = JSON.parse(accessibilityScores)
const categoriesScoresObject = {}
Expand All @@ -45,7 +45,9 @@ const execResult = (err = null, out, outerr = null) => {

if (!existsSync('./out/logs')) mkdirSync('./out/logs')

const logFileNameBasedOnUrl = data?.requestedUrl.replace(/^(http|https):\/\/(www.|)/g, '').replaceAll("/", "").split('.').reverse().join('.')
const REGEX_HTTPS_HTTP = /^(http|https):\/\/(www.|)/g

const logFileNameBasedOnUrl = data?.requestedUrl.replace(REGEX_HTTPS_HTTP, '').replaceAll("/", "").split('.').reverse().join('.')
const rawOutputFilename = `./out/logs/${logFileNameBasedOnUrl}-${optionCategories
.join('-')}-${Date.now()}.json`

Expand All @@ -54,9 +56,8 @@ const execResult = (err = null, out, outerr = null) => {
}

const testURL = (urlToCheck, options = {}) => {
const commandToRun = makeCommandFromURL(urlToCheck, options)

console.log(`running command: ${commandToRun}`)
const { commandToRun } = makeCommandFromURL(urlToCheck, options)
if (options?.consoleLog ?? true) console.log(`Running Test on ${urlToCheck}`)

series([
() => exec(commandToRun, execOptions, execResult),
Expand All @@ -65,4 +66,14 @@ const testURL = (urlToCheck, options = {}) => {
])
}

urlList.forEach(url => testURL(url, options))
const main = (urlList, options) => {
const isOptionsCategories = getCategoriesFlags(options?.categories)
const currentFlags = `${isOptionsCategories}--output json --disable-full-page-screenshot --chrome-flags="--no-sandbox --headless --disable-gpu"`

console.log(`TLighthouse ${process.env.npm_package_version} - Thesis Example Code`)
console.log(`Running with these Flags: ${currentFlags}\n`)

urlList.forEach((url, index) => { testURL(url, options) })
}

main(urlList, options)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lighthouse-link-thesis",
"version": "0.0.3",
"version": "0.0.4",
"description": "a way to automatically use lighthouse to get accessibility report number",
"main": "index.js",
"type": "module",
Expand Down
4 changes: 3 additions & 1 deletion src/lib/commandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { getCategoriesFlags } from "./categoriesHandlers.js"

const makeCommandFromURL = (url, options) => {
const isOptionsCategories = getCategoriesFlags(options?.categories)
return `lighthouse ${url} ${isOptionsCategories}--output json --disable-full-page-screenshot`
const currentFlags = `${isOptionsCategories}--output json --disable-full-page-screenshot --chrome-flags="--no-sandbox --headless --disable-gpu"`
const commandToRun = `lighthouse ${url} ${currentFlags}`
return { commandToRun, currentFlags }
}

export { makeCommandFromURL }

0 comments on commit a9ac01a

Please sign in to comment.