|
| 1 | +import fs from "fs"; |
| 2 | +import path from "path"; |
| 3 | +// --- |
| 4 | +// custom script to check for tailwind prefixing on src. |
| 5 | +// --- |
| 6 | + |
| 7 | +const prefix = "ae:"; |
| 8 | +const fileExtensions = [ |
| 9 | + ".js", |
| 10 | + ".jsx", |
| 11 | + ".ts", |
| 12 | + ".tsx", |
| 13 | + ".html", |
| 14 | + ".vue", |
| 15 | + ".svelte", |
| 16 | +]; |
| 17 | +const ignoreDirs = ["node_modules", "dist", "build", ".vite"]; |
| 18 | +const ignoreFiles = ["src/App.jsx"]; // files to skip |
| 19 | + |
| 20 | +const classPattern = /class(Name)?=["'`]([^"'`]+)["'`]/g; |
| 21 | + |
| 22 | +let filesScanned = 0; |
| 23 | +let warningsFound = 0; |
| 24 | + |
| 25 | +function checkFile(filePath) { |
| 26 | + // skip ignored files |
| 27 | + if (ignoreFiles.some((f) => path.resolve(f) === path.resolve(filePath))) |
| 28 | + return; |
| 29 | + |
| 30 | + const code = fs.readFileSync(filePath, "utf-8"); |
| 31 | + const lines = code.split("\n"); |
| 32 | + filesScanned++; |
| 33 | + |
| 34 | + lines.forEach((line, index) => { |
| 35 | + let match; |
| 36 | + while ((match = classPattern.exec(line))) { |
| 37 | + const classes = match[2].split(/\s+/); |
| 38 | + for (const c of classes) { |
| 39 | + if ( |
| 40 | + c.length > 0 && |
| 41 | + !c.startsWith(prefix) && |
| 42 | + !c.startsWith("{") && |
| 43 | + !c.startsWith("[") && |
| 44 | + !c.startsWith("@") && |
| 45 | + !c.startsWith("explorer") && |
| 46 | + !c.startsWith("download") |
| 47 | + ) { |
| 48 | + console.warn( |
| 49 | + `⚠️ [PrefixCheck] Missing '${prefix}' in class '${c}' — ${filePath}:${index + 1}` |
| 50 | + ); |
| 51 | + warningsFound++; |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + }); |
| 56 | +} |
| 57 | + |
| 58 | +function walkDir(dir) { |
| 59 | + const entries = fs.readdirSync(dir, { withFileTypes: true }); |
| 60 | + for (const entry of entries) { |
| 61 | + const fullPath = path.join(dir, entry.name); |
| 62 | + if (entry.isDirectory()) { |
| 63 | + if (!ignoreDirs.includes(entry.name)) walkDir(fullPath); |
| 64 | + } else if (fileExtensions.includes(path.extname(entry.name))) { |
| 65 | + checkFile(fullPath); |
| 66 | + } |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +// run the check from src |
| 71 | +walkDir(path.join(process.cwd(), "src")); |
| 72 | + |
| 73 | +// summary |
| 74 | +console.log("\ae: tailwind prefix check completed!"); |
| 75 | +console.log(`Files scanned: ${filesScanned}`); |
| 76 | +console.log(`Warnings found: ${warningsFound}`); |
0 commit comments