PeerTube/scripts/client-build-stats.ts

38 lines
920 B
TypeScript
Raw Normal View History

2024-07-03 15:59:26 +02:00
import { root } from '@peertube/peertube-node-utils'
import { readdir, stat } from 'fs/promises'
2021-02-10 16:16:46 +01:00
import { join } from 'path'
async function run () {
const result = {
app: await buildResult(join(root(), 'client', 'dist', 'en-US')),
embed: await buildResult(join(root(), 'client', 'dist', 'standalone', 'videos'))
}
console.log(JSON.stringify(result))
}
run()
.catch(err => console.error(err))
2024-07-03 15:59:26 +02:00
async function buildResult (path: string, root = path) {
2021-02-10 16:16:46 +01:00
const distFiles = await readdir(path)
2024-07-03 15:59:26 +02:00
let files: { name: string, size: number }[] = []
2021-02-10 16:16:46 +01:00
for (const file of distFiles) {
const filePath = join(path, file)
const statsResult = await stat(filePath)
2024-07-03 15:59:26 +02:00
if (statsResult.isDirectory()) {
files = files.concat(await buildResult(filePath, root))
}
2021-02-11 08:41:12 +01:00
files.push({
2024-07-03 15:59:26 +02:00
name: filePath.replace(new RegExp(`^${root}/`), ''),
2021-02-11 08:41:12 +01:00
size: statsResult.size
})
2021-02-10 16:16:46 +01:00
}
return files
}