Skip to content

Instantly share code, notes, and snippets.

@theronic
Created February 28, 2018 08:00
Show Gist options
  • Save theronic/827c694ac2247a5fbc3afde41780931f to your computer and use it in GitHub Desktop.
Save theronic/827c694ac2247a5fbc3afde41780931f to your computer and use it in GitHub Desktop.
Convert Clojure project.clj :dependencies to deps.edn style
; using Clojure 1.9
(require '[clojure.pprint :as pprint])
(defn xform-dep [[lib version & korks]]
(let [args (into {} (apply hash-map korks))]
[lib (merge {:mvn/version version} args)]))
(defn xform-deps
"deps.edn utility function by @theronic 2018-02-28
Transforms a collection of project.clj :dependencies to deps.edn style
'[[org.clojure/clojurescript \"1.9.946\" :exclusions [org.clojure/clojure com.google.guava/guava]]
...]
=> {:deps {org.clojure/clojurescript {:mvn/version \" 1.9.946\", :exclusions [org.clojure/clojure com.google.guava/guava]}}
...}"
[coll]
(binding [*print-namespace-maps* false
pprint/*print-right-margin* 300]
(pprint/pprint (into {} (map xform-dep coll)))))
(comment
(xform-deps '[[org.clojure/clojure "1.9.0"]
[org.clojure/clojurescript "1.9.946" :exclusions [org.clojure/clojure com.google.guava/guava]]
[pandeiro/boot-http "0.8.3" :scope "test"]])
; => {org.clojure/clojure {:mvn/version "1.9.0"}
; org.clojure/clojurescript {:mvn/version "1.9.946", :exclusions [org.clojure/clojure com.google.guava/guava]}
; pandeiro/boot-http {:mvn/version "0.8.3", :scope "test"}}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment