1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.stats = void 0;
|
4 | const utils_1 = require("./utils");
|
5 | const PRECISION = 2;
|
6 | const KiB = 1024;
|
7 | const HUNDRED = 100;
|
8 | class Stats {
|
9 | constructor() {
|
10 | this.totalCssSize = 0;
|
11 | this.purgedCssSize = 0;
|
12 | }
|
13 | addSize(css) {
|
14 | this.totalCssSize = this.totalCssSize + Buffer.byteLength(css, 'utf8');
|
15 | }
|
16 | addRemovedSize(css) {
|
17 | this.purgedCssSize = this.purgedCssSize + Buffer.byteLength(css, 'utf8');
|
18 | }
|
19 | toKB(value) {
|
20 | return (value / KiB).toFixed(PRECISION);
|
21 | }
|
22 | get sizeDifference() {
|
23 | return this.toKB(this.totalCssSize - this.purgedCssSize);
|
24 | }
|
25 | get newSize() {
|
26 | return this.toKB(this.purgedCssSize);
|
27 | }
|
28 | get oldSize() {
|
29 | return this.toKB(this.totalCssSize);
|
30 | }
|
31 | get percentChange() {
|
32 | if (this.totalCssSize <= 0) {
|
33 | return '0.00';
|
34 | }
|
35 | return (((this.totalCssSize - this.purgedCssSize) / this.totalCssSize) *
|
36 | HUNDRED).toFixed(PRECISION);
|
37 | }
|
38 | printStats() {
|
39 | console.log(utils_1.color.FgGreen, `\ngatsby-plugin-purgecss:`);
|
40 | console.log(utils_1.color.FgCyan, `Previous CSS Size: ${this.oldSize} KB`);
|
41 | console.log(utils_1.color.FgCyan, `New CSS Size: ${this.newSize} KB (-${this.percentChange}%)`);
|
42 | console.log(utils_1.color.FgYellow, `Removed ~${this.sizeDifference} KB of CSS`);
|
43 | console.log(utils_1.color.Reset);
|
44 | }
|
45 | }
|
46 | exports.stats = new Stats();
|