Merge pull request #27 from cldwalker/use-ios-device

Add new command use-ios-device to support development on iOS device
This commit is contained in:
Artūr Girenko 2016-03-06 09:20:33 +01:00
commit df1c8fbd40
2 changed files with 50 additions and 8 deletions

View File

@ -87,7 +87,7 @@ Luckily, this can be improved by compiling with `optimizations :none` and using
Figwheel.
#### Using Figwheel in iOS simulator
Start your app from Xcode, or just run `react-native run-ios`
Start your app from Xcode and pick a simulator target, or just run `react-native run-ios`
Then, to start development mode execute commands:
```
@ -96,6 +96,13 @@ $ lein figwheel ios
```
This will generate index.ios.js and index.android.js which works with compiler mode`optimizations :none`.
#### Using Figwheel in real iOS device
Switch to using your iOS device: `re-natal use-ios-device real`.
If this doesn't correctly detect your computer's IP you can pass your IP address explicitly: `re-natal use-ios-device IP`
Then follow the remaining directions above for the iOS simulator except pick your connected device in Xcode
#### Using Figwheel in real Android device
To run figwheel with real Android device please read [Running on Device](https://facebook.github.io/react-native/docs/running-on-device-android.html#content).
To make it work on USB connected device I had also to do the following:
@ -137,7 +144,7 @@ Start your simulator and deploy your app:
```
$ react-native run-android
```
#### Swiching between Android devices
#### Switching between Android devices
Run `use-android-device` to configure device type you want to use in development:
```
$ re-natal use-android-device <real|genymotion|avd>

View File

@ -27,6 +27,7 @@ interfaceDepsRx = /\$INTERFACE_DEPS\$/g
platformRx = /\$PLATFORM\$/g
devHostRx = /\$DEV_HOST\$/g
figwheelUrlRx = /ws:\/\/[0-9a-zA-Z\.]*:/g
appDelegateRx = /http:\/\/[^:]+/g
rnVersion = '0.20.0'
rnPackagerPort = 8081
process.title = 're-natal'
@ -140,6 +141,7 @@ generateConfig = (interfaceName, projName) ->
name: projName
interface: interfaceName
androidHost: "localhost"
iosHost: "localhost"
modules: []
imageDirs: ["images"]
@ -158,7 +160,7 @@ writeConfig = (config) ->
message
verifyConfig = (config) ->
if !config.androidHost? || !config.modules? || !config.imageDirs? || !config.interface?
if !config.androidHost? || !config.modules? || !config.imageDirs? || !config.interface? || !config.iosHost?
throw new Error 're-natal project needs to be upgraded, please run: re-natal upgrade'
config
@ -212,6 +214,21 @@ configureDevHostForAndroidDevice = (deviceType) ->
catch {message}
logErr message
configureDevHostForIosDevice = (deviceType) ->
try
devHost = if deviceType == 'simulator'
'localhost'
else if deviceType == 'real'
exec('ipconfig getifaddr en0', true).toString().trim()
else
deviceType
config = readConfig()
config.iosHost = devHost
writeConfig(config)
catch {message}
logErr message
copyDevEnvironmentFiles = (interfaceName, projNameHyph, projName, devHost) ->
fs.mkdirpSync "env/dev/env/ios"
fs.mkdirpSync "env/dev/env/android"
@ -411,10 +428,16 @@ generateRequireModulesCode = (modules) ->
jsCode += "modules['#{m}']=require('#{m}');";
jsCode += '\n'
updateFigwheelUrlForAndroid= (devHost) ->
updateFigwheelUrls = (androidHost, iosHost) ->
mainAndroidDevPath = "env/dev/env/android/main.cljs"
edit mainAndroidDevPath, [[figwheelUrlRx, "ws://#{androidHost}:"]]
edit mainAndroidDevPath, [[figwheelUrlRx, "ws://#{devHost}:"]]
mainIosDevPath = "env/dev/env/ios/main.cljs"
edit mainIosDevPath, [[figwheelUrlRx, "ws://#{iosHost}:"]]
updateIosAppDelegate = (projName, iosHost) ->
appDelegatePath = "ios/#{projName}/AppDelegate.m"
edit appDelegatePath, [[appDelegateRx, "http://#{iosHost}"]]
generateDevScripts = () ->
try
@ -433,14 +456,18 @@ generateDevScripts = () ->
moduleMap = generateRequireModulesCode modulesAndImages
androidDevHost = config.androidHost
iosDevHost = config.iosHost
fs.writeFileSync 'index.ios.js', "#{moduleMap}require('figwheel-bridge').withModules(modules).start('#{projName}','ios','localhost');"
fs.writeFileSync 'index.ios.js', "#{moduleMap}require('figwheel-bridge').withModules(modules).start('#{projName}','ios','#{iosDevHost}');"
log 'index.ios.js was regenerated'
fs.writeFileSync 'index.android.js', "#{moduleMap}require('figwheel-bridge').withModules(modules).start('#{projName}','android','#{androidDevHost}');"
log 'index.android.js was regenerated'
updateFigwheelUrlForAndroid(androidDevHost)
log 'Dev server host for iOS: localhost'
updateIosAppDelegate(projName, iosDevHost)
log "AppDelegate.m was updated"
updateFigwheelUrls(androidDevHost, iosDevHost)
log 'Dev server host for iOS: ' + iosDevHost
log 'Dev server host for Android: ' + androidDevHost
catch {message}
@ -467,6 +494,9 @@ doUpgrade = (config) ->
unless config.androidHost
config.androidHost = "localhost"
unless config.iosHost
config.iosHost = "localhost"
writeConfig(config)
log 'upgraded .re-natal'
@ -542,6 +572,11 @@ cli.command 'use-android-device <type>'
.action (type) ->
configureDevHostForAndroidDevice type
cli.command 'use-ios-device <type>'
.description 'sets up the host for ios device type: \'simulator\' - localhost, \'device\' - auto detect IP on eth0, IP'
.action (type) ->
configureDevHostForIosDevice type
cli.command 'use-component <name>'
.description 'configures a custom component to work with figwheel. name is the value you pass to (js/require) function.'
.action (name) ->