-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate-readme.ts
43 lines (36 loc) · 1022 Bytes
/
generate-readme.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
import { writeFile, readFile, access, constants } from "node:fs/promises";
import tablemark from "tablemark";
async function fileExists(path: string): Promise<boolean> {
try {
await access(path, constants.F_OK);
return true;
} catch {
return false;
}
}
const sections: Record<
string,
{ description: string; rules: Array<Record<string, unknown>> }
> = JSON.parse(await readFile("./rules.json", "utf8"));
const tables = [];
for (const [name, { description, rules }] of Object.entries(sections)) {
for (const rule of rules) {
const implemented = await fileExists(`./src/rules/${rule.id}.ts`);
rule.implemented = implemented ? "✅" : "❌";
}
const table = tablemark(rules);
tables.push({
name,
description,
table,
});
}
const document = `
# accessbility-scanner
## AXE Rules
${tables
.map(({ name, description, table }) => {
return `### ${name}\n\n${description}\n\n${table}\n`;
})
.join("\n")}`.trim();
await writeFile("./README.md", document, "utf8");