mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 06:02:32 -05:00
Use penpot logging system instead of custom debug flag
This commit is contained in:
parent
77141887a8
commit
3bd2278dec
1 changed files with 19 additions and 22 deletions
|
@ -2,13 +2,16 @@
|
|||
(:require
|
||||
["@tokens-studio/sd-transforms" :as sd-transforms]
|
||||
["style-dictionary$default" :as sd]
|
||||
[app.common.logging :as l]
|
||||
[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.token :as wtt]
|
||||
[cuerdas.core :as str]
|
||||
[promesa.core :as p]
|
||||
[rumext.v2 :as mf]
|
||||
[app.main.ui.workspace.tokens.errors :as wte]))
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(l/set-level! "app.main.ui.workspace.tokens.style-dictionary" :warn)
|
||||
|
||||
(def StyleDictionary
|
||||
"Initiates the global StyleDictionary instance with transforms
|
||||
|
@ -25,7 +28,7 @@
|
|||
(defn tokens->style-dictionary+
|
||||
"Resolves references and math expressions using StyleDictionary.
|
||||
Returns a promise with the resolved dictionary."
|
||||
[tokens {:keys [debug?]}]
|
||||
[tokens]
|
||||
(let [data (cond-> {:tokens tokens
|
||||
:platforms {:json {:transformGroup "tokens-studio"
|
||||
:files [{:format "custom/json"
|
||||
|
@ -34,35 +37,31 @@
|
|||
:warnings "silent"
|
||||
:errors {:brokenReferences "console"}}
|
||||
:preprocessors ["tokens-studio"]}
|
||||
debug? (update :log merge {:verbosity "verbose"
|
||||
:warnings "warn"}))
|
||||
(l/enabled? "app.main.ui.workspace.tokens.style-dictionary" :debug)
|
||||
(update :log merge {:verbosity "verbose"
|
||||
:warnings "warn"}))
|
||||
js-data (clj->js data)]
|
||||
(when debug?
|
||||
(js/console.log "Input Data" js-data))
|
||||
(l/debug :hint "Input Data" :js/data js-data)
|
||||
(sd. js-data)))
|
||||
|
||||
(defn resolve-sd-tokens+
|
||||
"Resolves references and math expressions using StyleDictionary.
|
||||
Returns a promise with the resolved dictionary."
|
||||
[tokens & {:keys [debug?] :as config}]
|
||||
[tokens]
|
||||
(let [performance-start (js/performance.now)
|
||||
sd (tokens->style-dictionary+ tokens config)]
|
||||
(when debug?
|
||||
(js/console.log "StyleDictionary" sd))
|
||||
sd (tokens->style-dictionary+ tokens)]
|
||||
(l/debug :hint "StyleDictionary" :js/style-dictionary sd)
|
||||
(-> sd
|
||||
(.buildAllPlatforms "json")
|
||||
(.catch js/console.error)
|
||||
(.catch #(l/error :hint "Styledictionary build error" :js/error %))
|
||||
(.then (fn [^js resp]
|
||||
(js/console.log "resp" resp)
|
||||
(let [performance-end (js/performance.now)
|
||||
duration-ms (- performance-end performance-start)
|
||||
resolved-tokens (.-allTokens resp)]
|
||||
(when debug?
|
||||
(js/console.log "Time elapsed" duration-ms "ms")
|
||||
(js/console.log "Resolved tokens" resolved-tokens))
|
||||
(l/debug :hint (str "Time elapsed" duration-ms "ms") :duration duration-ms)
|
||||
(l/debug :hint "Resolved tokens" :js/tokens resolved-tokens)
|
||||
resolved-tokens))))))
|
||||
|
||||
|
||||
(defn humanize-errors [{:keys [errors value] :as _token}]
|
||||
(->> (map (fn [err]
|
||||
(case err
|
||||
|
@ -72,9 +71,9 @@
|
|||
(str/join "\n")))
|
||||
|
||||
(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)
|
||||
(resolve-sd-tokens+ config))]
|
||||
(resolve-sd-tokens+))]
|
||||
(let [resolved-tokens (reduce
|
||||
(fn [acc ^js cur]
|
||||
(let [identifier (if names-map?
|
||||
|
@ -99,8 +98,7 @@
|
|||
:unit (:unit token-or-err)))]
|
||||
(assoc acc (wtt/token-identifier output-token) output-token)))
|
||||
{} sd-tokens)]
|
||||
(when debug?
|
||||
(js/console.log "Resolved tokens" resolved-tokens))
|
||||
(l/debug :hint "Resolved tokens" :js/tokens resolved-tokens)
|
||||
resolved-tokens)))
|
||||
|
||||
;; Hooks -----------------------------------------------------------------------
|
||||
|
@ -140,7 +138,6 @@
|
|||
|
||||
(defn use-resolved-workspace-tokens [& {:as config}]
|
||||
(-> (mf/deref refs/workspace-selected-token-set-tokens)
|
||||
(doto js/console.log)
|
||||
(use-resolved-tokens config)))
|
||||
|
||||
(defn use-active-theme-sets-tokens [& {:as config}]
|
||||
|
|
Loading…
Add table
Reference in a new issue