Updating edn files using rewrite-clj
For some projects using shadow-cljs I can’t add my custom keys to the shadow-cljs, so I wrote this little clojure function to add my keys and git assume-unchanged.
Sadly there is no merge-config or similar for the shadow-cljs CLI.
So To edit shadow-cljs edn we can use rewrite-clj to add our keys to every :devtools.
I’m using rewrite-clj to keep the pre-existing formatting of the shadow-cljs.edn
clojure
(defn adjust-shadow-cljs!
"Adds dev keys to the `:devtools` of the shadow-cljs.edn"
[]
(let [file "./repo/frontend/shadow-cljs.edn"
zloc (-> (z/of-string (slurp file))
(z/prewalk
(fn [loc]
(when (and (z/map? loc)
(= (z/sexpr (z/left loc)) :devtools))
(-> loc
;; Loads my custom preload ns in dev/preload
(z/assoc :preloads ['preload])
;; I don't want shadow cljs logs in my console
(z/assoc :log false)))))
(z/root-string))]
(bp/shell shell-opts "git update-index --assume-unchanged frontend/shadow-cljs.edn")
(spit file zloc)
zloc))I always set :log false for the devtools as i don’t want to get noisy logs for every reloading of updated namespaces.
And I load my custom namespace per default.
In my preload namespace I do further noise log removal like this
clojure
(ns preload
(:require
[app.common.logging :as l]
[devtools.core :as devtools]))
(defn setup! []
(devtools/set-pref! :dont-display-banner true)
(devtools/set-pref! :min-expandable-sequable-count-for-well-known-types 0)
(remove-watch l/log-record ::l/default))
(setup!)