1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | const filesize = require("filesize");
|
7 |
|
8 | function _getAssetSize(asset) {
|
9 | return filesize(asset.size || 0);
|
10 | }
|
11 |
|
12 | function _getTotalSize(assetsList) {
|
13 | return filesize(assetsList.reduce((total, asset) => total + (asset.size || 0), 0));
|
14 | }
|
15 |
|
16 | function _printAssets(assetsList) {
|
17 | return [["Name", "Size"]]
|
18 | .concat(assetsList.map(asset => [asset.name, _getAssetSize(asset)]))
|
19 | .concat([["Total", _getTotalSize(assetsList)]]);
|
20 | }
|
21 |
|
22 | function formatAssets(assets) {
|
23 |
|
24 | const assetsList = Object.keys(assets).map(name => ({
|
25 | name,
|
26 | size: assets[name].meta.full
|
27 | }));
|
28 |
|
29 | return _printAssets(assetsList);
|
30 | }
|
31 |
|
32 | module.exports = { formatAssets, _getAssetSize, _getTotalSize, _printAssets };
|