1
0
Fork 0
peertube/scripts/client-build-stats.ts

38 lines
920 B
TypeScript
Raw Normal View History

2024-07-03 09:59:26 -04:00
import { root } from '@peertube/peertube-node-utils'
import { readdir, stat } from 'fs/promises'
2021-02-10 10:16:46 -05: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 09:59:26 -04:00
async function buildResult (path: string, root = path) {
2021-02-10 10:16:46 -05:00
const distFiles = await readdir(path)
2024-07-03 09:59:26 -04:00
let files: { name: string, size: number }[] = []
2021-02-10 10:16:46 -05:00
for (const file of distFiles) {
const filePath = join(path, file)
const statsResult = await stat(filePath)
2024-07-03 09:59:26 -04:00
if (statsResult.isDirectory()) {
files = files.concat(await buildResult(filePath, root))
}
2021-02-11 02:41:12 -05:00
files.push({
2024-07-03 09:59:26 -04:00
name: filePath.replace(new RegExp(`^${root}/`), ''),
2021-02-11 02:41:12 -05:00
size: statsResult.size
})
2021-02-10 10:16:46 -05:00
}
return files
}