2
1

client-build-stats.ts 920 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { root } from '@peertube/peertube-node-utils'
  2. import { readdir, stat } from 'fs/promises'
  3. import { join } from 'path'
  4. async function run () {
  5. const result = {
  6. app: await buildResult(join(root(), 'client', 'dist', 'en-US')),
  7. embed: await buildResult(join(root(), 'client', 'dist', 'standalone', 'videos'))
  8. }
  9. console.log(JSON.stringify(result))
  10. }
  11. run()
  12. .catch(err => console.error(err))
  13. async function buildResult (path: string, root = path) {
  14. const distFiles = await readdir(path)
  15. let files: { name: string, size: number }[] = []
  16. for (const file of distFiles) {
  17. const filePath = join(path, file)
  18. const statsResult = await stat(filePath)
  19. if (statsResult.isDirectory()) {
  20. files = files.concat(await buildResult(filePath, root))
  21. }
  22. files.push({
  23. name: filePath.replace(new RegExp(`^${root}/`), ''),
  24. size: statsResult.size
  25. })
  26. }
  27. return files
  28. }