mirror of
https://github.com/penpot/penpot.git
synced 2026-02-12 22:53:02 +00:00
🐛 Fix migration from tokens lib version 1.2
This commit is contained in:
@@ -167,6 +167,11 @@
|
||||
(get-tokens [_] "return an ordered sequence of all tokens in the set")
|
||||
(get-tokens-map [_] "return a map of tokens in the set, indexed by token-name"))
|
||||
|
||||
;; TODO: this structure is temporary. It's needed to be able to migrate TokensLib
|
||||
;; from 1.2 to 1.3 when TokenSet datatype was changed to a deftype. This should
|
||||
;; be removed after migrations are consolidated.
|
||||
(defrecord TokenSetLegacy [id name description modified-at tokens])
|
||||
|
||||
(deftype TokenSet [id name description modified-at tokens]
|
||||
#?@(:clj [clojure.lang.IDeref
|
||||
(deref [_] {:id id
|
||||
@@ -255,6 +260,10 @@
|
||||
[o]
|
||||
(instance? TokenSet o))
|
||||
|
||||
(defn token-set-legacy?
|
||||
[o]
|
||||
(instance? TokenSetLegacy o))
|
||||
|
||||
(def schema:token-set-attrs
|
||||
[:map {:title "TokenSet"}
|
||||
[:id ::sm/uuid]
|
||||
@@ -1717,10 +1726,11 @@ Will return a value that matches this schema:
|
||||
|
||||
migrate-sets-node
|
||||
(fn recurse [node]
|
||||
(if (token-set? node)
|
||||
(assoc node
|
||||
:id (uuid/next)
|
||||
:tokens (d/update-vals (:tokens node) migrate-token))
|
||||
(if (token-set-legacy? node)
|
||||
(make-token-set
|
||||
(assoc node
|
||||
:id (uuid/next)
|
||||
:tokens (d/update-vals (:tokens node) migrate-token)))
|
||||
(d/update-vals node recurse)))
|
||||
|
||||
sets
|
||||
@@ -1748,6 +1758,19 @@ Will return a value that matches this schema:
|
||||
|
||||
(->TokensLib sets themes active-themes))))
|
||||
|
||||
#?(:clj
|
||||
(defn- read-tokens-lib-v1-3
|
||||
"Reads the tokens lib data structure and removes the TokenSetLegacy data type,
|
||||
needed for a temporary migration step."
|
||||
[r]
|
||||
(let [sets (fres/read-object! r)
|
||||
themes (fres/read-object! r)
|
||||
active-themes (fres/read-object! r)
|
||||
|
||||
sets (d/update-vals sets make-token-set)]
|
||||
|
||||
(->TokensLib sets themes active-themes))))
|
||||
|
||||
#?(:clj
|
||||
(defn- write-tokens-lib
|
||||
[n w ^TokensLib o]
|
||||
@@ -1776,6 +1799,11 @@ Will return a value that matches this schema:
|
||||
(make-token obj)))}
|
||||
|
||||
{:name "penpot/token-set/v1"
|
||||
:rfn (fn [r]
|
||||
(let [obj (fres/read-object! r)]
|
||||
(map->TokenSetLegacy obj)))}
|
||||
|
||||
{:name "penpot/token-set/v2"
|
||||
:class TokenSet
|
||||
:wfn (fn [n w o]
|
||||
(fres/write-tag! w n 1)
|
||||
@@ -1803,8 +1831,11 @@ Will return a value that matches this schema:
|
||||
{:name "penpot/tokens-lib/v1.2"
|
||||
:rfn read-tokens-lib-v1-2}
|
||||
|
||||
;; CURRENT TOKENS LIB READER & WRITTER
|
||||
{:name "penpot/tokens-lib/v1.3"
|
||||
:rfn read-tokens-lib-v1-3}
|
||||
|
||||
;; CURRENT TOKENS LIB READER & WRITTER
|
||||
{:name "penpot/tokens-lib/v1.4"
|
||||
:class TokensLib
|
||||
:wfn write-tokens-lib
|
||||
:rfn read-tokens-lib}))
|
||||
|
||||
Reference in New Issue
Block a user