import fs from 'fs'; import path from 'path'; const componentsDir = 'apps/ssr/src/components'; const files = ['Navbar.tsx', 'Footer.tsx', 'CartDrawer.tsx', 'ProductCard.tsx']; for (const file of files) { const filePath = path.join(componentsDir, file); if (!fs.existsSync(filePath)) continue; let content = fs.readFileSync(filePath, 'utf8'); // Add "use client" if needed if (['Navbar.tsx', 'CartDrawer.tsx'].includes(file)) { if (!content.startsWith('"use client"')) { content = '"use client";\n' + content; } } // Replace imports content = content.replace(/import \{.*?Link.*?\} from 'react-router-dom'/g, "import Link from 'next/link'"); if (file === 'Navbar.tsx') { content = content.replace("import Link from 'next/link'", "import Link from 'next/link'\nimport { useRouter, usePathname } from 'next/navigation'"); content = content.replace(/const navigate = useNavigate\(\)/g, 'const router = useRouter()\n const pathname = usePathname()'); content = content.replace(/navigate\(/g, 'router.push('); } // Replace to= with href= content = content.replace(/]*)to=/g, ']*)to=/g, '/g, ''); // In Navbar, we need to fix NavLink className logic if (file === 'Navbar.tsx') { content = content.replace(/className=\{navLinkClass\}/g, 'className={navLinkClass}'); // Will fix manually content = content.replace(/className=\{\(\{ isActive \}\) =>/g, 'className={() =>'); // Will fix manually } fs.writeFileSync(filePath, content); console.log(`Updated ${file}`); }