-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.cjs
More file actions
34 lines (27 loc) · 920 Bytes
/
runner.cjs
File metadata and controls
34 lines (27 loc) · 920 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
const fs = require('fs');
const path = require('path');
const targetDir = path.resolve(__dirname, 'src');
const fromImport = '@utils';
const toImport = '~/Utility';
function walkAndReplace(dir) {
const files = fs.readdirSync(dir);
for (const file of files) {
const fullPath = path.join(dir, file);
const stat = fs.statSync(fullPath);
if (stat.isDirectory()) {
walkAndReplace(fullPath);
} else if (stat.isFile() && /\.(ts|tsx|js|jsx)$/.test(file)) {
let content = fs.readFileSync(fullPath, 'utf8');
if (content.includes(fromImport)) {
const updated = content.replace(
new RegExp(`(['"\`])${fromImport}\\1`, 'g'),
`'${toImport}'`
);
fs.writeFileSync(fullPath, updated, 'utf8');
console.log(`✅ Updated: ${fullPath}`);
}
}
}
}
walkAndReplace(targetDir);
console.log('🎉 Done replacing @utils with ~/Utility');