-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
79 lines (76 loc) · 1.97 KB
/
index.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const { table, getBorderCharacters } = require("table");
const filesize = require("filesize");
const chalk = require("chalk");
const AdmZip = require("adm-zip");
const bar = require("precisebar");
const tableOptions = {
border: getBorderCharacters("void"),
columnDefault: {
paddingLeft: 0,
paddingRight: 1,
},
columns: {
0: {
alignment: "right",
},
},
drawHorizontalLine: () => false,
};
const fs = (size) => filesize(size, { standard: "iec" });
module.exports = (filename) => {
const zip = new AdmZip(filename);
let totalSize = 0;
let totalCompressedSize = 0;
const entries = zip.getEntries();
entries.forEach((zipEntry) => {
const {
header: { size, compressedSize },
} = zipEntry;
totalSize += size;
totalCompressedSize += compressedSize;
});
return table(
[
["", "", "", "", "", ""],
[
chalk.bold.whiteBright("Asset"),
chalk.bold.whiteBright("Actual"),
"",
chalk.bold.whiteBright("Zip"),
chalk.bold.whiteBright("Diff"),
chalk.bold.whiteBright("% of Zip"),
],
...zip.getEntries().map((zipEntry) => {
const {
entryName,
header: { size, compressedSize },
} = zipEntry;
return [
chalk.bold.green(entryName),
chalk.white(fs(size)),
"=>",
chalk.yellow(fs(compressedSize)),
`${chalk.gray(fs(compressedSize - size))}`,
`${`${((100 * compressedSize) / totalCompressedSize).toFixed(
1
)}%`.padEnd(5)} ${chalk.bgGray.white(bar.getProgress(
compressedSize / totalCompressedSize,
10,
'',
''
))}`,
];
}),
["", "", "", "", "", ""],
[
chalk.bold.whiteBright("Total"),
fs(totalSize),
"=>",
chalk.yellow(fs(totalCompressedSize)),
`${chalk.grey(fs(totalCompressedSize - totalSize))}`,
"",
],
],
tableOptions
);
};