diff --git a/README.md b/README.md index ab8a6a6..cc6673b 100644 --- a/README.md +++ b/README.md @@ -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 ) - Source maps are available when you "Debug in Chrome" - Optimizations :simple is used to compile "production" index.ios.js and index.android.js @@ -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: @@ -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 +$ 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: @@ -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 diff --git a/re-natal.coffee b/re-natal.coffee index fd67ba0..5a7e60e 100644 --- a/re-natal.coffee +++ b/re-natal.coffee @@ -120,6 +120,7 @@ generateConfig = (name) -> log 'Creating Re-Natal config' config = name: name + androidHost: "localhost" modules: [] imageDirs: ["images"] @@ -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" @@ -439,7 +453,7 @@ updateFigwheelUrlForAndroid= (devHost) -> edit mainAndroidDevPath, [[figwheelUrlRx, "ws://#{devHost}:"]] -generateDevScripts = (devHost) -> +generateDevScripts = () -> try config = readConfig() projName = config.name @@ -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 \ @@ -487,6 +503,9 @@ doUpgrade = (config) -> if (!config.imageDirs) config.imageDirs = ["images"] + if (!config.androidHost) + config.androidHost = "localhost" + writeConfig(config) log 'upgraded .re-natal' @@ -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 ' + .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 ' .description 'configures a custom component to work with figwheel. name is the value you pass to (js/require) function.' diff --git a/resources/user.clj b/resources/user.clj index 824ee75..4c2ca8b 100644 --- a/resources/user.clj +++ b/resources/user.clj @@ -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)) \ No newline at end of file + (ra/stop-figwheel!)) \ No newline at end of file