forked from element-plus/element-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-table.ts
56 lines (46 loc) · 1.25 KB
/
build-table.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
import fs from 'fs/promises'
import path from 'path'
async function main() {
const threshold = Number(process.env.THRESHOLD) || 40
let output: string
const diffOutput = await fs.readFile(
path.resolve(__dirname, '..', 'tmp/diff.txt'),
'utf-8'
)
const fileDiffs = diffOutput
.split('\n')
.map((s) => s.trim())
.filter((s) => s)
.map((s) => s.split(':'))
if (fileDiffs.length === 0) {
output = ''
} else {
const table = fileDiffs.reduce(
(prev, [source, filename]) => {
const row = `|${filename}`
let status: 'Added 🟢' | 'Removed ⛔️'
if (!source.startsWith('./dist')) {
status = 'Removed ⛔️'
} else {
status = 'Added 🟢'
}
return `${prev}
${row}|${status}|`
},
`| Filename | Status |
|:---|:---:|`
)
output = `**Total changed files:** ${fileDiffs.length}
${
fileDiffs.length >= threshold
? `#### 🚔 Attention: the changed file has exceeded the threshold`
: ''
}
<details><summary>:information_source: Files have been changed</summary>
${table}
</details>
<sub>Generated with :heart: by Element Plus bot</sub>`
}
await fs.writeFile(path.resolve(__dirname, '..', 'tmp/diff.md'), output)
}
main()