Skip to content

Commit 1c9985a

Browse files
Output when only requesting a single compression per path tweaks
1 parent fff1df5 commit 1c9985a

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

log.ts

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,40 @@ export function LogReport({ silent }: Context, report: Map<ItemConfig['path'], C
7070
if (!silent && [...report.keys()].length > 0) {
7171
console.log(bold('\nFilesize Report'));
7272
for (const [originalPath, values] of report) {
73-
console.log(grey(`\npath: ${originalPath}`));
74-
for (const [compression, compressionResults] of values) {
75-
const [size, maxSize] = compressionResults;
76-
const compressedPath = originalPath + grey(compressedExtension(compression));
77-
if (size === null || maxSize === null) {
78-
continue;
79-
} else if (size < maxSize) {
80-
success++;
81-
console.log(` ✔️ ${compressedPath} ${prettyBytes(size)} ${green('<')} ${prettyBytes(maxSize)}`);
82-
} else {
83-
failure++;
84-
console.log(` ❌ ${compressedPath} ${prettyBytes(size)} ${red('>')} ${prettyBytes(maxSize)}`);
73+
const multipleOutputs = Array.from(values.values()).filter(([before]) => before !== null).length > 1;
74+
if (multipleOutputs) {
75+
console.log(grey(`\npath: ${originalPath}`));
76+
for (const [compression, compressionResults] of values) {
77+
const [size, maxSize] = compressionResults;
78+
const compressedPath = originalPath + grey(compressedExtension(compression));
79+
if (size === null || maxSize === null) {
80+
continue;
81+
} else if (size < maxSize) {
82+
success++;
83+
console.log(` ✔️ ${compressedPath} ${prettyBytes(size)} ${green('<')} ${prettyBytes(maxSize)}`);
84+
} else {
85+
failure++;
86+
console.log(` ❌ ${compressedPath} ${prettyBytes(size)} ${red('>')} ${prettyBytes(maxSize)}`);
87+
}
88+
}
89+
} else {
90+
const maximumPath =
91+
Math.max.apply(
92+
null,
93+
Array.from(report.keys()).map(item => item.length),
94+
) + 1;
95+
for (const [compression, compressionResults] of values) {
96+
const [size, maxSize] = compressionResults;
97+
const compressedPath = originalPath + grey(compressedExtension(compression)) + new Array(maximumPath - originalPath.length).join(' ');
98+
if (size === null || maxSize === null) {
99+
continue;
100+
} else if (size < maxSize) {
101+
success++;
102+
console.log(` ✔️ ${compressedPath} ${prettyBytes(size)} ${green('<')} ${prettyBytes(maxSize)}`);
103+
} else {
104+
failure++;
105+
console.log(` ❌ ${compressedPath} ${prettyBytes(size)} ${red('>')} ${prettyBytes(maxSize)}`);
106+
}
85107
}
86108
}
87109
}

0 commit comments

Comments
 (0)