From c09f281f5842b1ee9065928bc2c35a84c44d8038 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 11 Mar 2020 09:20:12 +0100 Subject: [PATCH] :tada: Make the build to be config independent. Loading the configuration dinamically using global variables defined in index.html. --- frontend/gulpfile.js | 14 +++++++++++++- frontend/resources/templates/index.mustache | 6 +++++- frontend/src/uxbox/config.cljs | 15 ++++++++++----- frontend/src/uxbox/main.cljs | 12 +++++++----- frontend/src/uxbox/main/data/workspace.cljs | 3 +++ frontend/tools.clj | 9 --------- 6 files changed, 38 insertions(+), 21 deletions(-) diff --git a/frontend/gulpfile.js b/frontend/gulpfile.js index 04aa654a0..968fe3717 100644 --- a/frontend/gulpfile.js +++ b/frontend/gulpfile.js @@ -100,6 +100,16 @@ function readLocales() { return JSON.stringify(result); } +function readConfig() { + const apiUrl = process.env.UXBOX_API_URL; + const demoWarn = process.env.UXBOX_DEMO_WARNING; + + return JSON.stringify({ + apiUrl: (apiUrl === undefined ? "http://localhost:6060" : apiUrl.trim()), + demoWarning: demoWarn === "true", + }); +} + function templatePipeline(options) { return function() { const input = options.input; @@ -108,11 +118,13 @@ function templatePipeline(options) { const locales = readLocales(); const icons = readSvgSprite(); + const config = readConfig(); const tmpl = mustache({ ts: ts, ic: icons, - tr: JSON.stringify(locales), + config: JSON.stringify(config), + translations: JSON.stringify(locales), }); return gulp.src(input) diff --git a/frontend/resources/templates/index.mustache b/frontend/resources/templates/index.mustache index 7c2a08582..88c30382e 100644 --- a/frontend/resources/templates/index.mustache +++ b/frontend/resources/templates/index.mustache @@ -14,8 +14,12 @@
+ - + diff --git a/frontend/src/uxbox/config.cljs b/frontend/src/uxbox/config.cljs index c3d6ea5b0..9080abfdb 100644 --- a/frontend/src/uxbox/config.cljs +++ b/frontend/src/uxbox/config.cljs @@ -2,10 +2,15 @@ ;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;; -;; Copyright (c) 2016 Andrey Antukh +;; This Source Code Form is "Incompatible With Secondary Licenses", as +;; defined by the Mozilla Public License, v. 2.0. +;; +;; Copyright (c) 2016-2020 Andrey Antukh -(ns uxbox.config) +(ns uxbox.config + (:require [goog.object :as gobj])) -(goog-define url "") -(goog-define demo-warning false) -(goog-define default-language "en") +(let [config (gobj/get goog.global "uxboxConfig")] + (def default-language "en") + (def url (gobj/get config "apiUrl" "http://localhost:6060/")) + (def demo-warning (gobj/get config "demoWarning" true))) diff --git a/frontend/src/uxbox/main.cljs b/frontend/src/uxbox/main.cljs index 47bfd8ead..50a39dc87 100644 --- a/frontend/src/uxbox/main.cljs +++ b/frontend/src/uxbox/main.cljs @@ -11,6 +11,7 @@ (:require [cljs.spec.alpha :as s] [beicon.core :as rx] + [goog.object :as gobj] [rumext.alpha :as mf] [uxbox.main.data.auth :refer [logout]] [uxbox.main.data.users :as udu] @@ -66,11 +67,12 @@ (def app-sym (.for js/Symbol "uxbox.app")) (defn ^:export init - [translations] - (i18n/init! (js/JSON.parse translations)) - (unchecked-set js/window app-sym "main") - (st/init) - (init-ui)) + [] + (let [translations (gobj/get goog.global "uxboxTranslations")] + (i18n/init! translations) + (unchecked-set js/window app-sym "main") + (st/init) + (init-ui))) (defn reinit [] diff --git a/frontend/src/uxbox/main/data/workspace.cljs b/frontend/src/uxbox/main/data/workspace.cljs index 6caaafde3..ead4a6401 100644 --- a/frontend/src/uxbox/main/data/workspace.cljs +++ b/frontend/src/uxbox/main/data/workspace.cljs @@ -2,6 +2,9 @@ ;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;; +;; This Source Code Form is "Incompatible With Secondary Licenses", as +;; defined by the Mozilla Public License, v. 2.0. +;; ;; Copyright (c) 2015-2019 Andrey Antukh (ns uxbox.main.data.workspace diff --git a/frontend/tools.clj b/frontend/tools.clj index fc95e1eca..57c437747 100644 --- a/frontend/tools.clj +++ b/frontend/tools.clj @@ -28,20 +28,11 @@ ;; --- Generic Build Options -(def closure-defines - (let [url (some-> (:uxbox-api-url env) - (str/trim)) - demo-warn (some-> (:uxbox-demo-warning env) - (str/trim))] - {'uxbox.config.url (if (nil? url) "http://localhost:6060" url) - 'uxbox.config.demo-warning (= "true" demo-warn)})) - (def default-build-options {:cache-analysis true :parallel-build true :language-in :ecmascript6 :language-out :ecmascript5 - :closure-defines closure-defines :anon-fn-naming-policy :mapped :optimizations :none :infer-externs true