mirror of
https://github.com/penpot/penpot.git
synced 2025-07-16 12:55:17 +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:
|
"Searches through decoded token file and returns:
|
||||||
- `:json-format/legacy` when first node satisfies `legacy-node?` predicate
|
- `:json-format/legacy` when first node satisfies `legacy-node?` predicate
|
||||||
- `:json-format/dtcg` when first node satisfies `dtcg-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]
|
([decoded-json]
|
||||||
(get-json-format decoded-json legacy-node? dtcg-node?))
|
(get-json-format decoded-json legacy-node? dtcg-node?))
|
||||||
([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)
|
(check-node node)
|
||||||
(when (branch? node)
|
(when (branch? node)
|
||||||
(mapcat walk (children node))))))]
|
(mapcat walk (children node))))))]
|
||||||
(->> (walk decoded-json)
|
(d/nilv (->> (walk decoded-json)
|
||||||
(filter some?)
|
(filter some?)
|
||||||
first)))) ;; TODO: throw error if format cannot be determined
|
first)
|
||||||
|
:json-format/dtcg))))
|
||||||
|
|
||||||
(defn- legacy-json->dtcg-json
|
(defn- legacy-json->dtcg-json
|
||||||
"Converts a decoded json file in legacy format into DTCG format."
|
"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]
|
[set-name decoded-json-tokens]
|
||||||
(assert (map? decoded-json-tokens) "expected a plain clojure map for `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`")
|
(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)
|
(let [set-name (normalize-set-name set-name)
|
||||||
:tokens (flatten-nested-tokens-json decoded-json-tokens "")))))
|
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
|
(defn- parse-single-set-legacy-json
|
||||||
"Parse a decoded json file with a single set of tokens in legacy format into a TokensLib."
|
"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
|
library
|
||||||
active-theme-names)]
|
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))
|
library))
|
||||||
|
|
||||||
(defn- parse-multi-set-legacy-json
|
(defn- parse-multi-set-legacy-json
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue