From d496831e7198740b2418f3a59e005509d93ede8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Som=C4=93=20Cho?= Date: Sun, 2 Jul 2023 16:28:39 +0200 Subject: [PATCH] 0.0.19 - implement project.clj multimethod for updating dependencies --- build.clj | 2 +- project.clj | 3 +++ src/depo/core.clj | 2 +- src/depo/readwrite.clj | 44 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 project.clj diff --git a/build.clj b/build.clj index d8cf724..7a942d3 100644 --- a/build.clj +++ b/build.clj @@ -3,7 +3,7 @@ [deps-deploy.deps-deploy :as dd])) (def lib 'org.clojars.some/depo) -(def version "0.0.18") +(def version "0.0.19") (def jar-file (format "target/%s-%s.jar" (name lib) version)) (def class-dir "target/classes") (def url "https://github.com/somecho/depo") diff --git a/project.clj b/project.clj new file mode 100644 index 0000000..f0bbb59 --- /dev/null +++ b/project.clj @@ -0,0 +1,3 @@ +(defproject depo "0.0.1" + :dependencies [[reagent "1.2.0"] + [metosin/malli "0.11.0"]]) \ No newline at end of file diff --git a/src/depo/core.clj b/src/depo/core.clj index 80f1689..1e1f24c 100644 --- a/src/depo/core.clj +++ b/src/depo/core.clj @@ -27,7 +27,7 @@ (def CONFIGURATION {:command "depo" :description "Manage dependencies for Clojure projects easily" - :version "0.0.18" + :version "0.0.19" :opts [{:as "path to configuration file" :default nil :option "file" diff --git a/src/depo/readwrite.clj b/src/depo/readwrite.clj index 589b4e0..f242496 100644 --- a/src/depo/readwrite.clj +++ b/src/depo/readwrite.clj @@ -170,4 +170,46 @@ :map {:sort? false :hang? false}}) (as-> new-conf (spit config-path new-conf)))) - (println (str identifier) current-version "is up to date. Skipping"))))) + (println (str identifier) current-version "is up to date. Skipping."))))) + +(defmethod update-dependency "project.clj" + [config-path arg] + (let [zloc (z/of-string (slurp config-path)) + {:keys [groupID artifactID version]} (dp/parse arg) + identifier (symbol (if (= groupID artifactID) + artifactID + (str groupID "/" artifactID))) + dep-vec (-> zloc + (z/find-value z/next :dependencies) + (z/next) + (z/string) + (read-string)) + dep-item (first (filter #(= (first %) identifier) dep-vec)) + current-version (second dep-item) + dependency-exists? (seq dep-item) + {:keys [groupID artifactID version]} (if dependency-exists? + (r/conform-version arg) + nil)] + (if-not dependency-exists? + (println arg "isn't a dependency. Skipping.") + (if-not (= current-version version) + (do + (println "Updating" (str identifier)) + (println "Current version:" current-version) + (println "Latest version:" version) + (-> zloc + (z/find-value z/next :dependencies) + (z/next) + (z/replace (vec (map #(if (= (first %) identifier) + [identifier version] + %) dep-vec))) + (as-> veczip + (z/map (fn [z] (if (z/rightmost? z) + z + (z/insert-newline-right z))) veczip)) + (z/root-string) + (zp/zprint-str {:parse-string? true + :vector {:respect-nl? true + :wrap-coll? nil}}) + (as-> new-conf (spit config-path new-conf)))) + (println (str identifier) current-version "is up to date. Skipping.")))))