Skip to content

Commit b38954c

Browse files
committed
minor(figwheel): Load figwheel config from Gradle
Now that Gradle can expose Figwheel options, we can pull that in from the tooling API. Fixes #2
1 parent 0e2e2d1 commit b38954c

File tree

3 files changed

+44
-24
lines changed

3 files changed

+44
-24
lines changed

src/main/clojure/dev/clojurephant/tooling/api.clj

+40-20
Original file line numberDiff line numberDiff line change
@@ -58,37 +58,57 @@
5858
[]
5959
(-> @db :model :repl :dir))
6060

61+
(defn ^:private reroot-dir
62+
"Takes the old and new root directories and returns
63+
a function that relatives a path starting under old
64+
to now be under new."
65+
[old-dir new-dir]
66+
(fn [dir]
67+
(cond
68+
(nil? dir) nil
69+
(boolean? dir) dir
70+
:else (-> dir
71+
(string/replace old-dir new-dir)
72+
(string/replace (str (System/getProperty "user.dir") "/") "")))))
73+
74+
(defn ^:private reroot-cljs-compiler
75+
[compiler rerooter]
76+
(-> compiler
77+
(update-in [:output-dir] rerooter)
78+
(update-in [:output-to] rerooter)
79+
(update-in [:source-map] rerooter)))
80+
81+
(defn ^:private reroot-figwheel
82+
[figwheel rerooter]
83+
(update-in figwheel [:target-dir] rerooter))
84+
6185
(defn ^:private reroot-cljs-build
6286
"Takes a ClojureScript build and re-evaluates the
6387
output directories to be relative to the REPL's
6488
output directory."
6589
[build new-dir]
6690
(let [old-dir (:output-dir build)
67-
replacer (fn [dir]
68-
(cond
69-
(nil? dir) nil
70-
(boolean? dir) dir
71-
:else (-> dir
72-
(string/replace old-dir new-dir)
73-
(string/replace (str (System/getProperty "user.dir") "/") ""))))]
74-
(-> (:compiler build)
75-
(update-in [:output-dir] replacer)
76-
(update-in [:output-to] replacer)
77-
(update-in [:source-map] replacer))))
91+
rerooter(reroot-dir old-dir new-dir)]
92+
(-> build
93+
(update :compiler (fn [c] (reroot-cljs-compiler c rerooter)))
94+
(update :figwheel (fn [f] (reroot-figwheel f rerooter))))))
7895

79-
(defn cljs-all-build-opts
80-
"Returns a map of all ClojureScript build's compiler options.
81-
Key is a keyword of the build name, value is a map of compiler
82-
options."
96+
(defn cljs-builds
97+
"Returns a map of all ClojureScript builds.
98+
Key is a keyword of the build name."
8399
[]
84-
(let [m (:model @db)
85-
repl-dir (repl-output-dir)
86-
builds (:clojurescript m)]
100+
(let [builds (get-in @db [:model :clojurescript])
101+
repl-dir (repl-output-dir)]
87102
(into {} (map (fn [[id build]]
88-
[id (reroot-cljs-build build repl-dir)]))
103+
[id (reroot-cljs-build build repl-dir)]))
89104
builds)))
90105

91106
(defn cljs-build-opts
92107
"Returns a map of compiler options for the build ID."
93108
[id]
94-
(get (cljs-all-build-opts) id))
109+
(get-in (cljs-builds) [id :compiler]))
110+
111+
(defn figwheel-opts
112+
"Returns a map of Figwheel options for the build ID."
113+
[id]
114+
(get-in (cljs-builds) [id :figwheel]))

src/main/clojure/dev/clojurephant/tooling/figwheel_main.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
[id]
1717
{:id (name id)
1818
:options (api/cljs-build-opts id)
19-
:config {}})
19+
:config (api/figwheel-opts id)})
2020

2121
(defn cljs-repl
2222
"Starts a ClojureScript REPL using

src/main/clojure/dev/clojurephant/tooling/figwheel_repl.clj

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
Uses the build configuration from Gradle. Presumes
1717
(api/reload-model!) has been called beforehand."
1818
[id]
19-
(let [opts (assoc (cljs/build-opts id)
20-
:open-url false)
21-
env (repl/repl-env* opts)]
19+
(let [opts (merge (api/cljs-build-opts id)
20+
(api/figwheel-opts id))
21+
env (repl/repl-env* opts)]
2222
(cljs/repl-env! id env)))
2323

2424
(defn cljs-repl

0 commit comments

Comments
 (0)