-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.clj
More file actions
165 lines (148 loc) · 4.76 KB
/
build.clj
File metadata and controls
165 lines (148 loc) · 4.76 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
(ns build
(:require
[clojure.java.io :as io]
[clojure.java.shell :refer [sh]]
[clojure.pprint :refer [pprint]]
[clojure.string :as str]
[clojure.tools.build.api :as b]
[cognitect.aws.client.api :as aws]
[deps-deploy.deps-deploy :as dd]))
(def lib 'neyho/eywa)
(def class-dir "target/classes")
(def basis
(b/create-basis
{:project "deps.edn"
:aliases [:prod]}))
(def version
(let [{:keys [out err]} (sh "clj" "-M" "-e" "(require '[neyho.eywa.core])(require '[patcho.patch :as patch]) (println (patch/version :eywa/core))")
version (str/trim (last (str/split-lines (some not-empty [out err]))))]
(when (empty? version)
(throw
(ex-info "Couldn't resolve version"
{:command "clj -M -m neyho.eywa.core version"})))
version))
(def uber-file (format "target/%s.jar" version))
(println "UBER FILE: " uber-file)
(defn clean [_]
(b/delete {:path "target"}))
(def exclude-uber-basis-pattern #"src.*$")
(def uber-basis
(update basis :libs
(fn [libs]
(reduce-kv
(fn [libs lib context]
(if (contains? context :local/root)
(update-in libs [lib :paths]
(fn [paths]
(vec
(remove
(fn [path]
(re-find exclude-uber-basis-pattern path))
paths))))
libs))
libs
libs))))
(defn compile-backend
[& _]
(println "Compiling backend")
(b/compile-clj
{:basis basis
:src-dirs ["src/clj" "resources" "src/prod"]
:ns-compile ['neyho.eywa.core]
:class-dir class-dir})
(b/copy-dir
{:src-dirs ["resources"]
:target-dir class-dir})
(b/copy-file
{:src "src/prod/logback.xml"
:target (str class-dir "/logback.xml")}))
(defn copy-frontend
[& _]
(b/process
{:command-args ["clj" "-X:css"]})
#_(b/copy-dir
{:src-dirs ["frontend/dist/graphiql"]
:target-dir (str class-dir "/graphiql")})
#_(b/copy-dir
{:src-dirs ["frontend/dist/eywa"]
:target-dir (str class-dir "/eywa")})
(b/copy-dir
{:src-dirs ["frontend/dist/oauth"]
:target-dir (str class-dir "/oauth")}))
(defn uber [& _]
(println "Creating uberjar file")
(b/uber
{:class-dir class-dir
:uber-file uber-file
:main 'neyho.eywa.core
:manifest {"Application-Name" "EYWA"}
;; Exclude source code
:basis uber-basis}))
(defn docs
[& _]
(b/delete {:path "../docs/eywa"})
(b/process
{:command-args ["npm" "run" "build"]
:dir "../docs"})
(b/copy-dir
{:src-dirs ["../docs/eywa/docs"]
:target-dir "target/classes/eywa/docs"}))
(defn release
[& _]
(println "Cleaning: " class-dir)
(clean nil)
(println "Writting pom.xml")
(b/write-pom {:class-dir class-dir
:lib lib
:version version
:basis basis
:src-dirs ["src/clj" "src/prod"]})
(compile-backend)
(copy-frontend)
; (docs)
(uber))
(defn upload [& _]
(let [s3 (aws/client {:api :s3})
s3-path (str version ".jar")
bucket "eywa.core"]
(println (format "Uploading file: %s to S3: %s:%s" uber-file bucket s3-path))
(with-open [file (io/input-stream (io/file uber-file))]
(pprint
(aws/invoke
s3 {:op :PutObject
:request {:ACL "public-read"
:Bucket bucket
:Key s3-path
:Body file}})))))
(defn all [& _]
(release nil)
(upload nil))
;; Clojars deployment
(def clojars-lib 'org.neyho/eywa-core)
(def jar-file (format "target/%s-%s.jar" (name clojars-lib) version))
(defn jar
"Build a thin JAR for Clojars (source only, no AOT)"
[_]
(println "Building JAR for Clojars:" jar-file)
(b/delete {:path "target"})
(b/write-pom {:class-dir class-dir
:lib clojars-lib
:version version
:basis basis
:src-dirs ["src/clj"]
:scm {:url "https://github.com/neyho/eywa-core"
:connection "scm:git:git://github.com/neyho/eywa-core.git"
:developerConnection "scm:git:ssh://git@github.com/neyho/eywa-core.git"
:tag (str "v" version)}})
(b/copy-dir {:src-dirs ["src/clj" "resources"]
:target-dir class-dir})
(b/jar {:class-dir class-dir
:jar-file jar-file}))
(defn deploy
"Deploy to Clojars. Requires CLOJARS_USERNAME and CLOJARS_PASSWORD env vars."
[_]
(jar nil)
(println "Deploying to Clojars:" clojars-lib version)
(dd/deploy {:installer :remote
:artifact jar-file
:pom-file (b/pom-path {:lib clojars-lib :class-dir class-dir})}))