0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-11 01:28:30 -05:00

🔥 Remove the need of static (build time) configuration.

This commit is contained in:
Andrey Antukh 2020-08-18 16:33:12 +02:00
parent 2746d598b0
commit fb910a24e1
4 changed files with 32 additions and 64 deletions

View file

@ -1,4 +0,0 @@
#!/usr/bin/env bash
set -ex
#clojure -Ojmx-remote -A:dev -e "(set! *warn-on-reflection* true)" -m rebel-readline.main
clojure -Ojmx-remote -A:dev -m rebel-readline.main

View file

@ -108,44 +108,15 @@ function readLocales() {
return JSON.stringify(result);
}
function readConfig(data) {
const googleClientID = process.env.UXBOX_GOOGLE_CLIENT_ID;
const demoWarn = process.env.UXBOX_DEMO_WARNING;
const deployDate = process.env.UXBOX_DEPLOY_DATE;
const deployCommit = process.env.UXBOX_DEPLOY_COMMIT;
const loginWithLDAP = process.env.UXBOX_LOGIN_WITH_LDAP;
let cfg = {
demoWarning: demoWarn === "true"
};
if (googleClientID !== undefined) {
cfg.googleClientID = googleClientID;
}
if (deployDate !== undefined) {
cfg.deployDate = deployDate;
}
if (deployCommit !== undefined) {
cfg.deployCommit = deployCommit;
}
if (loginWithLDAP !== undefined) {
cfg.loginWithLDAP = loginWithLDAP;
}
Object.assign(cfg, data);
return JSON.stringify(cfg);
}
function readManifest(publicURI) {
function readManifest() {
try {
const path = __dirname + "/resources/public/js/manifest.json";
const content = JSON.parse(fs.readFileSync(path, {encoding: "utf8"}));
const index = {};
const index = {
"config": "/js/config.js?ts=" + Date.now()
};
for (let item of content) {
index[item.name] = "/js/" + item["output-name"];
};
@ -154,6 +125,7 @@ function readManifest(publicURI) {
} catch (e) {
console.error("Error on reading manifest, using default.");
return {
"config": "/js/config.js",
"main": "/js/main.js",
"shared": "/js/shared.js",
"worker": "/js/worker.js"
@ -180,24 +152,23 @@ function templatePipeline(options) {
const output = options.output;
const ts = Math.floor(new Date());
const publicURI = process.env.UXBOX_PUBLIC_URI || "http://localhost:3449";
const th = process.env.UXBOX_THEME || "default";
const deployDate = process.env.UXBOX_DEPLOY_DATE;
const deployCommit = process.env.UXBOX_DEPLOY_COMMIT;
const themes = ["default"];
const locales = readLocales();
const manifest = readManifest(publicURI);
const manifest = readManifest();
const config = readConfig({
workerURI: manifest.worker,
publicURI: publicURI
});
const defaultConf = `var uxboxConfig = {demoWarning: false, googleClientID: null, loginWithLDAP: null, publicURI: null};`
fs.writeFileSync(__dirname + "/resources/public/js/config.js", defaultConf)
const tmpl = mustache({
deployCommit,
deployDate,
ts: ts,
th: th,
manifest: manifest,
config: JSON.stringify(config),
translations: JSON.stringify(locales),
themes: JSON.stringify(themes),
});

View file

@ -12,13 +12,17 @@
<section id="app" tabindex="1"></section>
<section id="modal"></section>
<script>
window.uxboxConfig = JSON.parse({{& config }});
window.uxboxTranslations = JSON.parse({{& translations }});
window.uxboxThemes = {{& themes }};
window.uxboxTranslations = JSON.parse({{& translations }});
window.uxboxThemes = {{& themes }};
window.uxboxDeployDate = "{{& deployDate }}";
window.uxboxDeployCommit = "{{& deployCommit }}";
</script>
{{# manifest}}
<script src="{{& shared}}"></script>
<script src="{{& main}}"></script>
<script>window.uxboxWorkerURI="{{& worker}}"</script>
<script src="{{& config}}"></script>
<script src="{{& shared}}"></script>
<script src="{{& main}}"></script>
{{/manifest}}
</body>
</html>

View file

@ -11,20 +11,17 @@
(:require [uxbox.util.object :as obj]))
(this-as global
(let [config (obj/get global "uxboxConfig")
puri (obj/get config "publicURI")
wuri (obj/get config "workerURI")
gcid (obj/get config "googleClientID" true)
lwl (obj/get config "loginWithLDAP" false)
warn (obj/get config "demoWarning" true)]
(let [config (obj/get global "uxboxConfig" {})
wuri (obj/get global "uxboxWorkerURI" "/js/worker.js")]
(def default-language "en")
(def demo-warning warn)
(def google-client-id gcid)
(def login-with-ldap lwl)
(def worker-uri wuri)
(def public-uri puri)
(def media-uri (str puri "/media"))
(def default-theme "default")))
(def demo-warning (obj/get config "demoWarning" false))
(def google-client-id (obj/get config "googleClientID"))
(def login-with-ldap (obj/get config "loginWithLDAP" false))
(def worker-uri wuri)
(def public-uri (or (obj/get config "publicURI")
(.-origin ^js js/location)))
(def media-uri (str public-uri "/media"))
(def default-theme "default")))
(defn resolve-media-path
[path]