|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | + <head> |
| 4 | + <meta charset="UTF-8" /> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 6 | + <title>Bundle Analyser</title> |
| 7 | + <link href=" https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel=" stylesheet" /> |
| 8 | + <style> |
| 9 | + html, |
| 10 | + body { |
| 11 | + height: 100%; |
| 12 | + margin: 0; |
| 13 | + } |
| 14 | + #main-content { |
| 15 | + display: flex; |
| 16 | + flex-direction: column; |
| 17 | + height: 100%; |
| 18 | + } |
| 19 | + #frame { |
| 20 | + flex-grow: 1; |
| 21 | + } |
| 22 | + |
| 23 | + .navbar { |
| 24 | + background-color: rgb(255, 235, 255); |
| 25 | + border-bottom: 1px solid purple; |
| 26 | + padding: 0 12px; |
| 27 | + } |
| 28 | + |
| 29 | + .navbar .nav-link { |
| 30 | + color: black; |
| 31 | + } |
| 32 | + .total-size { |
| 33 | + color: white; |
| 34 | + background-color: purple; |
| 35 | + padding: 5px 10px; |
| 36 | + border-radius: 5px; |
| 37 | + } |
| 38 | + </style> |
| 39 | + </head> |
| 40 | + <body onload="updateLabelOnStart()"> |
| 41 | + <div id="main-content"> |
| 42 | + <nav class="navbar navbar-expand-lg"> |
| 43 | + <a class="navbar-brand" href="#">Bundle Analyser</a> |
| 44 | + |
| 45 | + <div class="navbar-collapse" id="navbarNavDropdown"> |
| 46 | + <ul class="navbar-nav"> |
| 47 | + <li class="nav-item dropdown"> |
| 48 | + <button |
| 49 | + class="nav-link dropdown-toggle" |
| 50 | + href="#" |
| 51 | + id="navbarDropdownMenuLink" |
| 52 | + data-bs-toggle="dropdown" |
| 53 | + aria-expanded="false" |
| 54 | + onkeypress="event.preventDefault()" |
| 55 | + > |
| 56 | + Loading... |
| 57 | + </button> |
| 58 | + |
| 59 | + <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink"> |
| 60 | + <button class="dropdown-item" href="#" onclick="updateIframe('account-v2')"> |
| 61 | + account-v2 |
| 62 | + </button> |
| 63 | + <button class="dropdown-item" href="#" onclick="updateIframe('account')"> |
| 64 | + account |
| 65 | + </button> |
| 66 | + <button class="dropdown-item" href="#" onclick="updateIframe('appstore')"> |
| 67 | + appstore |
| 68 | + </button> |
| 69 | + <button class="dropdown-item" href="#" onclick="updateIframe('bot-web-ui')"> |
| 70 | + bot-web-ui |
| 71 | + </button> |
| 72 | + <button class="dropdown-item" href="#" onclick="updateIframe('cashier-v2')"> |
| 73 | + cashier-v2 |
| 74 | + </button> |
| 75 | + <button class="dropdown-item" href="#" onclick="updateIframe('cashier')"> |
| 76 | + cashier |
| 77 | + </button> |
| 78 | + <button class="dropdown-item" href="#" onclick="updateIframe('cfd')">cfd</button> |
| 79 | + <button class="dropdown-item" href="#" onclick="updateIframe('core')">core</button> |
| 80 | + <button class="dropdown-item" href="#" onclick="updateIframe('p2p-v2')">p2p-v2</button> |
| 81 | + <button class="dropdown-item" href="#" onclick="updateIframe('p2p')">p2p</button> |
| 82 | + <button class="dropdown-item" href="#" onclick="updateIframe('reports')"> |
| 83 | + reports |
| 84 | + </button> |
| 85 | + <button class="dropdown-item" href="#" onclick="updateIframe('trader')">trader</button> |
| 86 | + <button class="dropdown-item" href="#" onclick="updateIframe('tradershub')"> |
| 87 | + tradershub |
| 88 | + </button> |
| 89 | + <button class="dropdown-item" href="#" onclick="updateIframe('wallets')"> |
| 90 | + wallets |
| 91 | + </button> |
| 92 | + </div> |
| 93 | + </li> |
| 94 | + </ul> |
| 95 | + </div> |
| 96 | + |
| 97 | + <span class="total-size" id="bundleSize">Bundle Size: Loading...</span> |
| 98 | + </nav> |
| 99 | + <iframe |
| 100 | + id="frame" |
| 101 | + title="bundle-view" |
| 102 | + src="./packages/core/analyzed.html" |
| 103 | + style="width: 100%; border: none" |
| 104 | + ></iframe> |
| 105 | + </div> |
| 106 | + <script |
| 107 | + src=" https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" |
| 108 | + integrity="sha256-CDOy6cOibCWEdsRiZuaHf8dSGGJRYuBGC+mjoJimHGw=" |
| 109 | + crossorigin="anonymous" |
| 110 | + ></script> |
| 111 | + <script> |
| 112 | + async function updateIframe(packageName) { |
| 113 | + const iframeSrc = './packages/' + packageName + '/analyzed.html'; |
| 114 | + document.getElementById('frame').src = iframeSrc; |
| 115 | + document.getElementById('navbarDropdownMenuLink').textContent = |
| 116 | + packageName.charAt(0).toUpperCase() + packageName.slice(1); |
| 117 | + updateBundleSize(packageName); |
| 118 | + } |
| 119 | + |
| 120 | + async function updateBundleSize(packageName) { |
| 121 | + const response = await fetch(`./packages/${packageName}/report.json`); |
| 122 | + if (!response.ok) { |
| 123 | + document.getElementById('bundleSize').textContent = 'Bundle Size: Error loading data'; |
| 124 | + return; |
| 125 | + } |
| 126 | + const data = await response.json(); |
| 127 | + const totalStatSize = data.reduce((acc, item) => acc + item.statSize, 0); |
| 128 | + const totalParsedSize = data.reduce((acc, item) => acc + item.parsedSize, 0); |
| 129 | + const totalGzipSize = data.reduce((acc, item) => acc + item.gzipSize, 0); |
| 130 | + document.getElementById('bundleSize').innerHTML = |
| 131 | + '<strong>Stat Size:</strong> ' + |
| 132 | + formatBytes(totalStatSize) + |
| 133 | + ', <strong>Parsed Size:</strong> ' + |
| 134 | + formatBytes(totalParsedSize) + |
| 135 | + ', <strong>Gzip Size:</strong> ' + |
| 136 | + formatBytes(totalGzipSize); |
| 137 | + } |
| 138 | + |
| 139 | + function formatBytes(bytes, decimals = 2) { |
| 140 | + if (bytes === 0) return '0 Bytes'; |
| 141 | + const k = 1024; |
| 142 | + const dm = decimals < 0 ? 0 : decimals; |
| 143 | + const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; |
| 144 | + const i = Math.floor(Math.log(bytes) / Math.log(k)); |
| 145 | + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; |
| 146 | + } |
| 147 | + |
| 148 | + function updateLabelOnStart() { |
| 149 | + updateIframe('core'); |
| 150 | + } |
| 151 | + </script> |
| 152 | + </body> |
| 153 | +</html> |
0 commit comments