pmtool / run-live-reload.js
devarshia5's picture
Upload 487 files
d97b8f9 verified
Raw
History Blame Contribute Delete
2.36 kB
// Script to run Capacitor with development config
import { execSync } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import { fileURLToPath } from 'url';
// Get the directory name in ES modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Copy dev config to the main config location
const devConfig = fs.readFileSync(path.join(__dirname, 'capacitor.config.dev.json'), 'utf8');
fs.writeFileSync(path.join(__dirname, 'android/app/src/main/assets/capacitor.config.json'), devConfig);
// Parse the config to extract the URL
const config = JSON.parse(devConfig);
const serverUrl = config.server.url || 'http://10.0.2.2:8080';
console.log('βœ… Development config applied');
try {
// Run cap sync
console.log('πŸ“± Synchronizing Capacitor project...');
execSync('npx cap sync android', { stdio: 'inherit' });
// Check for connected devices
const adbDevices = execSync('adb devices').toString();
console.log('πŸ“± Available devices:');
console.log(adbDevices);
// If no device is connected, run the app with Capacitor
if (!adbDevices.includes('\tdevice')) {
console.log('πŸ”„ No emulator running, starting with Capacitor...');
execSync('npx cap run android --target "Pixel_9_Pro_API_35"', { stdio: 'inherit' });
} else {
// Get device ID (find the line that has "device" in it)
const deviceLines = adbDevices.split('\n').filter(line => line.includes('\tdevice'));
if (deviceLines.length === 0) {
throw new Error('No connected devices found');
}
const deviceId = deviceLines[0].split('\t')[0].trim();
console.log(`Found device: ${deviceId}`);
// Deploy to connected device
console.log(`πŸ“² Deploying to device ${deviceId}...`);
execSync(`adb -s ${deviceId} install -r android/app/build/outputs/apk/debug/app-debug.apk`, { stdio: 'inherit' });
// Launch the app
console.log('πŸš€ Launching app...');
execSync(`adb -s ${deviceId} shell am start -n com.sspl.app/com.sspl.app.MainActivity`, { stdio: 'inherit' });
}
console.log('✨ App is running! Make changes to see live updates');
console.log(`πŸ”— Connected to dev server at ${serverUrl}`);
} catch (error) {
console.error('❌ Error:', error.message);
}