-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle-mode.js
More file actions
36 lines (31 loc) · 1.23 KB
/
Copy pathtoggle-mode.js
File metadata and controls
36 lines (31 loc) · 1.23 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
const fs = require('fs');
const path = require('path');
const configPath = path.join(__dirname, 'capacitor.config.ts');
const mode = process.argv[2]; // 'local' or 'live'
if (!['local', 'live'].includes(mode)) {
console.error('Usage: node toggle-mode.js <local|live>');
process.exit(1);
}
let content = fs.readFileSync(configPath, 'utf8');
if (mode === 'live') {
// Add or uncomment server block
if (!content.includes('server: {')) {
const replacement = ` webDir: 'dist',
server: {
url: 'https://mirhal.app',
cleartext: false,
},`;
content = content.replace(" webDir: 'dist',", replacement);
} else {
console.log('Already in live mode (or similar). Please check file manually if unsure.');
}
console.log('✅ Switched to LIVE mode (pointing to mirhal.app)');
console.log('⚠️ REMINDER: You must DEPLOY your changes to cPanel for them to appear!');
} else {
// Remove server block to use local dist
// We regex replace the server block
content = content.replace(/ server: {[\s\S]*?},\n/g, '');
console.log('✅ Switched to LOCAL mode (using local dist folder)');
console.log('ℹ️ Run "npx cap sync ios" to apply.');
}
fs.writeFileSync(configPath, content);