From ff44bf72ba2801379d03acd66e2147705812ff94 Mon Sep 17 00:00:00 2001 From: emptywork <22065214+EmptyWork@users.noreply.github.com> Date: Sun, 11 Jun 2023 12:19:37 +0900 Subject: [PATCH 1/6] Update `.gitignore` added `test.js` --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a59384b..022ade6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ node_modules/ /out/ /src/urlList.js -.gitlog \ No newline at end of file +.gitlog + +test.js \ No newline at end of file From 0a4ad920219096f31b395aca1c786327590ee64b Mon Sep 17 00:00:00 2001 From: emptywork <22065214+EmptyWork@users.noreply.github.com> Date: Sun, 11 Jun 2023 12:20:38 +0900 Subject: [PATCH 2/6] Update `src/urlList.example` added execOptions --- src/urlList.example | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/urlList.example b/src/urlList.example index 92d989a..a0b971f 100644 --- a/src/urlList.example +++ b/src/urlList.example @@ -2,9 +2,14 @@ const _urlList = [ // you can add more links in here, but keep in mind, the more links you add // the more resource it will use "https://www.emptywork.my.id" -]; +] const _options = { + // "categories": [] } -export { _urlList as urlList, _options as options }; \ No newline at end of file +const execOptions = { + "maxBuffer": 2048 * 1024 +} + +export { _urlList as urlList, _options as options } \ No newline at end of file From dd9083d4f872ff374209036107e50c5b098aed81 Mon Sep 17 00:00:00 2001 From: emptywork <22065214+EmptyWork@users.noreply.github.com> Date: Sun, 11 Jun 2023 12:21:44 +0900 Subject: [PATCH 3/6] Update `index.js` added import for execOptions --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 855e962..62933f6 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,8 @@ import { series } from 'async' import { exec } from 'child_process' -import { readFileSync, writeFileSync, existsSync, mkdirSync, copyFileSync, write, writeFile } from 'fs' +import { readFileSync, writeFileSync, existsSync, mkdirSync, copyFileSync } from 'fs' if (!existsSync('./src/urlList.js')) copyFileSync('./src/urlList.example', './src/urlList.js') -import { urlList, options } from './src/urlList.js' +import { urlList, options, execOptions } from './src/urlList.js' Object.prototype.isEmpty = (obj) => { for (const prop in obj) { From abb29203ad70c0bede602254380196c2cf993d8e Mon Sep 17 00:00:00 2001 From: emptywork <22065214+EmptyWork@users.noreply.github.com> Date: Sun, 11 Jun 2023 12:22:24 +0900 Subject: [PATCH 4/6] Update `index.js` improved Object.isEmpty and added Array.isEmpty --- index.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 62933f6..fd071db 100644 --- a/index.js +++ b/index.js @@ -5,13 +5,15 @@ if (!existsSync('./src/urlList.js')) copyFileSync('./src/urlList.example', './sr import { urlList, options, execOptions } from './src/urlList.js' Object.prototype.isEmpty = (obj) => { - for (const prop in obj) { - if (Object.hasOwn(obj, prop)) { - return false; - } - } + for (const prop in obj) + if (Object.hasOwn(obj, prop)) return false - return true; + return true +} + +Array.prototype.isEmpty = (arr) => { + if (arr === undefined || arr.length === 0) return false + return true } const execResult = (err = null, out, outerr = null) => { From 7868d6704e90eaf4b02f37103976fc7003b66f1a Mon Sep 17 00:00:00 2001 From: emptywork <22065214+EmptyWork@users.noreply.github.com> Date: Sun, 11 Jun 2023 12:23:10 +0900 Subject: [PATCH 5/6] Update `index.js` added support for execOptions and more --- index.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index fd071db..95efc4f 100644 --- a/index.js +++ b/index.js @@ -17,13 +17,19 @@ 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` + console.log(`command stopped: ${commandToRun}`) + const accessibilityScoresJSON = JSON.parse(accessibilityScores) const categoriesScoresObject = {} - const optionCategories = options.categories ?? ["accessibility", "pwa", "best-practices", "performance", "seo"]; + const categories = (!Array.isEmpty(options?.categories)) ? options?.categories : undefined + const optionCategories = categories ?? ["accessibility", "pwa", "best-practices", "performance", "seo"] optionCategories.forEach(category => { let categoryScore = data?.categories[category].score @@ -31,28 +37,32 @@ const execResult = (err = null, out, outerr = null) => { categoriesScoresObject[category] = categoryScore }) - accessibilityScoresJSON[data.requestedUrl] = categoriesScoresObject + accessibilityScoresJSON[data?.requestedUrl] = categoriesScoresObject const newAccessibilityJSON = JSON.stringify(accessibilityScoresJSON) if (!existsSync('./out/')) mkdirSync('./out/') if (!existsSync('./out/logs')) mkdirSync('./out/logs') - const rawOutputFilename = `./out/logs/${data.requestedUrl.split('.')[1]}_${Date.now()}.json` + + const logFileNameBasedOnUrl = data?.requestedUrl.replace(/^(http|https):\/\/(www.|)/g, '').replaceAll("/", "").split('.').reverse().join('.') + const rawOutputFilename = `./out/logs/${logFileNameBasedOnUrl}-${optionCategories + .join('-')}-${Date.now()}.json` writeFileSync(rawOutputFilename, JSON.stringify(data), { flag: 'w' }) return writeFileSync('./out/scores.json', newAccessibilityJSON, { flag: 'w' }) } const testURL = (urlToCheck, options = {}) => { - const isOptionsCategories = (!Object.isEmpty(options.categories) ?? false) ? `--only-categories=${lighthouseCategories(options?.categories ?? "accessibility")}` : "" - const commandToRun = `lighthouse ${urlToCheck} ${isOptionsCategories} --output json` + const isOptionsCategories = (!Array.isEmpty(options?.categories) ?? false) ? `--only-categories=${lighthouseCategories(options?.categories ?? "accessibility")} ` : "" + const commandToRun = `lighthouse ${urlToCheck} ${isOptionsCategories}--output json --disable-full-page-screenshot` console.log(`running command: ${commandToRun}`) series([ - () => exec(commandToRun, execResult), + () => exec(commandToRun, execOptions, execResult), // () => exec("lighthouse https://emptywork.my.id --output json >> dump", (err, stdout, stderr) => console.log(stdout)) + // () => exec("lighthouse --help", (err, stdout, stderr) => console.log(stdout)) ]) } From efbacce0d50920d3273089f5810f5af3c8ee8d63 Mon Sep 17 00:00:00 2001 From: emptywork <22065214+EmptyWork@users.noreply.github.com> Date: Sun, 11 Jun 2023 12:24:03 +0900 Subject: [PATCH 6/6] Update `package.json` new version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2e65fcb..87b3437 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lighthouse-link-thesis", - "version": "0.0.1", + "version": "0.0.2", "description": "a way to automatically use lighthouse to get accessibility report number", "main": "index.js", "type": "module",