mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 07:29:08 -05:00
Merge pull request #2623 from penpot/niwinz-parse-frontend-features-from-flags
✨ Parse frontend features from flags
This commit is contained in:
commit
efb4b2cb7d
2 changed files with 48 additions and 32 deletions
|
@ -65,11 +65,6 @@
|
|||
flags (sequence (map keyword) (str/words flags))]
|
||||
(flags/parse flags/default default-flags flags)))
|
||||
|
||||
(defn- parse-features
|
||||
[global]
|
||||
(when-let [features-str (obj/get global "penpotFeatures")]
|
||||
(map keyword (str/words features-str))))
|
||||
|
||||
(defn- parse-version
|
||||
[global]
|
||||
(-> (obj/get global "penpotVersion")
|
||||
|
@ -94,7 +89,6 @@
|
|||
|
||||
(def build-date (parse-build-date global))
|
||||
(def flags (atom (parse-flags global)))
|
||||
(def features (atom (parse-features global)))
|
||||
(def version (atom (parse-version global)))
|
||||
(def target (atom (parse-target global)))
|
||||
(def browser (atom (parse-browser)))
|
||||
|
|
|
@ -8,38 +8,54 @@
|
|||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.logging :as log]
|
||||
[app.config :as cfg]
|
||||
[app.config :as cf]
|
||||
[app.main.store :as st]
|
||||
[app.util.timers :as tm]
|
||||
[cuerdas.core :as str]
|
||||
[okulary.core :as l]
|
||||
[potok.core :as ptk]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(log/set-level! :debug)
|
||||
(log/set-level! :trace)
|
||||
|
||||
(def available-features #{:auto-layout :components-v2})
|
||||
(def available-features
|
||||
#{:auto-layout :components-v2})
|
||||
|
||||
(defn- toggle-feature
|
||||
[feature]
|
||||
(ptk/reify ::toggle-feature
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(log/debug :msg "toggle-feature"
|
||||
:feature (d/name feature)
|
||||
:result (if (not (contains? (:features state) feature))
|
||||
"enabled"
|
||||
"disabled"))
|
||||
(-> state
|
||||
(update :features
|
||||
(fn [features]
|
||||
(let [features (or features #{})]
|
||||
(let [features (or (:features state) #{})]
|
||||
(if (contains? features feature)
|
||||
(disj features feature)
|
||||
(conj features feature)))))))))
|
||||
(do
|
||||
(log/debug :hint "feature disabled" :feature (d/name feature))
|
||||
(assoc state :features (disj features feature)))
|
||||
(do
|
||||
(log/debug :hint "feature enabled" :feature (d/name feature))
|
||||
(assoc state :features (conj features feature))))))))
|
||||
|
||||
(defn- enable-feature
|
||||
[feature]
|
||||
(ptk/reify ::enable-feature
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [features (or (:features state) #{})]
|
||||
(if (contains? features feature)
|
||||
state
|
||||
(do
|
||||
(log/debug :hint "feature enabled" :feature (d/name feature))
|
||||
(assoc state :features (conj features feature))))))))
|
||||
|
||||
(defn toggle-feature!
|
||||
[feature]
|
||||
(assert (contains? available-features feature) "Not supported feature")
|
||||
(st/emit! (toggle-feature feature)))
|
||||
(tm/schedule-on-idle #(st/emit! (toggle-feature feature))))
|
||||
|
||||
(defn enable-feature!
|
||||
[feature]
|
||||
(assert (contains? available-features feature) "Not supported feature")
|
||||
(tm/schedule-on-idle #(st/emit! (enable-feature feature))))
|
||||
|
||||
(defn active-feature?
|
||||
([feature]
|
||||
|
@ -62,14 +78,20 @@
|
|||
active-feature? (mf/deref active-feature-ref)]
|
||||
active-feature?))
|
||||
|
||||
;; Read initial enabled features from config, if set
|
||||
(if-let [enabled-features @cfg/features]
|
||||
(doseq [f enabled-features]
|
||||
(toggle-feature! f))
|
||||
;; Enable all features set on the configuration
|
||||
(->> @cf/flags
|
||||
(map str)
|
||||
(keep (fn [flag]
|
||||
(when (str/starts-with? flag "frontend-feature-")
|
||||
(subs flag 17))))
|
||||
(map keyword)
|
||||
(run! enable-feature!))
|
||||
|
||||
(when *assert*
|
||||
;; Enable the rest of available configuration if we are on development
|
||||
;; environemnt (aka devenv).
|
||||
(when *assert*
|
||||
;; By default, all features disabled, except in development
|
||||
;; environment, that are enabled except components-v2
|
||||
(doseq [f available-features]
|
||||
(when (not= f :components-v2)
|
||||
(toggle-feature! f)))))
|
||||
(->> available-features
|
||||
(remove #(= % :components-v2))
|
||||
(run! enable-feature!)))
|
||||
|
|
Loading…
Add table
Reference in a new issue