Last active
August 9, 2024 09:56
-
-
Save borkdude/58f099b2694d206e6eec18daedc5077b to your computer and use it in GitHub Desktop.
Gen deps.edns in mono-repo using babashka script. Merge default dep versions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bb | |
(ns update-deps | |
(:require [clojure.edn :as edn] | |
[clojure.java.io :as io] | |
[clojure.pprint :as pp :refer [pprint]] | |
[clojure.walk :as walk])) | |
(defn- merge-defaults [deps defaults] | |
(let [ff (some-fn deps (complement (partial contains? deps))) | |
overriden-deps (remove ff (keys defaults)) | |
defaults (select-keys defaults overriden-deps)] | |
(merge deps defaults))) | |
(defn merge-default-deps [deps-map defaults] | |
(let [paths (into [[:deps]] | |
(map (fn [alias] | |
[:aliases alias :extra-deps]) | |
(keys (:aliases deps-map))))] | |
(reduce | |
(fn [acc path] | |
(if-let [m (get-in acc path)] | |
(assoc-in acc path (merge-defaults m defaults)) | |
acc)) | |
deps-map | |
paths))) | |
(def base-deps (edn/read-string (slurp "base/deps.edn"))) | |
(def default-deps (-> base-deps :aliases :base :default-deps)) | |
(def repos (-> base-deps :mvn/repos)) | |
(def key-order | |
{:paths 0 | |
:deps 1 | |
:aliases 2}) | |
(defn comparator* [x y] | |
(if-let [o1 (key-order x)] | |
(if-let [o2 (key-order y)] | |
(compare o1 o2) | |
-1) ;; defined order goes first | |
(if (key-order y) | |
1 ;; defined order goes first | |
;; compare keywords by string, regardless of namespace | |
(compare (str x) (str y))))) | |
(defn sort-maps [m] | |
(walk/postwalk | |
(fn [m] | |
(if (map? m) | |
(into (sorted-map-by comparator*) m) | |
m)) | |
m)) | |
(defn gen-deps [dir] | |
(let [deps-template (edn/read-string (slurp (io/file dir "deps.template.edn"))) | |
deps (merge-default-deps deps-template default-deps) | |
deps (update deps :mvn/repos merge repos) | |
deps (sort-maps deps) | |
writer (io/writer (io/file dir "deps.edn"))] | |
(binding [*out* writer | |
*print-namespace-maps* false] | |
(println ";; WARNING: Generated from deps.template.edn. Do not edit here. Use script/gen-deps.clj from the root dir to regenerate.") | |
(binding [pp/*print-right-margin* 100] | |
(pprint deps))))) | |
(gen-deps "common") | |
(gen-deps "genseng") | |
(gen-deps "app") | |
(gen-deps "annotator") | |
(gen-deps "feeds") | |
(gen-deps "lvg") | |
(gen-deps "cuisine") | |
(gen-deps "integration") | |
(gen-deps "ontolog") | |
(gen-deps "triplestore_import") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
deps.template.edn
which we then use to generate a correspondingdeps.edn
.deps.edn
are a bunch of sorted maps, to be more friendly with git etc.:init
phase ofbb.edn
so any time we execute a task, thedeps.edns
are synced. You could also hook it up to a git hook.