const { readFileSync, writeFileSync } = require('node:fs'); const fg = require('fast-glob'); const prettyBytes = require('./prettyBytes.cjs'); let brotliWasm; (() => { brotliWasm = require('brotli-wasm'); })(); const { compress } = brotliWasm; (( /** @type {string} */ globPattern ) => { console.warn('Warning: If you provide more than two glob patterns as arguments'); console.warn('it will only compress the first glob pattern due to performance'); console.warn('reasons. You can change this behavior by modifying the'); console.warn('function calling at the end of the script.'); for (const file of fg.globSync(globPattern)) { const compressedFile = compress(readFileSync(file), { quality: 11, }); console.log(`Compressed ${file} from ${prettyBytes(readFileSync(file).length)} to ${prettyBytes(compressedFile.length)}`); writeFileSync(file, compressedFile); } })(process.argv[2]);