Use plain vanilla React Native reload based development flow for iOS and Android

- Removed REPL based on ambly for now, need to find a good solution for both iOS and Android
This commit is contained in:
Artur Girenko 2015-11-24 22:44:57 +01:00
parent 720903fda6
commit f70ae59b55
3 changed files with 19 additions and 93 deletions

View File

@ -219,9 +219,7 @@ init = (projName) ->
exec "cp #{resources}core-ios.cljs #{coreIosPath}"
edit coreIosPath, [[projNameHyphRx, projNameHyph], [projNameRx, projName]]
log 'Creating React Native skeleton'
fs.mkdirSync 'native'
process.chdir 'native'
log 'Creating React Native skeleton. Relax, this takes a while...'
fs.writeFileSync 'package.json', JSON.stringify
name: projName
@ -234,91 +232,19 @@ init = (projName) ->
, null, 2
exec 'npm i'
fs.unlinkSync '.gitignore'
exec "
node -e
\"require('react-native/local-cli/cli').init('.', '#{projName}')\"
"
fs.unlinkSync 'index.android.js'
fs.unlinkSync 'index.ios.js'
log 'Installing Pod dependencies'
process.chdir 'ios'
exec "cp #{resources}Podfile ."
exec 'pod install'
log 'Updating Xcode project'
for ext in ['m', 'h']
path = "#{projName}/AppDelegate.#{ext}"
exec "cp #{resources}AppDelegate.#{ext} #{path}"
edit path, [[projNameRx, projName], [projNameHyphRx, projNameHyph]]
uuid1 = crypto
.createHash 'md5'
.update projName, 'utf8'
.digest('hex')[...24]
.toUpperCase()
uuid2 = uuid1.split ''
uuid2.splice 7, 1, ((parseInt(uuid1[7], 16) + 1) % 16).toString(16).toUpperCase()
uuid2 = uuid2.join ''
edit \
"#{projName}.xcodeproj/project.pbxproj",
[
[
/OTHER_LDFLAGS = "-ObjC";/g
'OTHER_LDFLAGS = "${inherited}";'
]
[
/\/\* End PBXBuildFile section \*\//
"\t\t#{uuid2} /* out in Resources */ =
{isa = PBXBuildFile; fileRef = #{uuid1} /* out */; };
\n/* End PBXBuildFile section */"
]
[
/\/\* End PBXFileReference section \*\//
"\t\t#{uuid1} /* out */ = {isa = PBXFileReference; lastKnownFileType
= folder; name = out; path = ../../target/out;
sourceTree = \"<group>\"; };\n/* End PBXFileReference section */"
]
[
/main.jsbundle \*\/\,/
"main.jsbundle */,\n\t\t\t\t#{uuid1} /* out */,"
]
[
/\/\* LaunchScreen.xib in Resources \*\/\,/
"/* LaunchScreen.xib in Resources */,
\n\t\t\t\t#{uuid2} /* out in Resources */,"
]
]
testId = readFile("#{projName}.xcodeproj/project.pbxproj")
.match(new RegExp "([0-9A-F]+) \/\\* #{projName}Tests \\*\/ = \\{")[1]
edit \
"#{projName}.xcodeproj/xcshareddata/xcschemes/#{projName}.xcscheme",
[
[
/\<Testables\>\n\s*\<\/Testables\>/
"""
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "#{testId}"
BuildableName = "#{projName}Tests.xctest"
BlueprintName = "#{projName}Tests"
ReferencedContainer = "container:#{projName}.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
"""
]
]
process.chdir '../..'
launch generateConfig projName
log 'Compiling ClojureScript'
exec 'lein cljsbuild once dev'
exec 'lein cljsbuild once android'
log ''
log 'To get started with your new app, first cd into its directory:', 'yellow'

View File

@ -6,6 +6,7 @@
(set! js/React (js/require "react-native/Libraries/react-native/react-native.js"))
(def app-registry (.-AppRegistry js/React))
(def text (r/adapt-react-class (.-Text js/React)))
(def view (r/adapt-react-class (.-View js/React)))
(def image (r/adapt-react-class (.-Image js/React)))
@ -21,9 +22,7 @@
[touchable-highlight {:style {:backgroundColor "#999" :padding 10 :borderRadius 5}}
[text {:style {:color "white" :textAlign "center" :fontWeight "bold"}} "press me"]]])))
(r/render [widget] 1)
(defn ^:export init []
(dispatch-sync [:initialize-db])
((fn render []
(.requestAnimationFrame js/window render))))
(.registerRunnable app-registry "$PROJECT_NAME$"
(fn [params]
(dispatch-sync [:initialize-db])
(r/render [widget] (.-rootTag params))))

View File

@ -4,16 +4,17 @@
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.7.145"]
[org.clojure/clojurescript "1.7.170"]
[reagent "0.5.1" :exclusions [cljsjs/react]]
[org.omcljs/ambly "0.6.0"]
[re-frame "0.5.0"]]
:plugins [[lein-cljsbuild "1.1.0"]]
:plugins [[lein-cljsbuild "1.1.1"]]
:cljsbuild {:builds {:dev {:source-paths ["src"]
:compiler {:output-to "target/out/main.js"
:compiler {:output-to "index.ios.js"
:main "$PROJECT_NAME_HYPHENATED$.ios.core"
:output-dir "target/out"
:optimizations :none}}
:optimizations :simple}}
:android {:source-paths ["src"]
:compiler {:output-to "native/index.android.js"
:compiler {:output-to "index.android.js"
:main "$PROJECT_NAME_HYPHENATED$.android.core"
:output-dir "target/android"
:optimizations :simple}}}})