allow to specify IP in command use-android-device, fixes #67

This commit is contained in:
Artur Girenko 2016-09-24 13:51:05 +02:00
parent bc65ccf355
commit 52a98ae843
1 changed files with 20 additions and 11 deletions

View File

@ -233,13 +233,18 @@ scanImages = (dirs) ->
imgs = imgs.concat(scanImageDir(dir)); imgs = imgs.concat(scanImageDir(dir));
imgs 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) -> configureDevHostForAndroidDevice = (deviceType) ->
try try
allowedTypes = {'real': 'localhost', 'avd': '10.0.2.2', 'genymotion': '10.0.3.2'} devHost = resolveAndroidDevHost(deviceType)
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}'"
config = readConfig() config = readConfig()
config.androidHost = devHost config.androidHost = devHost
writeConfig(config) writeConfig(config)
@ -255,12 +260,8 @@ resolveIosDevHost = (deviceType) ->
en0Ip = exec('ipconfig getifaddr en0', true).toString().trim() en0Ip = exec('ipconfig getifaddr en0', true).toString().trim()
log "Using IP of interface en0:'#{en0Ip}' for real iOS device" log "Using IP of interface en0:'#{en0Ip}' for real iOS device"
en0Ip en0Ip
else if deviceType.match(ipAddressRx)
log "Using development host IP: '#{deviceType}'"
deviceType
else else
log("Value '#{deviceType}' is not a valid IP address, still configured it as development host for iOS", 'yellow') deviceTypeIsIpAddress(deviceType, ['simulator', 'real'])
deviceType
configureDevHostForIosDevice = (deviceType) -> configureDevHostForIosDevice = (deviceType) ->
try try
@ -272,6 +273,14 @@ configureDevHostForIosDevice = (deviceType) ->
catch {message} catch {message}
logErr 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) -> copyDevEnvironmentFiles = (interfaceName, projNameHyph, projName, devEnvRoot, devHost) ->
fs.mkdirpSync "#{devEnvRoot}/env/ios" fs.mkdirpSync "#{devEnvRoot}/env/ios"
fs.mkdirpSync "#{devEnvRoot}/env/android" fs.mkdirpSync "#{devEnvRoot}/env/android"
@ -611,7 +620,7 @@ cli.command 'use-figwheel'
generateDevScripts() generateDevScripts()
cli.command 'use-android-device <type>' 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) -> .action (type) ->
configureDevHostForAndroidDevice type configureDevHostForAndroidDevice type