@@ -381,6 +381,19 @@ present"
381
381
*out* log-out]
382
382
(build/watch path (dissoc opts :watch ) cenv)))))
383
383
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
+
384
397
(defn default-compile
385
398
[repl-env {:keys [ns args options] :as cfg}]
386
399
(let [env-opts (repl/repl-options (repl-env ))
@@ -409,6 +422,7 @@ present"
409
422
source (when (= :none (:optimizations opts :none ))
410
423
(:uri (build/ns->location main-ns)))
411
424
repl? (boolean (#{" -r" " --repl" } (first args)))
425
+ serve? (boolean (#{" -s" " --serve" } (first args)))
412
426
cenv (env/default-compiler-env )]
413
427
(if-let [path (:watch opts)]
414
428
(if repl?
@@ -417,26 +431,15 @@ present"
417
431
(build/build source opts cenv))
418
432
(when repl?
419
433
(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))))
421
437
422
438
(defn- compile-opt
423
439
[repl-env [_ ns & args] cfg]
424
440
((::compile (repl/-repl-options (repl-env )) default-compile )
425
441
repl-env (merge cfg {:args args :ns ns })))
426
442
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
-
440
443
(defn get-options [commands k]
441
444
(if (= :all k)
442
445
(into (get-options commands :main ) (get-options commands :init ))
0 commit comments