/** * Remove all !important declarations from a CSS file. * For use with base.css and other files that no longer need !important * because they are unlayered and override layered ecommerce.css by cascade priority. */ import { readFileSync, writeFileSync } from "node:fs"; const filePath = process.argv[2]; if (!filePath) { console.error("Usage: node cleanup-css-important.mjs "); process.exit(1); } let content = readFileSync(filePath, "utf-8"); // Strip BOM content = content.replace(/^\uFEFF/, ""); // Remove !important const before = (content.match(/!important/g) || []).length; content = content.replace(/\s*!important/g, ""); // Fix artifacts content = content.replace(/;\s*;/g, ";"); content = content.replace(/;\s*}/g, "}"); content = content.replace(/[ \t]+$/gm, ""); const after = (content.match(/!important/g) || []).length; const lines = content.split("\n").length; writeFileSync(filePath, content, "utf-8"); console.log(`Processed: ${filePath}`); console.log(` Lines: ${lines}`); console.log(` !important: ${before} → ${after} (removed ${before - after})`);