Spaces:
Sleeping
Sleeping
| // 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); | |
| } |