-
Notifications
You must be signed in to change notification settings - Fork 0
/
readme-gen.mjs
44 lines (42 loc) · 1.57 KB
/
readme-gen.mjs
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
import * as fs from 'fs/promises';
const capitalize = str => str.charAt(0).toUpperCase() + str.slice(1);
(await fs.writeFile('README.md',
"<!-- THIS FILE IS GENERATED AUTOMATICALLY, ALL CHANGES WILL BE LOST -->\n" +
"<!-- Generated from README_TEMPLATE.md -->\n\n" +
(await fs.readFile('README_TEMPLATE.md', 'utf-8'))
.replace(
'___TEST_TABLE___',
(`
<!--n--><!-- GENERATED TABLE START --><!--n-->
<table>
<tr>
<th>Test suite</th>
<th>Test name</th>
<th>Result</th>
</tr>
${
(await fs.readFile('_test_result.json', 'utf-8'))
.replace(/\r/g, '')
.split('\n')
.filter(str => str)
.map(str => JSON.parse(str))
.filter(row =>
(row.type === 'test') && (
(row.event === "ok") ||
(row.event === "failed")
)
)
.sort((a,b) => (a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0))
.map(row => `
<tr>
<td><b>${ capitalize(row.name.split('::')[0].replace(/_/g, ' ')) }</b></td>
<td><code>${ row.name.split('::').slice(1).join('/') }</code></td>
<td align="center">${(row.event === 'ok') ? '✔️' : '❌'}</td>
</tr>
`).join('')
}
</table>
<!--n--><!-- GENERATED TABLE END --><!--n-->
`).replace(/\s{2,}/g, ' ').replace(/\>\s\</g, '><').replace(/\<\!\-\-n\-\-\>/g, '\n')
)
));