import fs from 'fs'; import path from 'path'; const baseDir = path.join(process.cwd(), 'components'); const subDirs = ['ui', 'blocks', 'assistant', 'layout', 'brand']; subDirs.forEach(sub => { const dir = path.join(baseDir, sub); if (!fs.existsSync(dir)) return; const items = fs.readdirSync(dir); const kebabMap = new Map(); items.forEach(item => { const kebab = item .toLowerCase() .replace(/([a-z])([A-Z])/g, '$1-$2') .toLowerCase(); // Simple tolower usually covers most cases here since I used kebab-case for folders const simpleKebab = item.toLowerCase(); if (!kebabMap.has(simpleKebab)) kebabMap.set(simpleKebab, []); kebabMap.get(simpleKebab)!.push(item); }); kebabMap.forEach((originals, kebab) => { if (originals.length > 1) { console.log(`Potential duplication in ${sub}: ${originals.join(', ')}`); // Usually there's one kebab-case and one PascalCase const kebabCase = originals.find(o => o === kebab) || originals[0]; const others = originals.filter(o => o !== kebabCase); others.forEach(other => { const otherPath = path.join(dir, other); const kebabPath = path.join(dir, kebabCase); if (fs.statSync(otherPath).isDirectory()) { console.log(`Merging ${otherPath} into ${kebabPath}...`); const files = fs.readdirSync(otherPath); files.forEach(file => { const oldFile = path.join(otherPath, file); const newFile = path.join(kebabPath, file); if (!fs.existsSync(newFile)) { fs.renameSync(oldFile, newFile); } else { // If index.ts exists in both, maybe merge or skip? // Usually index.ts in the PascalCase folder was older. console.log(`File ${file} already exists in ${kebabCase}, skipping.`); } }); // Try to remove the empty folder try { fs.rmdirSync(otherPath); } catch (e) { console.log(`Could not remove ${otherPath}, might not be empty.`); } } }); } }); }); console.log('Cleanup complete.');