#!/usr/bin/env node /** * Check for hardcoded colors in the codebase * This script scans for hex colors, rgb(), rgba(), and other hardcoded color patterns */ import { exec } from 'child_process'; import { promisify } from 'util'; const execAsync = promisify(exec); const colorPatterns = [ // Hex colors '#[0-9a-fA-F]{3,8}', // RGB/RGBA functions 'rgb\\s*\\(', 'rgba\\s*\\(', // HSL/HSLA functions 'hsl\\s*\\(', 'hsla\\s*\\(', // Hardcoded Tailwind classes 'bg-white', 'bg-black', 'text-white', 'text-black' ]; const excludePaths = [ 'node_modules', 'dist', 'build', '.git', 'scripts', 'tailwind.config.js', 'tokens.ts', 'tokens.css' ]; async function checkHardcodedColors() { console.log('šŸŽØ Checking for hardcoded colors in codebase...\n'); let hasViolations = false; for (const pattern of colorPatterns) { const excludeArgs = excludePaths.map(path => `--exclude-dir=${path}`).join(' '); const command = `grep -r -n --color=never ${excludeArgs} "${pattern}" src/ || true`; try { const { stdout } = await execAsync(command); if (stdout.trim()) { console.log(`āŒ Found hardcoded color pattern: ${pattern}`); console.log(stdout); hasViolations = true; } } catch (error) { // grep returns non-zero exit code when no matches found, which is expected if (error.code !== 1) { console.error(`Error checking pattern ${pattern}:`, error); } } } if (hasViolations) { console.log('\nāŒ Hardcoded colors found! Please use design tokens instead.'); console.log('šŸ“– See src/theme/tokens.ts for available tokens.'); process.exit(1); } else { console.log('āœ… No hardcoded colors found! All colors are using design tokens.'); } } checkHardcodedColors().catch(console.error);