add support for configuring server host to support Android simulators
- Genymotion simulator should use 10.0.3.2 instead of localhost - Stock android emulator should use 10.0.2.2 instead of localhost
This commit is contained in:
parent
8ec6608919
commit
577f7c6954
|
@ -22,6 +22,7 @@ projNameRx = /\$PROJECT_NAME\$/g
|
|||
projNameHyphRx = /\$PROJECT_NAME_HYPHENATED\$/g
|
||||
projNameUsRx = /\$PROJECT_NAME_UNDERSCORED\$/g
|
||||
platformRx = /\$PLATFORM\$/g
|
||||
devHostRx = /\$DEV_HOST\$/g
|
||||
rnVersion = '0.15.0'
|
||||
rnPackagerPort = 8081
|
||||
podMinVersion = '0.38.2'
|
||||
|
@ -157,24 +158,29 @@ getBundleId = (name) ->
|
|||
logErr message
|
||||
|
||||
|
||||
copyEnvironmentFiles = (projNameHyph, projName) ->
|
||||
copyDevEnvironmentFiles = (projNameHyph, projName, devHost) ->
|
||||
mainIosDevPath = "env/dev/env/ios/main.cljs"
|
||||
mainIosProdPath = "env/prod/env/ios/main.cljs"
|
||||
mainAndroidDevPath = "env/dev/env/android/main.cljs"
|
||||
mainAndroidProdPath = "env/prod/env/android/main.cljs"
|
||||
|
||||
exec "cp #{resources}cljs/main_dev.cljs #{mainIosDevPath}"
|
||||
edit mainIosDevPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "ios"]]
|
||||
edit mainIosDevPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "ios"], [devHostRx, devHost] ]
|
||||
exec "cp #{resources}cljs/main_dev.cljs #{mainAndroidDevPath}"
|
||||
edit mainAndroidDevPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "android"], [devHostRx, devHost]]
|
||||
|
||||
requestImgMacroDevPath = "env/dev/env/require_img.clj"
|
||||
exec "cp #{resources}require_img_dev.clj #{requestImgMacroDevPath}"
|
||||
edit requestImgMacroDevPath, [[devHostRx, devHost]]
|
||||
|
||||
copyProdEnvironmentFiles = (projNameHyph, projName) ->
|
||||
mainIosProdPath = "env/prod/env/ios/main.cljs"
|
||||
mainAndroidProdPath = "env/prod/env/android/main.cljs"
|
||||
|
||||
exec "cp #{resources}cljs/main_prod.cljs #{mainIosProdPath}"
|
||||
edit mainIosProdPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "ios"]]
|
||||
exec "cp #{resources}cljs/main_dev.cljs #{mainAndroidDevPath}"
|
||||
edit mainAndroidDevPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "android"]]
|
||||
exec "cp #{resources}cljs/main_prod.cljs #{mainAndroidProdPath}"
|
||||
edit mainAndroidProdPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName], [platformRx, "android"]]
|
||||
|
||||
requestImgMacroDevPath = "env/dev/env/require_img.clj"
|
||||
requestImgMacroProdPath = "env/prod/env/require_img.clj"
|
||||
exec "cp #{resources}require_img_dev.clj #{requestImgMacroDevPath}"
|
||||
exec "cp #{resources}require_img_prod.clj #{requestImgMacroProdPath}"
|
||||
|
||||
copyFigwheelBridge = (projNameUs) ->
|
||||
|
@ -249,7 +255,8 @@ init = (projName) ->
|
|||
fs.mkdirSync "env/prod/env/ios"
|
||||
fs.mkdirSync "env/prod/env/android"
|
||||
|
||||
copyEnvironmentFiles(projNameHyph, projName)
|
||||
copyDevEnvironmentFiles(projNameHyph, projName, "localhost")
|
||||
copyProdEnvironmentFiles(projNameHyph, projName)
|
||||
|
||||
exec "cp -r #{resources}images ."
|
||||
|
||||
|
@ -377,13 +384,18 @@ getDeviceUuids = ->
|
|||
getDeviceList().map (line) -> line.match(/\[(.+)\]/)[1]
|
||||
|
||||
|
||||
generateDevScripts = () ->
|
||||
generateDevScripts = (devHost) ->
|
||||
try
|
||||
appName = readConfig().name
|
||||
fs.writeFileSync 'index.ios.js', "require('figwheel-bridge').start('" + appName + "','ios');"
|
||||
projName = readConfig().name
|
||||
projNameHyph = projName.replace(camelRx, '$1-$2').toLowerCase()
|
||||
|
||||
fs.writeFileSync 'index.ios.js', "require('figwheel-bridge').start('" + projName + "','ios', '" + devHost + "');"
|
||||
log 'index.ios.js was regenerated'
|
||||
fs.writeFileSync 'index.android.js', "require('figwheel-bridge').start('" + appName + "','android');"
|
||||
fs.writeFileSync 'index.android.js', "require('figwheel-bridge').start('" + projName + "','android', '" + devHost + "');"
|
||||
log 'index.android.js was regenerated'
|
||||
|
||||
copyDevEnvironmentFiles(projNameHyph, projName, devHost)
|
||||
log 'Dev server host: ' + devHost
|
||||
catch {message}
|
||||
logErr \
|
||||
if message.match /EACCES/i
|
||||
|
@ -391,35 +403,13 @@ generateDevScripts = () ->
|
|||
else
|
||||
message
|
||||
|
||||
startRepl = (name, autoChoose) ->
|
||||
log 'Starting REPL'
|
||||
hasRlwrap =
|
||||
try
|
||||
exec 'type rlwrap'
|
||||
true
|
||||
catch
|
||||
log '
|
||||
Warning: rlwrap is not installed.\nInstall it to make the REPL a much
|
||||
better experience with arrow key support.
|
||||
', 'red'
|
||||
false
|
||||
|
||||
try
|
||||
child.spawn (if hasRlwrap then 'rlwrap' else 'lein'),
|
||||
"#{if hasRlwrap then 'lein ' else ''}figwheel ios",
|
||||
cwd: process.cwd()
|
||||
env: process.env
|
||||
stdio: 'inherit'
|
||||
|
||||
catch {message}
|
||||
logErr message
|
||||
|
||||
doUpgrade = (config) ->
|
||||
projName = config.name;
|
||||
projNameHyph = projName.replace(camelRx, '$1-$2').toLowerCase()
|
||||
projNameUs = toUnderscored projName
|
||||
|
||||
copyEnvironmentFiles(projNameHyph, projName)
|
||||
copyDevEnvironmentFiles(projNameHyph, projName, "localhost")
|
||||
copyProdEnvironmentFiles(projNameHyph, projName)
|
||||
log 'upgraded files in env/'
|
||||
|
||||
copyFigwheelBridge(projNameUs)
|
||||
|
@ -484,8 +474,9 @@ cli.command 'deps'
|
|||
|
||||
cli.command 'use-figwheel'
|
||||
.description 'generate index.ios.js and index.android.js for development with figwheel'
|
||||
.action ->
|
||||
generateDevScripts()
|
||||
.option "-H, --host [host or IP address}]", 'specify server host (default localhost)', "localhost"
|
||||
.action (cmd) ->
|
||||
generateDevScripts(cmd.host)
|
||||
|
||||
cli.on '*', (command) ->
|
||||
logErr "unknown command #{command[0]}. See re-natal --help for valid commands"
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
(ns ^:figwheel-no-load env.$PLATFORM$.main
|
||||
(:require [$PROJECT_NAME_HYPHENATED$.$PLATFORM$.core :as core]))
|
||||
(:require [$PROJECT_NAME_HYPHENATED$.$PLATFORM$.core :as core]
|
||||
[figwheel.client :as figwheel :include-macros true]))
|
||||
|
||||
(enable-console-print!)
|
||||
|
||||
(figwheel/watch-and-reload
|
||||
:websocket-url "ws://$DEV_HOST$:3449/figwheel-ws"
|
||||
:heads-up-display false
|
||||
:jsload-callback core/mount-root)
|
||||
|
||||
(core/init)
|
||||
(core/mount-root)
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ var CLOSURE_UNCOMPILED_DEFINES = null;
|
|||
var React = require('react-native');
|
||||
|
||||
var config = {
|
||||
server: 'http://localhost:8081',
|
||||
basePath: "target/",
|
||||
googBasePath: 'goog/',
|
||||
splash: React.createClass({
|
||||
|
@ -25,6 +24,7 @@ var config = {
|
|||
};
|
||||
|
||||
var scriptQueue = [];
|
||||
var server = null; // will be set dynamically
|
||||
var fileBasePath = null; // will be set dynamically
|
||||
var evaluate = eval; // This is needed, direct calls to eval does not work (RN packager???)
|
||||
|
||||
|
@ -56,7 +56,7 @@ function customEval(url, javascript, success, error) {
|
|||
}
|
||||
}
|
||||
function asyncImportScripts(path, success, error) {
|
||||
var url = config.server + '/' + path;
|
||||
var url = server + '/' + path;
|
||||
|
||||
console.info('(asyncImportScripts) Importing: ' + url);
|
||||
scriptQueue.push(url);
|
||||
|
@ -92,7 +92,8 @@ function importJs(src, success, error) {
|
|||
}
|
||||
|
||||
|
||||
function loadApp(platform) {
|
||||
function loadApp(platform, devHost) {
|
||||
server = "http://"+ devHost + ":8081";
|
||||
fileBasePath = config.basePath + platform;
|
||||
|
||||
if (typeof goog === "undefined") {
|
||||
|
@ -116,10 +117,10 @@ function loadApp(platform) {
|
|||
}
|
||||
}
|
||||
|
||||
function startApp(appName, platform) {
|
||||
function startApp(appName, platform, devHost) {
|
||||
React.AppRegistry.registerComponent(appName, () => config.splash);
|
||||
if (typeof goog === "undefined") {
|
||||
loadApp(platform);
|
||||
loadApp(platform, devHost);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,17 +15,13 @@
|
|||
["with-profile" "prod" "cljsbuild" "once" "ios"]
|
||||
["with-profile" "prod" "cljsbuild" "once" "android"]]}
|
||||
:profiles {:dev {:cljsbuild {:builds {:ios {:source-paths ["src" "env/dev"]
|
||||
:figwheel {:on-jsload $PROJECT_NAME_HYPHENATED$.ios.core/mount-root
|
||||
:heads-up-display false
|
||||
:debug false}
|
||||
:figwheel true
|
||||
:compiler {:output-to "target/ios/not-used.js"
|
||||
:main "env.ios.main"
|
||||
:output-dir "target/ios"
|
||||
:optimizations :none}}
|
||||
:android {:source-paths ["src" "env/dev"]
|
||||
:figwheel {:on-jsload $PROJECT_NAME_HYPHENATED$.android.core/mount-root
|
||||
:heads-up-display false
|
||||
:debug true}
|
||||
:figwheel true
|
||||
:compiler {:output-to "target/android/not-used.js"
|
||||
:main "env.android.main"
|
||||
:output-dir "target/android"
|
||||
|
|
|
@ -3,4 +3,4 @@
|
|||
(defmacro require-img
|
||||
"Load image from local packager service"
|
||||
[src]
|
||||
{:uri (str "http://localhost:8081/" src)})
|
||||
{:uri (str "http://$DEV_HOST$:8081/" src)})
|
||||
|
|
Loading…
Reference in New Issue