diff --git a/src/compress.ts b/src/compress.ts index f93d27f..7b481db 100644 --- a/src/compress.ts +++ b/src/compress.ts @@ -7,7 +7,7 @@ import { createBrotliCompress, createGzip } from "node:zlib"; import { Logger } from "./logger.js"; const filterFile = (file: string): boolean => { - return [".css", ".js", ".html", ".xml", ".cjs", ".mjs", ".svg", ".txt"].every((ext) => + return [".css", ".js", ".html", ".xml", ".cjs", ".mjs", ".svg", ".txt"].some((ext) => file.endsWith(ext), ); }; @@ -15,9 +15,8 @@ const filterFile = (file: string): boolean => { export const gzip = async (dir: URL): Promise => { const start = hrtime.bigint(); - const files = (await globby(dir.pathname)).filter(filterFile); + const files = (await globby(`${dir.pathname}/**/*`)).filter(filterFile); for (const file of files) { - if (filterFile(file)) continue; const source = createReadStream(file); const destination = createWriteStream(`${file}.gz`); const gzip = createGzip({ level: 9 }); @@ -25,16 +24,14 @@ export const gzip = async (dir: URL): Promise => { } const end = hrtime.bigint(); - - Logger.info(`finished gzip of ${files.length} files in ${(end - start) / 1000000n}m`); + Logger.success(`finished gzip of ${files.length} files in ${(end - start) / 1000000n}m`); }; export const brotli = async (dir: URL): Promise => { const start = hrtime.bigint(); - const files = (await globby(dir.pathname)).filter(filterFile); + const files = (await globby(`${dir.pathname}/**/*`)).filter(filterFile); for (const file of files) { - if (filterFile(file)) continue; const source = createReadStream(file); const destination = createWriteStream(`${file}.br`); const brotli = createBrotliCompress(); @@ -42,6 +39,5 @@ export const brotli = async (dir: URL): Promise => { } const end = hrtime.bigint(); - - Logger.info(`finished brotli of ${files.length} files in ${(end - start) / 1000000n}m`); + Logger.success(`finished brotli of ${files.length} files in ${(end - start) / 1000000n}m`); };