Last active
July 27, 2021 17:18
-
-
Save swlkr/3f346c66410e5c60c59530c4413a248e to your computer and use it in GitHub Desktop.
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
(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) |
I just changed it, that's incredible
that is, indeed, amazing. Simple yet effective. How cool.
@ordnungswidrig @swlkr I'd go so far and say leiningen core should be shipping this functionality.
FYI with a couple of minor changes I made this script work with babaksha https://github.com/borkdude/babashka which makes it run reaaally fast
#!/usr/bin/env bb
(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]
(clojure.pprint/pprint m))))
(defn spit-edn-deps []
(->> (lein-deps "project.clj")
(edn-deps)
(pprint-write "deps.edn")))
(spit-edn-deps)
nice! babashka is incredible
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you change this:
into this
(spit-edn-deps)
you can run it with
or download the file first and run
clj switch.clj