From e5bd7489a05a0977ba2ba00d65b785ca8b68c121 Mon Sep 17 00:00:00 2001 From: emptywork <22065214+EmptyWork@users.noreply.github.com> Date: Tue, 13 Jun 2023 07:41:25 +0900 Subject: [PATCH 1/5] Update `package-lock.json` to 0.0.2 --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0db6323..dd13b49 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "lighthouse-link-thesis", - "version": "0.0.1", + "version": "0.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "lighthouse-link-thesis", - "version": "0.0.1", + "version": "0.0.2", "license": "MIT", "dependencies": { "async": "^3.2.4", From 2d25c9542ba5275635f00e6dcf86737193d9f26a Mon Sep 17 00:00:00 2001 From: emptywork <22065214+EmptyWork@users.noreply.github.com> Date: Tue, 13 Jun 2023 08:08:22 +0900 Subject: [PATCH 2/5] Create `categoriesHandlers.js` --- src/lib/categoriesHandlers.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/lib/categoriesHandlers.js diff --git a/src/lib/categoriesHandlers.js b/src/lib/categoriesHandlers.js new file mode 100644 index 0000000..fbce6e5 --- /dev/null +++ b/src/lib/categoriesHandlers.js @@ -0,0 +1,18 @@ + +const getCategoriesFlags = array => { + return (!Array.isEmpty(array) ?? false) ? `--only-categories=${lighthouseCategories(array ?? "accessibility")} ` : "" +} + +const getCurrentCategories = categories => { + return categories ?? ["accessibility", "pwa", "best-practices", "performance", "seo"] +} + +const lighthouseCategories = (categories = []) => { + return (typeof categories == "string") ? categories : categories.join(',') +} + +const getCategoriesFromCategoriesFlags = array => { + return (!Array.isEmpty(array)) ? array : undefined +} + +export { getCategoriesFlags, lighthouseCategories, getCurrentCategories, getCategoriesFromCategoriesFlags } \ No newline at end of file From 8369622100d1901da69c99b928bbcbecf9c97cc2 Mon Sep 17 00:00:00 2001 From: emptywork <22065214+EmptyWork@users.noreply.github.com> Date: Tue, 13 Jun 2023 08:08:51 +0900 Subject: [PATCH 3/5] Create `commandHandlers.js` --- src/lib/commandHandlers.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/lib/commandHandlers.js diff --git a/src/lib/commandHandlers.js b/src/lib/commandHandlers.js new file mode 100644 index 0000000..dfe0548 --- /dev/null +++ b/src/lib/commandHandlers.js @@ -0,0 +1,8 @@ +import { getCategoriesFlags } from "./categoriesHandlers.js" + +const makeCommandFromURL = (url, options) => { + const isOptionsCategories = getCategoriesFlags(options?.categories) + return `lighthouse ${url} ${isOptionsCategories}--output json --disable-full-page-screenshot` +} + +export { makeCommandFromURL } \ No newline at end of file From 7df033149ccbe9f0cddfc30e3e68c54df9e13153 Mon Sep 17 00:00:00 2001 From: emptywork <22065214+EmptyWork@users.noreply.github.com> Date: Tue, 13 Jun 2023 08:09:09 +0900 Subject: [PATCH 4/5] Update `index.js` to import functions from new libs Details: - Get functions from `lib/categoriesHandlers.js` - Get function from `lib/commanndHandlers.js` --- index.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 95efc4f..35a60bc 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,8 @@ import { exec } from 'child_process' import { readFileSync, writeFileSync, existsSync, mkdirSync, copyFileSync } from 'fs' if (!existsSync('./src/urlList.js')) copyFileSync('./src/urlList.example', './src/urlList.js') import { urlList, options, execOptions } from './src/urlList.js' +import { makeCommandFromURL } from './src/lib/commandHandlers.js' +import { getCategoriesFromCategoriesFlags, getCurrentCategories } from './src/lib/categoriesHandlers.js' Object.prototype.isEmpty = (obj) => { for (const prop in obj) @@ -17,19 +19,17 @@ Array.prototype.isEmpty = (arr) => { } const execResult = (err = null, out, outerr = null) => { - const isOptionsCategories = (!Array.isEmpty(options?.categories) ?? false) ? `--only-categories=${lighthouseCategories(options?.categories ?? "accessibility")} ` : "" - let accessibilityScores = (!existsSync('./out/scores.json')) ? readFileSync('./src/scores.json') : readFileSync('./out/scores.json') const data = JSON.parse(out) - const commandToRun = `lighthouse ${data.requestedUrl} ${isOptionsCategories}--output json` + const commandToRun = makeCommandFromURL(data?.requestedUrl, options) console.log(`command stopped: ${commandToRun}`) const accessibilityScoresJSON = JSON.parse(accessibilityScores) const categoriesScoresObject = {} - const categories = (!Array.isEmpty(options?.categories)) ? options?.categories : undefined - const optionCategories = categories ?? ["accessibility", "pwa", "best-practices", "performance", "seo"] + const categories = getCategoriesFromCategoriesFlags(options?.categories) + const optionCategories = getCurrentCategories(categories) optionCategories.forEach(category => { let categoryScore = data?.categories[category].score @@ -54,8 +54,7 @@ const execResult = (err = null, out, outerr = null) => { } const testURL = (urlToCheck, options = {}) => { - const isOptionsCategories = (!Array.isEmpty(options?.categories) ?? false) ? `--only-categories=${lighthouseCategories(options?.categories ?? "accessibility")} ` : "" - const commandToRun = `lighthouse ${urlToCheck} ${isOptionsCategories}--output json --disable-full-page-screenshot` + const commandToRun = makeCommandFromURL(urlToCheck, options) console.log(`running command: ${commandToRun}`) @@ -66,9 +65,4 @@ const testURL = (urlToCheck, options = {}) => { ]) } -const lighthouseCategories = (categories = []) => { - if (typeof categories == "string") return categories - return categories.join(',') -} - urlList.forEach(url => testURL(url, options)) \ No newline at end of file From f1da68c1a3db367acb4e6cd0684d3e4462a2b098 Mon Sep 17 00:00:00 2001 From: emptywork <22065214+EmptyWork@users.noreply.github.com> Date: Tue, 13 Jun 2023 08:11:34 +0900 Subject: [PATCH 5/5] Update `package.json` new version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 87b3437..b478e7d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lighthouse-link-thesis", - "version": "0.0.2", + "version": "0.0.3", "description": "a way to automatically use lighthouse to get accessibility report number", "main": "index.js", "type": "module",