Skip to content

Commit 3ae14bc

Browse files
author
dnolen
committed
allow combining -c with -s
1 parent 2f9c703 commit 3ae14bc

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/main/clojure/cljs/cli.clj

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,19 @@ present"
381381
*out* log-out]
382382
(build/watch path (dissoc opts :watch) cenv)))))
383383

384+
(defn- serve-opt
385+
[_ [_ address-port & args] {:keys [options] :as cfg}]
386+
(let [[host port] (if address-port
387+
(string/split address-port #":")
388+
["localhost" 9000])]
389+
(require 'cljs.repl.browser)
390+
((ns-resolve 'cljs.repl.browser 'serve)
391+
{:host host
392+
:port (if port
393+
(cond-> port (string? port) Integer/parseInt)
394+
9000)
395+
:output-dir (:output-dir options "out")})))
396+
384397
(defn default-compile
385398
[repl-env {:keys [ns args options] :as cfg}]
386399
(let [env-opts (repl/repl-options (repl-env))
@@ -409,6 +422,7 @@ present"
409422
source (when (= :none (:optimizations opts :none))
410423
(:uri (build/ns->location main-ns)))
411424
repl? (boolean (#{"-r" "--repl"} (first args)))
425+
serve? (boolean (#{"-s" "--serve"} (first args)))
412426
cenv (env/default-compiler-env)]
413427
(if-let [path (:watch opts)]
414428
(if repl?
@@ -417,26 +431,15 @@ present"
417431
(build/build source opts cenv))
418432
(when repl?
419433
(repl-opt repl-env args
420-
(assoc-in cfg [:options :compiler-env] cenv)))))
434+
(assoc-in cfg [:options :compiler-env] cenv)))
435+
(when serve?
436+
(serve-opt repl-env args cfg))))
421437

422438
(defn- compile-opt
423439
[repl-env [_ ns & args] cfg]
424440
((::compile (repl/-repl-options (repl-env)) default-compile)
425441
repl-env (merge cfg {:args args :ns ns})))
426442

427-
(defn- serve-opt
428-
[_ [_ address-port & args] {:keys [options] :as cfg}]
429-
(let [[host port] (if address-port
430-
(string/split address-port #":")
431-
["localhost" 9000])]
432-
(require 'cljs.repl.browser)
433-
((ns-resolve 'cljs.repl.browser 'serve)
434-
{:host host
435-
:port (if port
436-
(cond-> port (string? port) Integer/parseInt)
437-
9000)
438-
:output-dir (:output-dir options "out")})))
439-
440443
(defn get-options [commands k]
441444
(if (= :all k)
442445
(into (get-options commands :main) (get-options commands :init))

0 commit comments

Comments
 (0)