refactor: flatten monorepo to single web package (#12)
Flatten the pnpm monorepo (apps/web + packages/*) into a single web package at the repo root. - Move app/lib/components/scripts/public to root; drop apps/web and packages/* wrappers - Rewrite tsconfig paths (@infiplot/*) to ./lib/*; turbopack.root = __dirname - Update Vercel (no root-directory) and Cloudflare (pnpm build:cf at root) deploy paths - Regenerate pnpm-lock.yaml to drop stale workspace importers - Bump engines.node to >=22 to match wrangler Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Compresses the freshly generated public/home/*.png into much
|
||||
* smaller .webp files alongside them, then deletes the originals.
|
||||
* Output webps target ~1200px on the long edge and quality 78.
|
||||
*/
|
||||
|
||||
import { readdirSync, statSync, unlinkSync } from "node:fs";
|
||||
import { resolve, dirname, extname, basename } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import sharp from "sharp";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const DIR = resolve(__dirname, "..", "public", "home");
|
||||
|
||||
const MAX_EDGE = 1200;
|
||||
const QUALITY = 78;
|
||||
|
||||
const files = readdirSync(DIR).filter((f) => f.toLowerCase().endsWith(".png"));
|
||||
let totalIn = 0;
|
||||
let totalOut = 0;
|
||||
|
||||
for (const f of files) {
|
||||
const inPath = resolve(DIR, f);
|
||||
const outPath = resolve(DIR, basename(f, extname(f)) + ".webp");
|
||||
const inSize = statSync(inPath).size;
|
||||
totalIn += inSize;
|
||||
|
||||
const img = sharp(inPath);
|
||||
const meta = await img.metadata();
|
||||
const longEdge = Math.max(meta.width ?? 0, meta.height ?? 0);
|
||||
const resized = longEdge > MAX_EDGE ? img.resize({ width: meta.width >= meta.height ? MAX_EDGE : undefined, height: meta.height > meta.width ? MAX_EDGE : undefined }) : img;
|
||||
await resized.webp({ quality: QUALITY, effort: 5 }).toFile(outPath);
|
||||
const outSize = statSync(outPath).size;
|
||||
totalOut += outSize;
|
||||
console.log(`${f.padEnd(16)} ${(inSize / 1024).toFixed(0).padStart(5)} KB → ${(outSize / 1024).toFixed(0).padStart(4)} KB`);
|
||||
unlinkSync(inPath);
|
||||
}
|
||||
|
||||
console.log(
|
||||
`\nTotal: ${(totalIn / 1024 / 1024).toFixed(1)} MB → ${(totalOut / 1024 / 1024).toFixed(2)} MB`,
|
||||
);
|
||||
Reference in New Issue
Block a user