|
| 1 | +#!/usr/bin/env node |
| 2 | +import fs from 'node:fs'; |
| 3 | +import path from 'node:path'; |
| 4 | + |
| 5 | +const ROOT = process.cwd(); |
| 6 | + |
| 7 | +const SHARED_DIRS = [ |
| 8 | + 'src/app/components/primitives', |
| 9 | + 'src/app/components/patterns', |
| 10 | + 'src/app/components/shared', |
| 11 | + 'src/app/components/system', |
| 12 | + 'src/app/ui-kit', |
| 13 | +]; |
| 14 | + |
| 15 | +const PUBLIC_EXPORT_DIRS = ['src/app/components/system', 'src/app/ui-kit']; |
| 16 | + |
| 17 | +const LEGACY_MODAL_ALLOWLIST = new Set([ |
| 18 | + 'src/app/features/security/components/camera-card/camera-settings-dialog.tsx', |
| 19 | + 'src/app/features/security/components/cover-card/view.tsx', |
| 20 | + 'src/app/features/climate/components/hvac-settings-dialog/index.tsx', |
| 21 | + 'src/app/features/weather/components/weather-card/weather-settings-dialog.tsx', |
| 22 | + 'src/app/features/lighting/components/light-card/light-settings-dialog.tsx', |
| 23 | + 'src/app/features/lighting/components/switch-settings-dialog.tsx', |
| 24 | +]); |
| 25 | + |
| 26 | +function walk(dir) { |
| 27 | + const entries = fs.readdirSync(path.join(ROOT, dir), { withFileTypes: true }); |
| 28 | + const files = []; |
| 29 | + |
| 30 | + for (const entry of entries) { |
| 31 | + const relativePath = path.join(dir, entry.name); |
| 32 | + |
| 33 | + if (entry.isDirectory()) { |
| 34 | + files.push(...walk(relativePath)); |
| 35 | + continue; |
| 36 | + } |
| 37 | + |
| 38 | + if (!entry.isFile()) { |
| 39 | + continue; |
| 40 | + } |
| 41 | + |
| 42 | + if (!/\.(ts|tsx|js|jsx|mjs)$/.test(entry.name) || entry.name.includes('.stories.')) { |
| 43 | + continue; |
| 44 | + } |
| 45 | + |
| 46 | + files.push(relativePath); |
| 47 | + } |
| 48 | + |
| 49 | + return files; |
| 50 | +} |
| 51 | + |
| 52 | +const violations = []; |
| 53 | + |
| 54 | +for (const dir of SHARED_DIRS) { |
| 55 | + for (const relativePath of walk(dir)) { |
| 56 | + const source = fs.readFileSync(path.join(ROOT, relativePath), 'utf8'); |
| 57 | + |
| 58 | + if (source.includes(`@/app/features/`)) { |
| 59 | + violations.push(`${relativePath}: shared UI layers must not import from feature modules`); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +for (const dir of PUBLIC_EXPORT_DIRS) { |
| 65 | + for (const relativePath of walk(dir)) { |
| 66 | + const source = fs.readFileSync(path.join(ROOT, relativePath), 'utf8'); |
| 67 | + |
| 68 | + if (/export\s+.*from\s+['"]@\/app\/features\//.test(source)) { |
| 69 | + violations.push(`${relativePath}: public UI-kit surfaces must not re-export feature modules`); |
| 70 | + } |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +for (const relativePath of [...walk('src/app/components/layout'), ...walk('src/app/features')]) { |
| 75 | + const source = fs.readFileSync(path.join(ROOT, relativePath), 'utf8'); |
| 76 | + |
| 77 | + const hasLegacyModalRecipe = |
| 78 | + /(fixed (left-1\/2 top-1\/2|top-1\/2 left-1\/2) z-50 .*shadow-2xl backdrop-blur-xl)/.test( |
| 79 | + source |
| 80 | + ) || /fixed inset-x-0 bottom-0 z-50 .*rounded-\[30px\].*shadow-2xl/.test(source); |
| 81 | + |
| 82 | + if (hasLegacyModalRecipe && !LEGACY_MODAL_ALLOWLIST.has(relativePath)) { |
| 83 | + violations.push( |
| 84 | + `${relativePath}: use shared ModalSurface or SheetSurface instead of reauthoring shell recipes` |
| 85 | + ); |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +if (violations.length > 0) { |
| 90 | + console.error('\nUI kit boundary check failed:\n'); |
| 91 | + for (const violation of violations) { |
| 92 | + console.error(`- ${violation}`); |
| 93 | + } |
| 94 | + process.exit(1); |
| 95 | +} |
| 96 | + |
| 97 | +console.log('UI kit boundary check passed.'); |
0 commit comments