Skip to content

Commit 3e588ea

Browse files
committed
reloadable js resources for jail
Former-commit-id: 958d900
1 parent 321935e commit 3e588ea

17 files changed

Lines changed: 144 additions & 97 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ figwheel_server.log
5959
# Lein
6060
#
6161
.lein-failures
62+
.lein-repl-history
6263

6364
## Doo
6465
#

env/dev/env/android/main.cljs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns ^:figwheel-no-load env.android.main
1+
(ns ^:figwheel-no-load env.android.main
22
(:require [reagent.core :as r]
33
[status-im.android.core :as core]
44
[figwheel.client :as figwheel :include-macros true]))
@@ -8,10 +8,14 @@
88
(def cnt (r/atom 0))
99
(defn reloader [] @cnt [core/app-root])
1010
(def root-el (r/as-element [reloader]))
11+
(defn callback []
12+
(swap! cnt inc)
13+
(status-im.components.status/init-jail)
14+
(re-frame.core/dispatch [:load-commands!]))
1115

1216
(figwheel/watch-and-reload
13-
:websocket-url "ws://10.0.2.2:3449/figwheel-ws"
14-
:heads-up-display false
15-
:jsload-callback #(swap! cnt inc))
17+
:websocket-url "ws://10.0.3.2:3449/figwheel-ws"
18+
:heads-up-display false
19+
:jsload-callback callback)
1620

1721
(core/init)

env/dev/env/android_test/main.cljs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
(:require [reagent.core :as r]
33
[status-im.android.core :as core]
44
[figwheel.client :as figwheel :include-macros true]
5-
[status-im.test.handlers-stubs :refer [init-stubs]]))
6-
5+
;[status-im.test.handlers-stubs :refer [init-stubs]]
6+
))
77
(enable-console-print!)
88

99
(set! js/console.disableYellowBox true)
@@ -18,4 +18,4 @@
1818
:jsload-callback #(swap! cnt inc))
1919

2020
(core/init :test)
21-
(init-stubs)
21+
;(init-stubs)

env/dev/user.clj

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
(ns user
2-
(:use [figwheel-sidecar.repl-api :as ra]))
2+
(:use [figwheel-sidecar.repl-api :as ra])
3+
(:require [hawk.core :as hawk]
4+
[clojure.string :as s]))
35
;; This namespace is loaded automatically by nREPL
46

57
;; read project.clj to get build configs
@@ -10,17 +12,34 @@
1012
(apply hash-map)
1113
:profiles))
1214

13-
(def cljs-builds (get-in profiles [:dev :cljsbuild :builds]))
15+
(def cljs-builds
16+
(get-in profiles [:dev :cljsbuild :builds]))
1417

1518
(defn start-figwheel
16-
"Start figwheel for one or more builds"
17-
[& build-ids]
18-
(ra/start-figwheel!
19-
{:build-ids build-ids
20-
:all-builds cljs-builds})
21-
(ra/cljs-repl))
19+
"Start figwheel for one or more builds"
20+
[build-ids]
21+
(ra/start-figwheel!
22+
{:figwheel-options {:nrepl-port 7888}
23+
:build-ids build-ids
24+
:all-builds cljs-builds}))
25+
26+
(def start-cljs-repl ra/cljs-repl)
2227

