-
Notifications
You must be signed in to change notification settings - Fork 16
/
tools.clj
112 lines (98 loc) · 3.49 KB
/
tools.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
(require '[clojure.java.shell :as shell]
'[clojure.main])
(require '[rebel-readline.core]
'[rebel-readline.clojure.main]
'[rebel-readline.clojure.line-reader]
'[rebel-readline.clojure.service.local]
'[rebel-readline.cljs.service.local]
'[rebel-readline.cljs.repl]
'[eftest.runner :as ef])
(require '[cljs.build.api :as api]
'[cljs.repl :as repl]
'[cljs.repl.node :as node])
(defmulti task first)
(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)))
(defmethod task "repl"
[[_ type]]
(case type
(nil "clj")
(rebel-readline.core/with-line-reader
(rebel-readline.clojure.line-reader/create
(rebel-readline.clojure.service.local/create))
(clojure.main/repl
:prompt (fn []) ;; prompt is handled by line-reader
:read (rebel-readline.clojure.main/create-repl-read)))
"node"
(rebel-readline.core/with-line-reader
(rebel-readline.clojure.line-reader/create (rebel-readline.cljs.service.local/create))
(cljs.repl/repl
(node/repl-env)
:prompt (fn []) ;; prompt is handled by line-reader
:read (rebel-readline.cljs.repl/create-repl-read)
:output-dir "out"
:cache-analysis false))
(println "Unknown repl: " type)
(System/exit 1)))
(def options
{:main 'struct.tests
:output-to "out/tests.js"
:output-dir "out/tests"
:target :nodejs
:pretty-print true
:optimizations :advanced
:language-in :ecmascript5
:language-out :ecmascript5
:verbose true})
(defmethod task "test"
[[_ exclude]]
(let [tests (ef/find-tests "test")
tests (if (string? exclude)
(ef/find-tests (symbol exclude))
tests)]
(ef/run-tests tests
{:fail-fast? true
:capture-output? false
:multithread? false})
(System/exit 1)))
(defmethod task "test-cljs"
[[_ type]]
(letfn [(build [optimizations]
(api/build (api/inputs "src" "test")
(cond-> (assoc options :optimizations optimizations)
(= optimizations :none) (assoc :source-map true))))
(run-tests []
(let [{:keys [out err]} (shell/sh "node" "out/tests.js")]
(println out err)))
(test-once []
(build :none)
(run-tests)
(shutdown-agents))
(test-watch []
(println "Start watch loop...")
(try
(api/watch (api/inputs "src", "test")
(assoc options
:parallel-build false
:watch-fn run-tests
:cache-analysis false
:optimizations :none
:source-map true))
(catch Exception e
(println "ERROR:" e)
(Thread/sleep 2000)
(test-watch))))]
(case type
(nil "once") (test-once)
"watch" (test-watch)
"build-none" (build :none)
"build-simple" (build :simple)
"build-advanced" (build :advanced)
(do (println "Unknown argument to test task:" type)
(System/exit 1)))))
;;; Build script entrypoint. This should be the last expression.
(task *command-line-args*)