cljs.repl.browser/setup
function | since v0.0-2665 | Edit |
(setup {:keys [working-dir launch-browser server-state], :as repl-env} {:keys [output-dir], :as opts})
(defn setup [{:keys [working-dir launch-browser server-state] :as repl-env} {:keys [output-dir] :as opts}]
(locking lock
(when-not (:socket @server-state)
(binding [browser-state (:browser-state repl-env)
ordering (:ordering repl-env)
es (:es repl-env)
server/state (:server-state repl-env)]
(swap! browser-state
(fn [old]
(assoc old :client-js
(cljsc/create-client-js-file
{:optimizations :simple
:output-dir working-dir}
(io/file working-dir "brepl_client.js"))
:closure-defines (:closure-defines opts))))
(when (and output-dir (not (.exists (io/file output-dir "clojure" "browser" "repl" "preload.js"))))
(let [target (io/file output-dir "brepl_deps.js")]
(util/mkdirs target)
(spit target
(build/build
'[(require '[clojure.browser.repl.preload])]
(merge (dissoc (select-keys opts cljsc/known-opts) :modules)
{:opts-cache "brepl_opts.edn"})))))
(server/start repl-env)
(let [base-url (str "http://" (:host repl-env) ":" (:port repl-env))]
(if launch-browser
(maybe-browse-url base-url)
(println (waiting-to-connect-message base-url)))))))
(.put outs (thread-name) *out*)
(swap! server-state update :listeners inc))