@@ -24,11 +24,13 @@ program
24
24
'The virtual android device name (the adb device name will be fetched from this)' ,
25
25
DEFAULT_AVD_NAME
26
26
)
27
+ . option ( '--device' , 'Use a physical device instead of emulator' )
27
28
. option ( '--port' , 'Port to run Express HTTP server for getting results on.' , DEFAULT_PORT )
28
29
. action ( async ( str , options ) => {
29
30
const opts = options . opts ( ) ;
30
31
const avdName = opts . avdName ;
31
- const deviceName = await getADBDeviceName ( avdName ) ;
32
+ const useDevice = opts . device ;
33
+ const deviceName = await getADBDeviceName ( avdName , useDevice ) ;
32
34
if ( ! deviceName ) {
33
35
throw new Error ( `Could not find adb device with AVD name ${ avdName } ` ) ;
34
36
}
@@ -38,7 +40,11 @@ program
38
40
await spawnP ( 'Reverse Port' , `adb` , [ `-s` , deviceName , `reverse` , `tcp:${ port } ` , `tcp:${ port } ` ] ) ;
39
41
40
42
/** Build and run the Expo app, don't await this, we will await a response. */
41
- spawnP ( 'Build Expo App' , `yarn` , [ `android` , `-d` , avdName ] ) ;
43
+ if ( ! useDevice ) {
44
+ spawnP ( 'Build Expo App' , `yarn` , [ `android` , `-d` , avdName ] ) ;
45
+ } else {
46
+ spawnP ( 'Build Expo App' , `yarn` , [ `android` ] ) ;
47
+ }
42
48
43
49
const app = express ( ) ;
44
50
app . use ( bodyParser . json ( ) ) ;
@@ -107,7 +113,7 @@ async function spawnP(tag, cmd, args = []) {
107
113
} ) ;
108
114
}
109
115
110
- async function getADBDeviceName ( avdName ) {
116
+ async function getADBDeviceName ( avdName , useDevice ) {
111
117
const tag = 'Get ADB Device' ;
112
118
const devicesOutput = await spawnP ( tag , 'adb' , [ 'devices' ] ) ;
113
119
const deviceNames = _ . chain ( devicesOutput . split ( '\n' ) )
@@ -116,7 +122,9 @@ async function getADBDeviceName(avdName) {
116
122
. map ( ( line ) => line . trim ( ) ) // Omit empty results
117
123
. filter ( ( line ) => ! ! line )
118
124
. value ( ) ;
119
-
125
+ if ( useDevice ) {
126
+ return deviceNames [ 0 ] ;
127
+ }
120
128
// Need to check all devices for their AVD name
121
129
for ( let deviceName of deviceNames ) {
122
130
try {
0 commit comments