File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -404,6 +404,19 @@ present"
404
404
((::compile (repl/-repl-options (repl-env )) default-compile )
405
405
repl-env (merge cfg {:args args :ns ns })))
406
406
407
+ (defn- serve-opt
408
+ [_ [_ address-port & args] {:keys [options] :as cfg}]
409
+ (let [[host port] (if address-port
410
+ (string/split address-port #":" )
411
+ [" localhost" 9000 ])]
412
+ (require 'cljs.repl.browser)
413
+ ((ns-resolve 'cljs.repl.browser 'serve)
414
+ {:host host
415
+ :port (if port
416
+ (cond-> port (string? port) Integer/parseInt)
417
+ 9000 )
418
+ :output-dir (:output-dir options " out" )})))
419
+
407
420
(defn get-options [commands k]
408
421
(if (= :all k)
409
422
(into (get-options commands :main ) (get-options commands :init ))
@@ -493,6 +506,9 @@ present"
493
506
:arg " ns"
494
507
:doc (str " Compile a namespace. If -r / --repl present after "
495
508
" namespace will launch a REPL after the compile completes" )}
509
+ [" -s" " --serve" ] {:fn serve-opt
510
+ :arg " host:port"
511
+ :doc (str " Start a simple web server to serve the current directory" )}
496
512
[nil ] {:fn null-opt}
497
513
[" -h" " --help" " -?" ] {:fn help-opt
498
514
:doc " Print this help message and exit" }}}))
Original file line number Diff line number Diff line change 275
275
[repl-env provides url]
276
276
(browser-eval (slurp url)))
277
277
278
+ (defn serve [{:keys [host port output-dir] :as opts}]
279
+ (println " Serving HTTP on" host " port" port)
280
+ (binding [ordering (agent {:expecting nil :fns {}})
281
+ es (Executors/newFixedThreadPool 16 )
282
+ server/state (atom {:socket nil :connection nil :promised-conn nil })]
283
+ (server/start
284
+ (merge opts
285
+ {:static-dir (cond-> [" ." " out/" ] output-dir (conj output-dir))}))))
286
+
278
287
; ; =============================================================================
279
288
; ; BrowserEnv
280
289
360
369
:launch-browser true
361
370
:working-dir (->> [" .repl" (util/clojurescript-version )]
362
371
(remove empty?) (string/join " -" ))
363
- :serve-static true
364
372
:static-dir (cond-> [" ." " out/" ] output-dir (conj output-dir))
365
373
:preloaded-libs []
366
374
:src " src/"
367
375
:browser-state (atom {:return-value-fn nil
368
- :client-js nil })
376
+ :client-js nil })
369
377
:ordering (agent {:expecting nil :fns {}})
370
378
:es (Executors/newFixedThreadPool 16 )
371
379
:server-state
386
394
working-dir: The directory where the compiled REPL client JavaScript will
387
395
be stored. Defaults to \" .repl\" with a ClojureScript version
388
396
suffix, eg. \" .repl-0.0-2138\" .
389
- serve-static: Should the REPL server attempt to serve static content?
390
- Defaults to true.
391
397
static-dir: List of directories to search for static content. Defaults to
392
398
[\" .\" \" out/\" ].
393
399
src: The source directory containing user-defined cljs files. Used to
You can’t perform that action at this time.
0 commit comments