Skip to content

Commit 551016b

Browse files
authored
Update workflows, Utility class and more files (#20)
Update `workflows, Utility class` and more files
2 parents 595db70 + 4ff0c4b commit 551016b

File tree

11 files changed

+192
-57
lines changed

11 files changed

+192
-57
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.github/workflows/tlighthouse.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: TLighthouse
2+
3+
on:
4+
pull_request:
5+
types: [synchronize, opened, reopened]
6+
push:
7+
branches: [main, development, dev-workflows]
8+
9+
jobs:
10+
install-ubuntu:
11+
name: Install on Ubuntu
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- name: Install Dependencies
18+
run: npm ci
19+
20+
install-macos:
21+
name: Install on MacOS
22+
runs-on: macos-latest
23+
24+
steps:
25+
- uses: actions/checkout@v3
26+
27+
- name: Install Dependencies
28+
run: npm ci
29+
30+
install-windows:
31+
name: Install on Windows
32+
runs-on: windows-latest
33+
34+
steps:
35+
- uses: actions/checkout@v3
36+
37+
- name: Install Dependencies
38+
run: npm ci
39+
40+
test:
41+
name: Test with Jest
42+
needs: [install-ubuntu, install-macos, install-windows]
43+
runs-on: ubuntu-latest
44+
45+
steps:
46+
- name: Check out code
47+
uses: actions/checkout@v3
48+
49+
- name: Install Dependencies
50+
run: npm ci
51+
52+
- name: Testing with Jest
53+
run: npm test
54+
55+
running:
56+
name: Run with Node
57+
needs: test
58+
runs-on: ubuntu-latest
59+
60+
steps:
61+
- name: Check out code
62+
uses: actions/checkout@v3
63+
64+
- name: Install Dependencies
65+
run: npm ci
66+
67+
- name: Set up Chrome
68+
uses: browser-actions/setup-chrome@v1
69+
70+
- name: Running the program
71+
run: npm start

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# TLighthouse - Lighthouse Accesibility Thesis
2+
3+
This is a small program that I created to help me to gather Accessibility report from Google Lighthouse™ for my Bachelor's Thesis.
4+
5+
## Requirement
6+
7+
Before you can install this program, you need to make sure that you have the latest version of [Google Chrome](https://www.google.com/chrome/) this due to [Lighthouse-CLI]() only support the use of Chrome as the program to run the test.
8+
9+
### Installation
10+
11+
To use this program you just need to follow this steps:
12+
13+
- `fork` this repo or `clone` this repo
14+
- move to the directory where this repo located on you local device, then do `npm install` to download all the dependecies
15+
- `npm run start` or `yarn start` to start initiate the program
16+
- you can then access newly created file on `src` named `urlList.class.js` and add the certain url of websites that you want to do test on.
17+
18+
19+
## Credits
20+
21+
- [Google Lighthouse](https://github.com/GoogleChrome/lighthouse) (opensource - owned and trademarked by Google inc.)
22+
- [Lighthouse CLI](https://github.com/GoogleChrome/lighthouse) (opensource - owned and trademarked by Google inc.)
23+
- [Async](https://github.com/caolan/async) (opensource)
24+
25+
### Supports
26+
27+
[![EmptyWork](https://raw.githubusercontent.com/EmptyWork/cpp-teaching/master/assets/active.svg)](https://emptywork.netlify.app)

clean.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { existsSync, rmSync } from 'fs'
2+
import { Logger, LoggerType } from "./src/lib/utilities.class.js"
23

34
const cleanDirectory = () => {
4-
if (!existsSync('./out/')) return console.error(`failed: dir out not exist`)
5+
if (!existsSync('./out/')) return Logger(`\`./out\` not exist`, LoggerType.warning)
56
rmSync('./out/', { recursive: true })
6-
console.log(`complete: dir out has been deleted`)
7+
Logger(`\`./out\` has been deleted`, LoggerType.info)
78
}
89

910
cleanDirectory()

legacy/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const main = (urlList, options) => {
7070
const isOptionsCategories = getCategoriesFlags(options?.categories)
7171
const currentFlags = `${isOptionsCategories}--output json --disable-full-page-screenshot --chrome-flags="--no-sandbox --headless --disable-gpu"`
7272

73+
console.log(`Copyright (c) 2023 Stevarth`)
7374
console.log(`[Legacy] TLighthouse ${process.env.npm_package_version} - Thesis Example Code`)
7475
console.log(`Running with these Flags: ${currentFlags}\n`)
7576

package-lock.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lighthouse-link-thesis",
3-
"version": "0.0.6c",
3+
"version": "0.0.7c",
44
"description": "a way to automatically use lighthouse to get accessibility report number",
55
"main": "index.class.js",
66
"type": "module",

setup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { existsSync, copyFileSync } from 'fs'
1+
import { copyIfNotExists } from "./src/lib/utilities.class.js";
22

3-
if (!existsSync('./src/urlList.class.js')) copyFileSync('./src/urlList.class.example', './src/urlList.class.js')
3+
copyIfNotExists('./src/urlList.class.js', './src/urlList.class.example')

src/lib/application.class.js

Lines changed: 24 additions & 12 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,11 +38,11 @@ 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

43-
this.#checkDir()
45+
this.#checkDir([`${this.#outputDir}`, `${this.#outputDir}logs`])
4446
const rawOutputFilename = this.#createFileName(data?.requestedUrl)
4547

4648
writeFileSync(rawOutputFilename, JSON.stringify(data), { flag: 'w' })
@@ -79,20 +81,30 @@ export default class ThesisLighthouse {
7981
return (!existsSync(location)) ? readFileSync(backup) : readFileSync(location)
8082
}
8183

82-
#checkDir = () => {
83-
if (!existsSync(`${this.#outputDir}`)) mkdirSync(`${this.#outputDir}`)
84-
if (!existsSync(`${this.#outputDir}logs`)) mkdirSync(`${this.#outputDir}logs`)
84+
#checkDir = (directories) => {
85+
switch (typeof directories) {
86+
case "object":
87+
directories.forEach(directory => this.#makeDirIfNotExists(directory))
88+
break;
89+
case "string":
90+
this.#makeDirIfNotExists(directories)
91+
break;
92+
}
8593
}
8694

87-
start = () => {
88-
if (this.options?.consoleLog) console.log(this.options)
95+
#makeDirIfNotExists = (location) => {
96+
if (!existsSync(location)) mkdirSync(location)
97+
}
8998

99+
start = () => {
90100
const isOptionsCategories = getCategoriesFlags(this.options?.categories)
91101
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"`
92102

93-
console.log(`ThesisLighthouse ${process.env.npm_package_version} - Thesis Example Code`)
94-
console.log(`Running with these flags: ${currentFlags}\n`)
103+
Logger(`Copyright (c) 2023 Stevarth`)
104+
Logger(`ThesisLighthouse ${process.env.npm_package_version} - Thesis Example Code`)
105+
Logger(this.options, LoggerType.info, this.options?.consoleLog)
106+
Logger(`Running with these flags: ${currentFlags}\n`)
95107

96-
this.urlList.forEach((url, index) => { this.testURL(url, this.options) })
108+
this.urlList.forEach((url, index) => { this.testURL(url, this.options, index) })
97109
}
98110
}

src/lib/utilities.class.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1+
import { existsSync, copyFileSync } from 'fs'
2+
13
class Utility {
4+
LoggerType = {
5+
'info': "Info",
6+
'warning': "Warning",
7+
'error': "Error",
8+
'empty': ""
9+
}
10+
211
isEmpty = data => {
312
switch (typeof data) {
413
case "array":
@@ -10,6 +19,15 @@ class Utility {
1019
}
1120
}
1221

22+
Logger = (text, type = LoggerType.empty, condition = true) => {
23+
const typeFormatted = (type === LoggerType.empty) ? `${type}` : `${type}:`
24+
if (condition) console.log(`${typeFormatted}`, text)
25+
}
26+
27+
copyIfNotExists = (location, source) => {
28+
if (!existsSync(location)) copyFileSync(source, location)
29+
}
30+
1331
#isArrayEmpty = (data = []) => {
1432
return (data === undefined || data.length === 0) ? false : true
1533
}
@@ -21,4 +39,5 @@ class Utility {
2139
}
2240
}
2341

24-
export default new Utility()
42+
export default new Utility()
43+
export const { Logger, LoggerType, copyIfNotExists } = new Utility()

0 commit comments

Comments
 (0)