Skip to content

Commit

Permalink
0.4.29 - huge refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
somecho committed Jul 5, 2023
1 parent d423c1d commit 83056fb
Show file tree
Hide file tree
Showing 11 changed files with 309 additions and 466 deletions.
2 changes: 1 addition & 1 deletion build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[deps-deploy.deps-deploy :as dd]))

(def lib 'org.clojars.some/depo)
(def version "0.3.28")
(def version "0.4.29")
(def jar-file (format "target/%s-%s.jar" (name lib) version))
(def class-dir "target/classes")
(def url "https://github.com/somecho/depo")
Expand Down
23 changes: 12 additions & 11 deletions src/depo/core.clj
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
(ns ^:no-doc depo.core
(:require [cli-matic.core :refer [run-cmd]]
[depo.readwrite :as rw]
[depo.errors :as e]))
[depo.dispatch :as dd]
[depo.errors :as e]
[depo.zoperations :as zo]))

(defn add-cmd [{:keys [_arguments file]}]
(let [args _arguments
config-path (if file file (rw/get-config))]
config-path (if file file (dd/get-config))]
(if-not (empty? args)
(do (mapv #(rw/apply-operation {:config-path config-path
(do (mapv #(dd/apply-operation {:config-path config-path
:id %
:operation :add}) args)
(println "Done!"))
(println (e/err :no-args)))))

(defn remove-cmd [{:keys [_arguments file]}]
(let [args _arguments
config-path (if file file (rw/get-config))]
config-path (if file file (dd/get-config))]
(if-not (empty? args)
(do (mapv #(rw/apply-operation {:config-path config-path
(do (mapv #(dd/apply-operation {:config-path config-path
:id %
:operation :remove}) args)
(println "Done!"))
(println (e/err :no-args)))))

(defn update-cmd [{:keys [_arguments file]}]
(let [args _arguments
config-path (if file file (rw/get-config))]
config-path (if file file (dd/get-config))]
(if (empty? args)
(do (mapv #(rw/apply-operation {:config-path config-path
(do (mapv #(dd/apply-operation {:config-path config-path
:id %
:operation :update})
(rw/get-all-dependency-names config-path))
(zo/get-all-dependency-names config-path))
(println "Done!"))
(mapv #(rw/apply-operation {:config-path config-path
(mapv #(dd/apply-operation {:config-path config-path
:id %
:operation :update}) args))))

(def CONFIGURATION
{:command "depo"
:description "Manage dependencies for Clojure projects easily"
:version "0.3.28"
:version "0.4.29"
:opts [{:as "path to configuration file"
:default nil
:option "file"
Expand Down
86 changes: 86 additions & 0 deletions src/depo/dispatch.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
(ns depo.dispatch
(:require [clojure.java.io :as io]
[depo.schema :as schema]
[depo.utils :as dutils]
[depo.zoperations :as zo]
[malli.core :as m]
[rewrite-clj.zip :as z]
[zprint.core :as zp]))

(defn skip-procedure
[{:keys [zloc]} & reason]
(apply println (concat reason ["Skipping."]))
zloc)

(defn ignore-pass
[{:keys [dep-data deps-type identifier]
:as procedure} f]
(case deps-type
:map (cond
(= "RELEASE" (:mvn/version dep-data))
(skip-procedure procedure "Version has been set as release.")
(contains? dep-data :local/root)
(skip-procedure procedure identifier "is a local dependency.")
:else (f))
:vector (f)))

(defn dispatch
[{:keys [operation dep-exists identifier]
:as procedure}]
(case operation
:add (if dep-exists
(ignore-pass procedure
#(zo/update-dependency procedure))
(zo/append-dependency procedure))
:remove (if dep-exists
(zo/remove-dependency procedure)
(skip-procedure identifier "is not a dependency."))
:update (if dep-exists
(ignore-pass procedure
#(zo/update-dependency procedure))
(skip-procedure procedure identifier "is not a dependency."))))

(defn apply-operation
[{:keys [config-path id operation]}]
(let [config-zip (z/of-string (slurp config-path))
project-type (dutils/get-project-type config-path)
access-keys [(dutils/create-keys project-type)]
deps (zo/get-deps config-zip access-keys project-type)
{:keys [groupID artifactID]} (dutils/parse id)
deps-type (cond
(z/map? deps) :map
(z/vector? deps) :vector)
identifier (symbol (dutils/create-identifier groupID artifactID deps-type))
dependency-data (zo/get-dependency-data deps identifier)
procedure {:operation operation
:dep-exists (if dependency-data true false)
:identifier identifier
:project-type project-type
:argument id
:dep-data dependency-data
:deps-type deps-type
:zloc deps}]
(if (m/validate schema/PROCEDURE procedure)
(-> (dispatch procedure)
(z/root-string)
(zp/zprint-str {:parse-string? true
:style :indent-only})
(as-> new-conf (spit config-path new-conf)))
(println "Failed to validate procedure."))))

(defn get-config
"Looks in the current directory for the following files
- deps.edn
- project.clj
- shadow-cljs.edn
- bb.edn
Returns the a string matching the first file that it finds.
Returns nil otherwise"
[]
(cond
(.exists (io/file "deps.edn")) "deps.edn"
(.exists (io/file "project.clj")) "project.clj"
(.exists (io/file "shadow-cljs.edn")) "shadow-cljs.edn"
(.exists (io/file "bb.edn")) "bb.edn"))
Loading

0 comments on commit 83056fb

Please sign in to comment.