mirror of
https://github.com/penpot/penpot.git
synced 2025-07-16 02:15:14 +02:00
🐛 Allow importing file without any token but with themes or sets (#6796)
This commit is contained in:
parent
3010abbf64
commit
5c4fd97541
1 changed files with 21 additions and 7 deletions
|
@ -1212,7 +1212,8 @@ Will return a value that matches this schema:
|
|||
"Searches through decoded token file and returns:
|
||||
- `:json-format/legacy` when first node satisfies `legacy-node?` predicate
|
||||
- `:json-format/dtcg` when first node satisfies `dtcg-node?` predicate
|
||||
- `nil` if neither combination is found"
|
||||
- If neither combination is found, return dtcg format by default (we assume that
|
||||
the file does not contain any token, so the format is irrelevan)."
|
||||
([decoded-json]
|
||||
(get-json-format decoded-json legacy-node? dtcg-node?))
|
||||
([decoded-json legacy-node? dtcg-node?]
|
||||
|
@ -1230,9 +1231,10 @@ Will return a value that matches this schema:
|
|||
(check-node node)
|
||||
(when (branch? node)
|
||||
(mapcat walk (children node))))))]
|
||||
(->> (walk decoded-json)
|
||||
(filter some?)
|
||||
first)))) ;; TODO: throw error if format cannot be determined
|
||||
(d/nilv (->> (walk decoded-json)
|
||||
(filter some?)
|
||||
first)
|
||||
:json-format/dtcg))))
|
||||
|
||||
(defn- legacy-json->dtcg-json
|
||||
"Converts a decoded json file in legacy format into DTCG format."
|
||||
|
@ -1291,9 +1293,17 @@ Will return a value that matches this schema:
|
|||
[set-name decoded-json-tokens]
|
||||
(assert (map? decoded-json-tokens) "expected a plain clojure map for `decoded-json-tokens`")
|
||||
(assert (= (get-json-format decoded-json-tokens) :json-format/dtcg) "expected a dtcg format for `decoded-json-tokens`")
|
||||
(-> (make-tokens-lib)
|
||||
(add-set (make-token-set :name (normalize-set-name set-name)
|
||||
:tokens (flatten-nested-tokens-json decoded-json-tokens "")))))
|
||||
|
||||
(let [set-name (normalize-set-name set-name)
|
||||
tokens (flatten-nested-tokens-json decoded-json-tokens "")]
|
||||
|
||||
(when (empty? tokens)
|
||||
(throw (ex-info "the file doesn't contain any tokens"
|
||||
{:error/code :error.import/invalid-json-data})))
|
||||
|
||||
(-> (make-tokens-lib)
|
||||
(add-set (make-token-set :name set-name
|
||||
:tokens tokens)))))
|
||||
|
||||
(defn- parse-single-set-legacy-json
|
||||
"Parse a decoded json file with a single set of tokens in legacy format into a TokensLib."
|
||||
|
@ -1385,6 +1395,10 @@ Will return a value that matches this schema:
|
|||
library
|
||||
active-theme-names)]
|
||||
|
||||
(when (and (empty? sets) (empty? themes))
|
||||
(throw (ex-info "the file doesn't contain any tokens"
|
||||
{:error/code :error.import/invalid-json-data})))
|
||||
|
||||
library))
|
||||
|
||||
(defn- parse-multi-set-legacy-json
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue