astro-compressor
Advanced tools
Comparing version
@@ -0,1 +1,11 @@ | ||
## v0.2.0 | ||
> 2022-12-29 | ||
## Summary | ||
Release v0.2.0 is our best yet! Many bugs were squashed, and yet more features added. | ||
### Commits | ||
- [[`f0840e5`](https://github.com/sondr3/astro-compressor)] Remove globby dependency, use stdlib | ||
## v0.1.3 | ||
@@ -2,0 +12,0 @@ > 2022-12-27 |
import { createReadStream, createWriteStream } from "node:fs"; | ||
import { readdir } from "node:fs/promises"; | ||
import { resolve } from "node:path"; | ||
import { hrtime } from "node:process"; | ||
import { promises as stream } from "node:stream"; | ||
import { createBrotliCompress, createGzip } from "node:zlib"; | ||
import { globby } from "globby"; | ||
import { Logger } from "./logger.js"; | ||
async function* walkDir(dir) { | ||
const entries = await readdir(dir, { withFileTypes: true }); | ||
for (const entry of entries) { | ||
const name = resolve(dir, entry.name); | ||
if (entry.isDirectory()) { | ||
yield* walkDir(name); | ||
} | ||
else if (filterFile(entry.name)) { | ||
yield name; | ||
} | ||
} | ||
} | ||
const filterFile = (file) => { | ||
@@ -12,4 +25,5 @@ return [".css", ".js", ".html", ".xml", ".cjs", ".mjs", ".svg", ".txt"].some((ext) => file.endsWith(ext)); | ||
const start = hrtime.bigint(); | ||
const files = (await globby(`${dir.pathname}/**/*`)).filter(filterFile); | ||
for (const file of files) { | ||
let counter = 0; | ||
for await (const file of walkDir(dir.pathname)) { | ||
counter += 1; | ||
const source = createReadStream(file); | ||
@@ -21,8 +35,9 @@ const destination = createWriteStream(`${file}.gz`); | ||
const end = hrtime.bigint(); | ||
Logger.success(`finished gzip of ${files.length} files in ${(end - start) / 1000000n}m`); | ||
Logger.success(`finished gzip of ${counter} files in ${(end - start) / 1000000n}m`); | ||
}; | ||
export const brotli = async (dir) => { | ||
const start = hrtime.bigint(); | ||
const files = (await globby(`${dir.pathname}/**/*`)).filter(filterFile); | ||
for (const file of files) { | ||
let counter = 0; | ||
for await (const file of walkDir(dir.pathname)) { | ||
counter += 1; | ||
const source = createReadStream(file); | ||
@@ -34,4 +49,4 @@ const destination = createWriteStream(`${file}.br`); | ||
const end = hrtime.bigint(); | ||
Logger.success(`finished brotli of ${files.length} files in ${(end - start) / 1000000n}m`); | ||
Logger.success(`finished brotli of ${counter} files in ${(end - start) / 1000000n}m`); | ||
}; | ||
//# sourceMappingURL=compress.js.map |
{ | ||
"name": "astro-compressor", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"description": "A gzip and brotli compressor for Astro", | ||
@@ -30,5 +30,2 @@ "type": "module", | ||
], | ||
"dependencies": { | ||
"globby": "13.1.3" | ||
}, | ||
"devDependencies": { | ||
@@ -35,0 +32,0 @@ "@sondr3/eslint-config": "0.7.1", |
@@ -37,3 +37,3 @@ <h1 align="center">astro-compressor</h1> | ||
# Using NPM | ||
npm run astro add astro-compressor | ||
npx astro add astro-compressor | ||
# Using Yarn | ||
@@ -40,0 +40,0 @@ yarn astro add astro-compressor |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
13858
7.18%0
-100%101
17.44%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed