forked from surajyog/nanomides
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-api-urls.cjs
More file actions
72 lines (63 loc) · 2.2 KB
/
fix-api-urls.cjs
File metadata and controls
72 lines (63 loc) · 2.2 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const fs = require('fs');
const path = require('path');
// Files to update
const files = [
'src/pages/Analytics.jsx',
'src/pages/Tasks.jsx',
'src/pages/History.jsx',
'src/pages/CreateTask.jsx',
'src/pages/CreateBots.jsx',
'src/pages/EditBot.jsx',
'src/pages/BotCategories.jsx',
'src/pages/TaskTypes.jsx',
'src/pages/TrainingLab.jsx',
'src/pages/WhatsAppConnect.jsx',
'src/components/TaskTypeSettings.jsx',
'src/components/TaskTypeModal.jsx'
];
files.forEach(file => {
const filePath = path.join(__dirname, file);
if (!fs.existsSync(filePath)) {
console.log(`❌ File not found: ${file}`);
return;
}
let content = fs.readFileSync(filePath, 'utf8');
// Check if already imports API_BASE_URL
if (content.includes("from '../config'")) {
console.log(`✅ ${file} already imports config`);
} else {
// Add import after Sidebar import or after last import
if (content.includes("import Sidebar from '../components/Sidebar';")) {
content = content.replace(
"import Sidebar from '../components/Sidebar';",
"import Sidebar from '../components/Sidebar';\nimport { API_BASE_URL } from '../config';"
);
} else {
// Find last import and add after it
const lines = content.split('\n');
let lastImportIndex = -1;
for (let i = 0; i < lines.length; i++) {
if (lines[i].startsWith('import ')) {
lastImportIndex = i;
}
}
if (lastImportIndex !== -1) {
lines.splice(lastImportIndex + 1, 0, "import { API_BASE_URL } from '../config';");
content = lines.join('\n');
}
}
}
// Replace all http://localhost:3001 with ${API_BASE_URL}
const originalContent = content;
content = content.replace(/http:\/\/localhost:3001/g, '${API_BASE_URL}');
// Fix template literals
content = content.replace(/fetch\('(\$\{API_BASE_URL\}[^']+)'/g, 'fetch(`$1`');
content = content.replace(/fetch\("(\$\{API_BASE_URL\}[^"]+)"/g, 'fetch(`$1`');
if (content !== originalContent) {
fs.writeFileSync(filePath, content, 'utf8');
console.log(`✅ Updated: ${file}`);
} else {
console.log(`⏭️ No changes needed: ${file}`);
}
});
console.log('\n✅ All files updated!');