-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.clj
50 lines (41 loc) · 1.72 KB
/
build.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
(require '[cljs.build.api :as api])
(def source-dir "src")
(def compiler-config {:main 'my-app.core
:output-to "target/my-app/main.js"
:output-dir "target/my-app/main"
:target :nodejs
:optimizations :simple
:source-map "target/my-app/main.js.map"})
(defn try-require [ns-sym]
(try (require ns-sym) true (catch Exception e false)))
(defmacro with-namespaces
[namespaces & body]
(if (every? try-require namespaces)
`(do ~@body)
`(println "task not available - required dependencies not found")))
(defmulti task first)
(defmethod task "compile"
[args]
(api/build source-dir compiler-config))
(defmethod task "figwheel"
[[_ port]]
(with-namespaces [figwheel-sidecar.repl-api]
(figwheel-sidecar.repl-api/start-figwheel!
{:figwheel-options (when port
{:nrepl-port (some-> port Long/parseLong)
:nrepl-middleware ["cider.nrepl/cider-middleware"
"refactor-nrepl.middleware/wrap-refactor"
"cmeric.piggieback/wrap-cljs-repl"]})
:all-builds [{:id "dev"
:figwheel true
:source-paths [source-dir]
:compiler dev-config}]})
(when-not port
(figwheel-sidecar.repl-api/cljs-repl))))
(defmethod task :default
[args]
(let [all-tasks (-> task methods (dissoc :default) keys sort)
interposed (->> all-tasks (interpose ", ") (apply str))]
(println "Unknown or missing task. Choose one of: " interposed)
(System/exit 1)))
(task *command-line-args*)