-
Notifications
You must be signed in to change notification settings - Fork 1
/
compile.mjs
51 lines (39 loc) · 1.58 KB
/
compile.mjs
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
import fs from 'fs';
import path from 'path';
const files = await fs.promises.readdir('./data', { withFileTypes: true });
const packageInfo = [];
const directories = files.filter(file => file.isDirectory());
for (const dir of directories) {
const reportPath = path.join('./data', dir.name, 'packages');
const gitInfoFilePath = path.join('./data', dir.name, 'git-info.json');
const gitInfoDataRaw = await fs.promises.readFile(gitInfoFilePath, 'utf8');
const gitInfoData = JSON.parse(gitInfoDataRaw);
const subFiles = await fs.promises.readdir(reportPath, { withFileTypes: true });
const subDirectories = subFiles.filter(subFile => subFile.isDirectory());
const projectSummaries = await Promise.all(subDirectories.map(async (pkg) => {
const reportFilePath = path.join(reportPath, pkg.name, 'report.json');
const reportDataRaw = await fs.promises.readFile(reportFilePath, 'utf8');
const reportData = JSON.parse(reportDataRaw);
const summary = reportData.reduce((acc, item) => {
return {
name: pkg.name,
statSize: acc.statSize + item.statSize,
parsedSize: acc.parsedSize + item.parsedSize,
gzipSize: acc.gzipSize + item.gzipSize,
};
}, {
name: '',
statSize: 0,
parsedSize: 0,
gzipSize: 0,
});
return summary;
}));
packageInfo.push({
hash: gitInfoData.hash,
commitTimestamp: gitInfoData.commitTimestamp,
summary: projectSummaries,
});
}
fs.promises.mkdir('generated', { recursive: true });
fs.promises.writeFile('generated/projects.json', JSON.stringify(packageInfo, null, 2));