-
Notifications
You must be signed in to change notification settings - Fork 0
/
testMin.mjs
44 lines (36 loc) · 1.46 KB
/
testMin.mjs
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
import child_process from 'child_process'
import fs from 'fs'
child_process.execSync('npx terser --mangle --module -- dist/index.js > index.min.js')
const minimizedSize = fs.readFileSync('index.min.js').length
child_process.execSync('gzip index.min.js')
const gzippedSize = fs.readFileSync('index.min.js.gz').length
fs.rmSync('index.min.js.gz')
console.log('Bytes:', minimizedSize, gzippedSize)
console.log('Kilobytes:', (minimizedSize / 1024).toFixed(3), (gzippedSize / 1024).toFixed(3))
const minimizedKb = (minimizedSize / 1024).toFixed(1)
const gzippedKb = (gzippedSize / 1024).toFixed(1)
console.log('Kilobytes:', minimizedKb, gzippedKb)
replaceInFile(
'README.md', [
[/Minified: [\d.]+ kB/, `Minified: ${minimizedKb} kB`],
[/Gzipped: [\d.]+ kB/, `Gzipped: ${gzippedKb} kB`]
]);
[
'../fluent-streams-docs/benchmarks/README.md',
'../fluent-streams-docs/src/benchmarks/util/intro.md',
].forEach(file => replaceInFile(
file, [
[
/\| Fluent Streams \| [\d.]+ kB 🌠 \| [\d.]+ kB 🌠 \|/,
`| Fluent Streams | ${minimizedKb} kB 🌠 | ${gzippedKb} kB 🌠 |`,
],
])
)
function replaceInFile(file, regexToReplacePairs) {
let content = fs.readFileSync(file, 'utf8')
for (const [regex, replace] of regexToReplacePairs) {
const m = regex.exec(content)
content = content.substring(0, m.index) + replace + content.substring(m.index + m[0].length)
}
fs.writeFileSync(file, content)
}