Skip to content

Commit

Permalink
Merge pull request #7 from apple-yagi/feature/issue#6
Browse files Browse the repository at this point in the history
feature: Display an icon according to the difference in file size.
  • Loading branch information
apple-yagi authored May 5, 2022
2 parents 4a66d22 + ab045c2 commit 832f9d8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 16 deletions.
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"]
}
}

0 comments on commit 832f9d8

Please sign in to comment.