Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(ns rewrite-field-spoec
(:require [ :as io]
[ :as z]))
(defn file? [f] (.isFile f))
(defn get-path [f] (.getPath f))
(defn all-source-files
(->> (io/file dir-path)
(filter file?)
(map get-path)))
(defn massage-field-spec
[{:keys [type form/widget-type] :as field-spec}]
(cond-> field-spec
(and type (not widget-type))
(assoc :form/widget-type type)))
(defn process-file
(prn filename)
(let [zloc (-> (z/of-file filename)
(fn select [zloc]
(let [x (z/sexpr zloc)]
(and (map? x)
(:type x)
(= (z/sexpr (z/left (z/up zloc))) :field-spec))))
(fn visit [zloc]
(z/edit zloc massage-field-spec))))]
(spit filename (z/root-string zloc))))
(comment (doall (map process-file (all-source-files "src/common/constants"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment