瀏覽代碼

refactor: move most goog-define var into ns frontend.compile-option

rcmerci 2 年之前
父節點
當前提交
5b0714c23a

+ 1 - 0
.clj-kondo/config.edn

@@ -45,6 +45,7 @@
              frontend.components.query query
              frontend.components.query.result query-result
              frontend.config config
+             frontend.compile-config cconfig
              frontend.date date
              frontend.db db
              frontend.db-mixins db-mixins

+ 2 - 2
package.json

@@ -63,8 +63,8 @@
         "cljs:release-publishing": "clojure -M:cljs release publishing",
         "cljs:test": "clojure -M:test compile test",
         "cljs:run-test": "node static/tests.js",
-        "cljs:dev-release-app": "clojure -M:cljs release app --config-merge \"{:closure-defines {frontend.config/DEV-RELEASE true}}\"",
-        "cljs:dev-release-electron": "clojure -M:cljs release app electron --debug --config-merge \"{:closure-defines {frontend.config/DEV-RELEASE true}}\" && clojure -M:cljs release publishing",
+        "cljs:dev-release-app": "clojure -M:cljs release app --config-merge \"{:closure-defines {frontend.compile-config/DEV-RELEASE true}}\"",
+        "cljs:dev-release-electron": "clojure -M:cljs release app electron --debug --config-merge \"{:closure-defines {frontend.compile-config/DEV-RELEASE true}}\" && clojure -M:cljs release publishing",
         "cljs:debug": "clojure -M:cljs release app --debug",
         "cljs:report": "clojure -M:cljs run shadow.cljs.build-report app report.html",
         "cljs:build-electron": "clojure -A:cljs compile app electron",

+ 7 - 8
shadow-cljs.edn

