Skip to content

Commit 7c8e97f

Browse files
committed
isolated tw via ae: prefix
1 parent 387dab7 commit 7c8e97f

36 files changed

Lines changed: 487 additions & 963 deletions

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ One can also manage the `rootNode` state outside the component (e.g. to sync wit
5151

5252
## Development
5353

54+
We use the prefix ae to isolate tailwind classes (ae:bg-slate-50).
55+
5456
### Using the demo page
5557

5658
For development, start the demo page by

check-prefix.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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

Comments
 (0)