Skip to content

Commit

Permalink
allow to specify IP in command use-android-device, fixes #67
Browse files Browse the repository at this point in the history
  • Loading branch information
drapanjanas committed Sep 24, 2016
1 parent bc65ccf commit 52a98ae
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions re-natal.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,18 @@ scanImages = (dirs) ->
imgs = imgs.concat(scanImageDir(dir));
imgs

resolveAndroidDevHost = (deviceType) ->
allowedTypes = {'real': 'localhost', 'avd': '10.0.2.2', 'genymotion': '10.0.3.2'}
devHost = allowedTypes[deviceType]
if (devHost?)
log "Using '#{devHost}' for device type #{deviceType}"
devHost
else
deviceTypeIsIpAddress(deviceType, Object.keys(allowedTypes))

configureDevHostForAndroidDevice = (deviceType) ->
try
allowedTypes = {'real': 'localhost', 'avd': '10.0.2.2', 'genymotion': '10.0.3.2'}
devHost = allowedTypes[deviceType]
if (! devHost?)
throw new Error "Unknown android device type #{deviceType}, known types are #{Object.keys(allowedTypes)}"
log "Using host '#{devHost}' for android device type '#{deviceType}'"
devHost = resolveAndroidDevHost(deviceType)
config = readConfig()
config.androidHost = devHost
writeConfig(config)
Expand All @@ -255,12 +260,8 @@ resolveIosDevHost = (deviceType) ->
en0Ip = exec('ipconfig getifaddr en0', true).toString().trim()
log "Using IP of interface en0:'#{en0Ip}' for real iOS device"
en0Ip
else if deviceType.match(ipAddressRx)
log "Using development host IP: '#{deviceType}'"
deviceType
else
log("Value '#{deviceType}' is not a valid IP address, still configured it as development host for iOS", 'yellow')
deviceType
deviceTypeIsIpAddress(deviceType, ['simulator', 'real'])

configureDevHostForIosDevice = (deviceType) ->
try
Expand All @@ -272,6 +273,14 @@ configureDevHostForIosDevice = (deviceType) ->
catch {message}
logErr message

deviceTypeIsIpAddress = (deviceType, allowedTypes) ->
if deviceType.match(ipAddressRx)
log "Using development host IP: '#{deviceType}'"
deviceType
else
log("Value '#{deviceType}' is not a valid IP address, still configured it as development host. Did you mean one of: [#{allowedTypes}] ?", 'yellow')
deviceType

copyDevEnvironmentFiles = (interfaceName, projNameHyph, projName, devEnvRoot, devHost) ->
fs.mkdirpSync "#{devEnvRoot}/env/ios"
fs.mkdirpSync "#{devEnvRoot}/env/android"
Expand Down Expand Up @@ -611,7 +620,7 @@ cli.command 'use-figwheel'
generateDevScripts()

cli.command 'use-android-device <type>'
.description 'sets up the host for android device type: \'real\' - localhost, \'avd\' - 10.0.2.2, \'genymotion\' - 10.0.3.2'
.description 'sets up the host for android device type: \'real\' - localhost, \'avd\' - 10.0.2.2, \'genymotion\' - 10.0.3.2, IP'
.action (type) ->
configureDevHostForAndroidDevice type

Expand Down

0 comments on commit 52a98ae

Please sign in to comment.