From fe315c619aa3de5966cceff69f6f349cf97131f9 Mon Sep 17 00:00:00 2001 From: Foo Pang Date: Sat, 6 Jan 2018 09:02:20 +0800 Subject: [PATCH] Improve custom figwheel script usability Signed-off-by: Dmitry Novotochinov --- env/dev/figwheel_api.clj | 51 +++++++++++++++++++++------------------- env/dev/run.clj | 5 ++++ project.clj | 2 +- 3 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 env/dev/run.clj diff --git a/env/dev/figwheel_api.clj b/env/dev/figwheel_api.clj index bc9daff592..535ef00430 100644 --- a/env/dev/figwheel_api.clj +++ b/env/dev/figwheel_api.clj @@ -45,28 +45,31 @@ :id id)) ids)) -(defn start-cljs-repl [] - (hawk/watch! [{:paths ["resources"] - :handler (fn [ctx e] - (let [path "src/status_im/utils/js_resources.cljs" - js-resourced (slurp path)] - (spit path (str js-resourced " ;;")) - (spit path js-resourced)) - ctx)}]) - (let [build-ids (if *command-line-args* - (map keyword *command-line-args*) - [:android]) - ;; read project.clj to get build configs - profiles (->> "project.clj" - slurp - read-string - (drop-while #(not= % :profiles)) - (apply hash-map) - :profiles) - cljs-builds (get-in profiles [:dev :cljsbuild :builds]) - builds (get-builds build-ids cljs-builds)] - (start-figwheel build-ids builds) - (rfs/-main)) - (ra/cljs-repl)) +(defn start + ([] + (start (if *command-line-args* + (map keyword *command-line-args*) + [:android]))) + ([build-ids] + (hawk/watch! [{:paths ["resources"] + :handler (fn [ctx e] + (let [path "src/status_im/utils/js_resources.cljs" + js-resourced (slurp path)] + (spit path (str js-resourced " ;;")) + (spit path js-resourced)) + ctx)}]) + ;; read project.clj to get build configs + (let [profiles (->> "project.clj" + slurp + read-string + (drop-while #(not= % :profiles)) + (apply hash-map) + :profiles) + cljs-builds (get-in profiles [:dev :cljsbuild :builds]) + builds (get-builds build-ids cljs-builds)] + (start-figwheel build-ids builds) + (rfs/-main)))) -(start-cljs-repl) +(def stop ra/stop-figwheel!) + +(def start-cljs-repl ra/cljs-repl) diff --git a/env/dev/run.clj b/env/dev/run.clj new file mode 100644 index 0000000000..c77dadcafc --- /dev/null +++ b/env/dev/run.clj @@ -0,0 +1,5 @@ +(ns dev-run + (:use [figwheel-api])) + +(start) +(start-cljs-repl) diff --git a/project.clj b/project.clj index febe2815b9..cd141737eb 100644 --- a/project.clj +++ b/project.clj @@ -19,7 +19,7 @@ ["do" "clean" ["with-profile" "prod" "cljsbuild" "once" "ios"] ["with-profile" "prod" "cljsbuild" "once" "android"]] - "figwheel-repl" ["run" "-m" "clojure.main" "env/dev/figwheel_api.clj"] + "figwheel-repl" ["run" "-m" "clojure.main" "env/dev/run.clj"] "test-cljs" ["with-profile" "test" "doo" "node" "test" "once"] "test-protocol" ["with-profile" "test" "doo" "node" "protocol" "once"]} :figwheel {:nrepl-port 7888}