| 116 | } |
| 117 | |
| 118 | const createComparisonReport = ( |
| 119 | entries: ReadonlyArray<{ |
| 120 | readonly current: BundleStats |
| 121 | readonly previous: BundleStats |
| 122 | readonly filename: string |
| 123 | }> |
| 124 | ): string => { |
| 125 | const lines: Array<string> = [ |
| 126 | "| File Name | Current Size | Previous Size | Difference |", |
| 127 | "|:----------|:------------:|:-------------:|:----------:|" |
| 128 | ] |
| 129 | for (const { current, previous, filename } of entries) { |
| 130 | const comparison = calculateDifference(current, previous) |
| 131 | const currKb = `${comparison.currKb} KB` |
| 132 | const prevKb = `${comparison.prevKb} KB` |
| 133 | const diffKb = `${comparison.diffKb} KB` |
| 134 | const diffPct = `${comparison.diffPct.toFixed(2)}%` |
| 135 | const sign = comparison.diff === 0 ? "" : comparison.diff > 0 ? "+" : "-" |
| 136 | const line = `| \`${filename}\` | ${currKb} | ${prevKb} | ${sign}${diffKb} (${sign}${diffPct}) |` |
| 137 | lines.push(line) |
| 138 | } |
| 139 | return lines.join("\n") + "\n" |
| 140 | } |
| 141 | |
| 142 | const createReport = (curr: ReadonlyArray<BundleStats>, prev: ReadonlyArray<BundleStats>): string => { |
| 143 | const entries: Array<{ |