Skip to content

Commit d5716f4

Browse files
Generate a basic directory listing (#112)
1 parent dd20706 commit d5716f4

File tree

5 files changed

+138
-27
lines changed

5 files changed

+138
-27
lines changed

_tpl/template.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<html lang="en">
1818
<meta charset="utf-8">
1919
<title>Chrome for Testing availability</title>
20-
<meta content="width=device-width" name="viewport">
20+
<meta name="viewport" content="width=device-width">
2121
<style>
2222
html { font: 1rem/1.6 sans-serif; }
2323
::selection { background: dodgerblue; color: #FFF; }

generate-directory-index.mjs

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the “License”);
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an “AS IS” BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import fs from 'node:fs/promises';
18+
19+
import {glob} from 'glob';
20+
21+
import {escapeHtml, minifyHtml} from './html-utils.mjs';
22+
23+
const files = await glob('./*', {
24+
cwd: './dist/',
25+
});
26+
27+
const results = {
28+
digit: [],
29+
json: [],
30+
capOnly: [],
31+
cap: [],
32+
other: [],
33+
};
34+
for (const fileName of files) {
35+
if (/^\d/.test(fileName)) {
36+
results.digit.push(fileName);
37+
continue;
38+
}
39+
if (fileName.endsWith('.json')) {
40+
results.json.push(fileName);
41+
continue;
42+
}
43+
if (/^[A-Z_]+$/.test(fileName)) {
44+
results.capOnly.push(fileName);
45+
continue;
46+
}
47+
if (/^[A-Z]/.test(fileName)) {
48+
results.cap.push(fileName);
49+
continue;
50+
}
51+
results.other.push(fileName);
52+
}
53+
54+
results.digit.sort();
55+
results.json.sort();
56+
results.capOnly.sort();
57+
results.cap.sort();
58+
results.other.sort();
59+
60+
const allFileNames = [
61+
...results.json,
62+
...results.capOnly,
63+
...results.cap,
64+
...results.digit,
65+
...results.other,
66+
];
67+
68+
const html = `
69+
<!DOCTYPE html>
70+
<html lang="en">
71+
<meta charset="utf-8">
72+
<title>Chrome for Testing dashboard + API directory listing</title>
73+
<meta name="viewport" content="width=device-width">
74+
<meta name="robots" content="noindex">
75+
<style>
76+
html { font: 1rem/1.6 sans-serif; }
77+
a { display: block; }
78+
</style>
79+
<ul>
80+
${allFileNames.map(fileName => {
81+
return `<li><a href="${escapeHtml(fileName)}"><code>${escapeHtml(fileName)}</code></a>`;
82+
}).join('\n')}
83+
</ul>
84+
`;
85+
const minified = await minifyHtml(html);
86+
await fs.writeFile('./dist/files.html', minified);

generate-html.mjs

+2-25
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616

1717
import fs from 'node:fs/promises';
1818

19-
import { escape as escapeHtml } from 'lodash-es';
20-
import { minify as minifyHtml } from 'html-minifier-terser';
21-
2219
import {predatesChromeDriverAvailability, predatesChromeHeadlessShellAvailability} from './is-older-version.mjs';
2320
import {readJsonFile} from './json-utils.mjs';
21+
import {escapeHtml, minifyHtml} from './html-utils.mjs';
2422

2523
const OK = '\u2705';
2624
const NOT_OK = '\u274C';
@@ -152,26 +150,5 @@ const htmlTemplate = await fs.readFile('./_tpl/template.html', 'utf8');
152150
const html = htmlTemplate.toString()
153151
.replace('%%%DATA%%%', render(data))
154152
.replace('%%%TIMESTAMP%%%', data.timestamp);
155-
const minifiedHtml = await minifyHtml(html, {
156-
collapseBooleanAttributes: true,
157-
collapseInlineTagWhitespace: false,
158-
collapseWhitespace: true,
159-
conservativeCollapse: false,
160-
decodeEntities: true,
161-
html5: true,
162-
includeAutoGeneratedTags: false,
163-
minifyCSS: true,
164-
minifyJS: true,
165-
preserveLineBreaks: false,
166-
preventAttributesEscaping: true,
167-
removeAttributeQuotes: true,
168-
removeComments: true,
169-
removeEmptyAttributes: true,
170-
removeEmptyElements: false,
171-
removeOptionalTags: false,
172-
removeRedundantAttributes: true,
173-
removeTagWhitespace: false,
174-
sortAttributes: true,
175-
sortClassName: true,
176-
});
153+
const minifiedHtml = await minifyHtml(html);
177154
await fs.writeFile('./dist/index.html', minifiedHtml);

html-utils.mjs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the “License”);
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an “AS IS” BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {minify} from 'html-minifier-terser';
18+
import {escape} from 'lodash-es';
19+
20+
export const minifyHtml = async (html) => {
21+
const minified = await minify(html, {
22+
collapseBooleanAttributes: true,
23+
collapseInlineTagWhitespace: false,
24+
collapseWhitespace: true,
25+
conservativeCollapse: false,
26+
decodeEntities: true,
27+
html5: true,
28+
includeAutoGeneratedTags: false,
29+
minifyCSS: true,
30+
minifyJS: true,
31+
preserveLineBreaks: false,
32+
preventAttributesEscaping: true,
33+
removeAttributeQuotes: true,
34+
removeComments: true,
35+
removeEmptyAttributes: true,
36+
removeEmptyElements: false,
37+
removeOptionalTags: false,
38+
removeRedundantAttributes: true,
39+
removeTagWhitespace: false,
40+
sortAttributes: true,
41+
sortClassName: true,
42+
});
43+
return minified;
44+
};
45+
46+
export const escapeHtml = escape;

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
"find": "node --no-warnings find-version.mjs",
1010
"json": "node generate-extra-json.mjs && for id in known-good-versions known-good-versions-with-downloads last-known-good-versions last-known-good-versions-with-downloads latest-patch-versions-per-build latest-patch-versions-per-build-with-downloads latest-versions-per-milestone latest-versions-per-milestone-with-downloads; do jsesc --object --json < \"data/${id}.json\" > \"dist/${id}.json\"; done",
1111
"txt": "node generate-latest-release.mjs",
12-
"render": "node generate-html.mjs && cp logo.svg dist/logo.svg",
12+
"index": "node generate-directory-index.mjs",
13+
"render": "node generate-html.mjs && cp logo.svg dist/logo.svg && node generate-directory-index.mjs",
1314
"build": "npm run find && npm run json && npm run txt && npm run render"
1415
},
1516
"devDependencies": {
17+
"glob": "^10.3.10",
1618
"html-minifier-terser": "7.2.0",
1719
"jsesc": "3.0.2",
1820
"lodash-es": "4.17.21"

0 commit comments

Comments
 (0)