Jelajahi Sumber

chore(dashboard): Pre-commit hook to check dashboard imports

Michael Bromley 6 bulan lalu
induk
melakukan
182e6a98c6
2 mengubah file dengan 7 tambahan dan 2 penghapusan
  1. 1 1
      .lintstagedrc.json
  2. 6 1
      packages/dashboard/scripts/check-lib-imports.js

+ 1 - 1
.lintstagedrc.json

@@ -3,7 +3,7 @@
     "admin-ui/**/*.html": ["npm run format", "git add"],
     "packages/!(dev-server)/**/*.ts": ["npm run lint", "npm run format", "git add"],
     "packages/dashboard/src/lib/**/use-*.{ts,tsx}": [
-        "cd packages/dashboard && node scripts/check-lib-imports.js",
+        "node packages/dashboard/scripts/check-lib-imports.js",
         "git add"
     ]
 }

+ 6 - 1
packages/dashboard/scripts/check-lib-imports.js

@@ -7,7 +7,12 @@ import { fileURLToPath } from 'url';
 const __filename = fileURLToPath(import.meta.url);
 const __dirname = path.dirname(__filename);
 
-const LIB_DIR = path.join(__dirname, '../src/lib');
+// Check if we're running from the dashboard directory or root directory
+const currentDir = process.cwd();
+const isDashboardDir = currentDir.endsWith('packages/dashboard');
+const LIB_DIR = isDashboardDir
+    ? path.join(__dirname, '../src/lib')
+    : path.join(currentDir, 'packages/dashboard/src/lib');
 
 // Allowlist of @/ imports that are safe to keep
 const ALLOWED_IMPORTS = ['@/lib/trans.js', '@/lib/utils.js', '@/components/ui'];