build-table.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import fs from 'fs/promises'
  2. import path from 'path'
  3. async function main() {
  4. const threshold = process.env.THRESHOLD || 40
  5. let output: string
  6. const diffOutput = await fs.readFile(
  7. path.resolve(__dirname, '..', 'tmp/diff.txt'),
  8. 'utf-8'
  9. )
  10. const fileDiffs = diffOutput
  11. .split('\n')
  12. .map((s) => s.trim())
  13. .filter((s) => s)
  14. .map((s) => s.split(':'))
  15. if (fileDiffs.length === 0) {
  16. output = ''
  17. } else {
  18. const table = fileDiffs.reduce(
  19. (prev, [source, filename]) => {
  20. const row = `|${filename}`
  21. let status: 'Added 🟢' | 'Removed ⛔️'
  22. if (!source.startsWith('./dist')) {
  23. status = 'Removed ⛔️'
  24. } else {
  25. status = 'Added 🟢'
  26. }
  27. return `${prev}
  28. ${row}|${status}|`
  29. },
  30. `| Filename | Status |
  31. |:---|:---:|`
  32. )
  33. output = `**Total changed files:** ${fileDiffs.length}
  34. ${
  35. fileDiffs.length >= threshold
  36. ? `#### 🚔 Attention: the changed file has exceeded the threshold`
  37. : ''
  38. }
  39. <details><summary>:information_source: Files have been changed</summary>
  40. ${table}
  41. </details>
  42. <sub>Generated with :heart: by Element Plus bot</sub>`
  43. }
  44. await fs.writeFile(path.resolve(__dirname, '..', 'tmp/diff.md'), output)
  45. }
  46. main()