forked from dailymotion/vast-client-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle_size.js
30 lines (26 loc) · 907 Bytes
/
bundle_size.js
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
const fs = require('fs');
const path = require('path');
const newDistPath = './dist';
const oldDistPath = './dist_old';
const getFileSizes = (folderPath) => {
return fs.readdirSync(folderPath).reduce((res, fileName) => {
res[fileName] = fs.readFileSync(path.join(folderPath, fileName)).byteLength;
return res;
}, {});
};
const oldValues = getFileSizes(oldDistPath);
const newValues = getFileSizes(newDistPath);
Object.entries(oldValues).forEach(([name, size]) => {
const newSize = newValues[name];
const delta = newSize - size;
const sizeColorFg = delta <= 0 ? '\x1b[32m' : '\x1b[31m';
const resetColorFg = '\x1b[0m';
const nameColorFg = '\x1b[36m';
// eslint-disable-next-line no-console
console.log(
`${nameColorFg}%s${resetColorFg}%s${sizeColorFg}%s${resetColorFg}`,
`${name}:`,
` ${size} B -> ${newSize} B `,
`(${delta >= 0 ? '+' : ''}${delta} B)`
);
});