Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(ns rewrite-field-spoec
(:require [clojure.java.io :as io]
[rewrite-clj.zip :as z]))
(defn file? [f] (.isFile f))
(defn get-path [f] (.getPath f))
(defn all-source-files
[dir-path]
(->> (io/file dir-path)
(file-seq)
(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
[filename]
(prn filename)
(let [zloc (-> (z/of-file filename)
(z/up)
(z/postwalk
(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