-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemulator.js
33 lines (27 loc) · 940 Bytes
/
emulator.js
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
const execa = require('execa');
const path = require('path');
const getAndroidHome = () => process.env.ANDROID_HOME || process.env.ANDROID_SDK;
const hasSdkPath = () => !!getAndroidHome();
const getEmulatorDir = () => path.join(getAndroidHome(), 'emulator');
const getExtendedPath = () => {
const platformTools = path.join(getAndroidHome(), 'platform-tools');
const emulator = getEmulatorDir();
const tools = path.join(getAndroidHome(), 'tools');
return `${process.env.PATH}:${tools}:${emulator}:${platformTools}`;
};
const listEmulators = async () => {
const { stdout } = await execa('emulator', ['-list-avds'], {
env: { PATH: getExtendedPath() },
});
return stdout.split('\n');
};
const startEmulator = async emulator => execa('./emulator', [`@${emulator}`], {
detached: true,
env: { PATH: getExtendedPath() },
cwd: getEmulatorDir(),
});
module.exports = {
hasSdkPath,
listEmulators,
startEmulator,
};