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