🔧 Convert tokens lib migration into file migration

This commit is contained in:
Andrés Moya 2026-05-07 12:49:48 +02:00
parent 48a5561b15
commit 7b36a85dba
2 changed files with 15 additions and 31 deletions

View File

@ -34,7 +34,7 @@
[app.common.types.shape.shadow :as ctss]
[app.common.types.shape.text :as ctst]
[app.common.types.text :as types.text]
[app.common.types.tokens-lib :as types.tokens-lib]
[app.common.types.tokens-lib :as ctob]
[app.common.uuid :as uuid]
[clojure.set :as set]
[cuerdas.core :as str]))
@ -1599,7 +1599,7 @@
(defmethod migrate-data "0014-fix-tokens-lib-duplicate-ids"
[data _]
(d/update-when data :tokens-lib types.tokens-lib/fix-duplicate-token-set-ids))
(d/update-when data :tokens-lib ctob/fix-duplicate-token-set-ids))
(defmethod migrate-data "0014-clear-components-nil-objects"
[data _]
@ -1805,6 +1805,13 @@
{})]
(cfcp/sync-component-id-with-ref-shape data libraries)))
(defmethod migrate-data "0021-repair-bad-tokens"
[data _]
(d/update-when data :tokens-lib
#(-> %
(ctob/fix-conflicting-token-names)
(ctob/fix-missing-sets-in-themes))))
(def available-migrations
(into (d/ordered-set)
["legacy-2"
@ -1882,4 +1889,5 @@
"0017-fix-layout-flex-dir"
"0018-remove-unneeded-objects-from-components"
"0019-fix-missing-swap-slots"
"0020-sync-component-id-with-near-main"]))
"0020-sync-component-id-with-near-main"
"0021-repair-bad-tokens"]))

View File

@ -2375,9 +2375,7 @@ Will return a value that matches this schema:
(migrate-to-v1-2)
(migrate-to-v1-3)
(migrate-to-v1-4)
(map->tokens-lib)
(fix-conflicting-token-names)
(fix-missing-sets-in-themes)))))
(map->tokens-lib)))))
#?(:clj
(defn- read-tokens-lib-v1-2
@ -2392,9 +2390,7 @@ Will return a value that matches this schema:
:active-themes active-themes}
(migrate-to-v1-3)
(migrate-to-v1-4)
(map->tokens-lib)
(fix-conflicting-token-names)
(fix-missing-sets-in-themes)))))
(map->tokens-lib)))))
#?(:clj
(defn- read-tokens-lib-v1-3
@ -2409,24 +2405,7 @@ Will return a value that matches this schema:
:themes themes
:active-themes active-themes}
(migrate-to-v1-4)
(map->tokens-lib)
(fix-conflicting-token-names)
(fix-missing-sets-in-themes)))))
#?(:clj
(defn- read-tokens-lib-v1-4
"Reads the tokens lib data structure and fix conflicting token names."
[r]
(let [sets (fres/read-object! r)
themes (fres/read-object! r)
active-themes (fres/read-object! r)]
(-> {:sets sets
:themes themes
:active-themes active-themes}
(map->tokens-lib)
(fix-conflicting-token-names)
(fix-missing-sets-in-themes)))))
(map->tokens-lib)))))
#?(:clj
(defn- write-tokens-lib
@ -2487,11 +2466,8 @@ Will return a value that matches this schema:
{:name "penpot/tokens-lib/v1.3"
:rfn read-tokens-lib-v1-3}
{:name "penpot/tokens-lib/v1.4"
:rfn read-tokens-lib-v1-4}
;; CURRENT TOKENS LIB READER & WRITTER
{:name "penpot/tokens-lib/v1.5"
{:name "penpot/tokens-lib/v1.4"
:class TokensLib
:wfn write-tokens-lib
:rfn read-tokens-lib}))