From d967daccea87fe7d2723ef72ca9788a94af2fc90 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Thu, 3 Mar 2016 17:32:06 -0500 Subject: [PATCH 1/2] Add use-ios-device command - close #26 Also updated related configuration default, check and upgrade --- re-natal.coffee | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/re-natal.coffee b/re-natal.coffee index dab3691..401cb5d 100644 --- a/re-natal.coffee +++ b/re-natal.coffee @@ -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 ' .action (type) -> configureDevHostForAndroidDevice type +cli.command 'use-ios-device ' + .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 ' .description 'configures a custom component to work with figwheel. name is the value you pass to (js/require) function.' .action (name) -> From e8c6cf89df8804fed4d3c6846dcddd9fd8a6c414 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Thu, 3 Mar 2016 17:33:45 -0500 Subject: [PATCH 2/2] Add README instructions for using real iOS device Also fixed typo in readme --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4e82aed..bf549a8 100644 --- a/README.md +++ b/README.md @@ -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