Skip to content
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

feature: Display an icon according to the difference in file size. #7

Merged
merged 2 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
35 changes: 29 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10276,27 +10276,50 @@ const createReport = (currentFileList, baseFileList) => {
const currentTotalSize = currentFileList.reduce((size, file) => size + file.size, 0);
const baseTotalSize = baseFileList.reduce((size, file) => size + file.size, 0);
const totalSizeDiff = currentTotalSize - baseTotalSize;
const icon = (baseTotalSize / currentTotalSize) * 100 > 10 ? "⚠️" : "✅";
const totalDiffIcon = getDiffIcon(totalSizeDiff, currentTotalSize);
let report = `
## 📦 Filesize Analysis

Size Change: ${totalSizeDiff === 0 ? "" : totalSizeDiff > 0 ? "+" : "-"} ${(0, filesize_1.default)(totalSizeDiff)} ${icon}

Total Size: ${(0, filesize_1.default)(currentTotalSize)}

Total Size Change: ${(0, filesize_1.default)(totalSizeDiff)} ${totalDiffIcon}

<details><summary>Display detail</summary>

| Filename | Size | Change | Size(Brotli compressed) | Change(Brotli compressed) |
| -------- | ---- | ------ | ----------------------- | ------------------------- |
| Filename | Size | Change | Size(Brotli compressed) | Change(Brotli compressed) | Status |
| -------- | ---- | ------ | ----------------------- | ------------------------- | ------ |
`;
for (const currentFile of currentFileList) {
const baseFile = baseFileList.filter((baseFile) => baseFile.filename === currentFile.filename)[0];
report += `| \`${currentFile.filename}\` | \`${(0, filesize_1.default)(currentFile.size)}\` | \`${(0, filesize_1.default)(currentFile.size - baseFile.size)}\` | \`${(0, filesize_1.default)(currentFile.brotliSize)}\` | \`${(0, filesize_1.default)(currentFile.brotliSize - baseFile.brotliSize)}\` \n`;
const diffIcon = getDiffIcon(baseFile.size - currentFile.size, currentFile.size);
report += `| \`${currentFile.filename}\` | \`${(0, filesize_1.default)(currentFile.size)}\` | \`${(0, filesize_1.default)(currentFile.size - baseFile.size)}\` | \`${(0, filesize_1.default)(currentFile.brotliSize)}\` | \`${(0, filesize_1.default)(currentFile.brotliSize - baseFile.brotliSize)}\` | ${diffIcon} \n`;
}
report += "</details>";
return report;
};
exports.createReport = createReport;
const getDiffIcon = (delta, filesize) => {
if (filesize === 0)
return "🆕";
const percentage = Math.round((delta / filesize) * 100);
if (percentage >= 50)
return "🆘";
if (percentage >= 20)
return "🚨";
if (percentage >= 10)
return "⚠️";
if (percentage >= 5)
return "🔍";
if (percentage <= -50)
return "🏆";
if (percentage <= -20)
return "🎉";
if (percentage <= -10)
return "👏";
if (percentage <= -5)
return "✅";
return "";
};


/***/ }),
Expand Down
35 changes: 27 additions & 8 deletions src/createReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,55 @@ export const createReport = (
);
const totalSizeDiff = currentTotalSize - baseTotalSize;

const icon = (baseTotalSize / currentTotalSize) * 100 > 10 ? "⚠️" : "✅";
const totalDiffIcon = getDiffIcon(totalSizeDiff, currentTotalSize);

let report = `
## 📦 Filesize Analysis

Size Change: ${
totalSizeDiff === 0 ? "" : totalSizeDiff > 0 ? "+" : "-"
} ${fileSize(totalSizeDiff)} ${icon}

Total Size: ${fileSize(currentTotalSize)}

Total Size Change: ${fileSize(totalSizeDiff)} ${totalDiffIcon}

<details><summary>Display detail</summary>

| Filename | Size | Change | Size(Brotli compressed) | Change(Brotli compressed) |
| -------- | ---- | ------ | ----------------------- | ------------------------- |
| Filename | Size | Change | Size(Brotli compressed) | Change(Brotli compressed) | Status |
| -------- | ---- | ------ | ----------------------- | ------------------------- | ------ |
`;

for (const currentFile of currentFileList) {
const baseFile = baseFileList.filter(
(baseFile) => baseFile.filename === currentFile.filename
)[0];
const diffIcon = getDiffIcon(
baseFile.size - currentFile.size,
currentFile.size
);

report += `| \`${currentFile.filename}\` | \`${fileSize(
currentFile.size
)}\` | \`${fileSize(currentFile.size - baseFile.size)}\` | \`${fileSize(
currentFile.brotliSize
)}\` | \`${fileSize(currentFile.brotliSize - baseFile.brotliSize)}\` \n`;
)}\` | \`${fileSize(
currentFile.brotliSize - baseFile.brotliSize
)}\` | ${diffIcon} \n`;
}

report += "</details>";

return report;
};

const getDiffIcon = (delta: number, filesize: number): string => {
if (filesize === 0) return "🆕";

const percentage = Math.round((delta / filesize) * 100);
if (percentage >= 50) return "🆘";
if (percentage >= 20) return "🚨";
if (percentage >= 10) return "⚠️";
if (percentage >= 5) return "🔍";
if (percentage <= -50) return "🏆";
if (percentage <= -20) return "🎉";
if (percentage <= -10) return "👏";
if (percentage <= -5) return "✅";
return "";
};
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true
},
"include": ["**/*.ts"]
}
}