;; shadow-cljs configuration
{:deps true
 :nrepl {:port 8701}
 :source-paths ["src/main" "src/electron" "src/resources"]

 ;; :ssl   {:password "logseq"}

 ;; "." for /static
 :dev-http {3001 ["static" "."]
            3002 "static/mobile"}

 :js-options {:js-package-dirs ["node_modules"]}

 :builds
 {:app {:target        :browser
        :module-loader true
        :js-options    {:ignore-asset-requires true
                        :resolve {"react" {:target :global
                                           :global "React"}
                                  "react-dom" {:target :global
                                               :global "ReactDOM"}}}
        :modules       {:main
                        {:init-fn frontend.core/init}
                        :code-editor
                        {:entries [frontend.extensions.code]
                         :depends-on #{:main}}}

        :output-dir       "./static/js"
        :asset-path       "/static/js"
        :compiler-options {:infer-externs      :auto
                           :output-feature-set :es-next-in
                           :source-map true
                           :externs ["datascript/externs.js"
                                     "externs.js"]
                           :warnings {:fn-deprecated false
                                      :redef false}}
        :build-hooks [(shadow.hooks/git-revision-hook "--long --always --dirty")]
        :closure-defines {lambdaisland.glogi.console/colorize "false"
                          lambdaisland.glogi.console/timestamp "true"
                          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]
                          ;; 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/ENABLE-RTC-SYNC-PRODUCTION #shadow/env ["ENABLE_RTC_SYNC_PRODUCTION" :as :bool :default true]
                          frontend.config/REVISION #shadow/env ["LOGSEQ_REVISION" :default "dev"]} ;; set by git-revision-hook

        :devtools {:before-load frontend.core/stop          ;; before live-reloading any code call this function
                   :after-load frontend.core/start          ;; after live-reloading finishes call this function
                   :watch-path "/static"
                   :preloads [devtools.preload
                              shadow.remote.runtime.cljs.browser]
                   :loader-mode :eval
                   ;; :ignore-warnings true
                   }}

  :db-worker {:target        :browser
              :module-loader true
              :js-options    {:js-provider    :external
                              :external-index "target/db-worker.js"
                              :external-index-format :esm
                              :entry-keys ["module" "browser" "main"]
                              :export-conditions ["module" "import", "browser" "require" "default"]}
              :modules       {:db-worker
                              {:init-fn frontend.worker.db-worker/init
                               :web-worker true
                               :prepend-js "importScripts('db-worker-bundle.js');"}}

              :output-dir       "./static/js"
              :asset-path       "/static/js"
              :release          {:asset-path "https://asset.logseq.com/static/js"}
              :compiler-options {:infer-externs      :auto
                                 :output-feature-set :es-next-in
                                 :source-map true
                                 :externs ["datascript/externs.js"
                                           "externs.js"]
                                 :warnings {:fn-deprecated false
                                            :redef false}}
              :closure-defines {goog.debug.LOGGING_ENABLED true
                                lambdaisland.glogi.console/colorize "false"
                                lambdaisland.glogi.console/timestamp "true"}
              :devtools {:watch-path "/static"
                         :preloads [devtools.preload
                                    shadow.remote.runtime.cljs.browser]
                         :loader-mode :eval}}

  :inference-worker {:target        :browser
                     :module-loader true
                     :js-options    {:js-provider    :external
                                     :external-index "target/inference-worker.js"
                                     :external-index-format :esm
                                     :entry-keys ["module" "browser" "main"]
                                     :export-conditions ["module" "import", "browser" "require" "default"]}
                     :modules       {:inference-worker
                                     {:init-fn frontend.inference-worker.inference-worker/init
                                      :web-worker true
                                      :prepend-js "importScripts('inference-worker-bundle.js');\n"}}

                     :output-dir       "./static/js"
                     :asset-path       "/static/js"
                     :release          {:asset-path "https://asset.logseq.com/static/js"}
                     :compiler-options {:infer-externs      :auto
                                        :output-feature-set :es-next-in
                                        :source-map true
                                        :externs ["datascript/externs.js"
                                                  "externs.js"]
                                        :warnings {:fn-deprecated false
                                                   :redef false}}
                     :closure-defines {goog.debug.LOGGING_ENABLED true}
                     :devtools {:watch-path "/static"
                                :preloads [devtools.preload
                                           shadow.remote.runtime.cljs.browser]}}
  :mobile {:target        :browser
           :module-loader true
           :js-options    {:ignore-asset-requires true
                           :resolve {"react" {:target :global
                                              :global "React"}
                                     "react-dom" {:target :global
                                                  :global "ReactDOM"}}}
           ;; handle `require(xxx.css)`
           :modules       {:main
                           {:init-fn mobile.core/init}
                           :code-editor
                           {:entries [frontend.extensions.code]
                            :depends-on #{:main}}}

           :output-dir       "./static/mobile/js"
           :asset-path       "./js"
           :release          {:asset-path "http://localhost"}
           :compiler-options {:infer-externs      :auto
                              :output-feature-set :es-next-in
                              :source-map true
                              :externs ["datascript/externs.js"
                                        "externs.js"]
                              :warnings {:fn-deprecated false
                                         :redef false}}
           :build-hooks [(shadow.hooks/git-revision-hook "--long --always --dirty")]
           :closure-defines
           {lambdaisland.glogi.console/colorize "false"
            lambdaisland.glogi.console/timestamp "true"
            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]
            ;; 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/ENABLE-RTC-SYNC-PRODUCTION #shadow/env ["ENABLE_RTC_SYNC_PRODUCTION" :as :bool :default true]
            frontend.config/REVISION #shadow/env ["LOGSEQ_REVISION" :default "dev"]}

           :devtools {:before-load mobile.core/stop!          ;; before live-reloading any code call this function
                      :after-load mobile.core/render!          ;; after live-reloading finishes call this function
                      :watch-path "/static/mobile"
                      :preloads [devtools.preload
                                 shadow.remote.runtime.cljs.browser]
                      :loader-mode :eval}}
  :electron {:target :node-script
             :output-to "static/electron.js"
             :main electron.core/main
             :devtools {:before-load electron.core/stop
                        :after-load electron.core/start}
             :compiler-options {:infer-externs :auto
                                :source-map true
                                :source-map-include-sources-content true
                                :source-map-detail-level :all

                                :externs ["datascript/externs.js"
                                          "externs.js"]
                                :warnings {:fn-deprecated false
                                           :redef false}}}

  :test {:target :node-test
         :output-to "static/tests.js"
         :closure-defines {frontend.util/NODETEST true
                           logseq.shui.util/NODETEST true}
         :devtools {:enabled false}
         ;; disable :static-fns to allow for with-redefs and repl development
         :compiler-options {:static-fns false}
         :main frontend.test.frontend-node-test-runner/main}

  :gen-malli-kondo-config {:target :node-script
                           :closure-defines {frontend.util/NODETEST true}
                           :devtools {:enabled false}
                           :compiler-options {:static-fns false}
                           :output-to "static/gen-malli-kondo-config.js"
                           :main gen-malli-kondo-config.core/main}

  :publishing {:target :browser
               :module-loader true
               :js-options {:ignore-asset-requires true
                            :resolve {"react" {:target :global
                                               :global "React"}
                                      "react-dom" {:target :global
                                                   :global "ReactDOM"}}}
               :modules {:main
                         {:init-fn frontend.publishing/init}
                         :code-editor
                         {:entries [frontend.extensions.code]
                          :depends-on #{:main}}}

               :output-dir "./static/js/publishing"
               :asset-path "static/js"
               :closure-defines {logseq.common.config/PUBLISHING true
                                 goog.debug.LOGGING_ENABLED true}
               :compiler-options {:infer-externs :auto
                                  :output-feature-set :es-next-in
                                  :source-map true
                                  :externs ["datascript/externs.js"
                                            "externs.js"]
                                  :warnings {:fn-deprecated false
                                             :redef false}}
               :devtools {:before-load frontend.core/stop
                          :after-load frontend.core/start
                          :preloads [devtools.preload]}}

  :stories-dev {:target :npm-module
                :entries [logseq.shui.storybook]
                :output-dir "packages/ui/.storybook/cljs"
                :devtools {:enabled true}
                :compiler-options {:optimizations :simple}}}}
