-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefactor_final.js
More file actions
48 lines (42 loc) · 1.5 KB
/
refactor_final.js
File metadata and controls
48 lines (42 loc) · 1.5 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
const fs = require('fs');
const path = require('path');
try {
function walk(dir) {
let results = [];
const list = fs.readdirSync(dir);
list.forEach(function(file) {
file = path.resolve(dir, file);
const stat = fs.statSync(file);
if (stat && stat.isDirectory()) {
results = results.concat(walk(file));
} else {
if (file.endsWith('.jsx') || file.endsWith('.js')) {
results.push(file);
}
}
});
return results;
}
// Use absolute path to avoid ambiguity
const rootDir = path.resolve('Frontend/src');
console.log('Scanning:', rootDir);
const files = walk(rootDir);
console.log('Found ' + files.length + ' files.');
let modifiedCount = 0;
files.forEach(file => {
let content = fs.readFileSync(file, 'utf8');
let original = content;
// Replace
content = content.split('"http://localhost:5000').join('window.API_BASE_URL + "');
content = content.split("'http://localhost:5000").join("window.API_BASE_URL + '");
content = content.split('`http://localhost:5000').join('`${window.API_BASE_URL}');
if (content !== original) {
console.log('Fixed:', path.basename(file));
fs.writeFileSync(file, content, 'utf8');
modifiedCount++;
}
});
console.log('Total files modified:', modifiedCount);
} catch (e) {
console.error('Error:', e);
}