Created
August 14, 2019 14:26
-
-
Save gorhom/62e43fa1c3c2207f13eda07623e7bbc5 to your computer and use it in GitHub Desktop.
Android Devices/Emulators JS Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { exec } = require('@tunnckocore/execa') | |
/** | |
* Get connected Android devices / emulators list. | |
* @returns {Promise<Array>} Promise<devices[]> | |
*/ | |
const getConnectedAndroidDevices = () => | |
exec(['adb devices'], { | |
preferLocal: true, | |
}).then(output => { | |
var devices = [] | |
const regex = /(?<=\n)[0-9A-Za-z\-]+/gm | |
while ((m = regex.exec(output[0].stdout)) !== null) { | |
if (m.index === regex.lastIndex) { | |
regex.lastIndex++ | |
} | |
m.forEach(match => { | |
devices.push(match) | |
}) | |
} | |
return Promise.resolve(devices) | |
}) | |
/** | |
* Get created emulators list. | |
* @returns {Promise<Array>} Promise<emulators[]> | |
*/ | |
const getAndroidEmulators = () => | |
exec(['emulator -list-avds'], { | |
preferLocal: true, | |
}).then(output => { | |
var devices = [] | |
const regex = /(?<=\n)[0-9A-Za-z-_]+/gm | |
while ((m = regex.exec(output[0].stdout)) !== null) { | |
if (m.index === regex.lastIndex) { | |
regex.lastIndex++ | |
} | |
m.forEach(match => { | |
devices.push(match) | |
}) | |
} | |
return Promise.resolve(devices) | |
}) | |
/** | |
* Start Android emulator. | |
* @param {string} name emulator name | |
* @returns {Promise<void>} Promise<void> | |
*/ | |
const startAndroidEmulator = name => { | |
// exec(`emulator -avd ${name}`) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment