Skip to content
This repository was archived by the owner on Jul 8, 2020. It is now read-only.

Commit 9fb3909

Browse files
committed
Update deps. Fix some linting issues
1 parent 94bb415 commit 9fb3909

File tree

8 files changed

+1232
-867
lines changed

8 files changed

+1232
-867
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module.exports = {
44
"extends": ["eslint:recommended", "google"],
55
"env": {
66
"node": true,
7-
"es6": true
7+
"es6": true,
8+
"browser": true,
89
},
910
"parserOptions": {
1011
"ecmaVersion": 8,

frontend/lighthouse-ci.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
'use strict';
1717

1818
const fetch = require('node-fetch'); // polyfill
19-
const Github = require('github');
19+
const Github = require('@octokit/rest');
2020
const URL = require('url').URL;
2121
const URLSearchParams = require('url').URLSearchParams;
2222

2323
class LighthouseCI {
24-
2524
/**
2625
* @param {!string} token Github OAuth token that has repo:status access.
2726
*/
@@ -49,11 +48,10 @@ class LighthouseCI {
4948
method: 'POST',
5049
body: JSON.stringify(body),
5150
headers
52-
})
53-
.then(resp => resp.json())
54-
.catch(err => {
55-
throw err;
56-
});
51+
}).then(resp => resp.json())
52+
.catch(err => {
53+
throw err;
54+
});
5755
}
5856

5957
/**

frontend/package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
"license": "Apache-2.0",
66
"scripts": {
77
"serve": "OAUTH_TOKEN=`cat .oauth_token` PORT=8081 node server.js",
8-
"start": "OAUTH_TOKEN=`cat .oauth_token` node server.js"
8+
"start": "OAUTH_TOKEN=`cat .oauth_token` node server.js",
9+
"lint": "npx eslint ."
910
},
1011
"engines": {
1112
"node": ">=8"
1213
},
1314
"dependencies": {
14-
"body-parser": "^1.17.1",
15-
"eslint": "^3.19.0",
16-
"eslint-config-google": "^0.8.0",
17-
"express": "^4.15.2",
18-
"github": "^9.2.0",
19-
"node-fetch": "^1.6.3"
15+
"@octokit/rest": "^15.13.0",
16+
"body-parser": "^1.18.3",
17+
"eslint": "^5.6.1",
18+
"eslint-config-google": "^0.10.0",
19+
"express": "^4.16.3",
20+
"node-fetch": "1.7.3"
2021
}
2122
}

frontend/public/app.js

Lines changed: 151 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,180 +1,181 @@
1-
(function() {
1+
/* global ga */
2+
23
'use strict';
34

