-
-
Notifications
You must be signed in to change notification settings - Fork 210
/
env_config.clj
41 lines (35 loc) · 1.39 KB
/
env_config.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(ns figwheel.env-config
(:require
[cljs.env]
[clojure.string :as string]))
(def figwheel-client-hook-keys [:on-jsload
:before-jsload
:on-cssload
:on-message
:on-compile-fail
:on-compile-warning
:eval-fn])
(defn figwheel-client-config-from-env []
(get-in (when-let [x cljs.env/*compiler*] @x)
[:options :external-config :figwheel/config]
{}))
(defn hook-name-to-js [hook-name]
(symbol
(str "js/"
(string/join "." (string/split (str hook-name) #"/")))))
(defn try-jsreload-hook [k hook-name]
;; change hook to js form to avoid compile warnings when it doesn't
;; exist, these compile warnings are confusing and prevent code loading
(let [hook-name' (hook-name-to-js hook-name)]
`(fn [& x#]
(if ~hook-name'
(apply ~hook-name' x#)
(figwheel.client.utils/log
:debug (str "Figwheel: " ~k " hook '" '~hook-name "' is missing"))))))
(defn protect-reload-hooks [figwheel-config]
(->> (select-keys figwheel-config figwheel-client-hook-keys)
(map (fn [[k v]] [k (try-jsreload-hook k v)]))
(into {})
(merge figwheel-config)))
(defmacro external-tooling-config []
(protect-reload-hooks (figwheel-client-config-from-env)))