-
Notifications
You must be signed in to change notification settings - Fork 1
/
prod.clj
79 lines (71 loc) · 2.61 KB
/
prod.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
(defmulti task first)
(defmethod task :default
[[task-name]]
(println "Unknown task:" task-name)
(System/exit 1))
(require
'[cljs.build.api :as api]
'[clojure.java.io :as io]
'[clojure.string :as str]
'[leiningen.core.project :as p :refer [defproject]]
'[leiningen.clean :refer [clean]]
'[leiningen.uberjar :refer [uberjar]])
(defn read-project-clj []
(p/ensure-dynamic-classloader)
(-> "project.clj" load-file var-get))
(defn read-deps-edn [aliases-to-include]
(let [{:keys [paths deps aliases]} (-> "deps.edn" slurp clojure.edn/read-string)
deps (->> (select-keys aliases aliases-to-include)
vals
(mapcat :extra-deps)
(into deps)
(map (fn parse-coord [coord]
(let [[artifact info] coord
s (str artifact)]
(if-let [i (str/index-of s "$")]
[(symbol (subs s 0 i))
(assoc info :classifier (subs s (inc i)))]
coord))))
(reduce
(fn [deps [artifact info]]
(if-let [version (:mvn/version info)]
(conj deps
(transduce cat conj [artifact version]
(select-keys info [:exclusions :classifier])))
deps))
[]))
paths (->> (select-keys aliases aliases-to-include)
vals
(mapcat :extra-paths)
(into paths))]
{:dependencies deps
:source-paths []
:resource-paths paths}))
(defn delete-children-recursively! [f]
(when (.isDirectory f)
(doseq [f2 (.listFiles f)]
(delete-children-recursively! f2)))
(when (.exists f) (io/delete-file f)))
(defmethod task nil
[_]
(require 'snake.start)
(let [out-file "resources/public/main.js"
out-dir "resources/public/main.out"]
(println "Building main.js")
(delete-children-recursively! (io/file out-dir))
(api/build "src" {:main 'snake.start
:optimizations :advanced
:output-to out-file
:output-dir out-dir})
(delete-children-recursively! (io/file out-dir))
(println "Build complete:" out-file)
(System/exit 0)))
(defmethod task "uberjar"
[_]
(let [project (-> (read-project-clj)
(merge (read-deps-edn [:play-cljc]))
p/init-project)]
(clean project)
(uberjar project)
(System/exit 0)))
(task *command-line-args*)