-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.ts
79 lines (62 loc) · 2.04 KB
/
build.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { get, objectifiedTesters, escape } from "./utils.ts";
import { render } from "./template.ts";
const results: Record<string, any> = {};
const headers: Record<string, any> = {};
const KEY = "result";
const [testers, count] = objectifiedTesters();
const encoder = new TextEncoder();
const decoder = new TextDecoder("utf-8");
function result(nodeVersion: string, path: string): string {
let result = get(results, nodeVersion);
if (result === undefined) return "";
result = get(result, KEY, path);
if (result === undefined) {
return '<div class="No">-</div>';
}
const title = result === true
? "Test passed"
: typeof result === "string"
? result
: "Test failed";
result = result === true
? "Yes"
: typeof result === "string" ? "Error" : "No";
return `<div class="${result}" title="${escape(title)}">${result}</div>`;
}
function percent(nodeVersion: string): number {
const data = get(results, nodeVersion, KEY);
return data ? Math.floor((data._passed / count) * 100) : 0;
}
function compare(x1: string, x2: string): number {
const y1 = x1.split(".").map((x) => parseInt(x));
const y2 = x2.split(".").map((x) => parseInt(x));
for (let i = 0; i < y1.length; i++) {
if (y1[i] === y2[i]) {
continue;
} else if (y1[i] < y2[i]) {
return 1;
} else {
return -1;
}
}
return 0;
}
export default async function build() {
const files: Deno.DirEntry[] = [];
for await (const dirEntry of Deno.readDir("./result")) {
if (dirEntry.isFile && dirEntry.name.substr(-5) === ".json") {
files.push(dirEntry);
}
}
const versions = files.map((x) => x.name!.replace(/\.json/, ""));
versions.sort(compare);
for (const version of versions) {
const content = await Deno.readFile(`./result/${version}.json`);
results[version] = JSON.parse(decoder.decode(content));
headers[version] = {
version: results[version].version,
};
}
const html = render({ headers, testers, result, percent });
await Deno.writeFile("./index.html", encoder.encode(html));
}