adb-connect.js 634 B

12345678910111213141516171819
  1. #!/usr/bin/env node
  2. const { execSync } = require('child_process')
  3. const config = require(process.cwd() + '/../../configs/config.js')
  4. const adbPath = config.adbPath?.path
  5. const deviceIp = '192.168.0.101'
  6. const devicePort = '5555'
  7. /** Run adb connect and return whether connected. */
  8. function connect() {
  9. const out = execSync(`"${adbPath}" connect ${deviceIp}:${devicePort}`, { encoding: 'utf-8' }).trim()
  10. return out.includes('connected') || out.includes('already connected')
  11. }
  12. const ok = connect()
  13. console.log(ok ? `${deviceIp}:${devicePort} Connected` : `${deviceIp}:${devicePort} Connect failed`)
  14. process.exit(ok ? 0 : 1)