[go: nahoru, domu]

Skip to content

Utility lib on top of rewrite-clj with common operations to update EDN while preserving whitespace and comments.

License

Notifications You must be signed in to change notification settings

borkdude/rewrite-edn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rewrite-edn

Clojars Project

Utility lib on top of rewrite-clj with common operations to update EDN while preserving whitespace and comments.

API

See docstrings in the borkdude.rewrite-edn namespace for details.

Currently implemented:

  • parse-string
  • sexpr
  • assoc
  • assoc-in
  • update
  • update-in
  • map-keys

Examples

Given deps.edn:

{:deps {foo {:mvn/version "0.1.0"}
        bar {:mvn/version "0.2.0"}
        ;; here's a comment and the next dep is ignored:
        #_baz #_{:mvn/version "0.3.0"}}}

and this script:

(require '[borkdude.rewrite-edn :as r])

(def edn-string (slurp "deps.edn"))

(def nodes (r/parse-string edn-string))

Add dependency

(println (str (r/assoc-in nodes [:deps 'my-other-dep] {:mvn/version "0.1.2"})))
{:deps {foo {:mvn/version "0.1.0"}
        bar {:mvn/version "0.2.0"}
        ;; here's a comment and the next dep is ignored:
        #_baz #_{:mvn/version "0.3.0"}
        my-other-dep {:mvn/version "0.1.2"}}}

Fully qualify dep symbols

(defn qualify-sym-node [sym-node]
  (let [sym (r/sexpr sym-node)]
    (if (or (not (symbol? sym))
            (qualified-symbol? sym))
      sym-node
      (symbol (str sym) (str sym)))))

(def updated-nodes (r/update nodes :deps #(r/map-keys qualify-sym-node %)))
(println (str updated-nodes))
{:deps {foo/foo {:mvn/version "0.1.0"}
        bar/bar {:mvn/version "0.2.0"}
        ;; here's a comment and the next dep is ignored:
        #_baz #_{:mvn/version "0.3.0"}}}

Also see examples.

License

Copyright © 2021 Michiel Borkent

Distributed under the EPL License, same as Clojure. See LICENSE.

About

Utility lib on top of rewrite-clj with common operations to update EDN while preserving whitespace and comments.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published