| 1 | import fs from "node:fs"; |
| 2 | import path from "node:path"; |
| 3 | import { fileURLToPath } from "node:url"; |
| 4 | |
| 5 | const scriptDir = path.dirname(fileURLToPath(import.meta.url)); |
| 6 | const frontendRoot = path.resolve(scriptDir, ".."); |
| 7 | const targets = process.argv.slice(2); |
| 8 | const files = targets.length > 0 ? targets : ["src/styles.css"]; |
| 9 | const zIndexDecl = /z-index\s*:\s*([^;]+);/g; |
| 10 | const tokenValue = /^var\(--z-[a-z0-9-]+\)$/; |
| 11 | |
| 12 | let failed = false; |
| 13 | |
| 14 | for (const file of files) { |
| 15 | const fullPath = path.resolve(frontendRoot, file); |
| 16 | const source = fs.readFileSync(fullPath, "utf8"); |
| 17 | let match; |
| 18 | while ((match = zIndexDecl.exec(source)) !== null) { |
| 19 | const value = match[1].trim().replace(/\s+/g, " "); |
| 20 | if (tokenValue.test(value)) continue; |
| 21 | failed = true; |
| 22 | const line = source.slice(0, match.index).split(/\r?\n/).length; |
| 23 | console.error(`${file}:${line}: z-index must use a --z-* token, got ${value}`); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | if (failed) { |
| 28 | process.exit(1); |
| 29 | } |
| 30 | |
| 31 | console.log(`z-index token check passed: ${files.join(", ")}`); |
| 32 |