@@ -22,7 +22,7 @@
                         :tldraw
                         {:entries    [frontend.extensions.tldraw]
                          :depends-on #{:main}}}
-                        
+
         :output-dir       "./static/js"
         :asset-path       "/static/js"
         :release          {:asset-path "https://asset.logseq.com/static/js"}
@@ -37,11 +37,11 @@
         :closure-defines  {goog.debug.LOGGING_ENABLED       true
                            frontend.modules.instrumentation.sentry/SENTRY-DSN #shadow/env "LOGSEQ_SENTRY_DSN"
                            frontend.modules.instrumentation.posthog/POSTHOG-TOKEN #shadow/env "LOGSEQ_POSTHOG_TOKEN"
-                           frontend.config/ENABLE-PLUGINS #shadow/env ["ENABLE_PLUGINS" :as :bool :default true]
+                           frontend.compile-config/ENABLE-PLUGINS #shadow/env ["ENABLE_PLUGINS" :as :bool :default true]
                            ;; Set to switch file sync server to dev, set this to false in `yarn watch`
-                           frontend.config/ENABLE-FILE-SYNC-PRODUCTION #shadow/env ["ENABLE_FILE_SYNC_PRODUCTION" :as :bool :default true]
-                           frontend.config/TEST #shadow/env ["LOGSEQ_CI" :as :bool :default false]
-                           frontend.config/REVISION #shadow/env ["LOGSEQ_REVISION" :default "dev"]} ;; set by git-revision-hook
+                           frontend.compile-config/ENABLE-FILE-SYNC-PRODUCTION #shadow/env ["ENABLE_FILE_SYNC_PRODUCTION" :as :bool :default true]
+                           frontend.compile-config/TEST #shadow/env ["LOGSEQ_CI" :as :bool :default false]
+                           frontend.compile-config/REVISION #shadow/env ["LOGSEQ_REVISION" :default "dev"]} ;; set by git-revision-hook
 
         ;; NOTE: electron, browser/mobile-app use different asset-paths.
         ;;   For browser/mobile-app devs, assets are located in /static/js(via HTTP root).
@@ -97,10 +97,10 @@
                                :tldraw
                                {:entries    [frontend.extensions.tldraw]
                                 :depends-on #{:main}}}
-                               
+
                :output-dir       "./static/js/publishing"
                :asset-path       "static/js"
-               :closure-defines  {frontend.config/PUBLISHING true
+               :closure-defines  {frontend.compile-config/PUBLISHING true
                                   goog.debug.LOGGING_ENABLED true}
                :compiler-options {:infer-externs      :auto
                                   :output-feature-set :es-next
@@ -111,4 +111,3 @@
                :devtools         {:before-load frontend.core/stop
                                   :after-load  frontend.core/start
                                   :preloads    [devtools.preload]}}}}
-  

+ 2 - 2
src/dev-cljs/shadow/hooks.clj

@@ -39,6 +39,6 @@
     (prn ::git-revision-hook revision)
     (-> build-state
         (assoc-in [:shadow.build/config :closure-defines]
-                  (assoc defines-in-config 'frontend.config/REVISION revision))
+                  (assoc defines-in-config 'frontend.compile-config/REVISION revision))
         (assoc-in [:compiler-options :closure-defines]
-                  (assoc defines-in-options 'frontend.config/REVISION revision)))))
+                  (assoc defines-in-options 'frontend.compile-config/REVISION revision)))))

+ 17 - 0
src/main/frontend/compile_config.cljs

@@ -0,0 +1,17 @@
+(ns frontend.compile-config
+  "This ns contains compile-options")
+
+
+(goog-define DEV-RELEASE false)
+
+(goog-define PUBLISHING false)
+
+(goog-define REVISION "unknown")
+
+(goog-define TEST false)
+
+(goog-define ENABLE-FILE-SYNC-FEATURE true)
+
+(goog-define ENABLE-FILE-SYNC-PRODUCTION false)
+
+(goog-define ENABLE-PLUGINS true)

+ 2 - 1
src/main/frontend/components/header.cljs

@@ -7,6 +7,7 @@
             [frontend.components.right-sidebar :as sidebar]
             [frontend.components.svg :as svg]
             [frontend.config :as config]
+            [frontend.compile-config :as cconfig]
             [frontend.context.i18n :refer [t]]
             [frontend.handler :as handler]
             [frontend.components.file-sync :as fs-sync]
@@ -65,7 +66,7 @@
   (let [ua (.-userAgent js/navigator)
         safe-ua (string/replace ua #"[^_/a-zA-Z0-9\.\(\)]+" " ")
         platform (str "App Version: " version "\n"
-                      "Git Revision: " config/REVISION "\n"
+                      "Git Revision: " cconfig/REVISION "\n"
                       "Platform: " safe-ua "\n"
                       "Language: " (.-language js/navigator) "\n"
                       "Plugins: " (string/join ", " (map (fn [[k v]]

+ 7 - 15
src/main/frontend/config.cljs

@@ -5,6 +5,7 @@
             [frontend.mobile.util :as mobile-util]
             [frontend.state :as state]
             [frontend.util :as util]
+            [frontend.compile-config :as cconfig]
             [logseq.common.path :as path]
             [logseq.graph-parser.config :as gp-config]
             [logseq.graph-parser.util :as gp-util]
@@ -12,30 +13,22 @@
             [goog.crypt.Md5]
             [goog.crypt :as crypt]))
 
-(goog-define DEV-RELEASE false)
-(defonce dev-release? DEV-RELEASE)
+(defonce dev-release? cconfig/DEV-RELEASE)
 (defonce dev? ^boolean (or dev-release? goog.DEBUG))
 
-(goog-define PUBLISHING false)
-(defonce publishing? PUBLISHING)
+(defonce publishing? cconfig/PUBLISHING)
 
-(goog-define REVISION "unknown")
-(defonce revision REVISION)
+(defonce revision cconfig/REVISION)
 
 (reset! state/publishing? publishing?)
 
-(goog-define TEST false)
-(def test? TEST)
-
-(goog-define ENABLE-FILE-SYNC-FEATURE true)
-
-(goog-define ENABLE-FILE-SYNC-PRODUCTION false)
+(def test? cconfig/TEST)
 
 ;; this is a feature flag to enable the account tab
 ;; when it launches (when pro plan launches) it should be removed
 (def ENABLE-SETTINGS-ACCOUNT-TAB false)
 
-(if ENABLE-FILE-SYNC-PRODUCTION
+(if cconfig/ENABLE-FILE-SYNC-PRODUCTION
   (do (def FILE-SYNC-PROD? true)
       (def LOGIN-URL
         "https://logseq-prod.auth.us-east-1.amazoncognito.com/login?client_id=3c7np6bjtb4r1k1bi9i049ops5&response_type=code&scope=email+openid+phone&redirect_uri=logseq%3A%2F%2Fauth-callback")
@@ -66,8 +59,7 @@
 ;; Feature flags
 ;; =============
 
-(goog-define ENABLE-PLUGINS true)
-(defonce feature-plugin-system-on? ENABLE-PLUGINS)
+(defonce feature-plugin-system-on? cconfig/ENABLE-PLUGINS)
 
 ;; Desktop only as other platforms requires better understanding of their
 ;; multi-graph workflows and optimal place for a "global" dir

+ 2 - 2
src/main/frontend/state.cljs

@@ -7,7 +7,7 @@
             [clojure.string :as string]
             [dommy.core :as dom]
             [electron.ipc :as ipc]
-            [frontend.config :as config]
+            [frontend.compile-config :as cconfig]
             [frontend.mobile.util :as mobile-util]
             [frontend.spec.storage :as storage-spec]
             [frontend.storage :as storage]
@@ -608,7 +608,7 @@ Similar to re-frame subscriptions"
 
 (defn enable-sync?
   []
-  (and config/ENABLE-FILE-SYNC-FEATURE
+  (and cconfig/ENABLE-FILE-SYNC-FEATURE
        (sub :feature/enable-sync?)))
 
 (defn enable-sync-diff-merge?