Skip to content

Commit

Permalink
Change file-sizes.json to only have .wasm files, but to also have the…
Browse files Browse the repository at this point in the history
… gzipped size
  • Loading branch information
curiousdannii committed Dec 11, 2024
1 parent c5642b9 commit 34c7676
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
22 changes: 15 additions & 7 deletions tools/write-file-sizes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,26 @@
import * as fs from 'fs'
import {dirname, resolve} from 'path'
import {fileURLToPath} from 'url'
import {gzipSync} from 'zlib'

const results = {
files: {},
files_gz: {},
};
const results = {};

function add_file(name, path) {
const data = fs.readFileSync(path)
const data_gz = gzipSync(data)
results[name] = {
size: data.length,
gz: data_gz.length,
}
}

const build_path = resolve(dirname(fileURLToPath(import.meta.url)), '../build')
for (const file of fs.readdirSync(build_path)) {
if (file.endsWith('.js') || file.endsWith('.wasm')) {
results.files[file] = fs.statSync(resolve(build_path, file)).size
// TODO: gzipped size
if (file.endsWith('.wasm')) {
add_file(file, resolve(build_path, file))
}
}

add_file('glkaudio_bg.wasm', resolve(build_path, '../asyncglk/src/glkaudio/pkg/glkaudio_bg.wasm'))

fs.writeFileSync(resolve(build_path, 'file-sizes.json'), JSON.stringify(results))

0 comments on commit 34c7676

Please sign in to comment.