Skip to content

Commit

Permalink
support development of iOS and Android apps simultaneously #4
Browse files Browse the repository at this point in the history
- remove setting up host from use-figwheel command
- introduce use-android-device command for changing android host. use-android-device command has to be executed only when user changes android device type for development
- change figwheel support functions in user.clj to support multiple builds
- add instructions to README of how to run iOS and Android simulators simultaneously
  • Loading branch information
drapanjanas committed Jan 24, 2016
1 parent b601f62 commit 1b37d60
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 22 deletions.
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Contributions are welcome.
- Works in Android simulator Genymotion (with re-natal use-figwheel -H 10.0.3.2)
- Works in stock Android emulator (with re-natal use-figwheel -H 10.0.2.2)
- Figwheel REPL can be started within nREPL
- Simultaneous development of iOS and Android apps is supported
- You can reload app any time, no problem.
- "Debug in Chrome" is not required anymore.
- Custom react-native components are supported (with re-natal use-component <name>)
- Source maps are available when you "Debug in Chrome"
- Optimizations :simple is used to compile "production" index.ios.js and index.android.js
Expand Down Expand Up @@ -114,7 +114,8 @@ $ react-native run-android
With genymotion Android simulator you have to use IP "10.0.3.2" in urls to refer to your local machine.
To specify this use:
```
$ re-natal use-figwheel -H 10.0.3.2
$ re-natal use-android-device genymotion
$ re-natal use-figwheel
$ lein figwheel android
```
Start your simulator and deploy your app:
Expand All @@ -126,13 +127,29 @@ $ react-native run-android
With stock Android emulator you have to use IP "10.0.2.2" in urls to refer to your local machine.
To specify this use:
```
$ re-natal use-figwheel -H 10.0.2.2
$ re-natal use-android-device avd
$ re-natal use-figwheel
$ lein figwheel android
```
Start your simulator and deploy your app:
```
$ react-native run-android
```
#### Swiching between Android devices
If you have to switch from using genymotion to real android device you have to execute `use-android-device`
command and `use-figwheel`:
```
$ re-natal use-android-device <real|genymotion|avd>
$ re-natal use-figwheel
$ lein figwheel android
```

#### Developing iOS and Android apps simultaneously
```
$ re-natal use-figwheel
$ lein figwheel ios android
```
Then start iOS app from xcode, and Android by executing `react-native run-android`

#### Starting Figwheel REPL from nREPL
To start Figwheel within nREPL session:
Expand All @@ -141,11 +158,15 @@ $ lein repl
```
Then in the nREPL prompt type:
```
user=> (figwheel-ios)
user=> (start-figwheel "ios")
```
Or, for Android build type:
```
user=> (figwheel-android)
user=> (start-figwheel "android")
```
Or, for both type:
```
user=> (start-figwheel "ios" "android")
```

## REPL
Expand Down
37 changes: 30 additions & 7 deletions re-natal.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ generateConfig = (name) ->
log 'Creating Re-Natal config'
config =
name: name
androidHost: "localhost"
modules: []
imageDirs: ["images"]

Expand Down Expand Up @@ -195,6 +196,19 @@ scanImages = (dirs) ->
imgs = imgs.concat(scanImageDir(dir));
imgs

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}'"
config = readConfig()
config.androidHost = devHost
writeConfig(config)
catch {message}
logErr message

copyDevEnvironmentFiles = (projNameHyph, projName, devHost) ->
mkdirSync "env/dev"
mkdirSync "env/dev/env"
Expand Down Expand Up @@ -439,7 +453,7 @@ updateFigwheelUrlForAndroid= (devHost) ->

edit mainAndroidDevPath, [[figwheelUrlRx, "ws://#{devHost}:"]]

generateDevScripts = (devHost) ->
generateDevScripts = () ->
try
config = readConfig()
projName = config.name
Expand All @@ -451,14 +465,16 @@ generateDevScripts = (devHost) ->
modulesAndImages = config.modules.concat images;
moduleMap = generateRequireModulesCode modulesAndImages

androidDevHost = config.androidHost

fs.writeFileSync 'index.ios.js', "#{moduleMap}require('figwheel-bridge').withModules(modules).start('#{projName}','ios','localhost');"
log 'index.ios.js was regenerated'
fs.writeFileSync 'index.android.js', "#{moduleMap}require('figwheel-bridge').withModules(modules).start('#{projName}','android','#{devHost}');"
fs.writeFileSync 'index.android.js', "#{moduleMap}require('figwheel-bridge').withModules(modules).start('#{projName}','android','#{androidDevHost}');"
log 'index.android.js was regenerated'

updateFigwheelUrlForAndroid(devHost)
updateFigwheelUrlForAndroid(androidDevHost)
log 'Dev server host for iOS: localhost'
log 'Dev server host for Android: ' + devHost
log 'Dev server host for Android: ' + androidDevHost

catch {message}
logErr \
Expand Down Expand Up @@ -487,6 +503,9 @@ doUpgrade = (config) ->
if (!config.imageDirs)
config.imageDirs = ["images"]

if (!config.androidHost)
config.androidHost = "localhost"

writeConfig(config)
log 'upgraded .re-natal'

Expand Down Expand Up @@ -565,9 +584,13 @@ cli.command 'deps'

cli.command 'use-figwheel'
.description 'generate index.ios.js and index.android.js for development with figwheel'
.option "-H, --host [host or IP address}]", 'specify server host (default localhost)', "localhost"
.action (cmd) ->
generateDevScripts(cmd.host)
.action () ->
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'
.action (type) ->
configureDevHostForAndroidDevice 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.'
Expand Down
17 changes: 7 additions & 10 deletions resources/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@

(def cljs-builds (get-in profiles [:dev :cljsbuild :builds]))

(defn figwheel-ios
"Start figwheel for iOS build"
[]
(defn start-figwheel
"Start figwheel for one or more builds"
[& build-ids]
(ra/start-figwheel!
{:build-ids ["ios"]
{:build-ids build-ids
:all-builds cljs-builds})
(ra/cljs-repl))

(defn figwheel-android
"Start figwheel for Android build"
(defn stop-figwheel
"Stops figwheel"
[]
(ra/start-figwheel!
{:build-ids ["android"]
:all-builds cljs-builds})
(ra/cljs-repl))
(ra/stop-figwheel!))

0 comments on commit 1b37d60

Please sign in to comment.