2328
(defn stop-figwheel
24-
"Stops figwheel"
25-
[]
26-
(ra/stop-figwheel!))
29+
"Stops figwheel"
30+
[]
31+
(ra/stop-figwheel!))
32+
33+
(hawk/watch! [{:paths ["resources"]
34+
:handler (fn [ctx e]
35+
(let [path "src/status_im/utils/js_resources.cljs"
36+
js-resourced (slurp path)]
37+
(spit path (str js-resourced " ;;"))
38+
(spit path js-resourced))
39+
ctx)}])
40+
41+
(let [env-build-ids (System/getenv "BUILD_IDS")
42+
build-ids (if env-build-ids
43+
(map keyword (s/split env-build-ids #","))
44+
[:android])]
45+
(start-figwheel build-ids))

figwheel-bridge.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,23 @@ function interceptRequire() {
164164
function compileWarningsToYellowBox() {
165165
var log = window.console.log;
166166
var compileWarningRx = /Figwheel: Compile/;
167+
var compileExceptionRx = /Figwheel: Compile Exception/;
168+
var errorInFileRx = /Error on file/;
169+
var isBuffering = false;
170+
var compileExceptionBuffer = "";
167171
window.console.log = function (msg) {
168-
if (compileWarningRx.test(msg)) {
172+
log.apply(window.console, arguments);
173+
if (compileExceptionRx.test(msg)) { // enter buffering mode to get all the messages for exception
174+
isBuffering = true;
175+
compileExceptionBuffer = msg + "\n";
176+
} else if (errorInFileRx.test(msg) && isBuffering) { // exit buffering mode and log buffered messages to YellowBox
177+
isBuffering = false;
178+
console.warn(compileExceptionBuffer + msg);
179+
compileExceptionBuffer = "";
180+
} else if (isBuffering) { //log messages buffering mode
181+
compileExceptionBuffer += msg + "\n";
182+
} else if (compileWarningRx.test(msg)) {
169183
console.warn(msg);
170-
} else {
171-
log.apply(window.console, arguments);
172184
}
173185
};
174186
}
@@ -208,7 +220,7 @@ function loadApp(platform, devHost, onLoadCb) {
208220
// seriously React packager? why.
209221
var googreq = goog.require;
210222

211-
googreq('figwheel.connect');
223+
googreq('figwheel.connect.' + platform);
212224
});
213225
});
214226
}
@@ -278,4 +290,4 @@ self = {
278290
start: startApp
279291
};
280292

281-
module.exports = self;
293+
module.exports = self;

