#!/usr/bin/env node /** * Quick check: are dist files present and fresh? * Exits 0 if ok, 1 if missing or stale. * * Staleness: any source file newer than the oldest dist file. */ import { statSync, existsSync, readdirSync } from "node:fs"; import { resolve, dirname } from "node:path"; import { fileURLToPath } from "node:url"; const __dirname = dirname(fileURLToPath(import.meta.url)); const root = resolve(__dirname, ".."); const distDir = resolve(root, "app/public/assets/dist"); const distFiles = readdirSync(distDir).filter( (f) => f.endsWith(".min.css") || f.endsWith(".min.js") ); if (distFiles.length === 0) { console.error("❌ No dist files found. Run: just build"); process.exit(1); } // Check each dist file exists for (const f of distFiles) { if (!existsSync(resolve(distDir, f))) { console.error(`❌ Missing: dist/${f}. Run: just build`); process.exit(1); } } // Check staleness: any source newer than the oldest dist? function walkDir(dir, ext) { const files = []; const entries = readdirSync(dir, { withFileTypes: true }); for (const e of entries) { const full = resolve(dir, e.name); if (e.isDirectory() && e.name !== "components") { files.push(...walkDir(full, ext)); } else if (e.isFile() && full.endsWith(ext)) { files.push(full); } } return files; } const cssSrcFiles = walkDir( resolve(root, "app/public/assets/css"), ".css" ).filter((f) => !f.includes("filepond") && !f.includes("modern-normalize")); const jsSrcFiles = walkDir( resolve(root, "app/public/assets/js/app"), ".js" ); const srcFiles = [...cssSrcFiles, ...jsSrcFiles]; const oldestDist = Math.min( ...distFiles.map((f) => statSync(resolve(distDir, f)).mtimeMs) ); let stale = false; for (const f of srcFiles) { try { if (statSync(f).mtimeMs > oldestDist) { console.error(`❌ Stale dist (source newer than output): ${f}`); stale = true; } } catch { // file may not exist (e.g. entry files), skip } } if (stale) { console.error("❌ Run: just build"); process.exit(1); } console.log("✅ Build output is up to date");