-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.clj
109 lines (96 loc) · 3.07 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
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
(ns build
"tools.build declarations for the leva.cljs library."
(:require [clojure.data.xml :as xml]
[clojure.tools.build.api :as b]
[clojure.tools.build.tasks.write-pom :as write-pom]))
(xml/alias-uri 'pom "http://maven.apache.org/POM/4.0.0")
(alter-var-root
#'write-pom/to-dep
(fn [old]
(fn [[_ {:keys [mvn/scope]} :as pair]]
(cond-> (old pair)
scope
(conj [::pom/scope scope])))))
;; ## Variables
(def lib 'org.mentat/leva.cljs)
(def version "0.3.0")
(def pom-deps
{'org.babashka/sci
{:mvn/version "0.6.37"
:mvn/scope "provided"}})
(defn- ->version
([] version)
([suffix]
(if suffix
(format "%s-%s" version suffix)
version)))
;; source for jar creation.
(def class-dir "target/classes")
(def basis
(b/create-basis
{:project "deps.edn"
:extra {:deps pom-deps}}))
(defn ->jar-file [version]
(format "target/%s-%s.jar" (name lib) version))
;; ## Tasks
(defn clean [opts]
(println "\nCleaning target...")
(b/delete {:path "target"})
opts)
(defn jar
"Builds a jar containing all library code and
Optionally supply a string via `:version-suffix` to append `-<suffix>` to the
generated version."
[{:keys [version-suffix] :as opts}]
(let [version (->version version-suffix)
jar-file (->jar-file version)]
(b/write-pom
{:class-dir class-dir
:lib lib
:version version
:scm
{:tag (str "v" version)
:connection "scm:git:git://github.com/mentat-collective/leva.cljs.git"
:developConnection "scm:git:ssh://[email protected]/mentat-collective/leva.cljs.git"
:url "https://github.com/mentat-collective/leva.cljs"}
:basis basis
:src-pom "template/pom.xml"
:src-dirs ["src"]})
(doseq [f ["README.md" "LICENSE" "deps.edn"]]
(b/copy-file {:src f :target (format "%s/%s" class-dir f)}))
(b/copy-dir {:src-dirs ["src"]
:target-dir class-dir})
(b/jar {:class-dir class-dir
:jar-file jar-file})
(println (str "Created " jar-file "."))
(assoc opts
:jar-file jar-file
:built-jar-version version)))
(defn install
"Clean, generate a jar and install the jar into the local Maven repository."
[opts]
(clean opts)
(let [{:keys [built-jar-version jar-file]} (jar opts)]
(b/install {:class-dir class-dir
:lib lib
:version built-jar-version
:basis basis
:jar-file jar-file})
(println (str "Installed " jar-file " to local Maven repository."))
opts))
(defn publish
"Generates a jar with all project sources and resources and publishes it to
Clojars."
[opts]
(clean opts)
(let [{:keys [jar-file]} (jar opts)]
(println (str "Publishing " jar-file " to Clojars!"))
((requiring-resolve 'deps-deploy.deps-deploy/deploy)
(merge {:installer :remote
:sign-releases? false
:artifact jar-file
:pom-file (b/pom-path {:lib lib :class-dir class-dir})}
opts))
;; TODO put a catch here if the version already exists?
(println "Published.")
opts))