project.clj

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,71 @@
55
:url "http://www.eclipse.org/legal/epl-v10.html"}
66
:dependencies [[org.clojure/clojure "1.9.0-alpha13"]
77
[org.clojure/clojurescript "1.9.229"]
8-
[reagent "0.5.1" :exclusions [cljsjs/react]]
8+
[reagent "0.6.0" :exclusions [cljsjs/react cljsjs/react-dom cljsjs/react-dom-server]]
99
[re-frame "0.7.0"]
1010
[natal-shell "0.3.0"]
1111
[com.andrewmcveigh/cljs-time "0.4.0"]
1212
[tailrecursion/cljs-priority-map "1.2.0"]
1313
[com.taoensso/timbre "4.7.4"]]
1414
:plugins [[lein-cljsbuild "1.1.4"]
15-
[lein-figwheel "0.5.0-2"]]
15+
[lein-figwheel "0.5.8"]]
1616
:clean-targets ["target/" "index.ios.js" "index.android.js"]
1717
:aliases {"prod-build" ^{:doc "Recompile code with prod profile."}
1818
["do" "clean"
1919
["with-profile" "prod" "cljsbuild" "once" "ios"]
2020
["with-profile" "prod" "cljsbuild" "once" "android"]]}
2121
:test-paths ["test/clj"]
2222
:figwheel {:nrepl-port 7888}
23-
:profiles {:dev {:dependencies [[figwheel-sidecar "0.5.0-2"]
23+
:profiles {:dev {:dependencies [[figwheel-sidecar "0.5.8"]
2424
[com.cemerick/piggieback "0.2.1"]
25-
[io.appium/java-client "3.4.1"]]
25+
[io.appium/java-client "3.4.1"]
26+
[hawk "0.2.10"]]
2627
:plugins [[lein-doo "0.1.6"]]
2728
:source-paths ["src" "env/dev"]
28-
:cljsbuild {:builds {:ios {:source-paths ["src" "env/dev"]
29-
:figwheel true
30-
:compiler {:output-to "target/ios/not-used.js"
31-
:main "env.ios.main"
32-
:output-dir "target/ios"
33-
:optimizations :none}}
34-
:android {:source-paths ["src" "env/dev"]
35-
:figwheel true
36-
:compiler {:output-to "target/android/not-used.js"
37-
:main "env.android.main"
38-
:output-dir "target/android"
39-
:optimizations :none}}
40-
:android-test {:source-paths ["src" "env/dev"]
41-
:figwheel true
42-
:compiler {:output-to "target/android/not-used.js"
43-
:main "env.android-test.main"
44-
:output-dir "target/android"
45-
:optimizations :none}}
46-
:test {:source-paths ["src" "test/cljs"]
47-
:compiler
48-
{:main status-im.test.runner
49-
:output-to "target/test/test.js"
50-
:optimizations :none
51-
:target :nodejs}}}}
52-
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}}
29+
:cljsbuild {:builds [{:id :ios
30+
:source-paths ["src" "env/dev"]
31+
:figwheel true
32+
:compiler {:output-to "target/ios/not-used.js"
33+
:main "env.ios.main"
34+
:output-dir "target/ios"
35+
:optimizations :none}}
36+
{:id :android
37+
:source-paths ["src" "env/dev"]
38+
:figwheel true
39+
:compiler {:output-to "target/android/not-used.js"
40+
:main "env.android.main"
41+
:output-dir "target/android"
42+
:optimizations :none}}
43+
{:id :android-test
44+
:source-paths ["src" "env/dev"]
45+
:compiler {:output-to "target/android/not-used.js"
46+
:main "env.android-test.main"
47+
:output-dir "target/android-test"
48+
:optimizations :none}}
49+
{:id :test
50+
:source-paths ["src" "test/cljs"]
51+
:compiler
52+
{:main status-im.test.runner
53+
:output-to "target/test/test.js"
54+
:optimizations :none
55+
:target :nodejs}}]}
56+
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]
57+
:timeout 120000}}
5358
:prod {:cljsbuild {:builds [{:id "ios"
5459
:source-paths ["src" "env/prod"]
55-
:compiler {:output-to "index.ios.js"
56-
:main "env.ios.main"
57-
:output-dir "target/ios"
58-
:static-fns true
60+
:compiler {:output-to "index.ios.js"
61+
:main "env.ios.main"
62+
:output-dir "target/ios-prod"
63+
:static-fns true
5964
:optimize-constants true
60-
:optimizations :simple
61-
:closure-defines {"goog.DEBUG" false}}}
62-
{:id "android"
65+
:optimizations :simple
66+
:closure-defines {"goog.DEBUG" false}}}
67+
{:id "android"
6368
:source-paths ["src" "env/prod"]
64-
:compiler {:output-to "index.android.js"
65-
:main "env.android.main"
66-
:output-dir "target/android"
67-
:static-fns true
69+
:compiler {:output-to "index.android.js"
70+
:main "env.android.main"
71+
:output-dir "target/android-prod"
72+
:static-fns true
6873
:optimize-constants true
69-
:optimizations :simple
70-
:closure-defines {"goog.DEBUG" false}}}]}}})
74+
:optimizations :simple
75+
:closure-defines {"goog.DEBUG" false}}}]}}})

run-osx.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fi
5757
lein deps && re-natal deps && re-natal use-android-device "${device_type}" && re-natal use-figwheel
5858

5959
# open figwheel in new tab
60-
tab "lein figwheel ${cljs_build}"
60+
tab "BUILD_IDS=${cljs_build} lein repl"
6161

6262
# open react-native package in new tab
6363
tab "react-native start"

src/cljsjs/react.cljs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
(ns cljsjs.react)
22

33
(when (exists? js/window)
4-
;; cause there is no window.document object in the newest version
5-
;; of React Native, but chance.js requires it
6-
(set! js/window.document #js {})
7-
8-
(set! js/window.React (js/require "react"))
94
(set! js/ReactNative (js/require "react-native")))

src/cljsjs/react/dom.cljs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(ns cljsjs.react.dom)

src/cljsjs/react/dom/server.cljs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(ns cljsjs.react.dom.server)

0 commit comments

Comments
 (0)