Skip to content

Improve tests & success message. Fix total saved size info. #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 3.1.2 (06.05.2022)

Fixed total saved size calculation.

Added file format to the success message in conversion mode.


## 3.1.1 (08.04.2022)

Removed logging unsupported symbols in CI environment.
Expand Down
5 changes: 3 additions & 2 deletions lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ async function convert({ paths, lossless, avif, webp, force, output: outputDir }
before: fs.statSync(filePath).size,
after: fileBuffer.length,
};
const isOptimized = fileSize.before > fileSize.after;

totalSize.before += fileSize.before;
totalSize.after += fileSize.after;
totalSize.after += isOptimized ? fileSize.after : fileSize.before;

checkResult({ fileBuffer, filePath, fileSize, outputFormat, force, outputDir });
});
Expand All @@ -101,7 +102,7 @@ function checkResult({ fileBuffer, filePath, fileSize, outputFormat, force, outp
const before = formatBytes(fileSize.before);
const after = formatBytes(fileSize.after);
const ratio = calcRatio(fileSize.before, fileSize.after);
const successMessage = `${before} → ${after}. Ratio: ${ratio}%`;
const successMessage = `${before} → ${outputFormat} ${after}. Ratio: ${ratio}%`;

const isChanged = !fs.readFileSync(filePath).equals(fileBuffer);
const isOptimised = ratio > 0;
Expand Down
3 changes: 2 additions & 1 deletion lib/optimize.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ async function optimize({ paths, lossless: isLossless, output: outputDir }) {
before: fs.statSync(filePath).size,
after: fileBuffer.length,
};
const isOptimized = fileSize.before > fileSize.after;

totalSize.before += fileSize.before;
totalSize.after += fileSize.after;
totalSize.after += isOptimized ? fileSize.after : fileSize.before;

checkResult(fileBuffer, filePath, fileSize, outputDir);
});
Expand Down
Loading