From 506c2b8d7b869ee363c033b478191065ae4a5a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Fri, 27 Jan 2023 09:30:23 +0100 Subject: [PATCH] :wrench: Add script to rename some layout attrs in existing files --- backend/src/app/srepl/fixes.clj | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/backend/src/app/srepl/fixes.clj b/backend/src/app/srepl/fixes.clj index 7192e8149..a294a25d3 100644 --- a/backend/src/app/srepl/fixes.clj +++ b/backend/src/app/srepl/fixes.clj @@ -41,3 +41,35 @@ ([file state] (repair-orphaned-shapes (:data file)) (update state :total (fnil inc 0)))) + +(defn rename-layout-attrs + ([file] + (let [found? (volatile! false)] + (letfn [(update-shape + [shape] + (when (or (= (:layout-flex-dir shape) :reverse-row) + (= (:layout-flex-dir shape) :reverse-column) + (= (:layout-wrap-type shape) :no-wrap)) + (vreset! found? true)) + (cond-> shape + (= (:layout-flex-dir shape) :reverse-row) + (assoc :layout-flex-dir :row-reverse) + (= (:layout-flex-dir shape) :reverse-column) + (assoc :layout-flex-dir :column-reverse) + (= (:layout-wrap-type shape) :no-wrap) + (assoc :layout-wrap-type :nowrap))) + + (update-page + [page] + (h/update-shapes page update-shape))] + + (let [new-file (update file :data h/update-pages update-page)] + (when @found? + (l/info :hint "Found attrs to rename in file" + :id (:id file) + :name (:name file))) + new-file)))) + + ([file state] + (rename-layout-attrs file) + (update state :total (fnil inc 0)))) \ No newline at end of file