Files
arsam c162c85fb1 Import source: global/scripts/compress-dist.mjs
Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
2026-09-18 23:27:05 +03:30

31 lines
987 B
JavaScript

#!/usr/bin/env node
import { readdirSync, statSync, createReadStream, createWriteStream } from 'fs';
import { join } from 'path';
import { createGzip, createBrotliCompress, constants } from 'zlib';
import { pipeline } from 'stream/promises';
const COMPRESS_EXT = ['.html', '.js', '.css', '.xml', '.json', '.svg'];
function walk(dir) {
const results = [];
for (const f of readdirSync(dir)) {
const p = join(dir, f);
if (statSync(p).isDirectory()) results.push(...walk(p));
else if (COMPRESS_EXT.some(e => f.endsWith(e))) results.push(p);
}
return results;
}
let gz = 0, br = 0;
for (const file of walk('dist')) {
await pipeline(createReadStream(file), createGzip({ level: 9 }), createWriteStream(`${file}.gz`));
gz++;
await pipeline(
createReadStream(file),
createBrotliCompress({ params: { [constants.BROTLI_PARAM_QUALITY]: 11 } }),
createWriteStream(`${file}.br`)
);
br++;
}
console.log(`[compress] gzip: ${gz} files, brotli: ${br} files`);