Skip to content

Commit 9de6111

Browse files
committed
Tidy deploy code
Make generate.js a module that is called by deploy.js. Add a list of browsers tested to generated index.html.
1 parent 8722f19 commit 9de6111

File tree

3 files changed

+54
-24
lines changed

3 files changed

+54
-24
lines changed

src/results-page/deploy.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
/* eslint-env node, shelljs */
2+
const fs = require("fs");
23
const path = require("path");
34
require("shelljs/global");
5+
const generate = require("./generate");
6+
7+
function generateIndexHtml() {
8+
const resultsPath = "./results/";
9+
const filename = path.resolve(__dirname, "index.html");
10+
return generate(filename, resultsPath);
11+
}
412

513
const ghTemp = "./temp/gh-pages";
614
const repo = require("../../package.json").repository.url;
@@ -13,15 +21,18 @@ if (!which("git")) {
1321
}
1422

1523
rm("-rf", ghTemp);
16-
mkdir("-p", ghTemp);
1724

25+
// git clone will also create the ghTemp folder
1826
exec("git clone " + repo + " --branch gh-pages --single-branch " + ghTemp);
1927

20-
exec("node src/results-page/generate.js", { silent: true })
21-
.to(path.resolve(ghTemp, "index.html"));
28+
generateIndexHtml()
29+
.then(html => {
30+
fs.writeFileSync(path.resolve(ghTemp, "index.html"), html);
2231

23-
cd(ghTemp);
32+
cd(ghTemp);
2433

25-
exec("git add .");
26-
exec("git commit --amend --no-edit");
27-
exec("git push -f origin gh-pages");
34+
exec("git add .");
35+
exec("git commit --amend --no-edit");
36+
exec("git push -f origin gh-pages");
37+
})
38+
.catch(err => console.error(err));

src/results-page/generate.js

+27-15
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ const cacheQuery = require("../shared/cache-query");
77
const decompress = require("../shared/entries-utils").decompress;
88
const makeTableData = require("../cli/show-captures/show-captures").makeTableData;
99

10-
const resultsPath = "./results/";
11-
const filename = path.resolve(__dirname, "index.html");
12-
13-
function loadResults() {
10+
function loadResults(resultsPath) {
1411
return fsp.readdir(resultsPath)
1512
.then(files => {
1613
// full paths
@@ -25,19 +22,27 @@ function resultsToTemplateData(results) {
2522
r.isCached = null;
2623
if (r.entries) {
2724
r.entries = decompress(r.entries);
28-
r.entries.forEach(e => e.isCached = cacheQuery.isEntryCached(e));
25+
r.entries.forEach(e => {
26+
e.isCached = cacheQuery.isEntryCached(e);
27+
});
2928
r.isCached = cacheQuery.areEntriesCached(r.entries);
3029
}
3130
const ua = useragent.parse(r.userAgent);
32-
r.name = ua.browser + " " + ua.version + " " + ua.os + " / " + r.tag;
31+
r.browser = ua.browser + " " + ua.version + " " + ua.os;
32+
r.name = r.browser + " / " + r.tag;
3333
return r;
3434
});
3535
}
3636

37-
function generate(templateStr, results) {
37+
function generateFromTemplateAndResults(templateStr, results) {
3838
let tableData = null;
3939
results = resultsToTemplateData(results);
4040

41+
const browsersTested = Object.keys(results.reduce((ob, r) => {
42+
ob[r.browser] = 1;
43+
return ob;
44+
}, {}));
45+
4146
const configurations = [
4247
{
4348
title: "Default options",
@@ -78,7 +83,9 @@ function generate(templateStr, results) {
7883
results.forEach(r => {
7984
r.isCached = null;
8085
if (r.entries) {
81-
r.entries.forEach(e => e.isCached = cacheQuery.isEntryCached(e, opts));
86+
r.entries.forEach(e => {
87+
e.isCached = cacheQuery.isEntryCached(e, opts);
88+
});
8289
r.isCached = cacheQuery.areEntriesCached(r.entries, opts);
8390
}
8491
return r;
@@ -87,6 +94,7 @@ function generate(templateStr, results) {
8794
}
8895

8996
const data = {
97+
browsersTested,
9098
configurations,
9199
funcs: {
92100
getResults,
@@ -105,12 +113,16 @@ function generate(templateStr, results) {
105113
compileDebug: true
106114
};
107115
const html = ejs.render(String(templateStr), data, renderOpts);
108-
console.log(html);
116+
return html;
109117
}
110118

111-
Promise.all([fsp.readFile(filename), loadResults()])
112-
.then(things => {
113-
const templateStr = things[0];
114-
const results = things[1];
115-
generate(templateStr, results);
116-
});
119+
function generate(filename, resultsPath) {
120+
return Promise.all([fsp.readFile(filename), loadResults(resultsPath)])
121+
.then(things => {
122+
const templateStr = things[0];
123+
const results = things[1];
124+
return generateFromTemplateAndResults(templateStr, results);
125+
});
126+
}
127+
128+
module.exports = generate;

src/results-page/index.html

+9-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@
4949
<p>If a single resource is considered to be cached/uncached, then its row will be green/red.
5050
If a cached/uncached determination cannot be accurately made, the row is uncoloured.
5151

52+
<p>Browsers tested:
53+
<ul>
54+
<% browsersTested.forEach(browser => { %>
55+
<li><%= browser %>
56+
<% }); %>
57+
</ul>
58+
5259
<hr>
5360

5461
<% configurations.forEach((configuration, configurationIndex) => { %>
@@ -67,9 +74,9 @@ <h1><%= configuration.title %></h1>
6774

6875
</div>
6976

70-
<% funcs.getResults(configurationIndex).forEach(result => { %>
77+
<% funcs.getResults(configurationIndex).forEach((result, resultIdx) => { %>
7178

72-
<h2><%= result.name %></h2>
79+
<h2><a name="result-<%= configurationIndex %>-<%= resultIdx %>"></a><%= result.name %></h2>
7380

7481
Full User Agent: <code><%= result.userAgent %></code>
7582
<br>

0 commit comments

Comments
 (0)