Skip to content

Instantly share code, notes, and snippets.

@swlkr

swlkr/switch.clj

Last active May 29, 2020
Embed
What would you like to do?
(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)
@tiagodalloca

This comment has been minimized.

Copy link

@tiagodalloca tiagodalloca commented Jan 10, 2018

Nice

@chenyong

This comment has been minimized.

Copy link

@chenyong chenyong commented Jan 10, 2018

Then probably:

mkdir src
mv switch.cljs src
clj -m switch
@ordnungswidrig

This comment has been minimized.

Copy link

@ordnungswidrig ordnungswidrig commented Jan 10, 2018

This is so hacky but unlike it. Maybe trunk it into a lein plugin ?

@ordnungswidrig

This comment has been minimized.

Copy link

@ordnungswidrig ordnungswidrig commented Jan 10, 2018

s/unlike/I like

@swlkr

This comment has been minimized.

Copy link
Owner Author

@swlkr swlkr commented Jan 10, 2018

Yeah I should make it a proper lein plugin, lein deps.edn or something like that?

@martinklepsch

This comment has been minimized.

Copy link

@martinklepsch martinklepsch commented Jan 11, 2018

If you change this:

(defn -main []
  (spit-edn-deps))

into this

(spit-edn-deps)

you can run it with

curl https://gist.githubusercontent.com/swlkr/[...]/raw/[...]/switch.clj | clj -

or download the file first and run clj switch.clj

@swlkr

This comment has been minimized.

Copy link
Owner Author

@swlkr swlkr commented Jan 12, 2018

I just changed it, that's incredible

@Kah0ona

This comment has been minimized.

Copy link

@Kah0ona Kah0ona commented Jan 18, 2018

that is, indeed, amazing. Simple yet effective. How cool.

@deas

This comment has been minimized.

Copy link

@deas deas commented Feb 4, 2018

@ordnungswidrig @swlkr I'd go so far and say leiningen core should be shipping this functionality.

@AndreaCrotti

This comment has been minimized.

Copy link

@AndreaCrotti AndreaCrotti commented Mar 30, 2020

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)
@swlkr

This comment has been minimized.

Copy link
Owner Author

@swlkr swlkr commented Mar 30, 2020

nice! babashka is incredible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.