Spaces:
Sleeping
Sleeping
File size: 2,359 Bytes
d97b8f9 | 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 | // 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);
} |