Compare commits
2 Commits
3a6fd107c0
...
017291f784
| Author | SHA1 | Date | |
|---|---|---|---|
| 017291f784 | |||
| 17a7a09ab0 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,5 @@
|
|||||||
/.clj-kondo/
|
/.clj-kondo/
|
||||||
/.cpcache/
|
/**/.cpcache/
|
||||||
/.lsp/
|
/.lsp/
|
||||||
/target/
|
/target/
|
||||||
.nrepl-port
|
.nrepl-port
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ clj-totp.sh import <alias> "<url>"
|
|||||||
- [x] Native compilation script corrections
|
- [x] Native compilation script corrections
|
||||||
|
|
||||||
### v2
|
### v2
|
||||||
|
- [x] Restructurate as a multiproject
|
||||||
- [ ] REST API
|
- [ ] REST API
|
||||||
- [ ] User management
|
- [ ] User management
|
||||||
- [ ] Robust BD backend (H2, datomic, or similar)
|
- [ ] Robust BD backend (H2, datomic, or similar)
|
||||||
@@ -176,14 +177,14 @@ The first step is to install Java JDK, version 11 or newer (version 21 recommend
|
|||||||
|
|
||||||
To execute manually the main function, simple use the `:run` alias:
|
To execute manually the main function, simple use the `:run` alias:
|
||||||
|
|
||||||
```clojure
|
```bash
|
||||||
clojure -M:run <commands and parameters>
|
clojure -M:run/cli <commands and parameters>
|
||||||
```
|
```
|
||||||
|
|
||||||
To build the uberjar:
|
To build the uberjar:
|
||||||
|
|
||||||
```clojure
|
```bash
|
||||||
clojure -T:build uber
|
clojure -T:build :uber/cli
|
||||||
```
|
```
|
||||||
|
|
||||||
There is a utility script to build a native executable using Graal VM. Please, edit the script and
|
There is a utility script to build a native executable using Graal VM. Please, edit the script and
|
||||||
|
|||||||
121
build.clj
121
build.clj
@@ -1,62 +1,91 @@
|
|||||||
(ns build
|
(ns build
|
||||||
(:refer-clojure :exclude [test])
|
(:refer-clojure :exclude [test])
|
||||||
(:require [clojure.tools.build.api :as b]
|
(:require [clojure.tools.build.api :as b]
|
||||||
[clojure.java.io :as io]))
|
[clojure.java.io :as io]
|
||||||
|
[clojure.pprint :as pp]
|
||||||
|
[clojure.java.basis :as basis]))
|
||||||
|
|
||||||
(def lib-group "es.rcorral")
|
(def lib-group "es.rcorral")
|
||||||
(def artifact-prefix "clj-totp")
|
(def artifact-prefix "clj-totp")
|
||||||
|
(def subprojs-base "projects")
|
||||||
(def curr-version (format "2.0.%s" (b/git-count-revs nil)))
|
(def curr-version (format "2.0.%s" (b/git-count-revs nil)))
|
||||||
|
|
||||||
|
|
||||||
;; Builds artifact's full descriptor for each subproject
|
;; Builds artifact's full descriptor for each subproject
|
||||||
(defn lib [subproj]
|
(defn lib [subproj]
|
||||||
(symbol (str lib-group "/" artifact-prefix "-" subproj )))
|
(symbol (str lib-group "/" artifact-prefix "-" subproj )))
|
||||||
|
|
||||||
|
|
||||||
;; Basis for each subproject, using their own deps.edn
|
;; Basis for each subproject, using their own deps.edn
|
||||||
|
;; Injects :extra-deps from :build as additional dependencies
|
||||||
(defn basis [subproj]
|
(defn basis [subproj]
|
||||||
;(b/create-basis {:project (str subproj "/deps.edn")}))
|
(delay (b/create-basis {:project (str subprojs-base "/" subproj "/deps.edn")
|
||||||
(delay (b/create-basis {:project (str "projects/" subproj "/deps.edn")})))
|
;; Inject extra deps as deps
|
||||||
|
:extra {:deps (get-in (basis/initial-basis) [:aliases :build :extra-deps])}
|
||||||
|
})))
|
||||||
|
|
||||||
|
|
||||||
|
;; Show basis generated for a subproject
|
||||||
|
#_{:clojure-lsp/ignore [:clojure-lsp/unused-public-var]}
|
||||||
|
(defn show-basis [subproj]
|
||||||
|
(println (with-out-str
|
||||||
|
(pp/pprint
|
||||||
|
@(basis subproj)
|
||||||
|
;(basis/initial-basis)
|
||||||
|
))))
|
||||||
|
|
||||||
|
(comment
|
||||||
|
(pp/pprint (keys (basis/initial-basis)))
|
||||||
|
(pp/pprint (:deps (basis/initial-basis)))
|
||||||
|
(pp/pprint (:libs (basis/initial-basis)))
|
||||||
|
(pp/pprint (sort (keys (:aliases (basis/initial-basis)))))
|
||||||
|
(get-in (basis/initial-basis) [:aliases :build :extra-deps])
|
||||||
|
)
|
||||||
|
|
||||||
;; Target dir for each subproject
|
;; Target dir for each subproject
|
||||||
(defn target-dir [subproj]
|
(defn target-dir [subproj]
|
||||||
(str "target/" subproj))
|
(str "target/" subproj))
|
||||||
|
|
||||||
|
|
||||||
;; Path for compiled classes
|
;; Path for compiled classes
|
||||||
(defn class-dir [subproj]
|
(defn class-dir [subproj]
|
||||||
(str (target-dir subproj) "/" "classes"))
|
(str (target-dir subproj) "/" "classes"))
|
||||||
|
|
||||||
|
|
||||||
;; Jar file for each subproject. :uber type adds -standalone suffix
|
;; Jar file for each subproject. :uber type adds -standalone suffix
|
||||||
(defn jar-file [subproj version type]
|
(defn jar-file [subproj version type]
|
||||||
(format "target/%s-%s-%s%s.jar" artifact-prefix subproj version
|
(format "target/%s-%s-%s%s.jar" artifact-prefix subproj version
|
||||||
(if (= type :uber) "-standalone" "")))
|
(if (= type :uber) "-standalone" "")))
|
||||||
|
|
||||||
|
|
||||||
;; Clean target dir for subproject
|
;; Clean target dir for subproject
|
||||||
(defn clean [{:keys [subproj]}]
|
(defn clean [{:keys [subproj]}]
|
||||||
(b/delete {:path (target-dir subproj)})
|
(b/delete {:path (target-dir subproj)})
|
||||||
(println "Project" subproj "cleaned"))
|
(println "Project" subproj "cleaned"))
|
||||||
|
|
||||||
|
|
||||||
;; Compile java classes, only if java subdir exists
|
;; Compile java classes, only if java subdir exists
|
||||||
(defn compile-java [subproj]
|
(defn compile-java [subproj]
|
||||||
(let [java-dir (str "projects/" subproj "/java")]
|
(let [java-dir (str subprojs-base "/" subproj "/java")]
|
||||||
(if (.exists (io/file java-dir))
|
(when (.exists (io/file java-dir))
|
||||||
(do
|
(println "Compiling java code for" subproj)
|
||||||
(println "Compiling java code for" subproj)
|
(b/javac {:src-dirs [java-dir]
|
||||||
(b/javac {:src-dirs [java-dir]
|
:class-dir (class-dir subproj)
|
||||||
:class-dir (class-dir subproj)
|
:basis @(basis subproj)
|
||||||
:basis @(basis subproj)
|
:javac-opts ["-source" "11" "--target" "11" "-proc:none"]}))))
|
||||||
:javac-opts ["-source" "11" "--target" "11" "-proc:none"]}))
|
|
||||||
(println "No java code for" subproj ", skipping compilation"))))
|
|
||||||
|
|
||||||
;; Create a jar file
|
;; Create a jar file
|
||||||
(defn jar
|
(defn jar
|
||||||
"Build a simple jar file, with no dependencies included."
|
"Build a simple jar file, with no dependencies included."
|
||||||
[{:keys [subproj version]}]
|
[{:keys [subproj version]
|
||||||
(let [real-version (if version version curr-version)
|
:or {version curr-version}}]
|
||||||
target-dir (target-dir subproj)
|
(let [target-dir (target-dir subproj)
|
||||||
class-dir (class-dir subproj)
|
class-dir (class-dir subproj)
|
||||||
src-dir (str "projects/" subproj "/src")
|
src-dir (str subprojs-base "/" subproj "/src")
|
||||||
resources-dir (str "projects/" subproj "/resources")
|
resources-dir (str subprojs-base "/" subproj "/resources")
|
||||||
basis (basis subproj)
|
basis (basis subproj)
|
||||||
jar-file (jar-file subproj real-version :plain)]
|
jar-file (jar-file subproj version :plain)]
|
||||||
;; Clean only class dir
|
;; Clean only class dir
|
||||||
(b/delete {:path class-dir})
|
(b/delete {:path class-dir})
|
||||||
;; Copy code
|
;; Copy code
|
||||||
@@ -72,19 +101,23 @@
|
|||||||
:basis @basis
|
:basis @basis
|
||||||
:jar-file jar-file
|
:jar-file jar-file
|
||||||
:lib (lib subproj)
|
:lib (lib subproj)
|
||||||
:version real-version})
|
:version version})
|
||||||
(println "Generated jar file:" jar-file)))
|
(println "Generated jar file:" jar-file)))
|
||||||
|
|
||||||
|
|
||||||
;; Create an uber jar, with all dependencies inside
|
;; Create an uber jar, with all dependencies inside
|
||||||
|
#_{:clojure-lsp/ignore [:clojure-lsp/unused-public-var]}
|
||||||
(defn uber
|
(defn uber
|
||||||
"Build a uberjar with all dependencies included"
|
"Build a uberjar with all dependencies included"
|
||||||
[{:keys [subproj version main-ns]}]
|
[{:keys [subproj version main-ns]
|
||||||
(let [real-version (if version version curr-version)target-dir (target-dir subproj)
|
:or {version curr-version}}]
|
||||||
|
(let [target-dir (target-dir subproj)
|
||||||
basis (basis subproj)
|
basis (basis subproj)
|
||||||
class-dir (class-dir subproj)
|
class-dir (class-dir subproj)
|
||||||
src-dir (str "projects/" subproj "/src")
|
src-dir (str subprojs-base "/" subproj "/src")
|
||||||
resources-dir (str "projects/" subproj "/resources")
|
resources-dir (str subprojs-base "/" subproj "/resources")
|
||||||
uber-file (jar-file subproj real-version :uber)]
|
uber-file (jar-file subproj version :uber)]
|
||||||
|
;(println "Using basis: ")(show-basis subproj)
|
||||||
(b/delete {:path class-dir})
|
(b/delete {:path class-dir})
|
||||||
(b/copy-dir {:src-dirs [src-dir]
|
(b/copy-dir {:src-dirs [src-dir]
|
||||||
:target-dir class-dir})
|
:target-dir class-dir})
|
||||||
@@ -99,3 +132,43 @@
|
|||||||
:main main-ns})
|
:main main-ns})
|
||||||
(println "Generated uberjar executable:" uber-file)))
|
(println "Generated uberjar executable:" uber-file)))
|
||||||
|
|
||||||
|
|
||||||
|
;; Multimethod to get the name of all subdirs in a dir.
|
||||||
|
;; Accepts strings or files
|
||||||
|
(defmulti get-subdirs type)
|
||||||
|
|
||||||
|
(defmethod get-subdirs
|
||||||
|
java.lang.String [dir]
|
||||||
|
(get-subdirs (io/file dir)))
|
||||||
|
|
||||||
|
(defmethod get-subdirs
|
||||||
|
java.io.File [dir]
|
||||||
|
(if (.isDirectory dir)
|
||||||
|
(filter #(.isDirectory %) (.listFiles dir))
|
||||||
|
(println "Directory" subprojs-base "doesn't exists!")))
|
||||||
|
|
||||||
|
|
||||||
|
;; Get the name of all subdir in a given directory
|
||||||
|
(defn get-subdir-names
|
||||||
|
"Get a list projects in the 'projects' directory"
|
||||||
|
[dir-name]
|
||||||
|
(map #(.getName %) (get-subdirs dir-name)))
|
||||||
|
|
||||||
|
(comment
|
||||||
|
(get-subdirs "projects")
|
||||||
|
(get-subdirs (io/file "projects"))
|
||||||
|
(get-subdir-names "projects")
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
;; Generate jar files for all projects
|
||||||
|
(defn jar-all
|
||||||
|
"Build jar files for all projects"
|
||||||
|
[& {:keys [version]
|
||||||
|
:or {version curr-version}}]
|
||||||
|
(dorun (map #(jar {:subproj % :version version}) (get-subdir-names subprojs-base))))
|
||||||
|
|
||||||
|
(comment
|
||||||
|
(jar-all )
|
||||||
|
|
||||||
|
)
|
||||||
84
deps.edn
84
deps.edn
@@ -1,58 +1,60 @@
|
|||||||
{:paths ["src" "resources" "target/classes"]
|
{:paths ["src" "resources" "target/classes"]
|
||||||
:deps {org.clojure/clojure {:mvn/version "1.12.1"}
|
:deps {org.clojure/clojure {:mvn/version "1.12.1"}
|
||||||
;; Native image (GraalVM)
|
;; Native image (GraalVM). Tutorial: https://shagunagrawal.me/posts/setup-clojure-with-graalvm-for-native-image/
|
||||||
com.github.clj-easy/graal-build-time {:mvn/version "1.0.5"}}
|
com.github.clj-easy/graal-build-time {:mvn/version "1.0.5"}
|
||||||
|
;; Local subprojects
|
||||||
|
clj-totp/core {:local/root "projects/core"}
|
||||||
|
clj-totp/cli {:local/root "projects/cli"}
|
||||||
|
clj-totp/web {:local/root "projects/web"}
|
||||||
|
}
|
||||||
|
|
||||||
:aliases {;; Execute the app. Tutorial: https://shagunagrawal.me/posts/setup-clojure-with-graalvm-for-native-image/
|
:aliases {;; Execute the app.
|
||||||
:run {:main-opts ["-m" "totp.app"]}
|
:run {:main-opts ["-m" "totp.app"]}
|
||||||
|
;:run {:exec-fn totp.app/-main}
|
||||||
|
|
||||||
|
;; Execute the app (prepared for more subprojects)
|
||||||
|
:run/cli {:main-opts ["-m" "totp.app"]}
|
||||||
|
;:run {:exec-fn totp.app/-main}
|
||||||
|
|
||||||
;; Kaocha runner. You can use the 'kaocha' wrapper located in ~/bin/kaocha
|
;; Kaocha runner. You can use the 'kaocha' wrapper located in ~/bin/kaocha
|
||||||
:test {:extra-paths ["test"]
|
;; Check test.edn for kaocha runner's config
|
||||||
:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}
|
:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}
|
||||||
|
lambdaisland/kaocha-cloverage {:mvn/version "1.1.89"}}
|
||||||
:main-opts ["-m" "kaocha.runner"]}
|
:main-opts ["-m" "kaocha.runner"]}
|
||||||
|
|
||||||
;; Run with clj -T:build function-in-build
|
;; Run with clj -T:build function-in-build
|
||||||
:build {:deps {io.github.clojure/tools.build {:mvn/version "0.10.10"}}
|
:build {:deps {io.github.clojure/tools.build {:mvn/version "0.10.10"}}
|
||||||
|
;; Used by all compilations
|
||||||
|
:extra-deps {clj-totp/core {:local/root "projects/core"}}
|
||||||
:ns-default build}
|
:ns-default build}
|
||||||
|
|
||||||
|
;; Aliases for easy building
|
||||||
;; COMMON ALIASES FOR ALL PROJECTS
|
:build/core {:deps {io.github.clojure/tools.build {:mvn/version "0.10.10"}}
|
||||||
:root/run-x {:exec-fn -main}
|
|
||||||
:root/extra-paths [:totp.core/extra-paths
|
|
||||||
:totp.cli/extra-paths
|
|
||||||
:totp.web/extra-paths]
|
|
||||||
|
|
||||||
:root/all {:extra-paths ["src" "resources"
|
|
||||||
:root/extra-paths]}
|
|
||||||
|
|
||||||
:root/test {:extra-paths ["test"]
|
|
||||||
:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}
|
|
||||||
:main-opts ["-m" "kaocha.runner"]}
|
|
||||||
|
|
||||||
:boot/build {:extra-paths ["build"]
|
|
||||||
:deps {io.github.clojure/tools.build {:mvn/version "0.10.10"}}
|
|
||||||
:ns-default build
|
:ns-default build
|
||||||
;:exec-fn ci
|
:exec-fn jar
|
||||||
;:exec-args {:app-alias :com.example.core}
|
:exec-args {:subproj "core"}}
|
||||||
}
|
|
||||||
|
|
||||||
:totp.core/extra-paths ["projects/core/src"
|
:build/cli {:deps {io.github.clojure/tools.build {:mvn/version "0.10.10"}
|
||||||
"projects/core/test"
|
clj-totp/core {:local/root "projects/core"}}
|
||||||
"projects/core/java"
|
:ns-default build
|
||||||
"projects/core/resources"]
|
:exec-fn jar
|
||||||
:totp.core {:ns-default totp.core
|
:exec-args {:subproj "cli"}}
|
||||||
:main-opts ["-m" "totp.core"]
|
|
||||||
:extra-deps {projects/core {:local/root "projects/core"}}
|
|
||||||
:exec-args {:dirs ["projects/core"]}}
|
|
||||||
|
|
||||||
|
:build/web {:deps {io.github.clojure/tools.build {:mvn/version "0.10.10"}}
|
||||||
|
:replace-deps {clj-totp/core {:local/root "projects/core"}}
|
||||||
|
:ns-default build
|
||||||
|
:exec-fn jar
|
||||||
|
:exec-args {:subproj "web"}}
|
||||||
|
|
||||||
:totp.cli/extra-paths ["projects/app/src"]
|
;; Build the three libraries
|
||||||
:totp.cli {:ns-default totp.cli
|
:build/all {:deps {io.github.clojure/tools.build {:mvn/version "0.10.10"}}
|
||||||
:main-opts ["-m" "totp.cli"]
|
:replace-deps {clj-totp/core {:local/root "projects/core"}}
|
||||||
:extra-deps {;; does not use parts/grugstack {:local/root "parts"}
|
:ns-default build
|
||||||
projects/cli {:local/root "projects/cli"}}
|
:exec-fn jar-all}
|
||||||
:exec-args {:dirs ["projects/cli"]}}
|
|
||||||
|
|
||||||
:totp.web/extra-paths ["projects/web/src"]
|
;; Build uber jar for CLI app
|
||||||
}}
|
:uber/cli {:deps {io.github.clojure/tools.build {:mvn/version "0.10.10"}}
|
||||||
|
:ns-default build
|
||||||
|
:exec-fn uber
|
||||||
|
:exec-args {:subproj "cli" :main-ns "totp.app"}}}}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
{:paths ["src" "resources" "target/classes"]
|
{:paths ["src" "resources" "target/classes"]
|
||||||
:deps {clj-totp/core {:local/root "projects/core"}
|
:deps {;clj-totp/core {:local/root "../core"}
|
||||||
org.clojure/clojure {:mvn/version "1.12.1"}
|
org.clojure/clojure {:mvn/version "1.12.1"}
|
||||||
io.github.clojure/tools.build {:mvn/version "0.10.10"}
|
|
||||||
cli-matic/cli-matic {:mvn/version "0.5.4"} ;; https://github.com/l3nz/cli-matic
|
cli-matic/cli-matic {:mvn/version "0.5.4"} ;; https://github.com/l3nz/cli-matic
|
||||||
;; Progress bar
|
;; Progress bar
|
||||||
com.github.pmonks/spinner {:mvn/version "2.0.284"}}
|
com.github.pmonks/spinner {:mvn/version "2.0.284"}}
|
||||||
|
|
||||||
:aliases {;; Execute the app
|
:aliases {;; Execute the app
|
||||||
:run {:main-opts ["-m" "totp.app"]}
|
;:run {:main-opts ["-m" "totp.app"]}
|
||||||
|
|
||||||
;; Kaocha runner. You can use the 'kaocha' wrapper located in ~/bin/kaocha
|
;; Kaocha runner. You can use the 'kaocha' wrapper located in ~/bin/kaocha
|
||||||
:test {:extra-paths ["test"]
|
:test {:extra-paths ["test"]
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
{:paths ["src" "resources" "target/classes"]
|
{:paths ["src" "resources" "target/classes"]
|
||||||
:deps {org.clojure/clojure {:mvn/version "1.12.1"}
|
:deps {org.clojure/clojure {:mvn/version "1.12.1"}
|
||||||
io.github.clojure/tools.build {:mvn/version "0.10.10"}
|
|
||||||
mvxcvi/alphabase {:mvn/version "3.0.185"} ;; https://github.com/greglook/alphabase
|
mvxcvi/alphabase {:mvn/version "3.0.185"} ;; https://github.com/greglook/alphabase
|
||||||
cli-matic/cli-matic {:mvn/version "0.5.4"} ;; https://github.com/l3nz/cli-matic
|
|
||||||
;; Protobuf for java
|
;; Protobuf for java
|
||||||
com.google.protobuf/protobuf-java {:mvn/version "3.25.8"}
|
com.google.protobuf/protobuf-java {:mvn/version "3.25.8"}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
{:paths ["src" "resources" "target/classes"]
|
{:paths ["src" "resources" "target/classes"]
|
||||||
:deps {clj-totp/core {:local/root "projects/core"}
|
:deps {;clj-totp/core {:local/root "../core"}
|
||||||
org.clojure/clojure {:mvn/version "1.12.1"}
|
org.clojure/clojure {:mvn/version "1.12.1"}
|
||||||
io.github.clojure/tools.build {:mvn/version "0.10.10"}
|
|
||||||
;; For SQLite
|
;; For SQLite
|
||||||
com.github.seancorfield/next.jdbc {:mvn/version "1.3.1048"}
|
com.github.seancorfield/next.jdbc {:mvn/version "1.3.1048"}
|
||||||
org.xerial/sqlite-jdbc {:mvn/version "3.50.3.0"}
|
org.xerial/sqlite-jdbc {:mvn/version "3.50.3.0"}
|
||||||
@@ -10,7 +9,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
:aliases {;; Execute the app
|
:aliases {;; Execute the app
|
||||||
:run {:main-opts ["-m" "totp.app"]}
|
;:run {:main-opts ["-m" "totp.app"]}
|
||||||
|
|
||||||
;; Kaocha runner. You can use the 'kaocha' wrapper located in ~/bin/kaocha
|
;; Kaocha runner. You can use the 'kaocha' wrapper located in ~/bin/kaocha
|
||||||
:test {:extra-paths ["test"]
|
:test {:extra-paths ["test"]
|
||||||
|
|||||||
@@ -1 +1,6 @@
|
|||||||
#kaocha/v1 {}
|
#kaocha/v1
|
||||||
|
{:tests [{:test-paths ["projects/core/src" "projects/core/test"]}]
|
||||||
|
:plugins [:kaocha.plugin/cloverage]
|
||||||
|
:cloverage/opts {:src-ns-path ["projects/core/src" "projects/core/test"]
|
||||||
|
:ns-regex ["totp\\..*(?<!test)$"] ;; All starting with "totp" but not ending by "test"
|
||||||
|
}}
|
||||||
Reference in New Issue
Block a user