|
58 | 58 | []
|
59 | 59 | (-> @db :model :repl :dir))
|
60 | 60 |
|
| 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 | + |
61 | 85 | (defn ^:private reroot-cljs-build
|
62 | 86 | "Takes a ClojureScript build and re-evaluates the
|
63 | 87 | output directories to be relative to the REPL's
|
64 | 88 | output directory."
|
65 | 89 | [build new-dir]
|
66 | 90 | (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)))))) |
78 | 95 |
|
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." |
83 | 99 | []
|
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)] |
87 | 102 | (into {} (map (fn [[id build]]
|
88 |
| - [id (reroot-cljs-build build repl-dir)])) |
| 103 | + [id (reroot-cljs-build build repl-dir)])) |
89 | 104 | builds)))
|
90 | 105 |
|
91 | 106 | (defn cljs-build-opts
|
92 | 107 | "Returns a map of compiler options for the build ID."
|
93 | 108 | [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])) |
0 commit comments