Add outdated example
This commit is contained in:
parent
bfea861cba
commit
33c0a76a99
2 changed files with 49 additions and 1 deletions
16
README.md
16
README.md
|
|
@ -630,7 +630,7 @@ less
|
||||||
|
|
||||||
### Portable tree command
|
### Portable tree command
|
||||||
|
|
||||||
See [examples/tree.clj](https://github.com/borkdude/babashka/blob/8afb87142e0e4da8b6f912cfd7daf9c30b805ab3/examples/tree.clj).
|
See [examples/tree.clj](https://github.com/borkdude/babashka/blob/master/examples/tree.clj).
|
||||||
|
|
||||||
``` shellsession
|
``` shellsession
|
||||||
$ clojure -Sdeps '{:deps {org.clojure/tools.cli {:mvn/version "0.4.2"}}}' examples/tree.clj src
|
$ clojure -Sdeps '{:deps {org.clojure/tools.cli {:mvn/version "0.4.2"}}}' examples/tree.clj src
|
||||||
|
|
@ -650,6 +650,20 @@ src
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### List outdated maven dependencies
|
||||||
|
|
||||||
|
See [examples/outdated.clj](https://github.com/borkdude/babashka/blob/master/examples/outdated.clj).
|
||||||
|
|
||||||
|
``` shellsession
|
||||||
|
$ cat /tmp/deps.edn
|
||||||
|
{:deps {cheshire {:mvn/version "5.8.1"}
|
||||||
|
clj-http {:mvn/version "3.4.0"}}}
|
||||||
|
|
||||||
|
$ examples/outdated.clj /tmp/deps.edn
|
||||||
|
clj-http/clj-http can be upgraded from 3.4.0 to 3.10.0
|
||||||
|
cheshire/cheshire can be upgraded from 5.8.1 to 5.9.0
|
||||||
|
```
|
||||||
|
|
||||||
## Thanks
|
## Thanks
|
||||||
|
|
||||||
- [adgoji](https://www.adgoji.com/) for financial support
|
- [adgoji](https://www.adgoji.com/) for financial support
|
||||||
|
|
|
||||||
34
examples/outdated.clj
Executable file
34
examples/outdated.clj
Executable file
|
|
@ -0,0 +1,34 @@
|
||||||
|
#!/usr/bin/env bb
|
||||||
|
|
||||||
|
(require '[clojure.edn :as edn])
|
||||||
|
(require '[clojure.java.shell :refer [sh]])
|
||||||
|
(require '[clojure.string :as str])
|
||||||
|
|
||||||
|
(def deps (-> (slurp (or (first *command-line-args*)
|
||||||
|
"deps.edn"))
|
||||||
|
edn/read-string
|
||||||
|
:deps))
|
||||||
|
(def with-release (zipmap (keys deps)
|
||||||
|
(map #(assoc % :mvn/version "RELEASE")
|
||||||
|
(vals deps))))
|
||||||
|
|
||||||
|
(defn deps->versions [deps]
|
||||||
|
(let [res (sh "clojure" "-Sdeps" (str {:deps deps}) "-Stree")
|
||||||
|
tree (:out res)
|
||||||
|
lines (str/split tree #"\n")
|
||||||
|
top-level (remove #(str/starts-with? % " ") lines)
|
||||||
|
deps (map #(str/split % #" ") top-level)]
|
||||||
|
(reduce (fn [acc [dep version]]
|
||||||
|
(assoc acc dep version))
|
||||||
|
{}
|
||||||
|
deps)))
|
||||||
|
|
||||||
|
(def version-map (deps->versions deps))
|
||||||
|
(def new-version-map (deps->versions with-release))
|
||||||
|
|
||||||
|
(doseq [[dep version] version-map
|
||||||
|
:let [new-version (get new-version-map dep)]
|
||||||
|
:when (not= version new-version)]
|
||||||
|
(println dep "can be upgraded from" version "to" new-version))
|
||||||
|
|
||||||
|
;; Inspired by an idea from @seancorfield on Clojurians Slack
|
||||||
Loading…
Reference in a new issue