forked from ClojureFinland/ClojureFinland.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev.clj
52 lines (39 loc) · 1.41 KB
/
dev.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(ns dev
(:require [ClojureFinland.core :as clojure-finland]
[watcher]
[server]))
(def html-src-dir "./src/ClojureFinland/html")
(def css-src-dir "./src/ClojureFinland/css")
(defn toggle-auto-refresh! []
(swap! clojure-finland/config update :dev not)
(clojure-finland/build!)
(let [state (if (:dev @clojure-finland/config) "ON" "OFF")]
(println "Auto-refresh is now" state)
(when (:dev @clojure-finland/config)
(println "Please refresh the page once for the change to take effect."))
state))
(def config @clojure-finland/config)
;; Dev server config
(def port 8889)
(def serve-dir "./dist")
(comment
;; Trigger build manually
(clojure-finland/build!)
;; Start watching html source changes
(watcher/start! :html html-src-dir (fn [fpath]
(load-file fpath) ;load changes to repl
(clojure-finland/build-html!)))
;; Start watching css source changes
(watcher/start! :css css-src-dir (fn [fpath]
(load-file fpath) ;load changes to repl
(clojure-finland/build-css!)))
;; Toggle browser auto-refresh every 1 second
(toggle-auto-refresh!)
;; Stop watchers
(watcher/stop! :html)
(watcher/stop! :css)
;; Start http server
(server/start! {:port port :root serve-dir})
;; Stop http server
(server/stop!)
)