From b9ff6eb8c13a409760d857472304cf0899c5b992 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Mon, 1 May 2023 18:43:09 +0200 Subject: [PATCH] wip --- bb.edn | 10 ++++-- build/deps.edn | 1 + build/src/scittle/build.clj | 69 +++++++++++++++++++++++++++++++++++++ deps.edn | 3 +- 4 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 build/deps.edn create mode 100644 build/src/scittle/build.clj diff --git a/bb.edn b/bb.edn index 802138b..9fd5a70 100644 --- a/bb.edn +++ b/bb.edn @@ -2,10 +2,13 @@ #_{:local/root "../sci.nrepl"} {:git/sha "2f8a9ed2d39a1b09d2b4d34d95494b56468f4a23"} io.github.babashka/http-server - {:git/sha "b38c1f16ad2c618adae2c3b102a5520c261a7dd3"}} + {:git/sha "b38c1f16ad2c618adae2c3b102a5520c261a7dd3"} + io.github.scittle/build + {:local/root "build"}} :tasks - {:requires ([babashka.fs :as fs] + {:requires ([scittle.build :as build] + [babashka.fs :as fs] [cheshire.core :as json] [babashka.process :as p :refer [process]]) @@ -34,7 +37,8 @@ (deref (promise)))} prod {:doc "Builds production artifacts." - :task (clojure {:extra-env {"SCI_ELIDE_VARS" "true"}} + :task (build/release *command-line-args* #_{:wrap-cmd-fn nil #_wrap-cmd}) + #_(clojure {:extra-env {"SCI_ELIDE_VARS" "true"}} "-M:dev -m shadow.cljs.devtools.cli release main")} dist {:doc "Prepare dist folder for npm package" diff --git a/build/deps.edn b/build/deps.edn new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/build/deps.edn @@ -0,0 +1 @@ +{} diff --git a/build/src/scittle/build.clj b/build/src/scittle/build.clj new file mode 100644 index 0000000..49c42ff --- /dev/null +++ b/build/src/scittle/build.clj @@ -0,0 +1,69 @@ +(ns scittle.build + "Provides bb tasks for building and releasing scittle" + (:require + [babashka.classpath :as classpath] + [babashka.fs :as fs] + [babashka.tasks :refer [clojure]] + [clojure.edn :as edn] + [clojure.string :as str])) + +(defn- feature-files + [] + (filter fs/exists? + (map (fn [d] + (fs/file d "scittle_features.edn")) + (classpath/split-classpath (classpath/get-classpath))))) + +(defn- read-configs + [files] + (->> files + (mapcat (comp edn/read-string slurp str)))) + +(defn- build-cmd [cmd scittle-dir] + (let [files (feature-files) + feature-configs (read-configs files) + ;; Each ./src/scittle_features.edn has a ./deps.edn + feature-dirs (map (comp fs/parent fs/parent) files) + cmd' (if (seq files) + (format "-Sdeps '%s' %s" + {:deps + (merge (into {} + (map (fn [dir] + [(symbol (str (fs/file-name dir) "/deps")) + {:local/root (str dir)}]) + feature-dirs)) + {'scittle/deps {:local/root scittle-dir}})} + cmd) + cmd)] + (when (seq feature-configs) + (println "Building features:" (str/join ", " (map :name feature-configs)) "...")) + (if (seq feature-configs) + (apply str cmd' + (map (fn [m] (format " --config-merge '%s'" (pr-str (:shadow-config m)))) + feature-configs)) + cmd'))) + +(defn build + "Build scittle shadow builds using clojure cmd and commandline args. Features on + classpath are automatically added" + [cmd args] + (let [building-outside-scittle? (not (fs/exists? "shadow-cljs.edn")) + scittle-dir (when building-outside-scittle? + (->> (classpath/get-classpath) + classpath/split-classpath + ;; Pull out scittle from local/root or git/url + (some #(when (re-find #"(scittle/[0-9a-f]+|scittle)/src" %) %)) + fs/parent))] + (when building-outside-scittle? + (fs/copy (fs/file scittle-dir "shadow-cljs.edn") "shadow-cljs.edn")) + (apply clojure {:extra-env {"SCI_ELIDE_VARS" "true"}} + (build-cmd cmd (str scittle-dir)) args) + (when building-outside-scittle? + (fs/delete "shadow-cljs.edn")))) + +(defn release + "Compiles release build." + [args & {:keys [wrap-cmd-fn] :or {wrap-cmd-fn identity}}] + (build (wrap-cmd-fn "-M -m shadow.cljs.devtools.cli --force-spawn release main") + args) + (run! fs/delete (fs/glob "lib" "**.map"))) diff --git a/deps.edn b/deps.edn index 58efc55..45092d5 100644 --- a/deps.edn +++ b/deps.edn @@ -2,6 +2,7 @@ :deps {org.clojure/clojure {:mvn/version "1.11.1"} + thheller/shadow-cljs {:mvn/version "2.20.15"} org.babashka/sci {:git/url "https://github.com/babashka/sci" :git/sha "a85c488ee45700bcbe67bc01ab1c27407fff7887"} #_{:local/root "../babashka/sci"} @@ -23,4 +24,4 @@ :aliases {:dev {:extra-paths ["dev"] - :extra-deps {thheller/shadow-cljs {:mvn/version "2.20.15"}}}}} + :extra-deps {}}}}