Fetching contributors…
Cannot retrieve contributors at this time
64 lines (58 sloc) 2.24 KB
;; Copyright (c) Rich Hickey. All rights reserved.
;; The use and distribution terms for this software are covered by the
;; Eclipse Public License 1.0 (
;; which can be found in the file epl-v10.html at the root of this distribution.
;; By using this software in any fashion, you are agreeing to be bound by
;; the terms of this license.
;; You must not remove this notice, or any other, from this software.
(ns cljs.main
(:require [cljs.repl.browser :as browser]
[cljs.cli :as cli])
(defn- get-js-opt [args]
(if (= 2 (count args))
(let [repl-ns (symbol
(str "cljs.repl."
(if (= 1 (count args))
(nth args 1))))]
(require repl-ns)
(if-let [repl-env (ns-resolve repl-ns 'repl-env)]
(ex-info (str "REPL namespace " repl-ns " does not define repl-env var")
{:repl-ns repl-ns})))
(catch Throwable _
(ex-info (str "REPL namespace " repl-ns " does not exist")
{:repl-ns repl-ns})))))
(defn- normalize* [args]
(if (not (cli/dispatch? cli/default-commands :main (first args)))
(let [pred (complement #{"-re" "--repl-env"})
[pre post] ((juxt #(take-while pred %)
#(drop-while pred %))
(if (= pre args)
[nil pre]
(let [[js-opt post'] (normalize* (nnext post))]
(if js-opt
[js-opt (concat pre post')]
[[(first post) (fnext post)] (concat pre post')]))))
[nil args]))
(defn normalize [args]
(let [[js-opt args] (normalize* args)]
(concat js-opt args)))
(defn -main [& args]
(let [args (normalize (cli/normalize cli/default-commands args))
pred (complement #{"-re" "--repl-env"})
[pre post] ((juxt #(take-while pred %)
#(drop-while pred %))
[js-args args] ((juxt #(take 2 %) #(drop 2 %)) post)
repl-opt (get-js-opt js-args)]
(apply cli/main repl-opt (concat pre args))