const fs = require('fs'); const path = require('path'); function walkDir(dir, callback) { fs.readdirSync(dir).forEach(f => { let dirPath = path.join(dir, f); let isDirectory = fs.statSync(dirPath).isDirectory(); isDirectory ? walkDir(dirPath, callback) : callback(dirPath); }); } walkDir('apps/website/src/app/[lang]', (filePath) => { if (filePath.endsWith('.tsx') || filePath.endsWith('.ts')) { let content = fs.readFileSync(filePath, 'utf8'); let changed = false; // Replace import ... from '../../lib/...' to import ... from '../../../lib/...' // Wait, the files were moved 1 level deeper. So any import starting with '../' needs an extra '../' // To be safe, let's just find and replace `from '../` with `from '../../` etc? // Actually, converting to `@/` is safer: // from '../../components/ => from '@/components/ // from '../../../components/ => from '@/components/ // from '../../lib/ => from '@/lib/ // from '../../../lib/ => from '@/lib/ // from '../components/ => from '@/components/ // from '../lib/ => from '@/lib/ const newContent = content.replace(/from '(\.\.\/)+components\//g, "from '@/components/") .replace(/from '(\.\.\/)+lib\//g, "from '@/lib/") .replace(/from '(\.\.\/)+store\//g, "from '@/store/") .replace(/from '(\.\.\/)+hooks\//g, "from '@/hooks/"); if (newContent !== content) { fs.writeFileSync(filePath, newContent, 'utf8'); console.log('Fixed', filePath); } } });