-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace_links.js
More file actions
35 lines (31 loc) · 989 Bytes
/
replace_links.js
File metadata and controls
35 lines (31 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const fs = require('fs');
const path = require('path');
function walkDir(dir, callback) {
fs.readdirSync(dir).forEach(f => {
const dirPath = path.join(dir, f);
const isDirectory = fs.statSync(dirPath).isDirectory();
if (isDirectory) {
walkDir(dirPath, callback);
} else {
if (f.endsWith('.tsx') || f.endsWith('.ts')) {
callback(dirPath);
}
}
});
}
function processFile(filePath) {
let content = fs.readFileSync(filePath, 'utf8');
if (content.includes("from 'next/link'") || content.includes('from "next/link"')) {
content = content.replace(/import\s+Link\s+from\s+['"]next\/link['"];?/g, "import Link from '@/components/ui/NativeLink';");
fs.writeFileSync(filePath, content);
console.log('Updated:', filePath);
}
}
const dirs = [
path.join(__dirname, 'app'),
path.join(__dirname, 'components')
];
dirs.forEach(dir => {
if (fs.existsSync(dir)) walkDir(dir, processFile);
});
console.log('Done replacing Links');