4-
const input = document.querySelector('#url');
5-
const logger = document.querySelector('#logger');
6-
const scoreEl = document.querySelector('#lighthouse-score');
7-
const reportLink = document.querySelector('#reportLink');
8-
const background = document.querySelector('#background');
9-
const logo = document.querySelector('.logo-section');
10-
const searchArrow = document.querySelector('.search-arrow');
11-
const startOver = document.querySelector('#startover');
12-
13-
// const params = new URLSearchParams(location.search);
14-
// let setTimeoutId_;
15-
const ENDPOINT_ORIGIN = location.hostname === 'localhost' ?
5+
(function() {
6+
const input = document.querySelector('#url');
7+
const logger = document.querySelector('#logger');
8+
const scoreEl = document.querySelector('#lighthouse-score');
9+
const reportLink = document.querySelector('#reportLink');
10+
const background = document.querySelector('#background');
11+
const logo = document.querySelector('.logo-section');
12+
const searchArrow = document.querySelector('.search-arrow');
13+
const startOver = document.querySelector('#startover');
14+
15+
// const params = new URLSearchParams(location.search);
16+
// let setTimeoutId_;
17+
const ENDPOINT_ORIGIN = location.hostname === 'localhost' ?
1618
'http://localhost:8080' : 'https://builder-dot-lighthouse-ci.appspot.com';
1719

18-
// /**
19-
// * @param {number} score
20-
// * @return {string}
21-
// */
22-
// function calculateRating(score) {
23-
// let rating = 'poor';
24-
// if (score > 45) {
25-
// rating = 'average';
26-
// }
27-
// if (score > 75) {
28-
// rating = 'good';
29-
// }
30-
// return rating;
31-
// }
32-
33-
// /**
34-
// * @param {(number|string)} score
35-
// */
36-
// function setScore(score) {
37-
// score = Number(score);
38-
39-
// const rating = calculateRating(score);
40-
41-
// scoreEl.textContent = score;
42-
// scoreEl.classList.add(rating);
43-
// document.body.classList.add(rating, 'done');
44-
// document.body.classList.remove('running');
45-
// }
46-
47-
function startNewRun() {
48-
resetUI(false);
49-
document.body.classList.add('running');
50-
}
51-
52-
/**
53-
* @param {string} url
54-
*/
55-
function finalizeRun(url) {
56-
// const match = logger.value.match(/.*LIGHTHOUSE SCORE:\s+(.*)/);
57-
// if (match) {
58-
// let score = Number(match[1]);
59-
// score = score.toLocaleString(undefined, {maximumFractionDigits: 1});
60-
61-
// setScore(score);
62-
startOver.tabIndex = 0;
63-
reportLink.tabIndex = 0;
64-
reportLink.href = url;
65-
// reportLink.setAttribute('href', url);
66-
reportLink.focus();
67-
68-
ga('send', 'event', 'Lighthouse', 'finish run');
69-
// } else {
70-
// const split = logger.value.split('\n');
71-
// ga('send', 'event', 'Lighthouse', 'error', split[split.length - 2]);
20+
// /**
21+
// * @param {number} score
22+
// * @return {string}
23+
// */
24+
// function calculateRating(score) {
25+
// let rating = 'poor';
26+
// if (score > 45) {
27+
// rating = 'average';
28+
// }
29+
// if (score > 75) {
30+
// rating = 'good';
31+
// }
32+
// return rating;
7233
// }
7334

74-
document.body.classList.remove('running');
75-
document.body.classList.add('done');
76-
}
35+
// /**
36+
// * @param {(number|string)} score
37+
// */
38+
// function setScore(score) {
39+
// score = Number(score);
7740

78-
function updateLog(data) {
79-
logger.value += data.replace(/.*GMT\s/, '') + '\n';
80-
logger.scrollTop = logger.scrollHeight;
81-
}
41+
// const rating = calculateRating(score);
8242

83-
function resetUI(clearInput=true) {
84-
if (clearInput) {
85-
input.value = null;
86-
}
87-
logger.value = '';
88-
document.body.className = '';
89-
reportLink.tabIndex = -1;
90-
reportLink.href = '#';
91-
startOver.tabIndex = -1;
92-
scoreEl.textContent = '';
93-
scoreEl.className = '';
94-
}
95-
96-
/**
97-
* @param {string} url URL to test in Lighthouse.
98-
*/
99-
function runLighthouse(url = '') {
100-
// If user inputs domain, make it a full URL.
101-
if (!url.match(/^https?:\/\//) && url.length) {
102-
url = `http://${url}`;
103-
input.value = url;
43+
// scoreEl.textContent = score;
44+
// scoreEl.classList.add(rating);
45+
// document.body.classList.add(rating, 'done');
46+
// document.body.classList.remove('running');
47+
// }
48+
49+
function startNewRun() {
50+
resetUI(false);
51+
document.body.classList.add('running');
10452
}
10553

106-
if (!input.validity.valid) {
107-
alert('URL is not valid. Please make sure to use a full URL (e.g. https://www.example.com).');
108-
return;
54+
/**
55+
* @param {string} url
56+
*/
57+
function finalizeRun(url) {
58+
// const match = logger.value.match(/.*LIGHTHOUSE SCORE:\s+(.*)/);
59+
// if (match) {
60+
// let score = Number(match[1]);
61+
// score = score.toLocaleString(undefined, {maximumFractionDigits: 1});
62+
63+
// setScore(score);
64+
startOver.tabIndex = 0;
65+
reportLink.tabIndex = 0;
66+
reportLink.href = url;
67+
// reportLink.setAttribute('href', url);
68+
reportLink.focus();
69+
70+
ga('send', 'event', 'Lighthouse', 'finish run');
71+
// } else {
72+
// const split = logger.value.split('\n');
73+
// ga('send', 'event', 'Lighthouse', 'error', split[split.length - 2]);
74+
// }
75+
76+
document.body.classList.remove('running');
77+
document.body.classList.add('done');
10978
}
11079

111-
let endpoint = `${ENDPOINT_ORIGIN}/stream?url=${url}`;
112-
if (document.querySelector('#useheadless').checked) {
113-
endpoint += '&headless=true';
80+
function updateLog(data) {
81+
logger.value += data.replace(/.*GMT\s/, '') + '\n';
82+
logger.scrollTop = logger.scrollHeight;
11483
}
11584

116-
const source = new EventSource(endpoint);
85+
function resetUI(clearInput=true) {
86+
if (clearInput) {
87+
input.value = null;
88+
}
89+
logger.value = '';
90+
document.body.className = '';
91+
reportLink.tabIndex = -1;
92+
reportLink.href = '#';
93+
startOver.tabIndex = -1;
94+
scoreEl.textContent = '';
95+
scoreEl.className = '';
96+
}
11797

118-
source.addEventListener('message', e => {
119-
if (e.data.startsWith('done')) {
120-
source.close();
98+
/**
99+
* @param {string} url URL to test in Lighthouse.
100+
*/
101+
function runLighthouse(url = '') {
102+
// If user inputs domain, make it a full URL.
103+
if (!url.match(/^https?:\/\//) && url.length) {
104+
url = `http://${url}`;
105+
input.value = url;
106+
}
121107

122-
let url = e.data.split(' ')[1];
123-
if (url.includes('localhost')) {
124-
url = url.replace('https://localhost', ENDPOINT_ORIGIN);
125-
}
126-
finalizeRun(url);
108+
if (!input.validity.valid) {
109+
alert('URL is not valid. Please make sure to use a full URL (e.g. https://www.example.com).');
127110
return;
128111
}
129112

130-
updateLog(e.data);
131-
})
113+
let endpoint = `${ENDPOINT_ORIGIN}/stream?url=${url}`;
114+
if (document.querySelector('#useheadless').checked) {
115+
endpoint += '&headless=true';
116+
}
132117

133-
source.addEventListener('open', e => {
134-
startNewRun();
135-
ga('send', 'event', 'Lighthouse', 'start run');
136-
});
118+
const source = new EventSource(endpoint);
137119

138-
source.addEventListener('error', e => {
139-
if (e.readyState === EventSource.CLOSED) {
140-
source.close();
141-
}
142-
});
143-
}
120+
source.addEventListener('message', e => {
121+
if (e.data.startsWith('done')) {
122+
source.close();
144123

145-
function attachEventListeners() {
146-
input.addEventListener('keydown', e => {
147-
if (e.keyCode === 13) { // Enter
148-
runLighthouse(e.target.value);
149-
}
150-
});
124+
let url = e.data.split(' ')[1];
125+
if (url.includes('localhost')) {
126+
url = url.replace('https://localhost', ENDPOINT_ORIGIN);
127+
}
128+
finalizeRun(url);
129+
return;
130+
}
151131

152-
document.addEventListener('click', e => input.focus());
132+
updateLog(e.data);
133+
});
153134

154-
logo.addEventListener('click', e => {
155-
if (document.body.classList.contains('done')) {
156-
fetch('/reset');
157-
resetUI();
158-
document.querySelector('#useheadless').checked = false;
159-
}
160-
});
135+
source.addEventListener('open', e => {
136+
startNewRun();
137+
ga('send', 'event', 'Lighthouse', 'start run');
138+
});
161139

162-
searchArrow.addEventListener('click', e => {
163-
runLighthouse(input.value);
164-
});
140+
source.addEventListener('error', e => {
141+
if (e.readyState === EventSource.CLOSED) {
142+
source.close();
143+
}
144+
});
145+
}
165146

166-
startOver.addEventListener('click', e => {
167-
e.preventDefault();
168-
resetUI();
169-
document.querySelector('#useheadless').checked = false;
170-
});
147+
function attachEventListeners() {
148+
input.addEventListener('keydown', e => {
149+
if (e.keyCode === 13) { // Enter
150+
runLighthouse(e.target.value);
151+
}
152+
});
171153

172-
reportLink.addEventListener('click', e => {
173-
ga('send', 'event', 'Lighthouse', 'open report');
174-
});
175-
}
154+
document.addEventListener('click', e => input.focus());
176155

177-
attachEventListeners();
178-
input.focus();
156+
logo.addEventListener('click', e => {
157+
if (document.body.classList.contains('done')) {
158+
fetch('/reset');
159+
resetUI();
160+
document.querySelector('#useheadless').checked = false;
161+
}
162+
});
163+
164+
searchArrow.addEventListener('click', e => {
165+
runLighthouse(input.value);
166+
});
167+
168+
startOver.addEventListener('click', e => {
169+
e.preventDefault();
170+
resetUI();
171+
document.querySelector('#useheadless').checked = false;
172+
});
173+
174+
reportLink.addEventListener('click', e => {
175+
ga('send', 'event', 'Lighthouse', 'open report');
176+
});
177+
}
179178

179+
attachEventListeners();
180+
input.focus();
180181
})();

0 commit comments

Comments
 (0)