mirror of
https://github.com/penpot/penpot.git
synced 2026-08-01 10:56:20 +00:00
🐛 Fix migration from tokens lib version 1.2
This commit is contained in:
parent
1acf78d57c
commit
351362bb50
@ -167,6 +167,11 @@
|
|||||||
(get-tokens [_] "return an ordered sequence of all tokens in the set")
|
(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"))
|
(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]
|
(deftype TokenSet [id name description modified-at tokens]
|
||||||
#?@(:clj [clojure.lang.IDeref
|
#?@(:clj [clojure.lang.IDeref
|
||||||
(deref [_] {:id id
|
(deref [_] {:id id
|
||||||
@ -255,6 +260,10 @@
|
|||||||
[o]
|
[o]
|
||||||
(instance? TokenSet o))
|
(instance? TokenSet o))
|
||||||
|
|
||||||
|
(defn token-set-legacy?
|
||||||
|
[o]
|
||||||
|
(instance? TokenSetLegacy o))
|
||||||
|
|
||||||
(def schema:token-set-attrs
|
(def schema:token-set-attrs
|
||||||
[:map {:title "TokenSet"}
|
[:map {:title "TokenSet"}
|
||||||
[:id ::sm/uuid]
|
[:id ::sm/uuid]
|
||||||
@ -1717,10 +1726,11 @@ Will return a value that matches this schema:
|
|||||||
|
|
||||||
migrate-sets-node
|
migrate-sets-node
|
||||||
(fn recurse [node]
|
(fn recurse [node]
|
||||||
(if (token-set? node)
|
(if (token-set-legacy? node)
|
||||||
(assoc node
|
(make-token-set
|
||||||
:id (uuid/next)
|
(assoc node
|
||||||
:tokens (d/update-vals (:tokens node) migrate-token))
|
:id (uuid/next)
|
||||||
|
:tokens (d/update-vals (:tokens node) migrate-token)))
|
||||||
(d/update-vals node recurse)))
|
(d/update-vals node recurse)))
|
||||||
|
|
||||||
sets
|
sets
|
||||||
@ -1748,6 +1758,19 @@ Will return a value that matches this schema:
|
|||||||
|
|
||||||
(->TokensLib sets themes active-themes))))
|
(->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
|
#?(:clj
|
||||||
(defn- write-tokens-lib
|
(defn- write-tokens-lib
|
||||||
[n w ^TokensLib o]
|
[n w ^TokensLib o]
|
||||||
@ -1776,6 +1799,11 @@ Will return a value that matches this schema:
|
|||||||
(make-token obj)))}
|
(make-token obj)))}
|
||||||
|
|
||||||
{:name "penpot/token-set/v1"
|
{:name "penpot/token-set/v1"
|
||||||
|
:rfn (fn [r]
|
||||||
|
(let [obj (fres/read-object! r)]
|
||||||
|
(map->TokenSetLegacy obj)))}
|
||||||
|
|
||||||
|
{:name "penpot/token-set/v2"
|
||||||
:class TokenSet
|
:class TokenSet
|
||||||
:wfn (fn [n w o]
|
:wfn (fn [n w o]
|
||||||
(fres/write-tag! w n 1)
|
(fres/write-tag! w n 1)
|
||||||
@ -1803,8 +1831,11 @@ Will return a value that matches this schema:
|
|||||||
{:name "penpot/tokens-lib/v1.2"
|
{:name "penpot/tokens-lib/v1.2"
|
||||||
:rfn read-tokens-lib-v1-2}
|
:rfn read-tokens-lib-v1-2}
|
||||||
|
|
||||||
;; CURRENT TOKENS LIB READER & WRITTER
|
|
||||||
{:name "penpot/tokens-lib/v1.3"
|
{: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
|
:class TokensLib
|
||||||
:wfn write-tokens-lib
|
:wfn write-tokens-lib
|
||||||
:rfn read-tokens-lib}))
|
:rfn read-tokens-lib}))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user