0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-21 14:12:36 -05:00

Use penpot logging system instead of custom debug flag

This commit is contained in:
Florian Schroedl 2024-09-18 11:15:11 +02:00
parent 77141887a8
commit 3bd2278dec

View file

@ -2,13 +2,16 @@
(:require (:require
["@tokens-studio/sd-transforms" :as sd-transforms] ["@tokens-studio/sd-transforms" :as sd-transforms]
["style-dictionary$default" :as sd] ["style-dictionary$default" :as sd]
[app.common.logging :as l]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.ui.workspace.tokens.errors :as wte]
[app.main.ui.workspace.tokens.tinycolor :as tinycolor] [app.main.ui.workspace.tokens.tinycolor :as tinycolor]
[app.main.ui.workspace.tokens.token :as wtt] [app.main.ui.workspace.tokens.token :as wtt]
[cuerdas.core :as str] [cuerdas.core :as str]
[promesa.core :as p] [promesa.core :as p]
[rumext.v2 :as mf] [rumext.v2 :as mf]))
[app.main.ui.workspace.tokens.errors :as wte]))
(l/set-level! "app.main.ui.workspace.tokens.style-dictionary" :warn)
(def StyleDictionary (def StyleDictionary
"Initiates the global StyleDictionary instance with transforms "Initiates the global StyleDictionary instance with transforms
@ -25,7 +28,7 @@
(defn tokens->style-dictionary+ (defn tokens->style-dictionary+
"Resolves references and math expressions using StyleDictionary. "Resolves references and math expressions using StyleDictionary.
Returns a promise with the resolved dictionary." Returns a promise with the resolved dictionary."
[tokens {:keys [debug?]}] [tokens]
(let [data (cond-> {:tokens tokens (let [data (cond-> {:tokens tokens
:platforms {:json {:transformGroup "tokens-studio" :platforms {:json {:transformGroup "tokens-studio"
:files [{:format "custom/json" :files [{:format "custom/json"
@ -34,35 +37,31 @@
:warnings "silent" :warnings "silent"
:errors {:brokenReferences "console"}} :errors {:brokenReferences "console"}}
:preprocessors ["tokens-studio"]} :preprocessors ["tokens-studio"]}
debug? (update :log merge {:verbosity "verbose" (l/enabled? "app.main.ui.workspace.tokens.style-dictionary" :debug)
:warnings "warn"})) (update :log merge {:verbosity "verbose"
:warnings "warn"}))
js-data (clj->js data)] js-data (clj->js data)]
(when debug? (l/debug :hint "Input Data" :js/data js-data)
(js/console.log "Input Data" js-data))
(sd. js-data))) (sd. js-data)))
(defn resolve-sd-tokens+ (defn resolve-sd-tokens+
"Resolves references and math expressions using StyleDictionary. "Resolves references and math expressions using StyleDictionary.
Returns a promise with the resolved dictionary." Returns a promise with the resolved dictionary."
[tokens & {:keys [debug?] :as config}] [tokens]
(let [performance-start (js/performance.now) (let [performance-start (js/performance.now)
sd (tokens->style-dictionary+ tokens config)] sd (tokens->style-dictionary+ tokens)]
(when debug? (l/debug :hint "StyleDictionary" :js/style-dictionary sd)
(js/console.log "StyleDictionary" sd))
(-> sd (-> sd
(.buildAllPlatforms "json") (.buildAllPlatforms "json")
(.catch js/console.error) (.catch #(l/error :hint "Styledictionary build error" :js/error %))
(.then (fn [^js resp] (.then (fn [^js resp]
(js/console.log "resp" resp)
(let [performance-end (js/performance.now) (let [performance-end (js/performance.now)
duration-ms (- performance-end performance-start) duration-ms (- performance-end performance-start)
resolved-tokens (.-allTokens resp)] resolved-tokens (.-allTokens resp)]
(when debug? (l/debug :hint (str "Time elapsed" duration-ms "ms") :duration duration-ms)
(js/console.log "Time elapsed" duration-ms "ms") (l/debug :hint "Resolved tokens" :js/tokens resolved-tokens)
(js/console.log "Resolved tokens" resolved-tokens))
resolved-tokens)))))) resolved-tokens))))))
(defn humanize-errors [{:keys [errors value] :as _token}] (defn humanize-errors [{:keys [errors value] :as _token}]
(->> (map (fn [err] (->> (map (fn [err]
(case err (case err
@ -72,9 +71,9 @@
(str/join "\n"))) (str/join "\n")))
(defn resolve-tokens+ (defn resolve-tokens+
[tokens & {:keys [names-map? debug?] :as config}] [tokens & {:keys [names-map?] :as config}]
(p/let [sd-tokens (-> (wtt/token-names-tree tokens) (p/let [sd-tokens (-> (wtt/token-names-tree tokens)
(resolve-sd-tokens+ config))] (resolve-sd-tokens+))]
(let [resolved-tokens (reduce (let [resolved-tokens (reduce
(fn [acc ^js cur] (fn [acc ^js cur]
(let [identifier (if names-map? (let [identifier (if names-map?
@ -99,8 +98,7 @@
:unit (:unit token-or-err)))] :unit (:unit token-or-err)))]
(assoc acc (wtt/token-identifier output-token) output-token))) (assoc acc (wtt/token-identifier output-token) output-token)))
{} sd-tokens)] {} sd-tokens)]
(when debug? (l/debug :hint "Resolved tokens" :js/tokens resolved-tokens)
(js/console.log "Resolved tokens" resolved-tokens))
resolved-tokens))) resolved-tokens)))
;; Hooks ----------------------------------------------------------------------- ;; Hooks -----------------------------------------------------------------------
@ -140,7 +138,6 @@
(defn use-resolved-workspace-tokens [& {:as config}] (defn use-resolved-workspace-tokens [& {:as config}]
(-> (mf/deref refs/workspace-selected-token-set-tokens) (-> (mf/deref refs/workspace-selected-token-set-tokens)
(doto js/console.log)
(use-resolved-tokens config))) (use-resolved-tokens config)))
(defn use-active-theme-sets-tokens [& {:as config}] (defn use-active-theme-sets-tokens [& {:as config}]