Skip to content

Instantly share code, notes, and snippets.

@mprokopov
Created December 4, 2023 13:52
Show Gist options
  • Save mprokopov/3753d14b989ff512c72d62fd9d713b66 to your computer and use it in GitHub Desktop.
Save mprokopov/3753d14b989ff512c72d62fd9d713b66 to your computer and use it in GitHub Desktop.
babushka generate dips.edn out of project.clj
#!/usr/bin/env bb
(ns switch
(:require [clojure.pprint :as pprint]))
(defn project-clj-map [filename]
(->> (slurp filename)
(read-string)
(drop 1)
(partition 2)
(map vec)
(into {})))
(defn lein-deps [filename]
(let [project-clj (project-clj-map filename)]
(get project-clj :dependencies)))
(defn edn-dep [lein-dep]
(let [[id version] lein-dep]
{id {:mvn/version version}}))
(defn edn-deps [lein-deps]
(let [deps (into {} (map edn-dep lein-deps))]
{:deps deps}))
(defn pprint-write [out-file m]
(with-open [w (clojure.java.io/writer out-file)]
(binding [*out* w]
(pprint/write m))))
(defn spit-edn-deps []
(->> (lein-deps "project.clj")
(edn-deps)
(pprint-write "deps.edn")))
(spit-edn-deps)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment