const fs = require('fs'); const path = require('path'); function walk(dir) { let results = []; const list = fs.readdirSync(dir); list.forEach(function(file) { file = path.join(dir, file); const stat = fs.statSync(file); if (stat && stat.isDirectory()) { results = results.concat(walk(file)); } else { if (file.endsWith('.tsx') || file.endsWith('.ts')) { results.push(file); } } }); return results; } const tokens = ['d3roPalette', 'd3roTypo', 'd3roRadius', 'd3roShadow', 'd3roFontSans']; const files = walk(path.join(__dirname, 'src/renderer')); let updatedCount = 0; files.forEach(file => { let content = fs.readFileSync(file, 'utf8'); let modified = false; const usedTokens = tokens.filter(t => content.includes(t)); if (usedTokens.length > 0) { const importRegex = /import\s+\{([^}]*)\}\s+from\s+['"]@d3ro\/ui\/theme['"]/; const match = importRegex.exec(content); if (match) { const existing = match[1].split(',').map(s => s.trim()).filter(Boolean); const missing = usedTokens.filter(t => !existing.includes(t)); if (missing.length > 0) { const allTokens = Array.from(new Set([...existing, ...missing])); content = content.replace(importRegex, `import { ${allTokens.join(', ')} } from '@d3ro/ui/theme'`); fs.writeFileSync(file, content, 'utf8'); console.log(`Updated ${path.relative(__dirname, file)} with tokens: ${missing.join(', ')}`); updatedCount++; } } else { // Add new import statement at top content = `import { ${usedTokens.join(', ')} } from '@d3ro/ui/theme';\n` + content; fs.writeFileSync(file, content, 'utf8'); console.log(`Added new theme import to ${path.relative(__dirname, file)}: ${usedTokens.join(', ')}`); updatedCount++; } } }); console.log(`Total files updated: ${updatedCount}`);