mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
✨ Keep warning for unsupported token types when FF is disabled
Some checks are pending
Commit Message Check / Check Commit Message (push) Waiting to run
Some checks are pending
Commit Message Check / Check Commit Message (push) Waiting to run
This commit is contained in:
committed by
Andrés Moya
parent
00c7411f92
commit
fe91201431
@@ -129,6 +129,8 @@
|
||||
|
||||
(def font-size-keys (schema-keys schema:font-size))
|
||||
|
||||
(def typography-keys (set/union font-size-keys))
|
||||
|
||||
(def ^:private schema:number
|
||||
[:map
|
||||
[:rotation {:optional true} token-name-ref]
|
||||
@@ -144,7 +146,7 @@
|
||||
spacing-keys
|
||||
dimensions-keys
|
||||
rotation-keys
|
||||
font-size-keys
|
||||
typography-keys
|
||||
number-keys))
|
||||
|
||||
(def ^:private schema:tokens
|
||||
|
||||
@@ -1498,26 +1498,29 @@ Will return a value that matches this schema:
|
||||
(defn get-tokens-of-unknown-type
|
||||
"Search for all tokens in the decoded json file that have a type that is not currently
|
||||
supported by Penpot. Returns a map token-path -> token type."
|
||||
([decoded-json]
|
||||
(get-tokens-of-unknown-type decoded-json "" (get-json-format decoded-json)))
|
||||
([decoded-json parent-path json-format]
|
||||
(let [type-key (if (= json-format :json-format/dtcg) "$type" "type")]
|
||||
(reduce-kv
|
||||
(fn [unknown-tokens k v]
|
||||
(let [child-path (if (empty? parent-path)
|
||||
(name k)
|
||||
(str parent-path "." k))]
|
||||
(if (and (map? v)
|
||||
(not (contains? v type-key)))
|
||||
(let [nested-unknown-tokens (get-tokens-of-unknown-type v child-path json-format)]
|
||||
(merge unknown-tokens nested-unknown-tokens))
|
||||
(let [token-type-str (get v type-key)
|
||||
token-type (cto/dtcg-token-type->token-type token-type-str)]
|
||||
(if (and (not (some? token-type)) (some? token-type-str))
|
||||
(assoc unknown-tokens child-path token-type-str)
|
||||
unknown-tokens)))))
|
||||
nil
|
||||
decoded-json))))
|
||||
[decoded-json {:keys [json-format parent-path process-token-type]
|
||||
:or {json-format (get-json-format decoded-json)
|
||||
parent-path ""
|
||||
process-token-type identity}
|
||||
:as opts}]
|
||||
(let [type-key (if (= json-format :json-format/dtcg) "$type" "type")]
|
||||
(reduce-kv
|
||||
(fn [unknown-tokens k v]
|
||||
(let [child-path (if (empty? parent-path)
|
||||
(name k)
|
||||
(str parent-path "." k))]
|
||||
(if (and (map? v)
|
||||
(not (contains? v type-key)))
|
||||
(let [nested-unknown-tokens (get-tokens-of-unknown-type v (assoc opts :parent-path child-path))]
|
||||
(merge unknown-tokens nested-unknown-tokens))
|
||||
(let [token-type-str (get v type-key)
|
||||
token-type (-> (cto/dtcg-token-type->token-type token-type-str)
|
||||
(process-token-type))]
|
||||
(if (and (not (some? token-type)) (some? token-type-str))
|
||||
(assoc unknown-tokens child-path token-type-str)
|
||||
unknown-tokens)))))
|
||||
nil
|
||||
decoded-json)))
|
||||
|
||||
;; === Serialization handlers for RPC API (transit) and database (fressian)
|
||||
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
(:require
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.json :as json]
|
||||
[app.common.types.token :as ctt]
|
||||
[app.common.types.tokens-lib :as ctob]
|
||||
[app.config :as cf]
|
||||
[app.main.data.notifications :as ntf]
|
||||
[app.main.data.style-dictionary :as sd]
|
||||
[app.main.data.workspace.tokens.errors :as wte]
|
||||
@@ -60,7 +62,17 @@
|
||||
[decoded-json file-name]
|
||||
(try
|
||||
{:tokens-lib (ctob/parse-decoded-json decoded-json file-name)
|
||||
:unknown-tokens (ctob/get-tokens-of-unknown-type decoded-json)}
|
||||
:unknown-tokens (ctob/get-tokens-of-unknown-type decoded-json
|
||||
;; Filter out FF token-types
|
||||
{:process-token-type
|
||||
(fn [dtcg-token-type]
|
||||
(if (or
|
||||
(and (not (contains? cf/flags :token-units))
|
||||
(= dtcg-token-type "number"))
|
||||
(and (not (contains? cf/flags :token-typography-types))
|
||||
(contains? ctt/typography-keys dtcg-token-type)))
|
||||
nil
|
||||
dtcg-token-type))})}
|
||||
(catch js/Error e
|
||||
(let [err (or (extract-name-error e)
|
||||
(wte/error-ex-info :error.import/invalid-json-data decoded-json e))]
|
||||
|
||||
Reference in New Issue
Block a user