From f92f3b2c21a7989be1862f27ff19c9f430d1dbf6 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 22 Mar 2021 19:19:44 +0100 Subject: [PATCH] copy push config in build script --- assets/config.json | 7 +++++++ scripts/build.mjs | 13 +++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 assets/config.json diff --git a/assets/config.json b/assets/config.json new file mode 100644 index 00000000..ae46ccfd --- /dev/null +++ b/assets/config.json @@ -0,0 +1,7 @@ +{ + "push": { + "appId": "io.element.hydrogen.web", + "gatewayUrl": "https://matrix.org", + "applicationServerKey": "tbc" + } +} diff --git a/scripts/build.mjs b/scripts/build.mjs index dbbeabcd..6622f092 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -79,6 +79,7 @@ async function build({modernOnly}) { await assets.write(`worker.js`, await buildJsLegacy("src/platform/web/worker/main.js", ['src/platform/web/worker/polyfill.js'])); } // copy over non-theme assets + const baseConfig = JSON.parse(await fs.readFile(path.join(projectDir, "assets/config.json"), {encoding: "utf8"})); const downloadSandbox = "download-sandbox.html"; let downloadSandboxHtml = await fs.readFile(path.join(projectDir, `assets/${downloadSandbox}`)); await assets.write(downloadSandbox, downloadSandboxHtml); @@ -95,7 +96,7 @@ async function build({modernOnly}) { const globalHash = assets.hashForAll(); await buildServiceWorker(swSource, version, globalHash, assets); - await buildHtml(doc, version, globalHash, modernOnly, assets); + await buildHtml(doc, version, baseConfig, globalHash, modernOnly, assets); console.log(`built hydrogen ${version} (${globalHash}) successfully with ${assets.size} files`); } @@ -135,7 +136,7 @@ async function copyThemeAssets(themes, assets) { return assets; } -async function buildHtml(doc, version, globalHash, modernOnly, assets) { +async function buildHtml(doc, version, baseConfig, globalHash, modernOnly, assets) { // transform html file // change path to main.css to css bundle doc("link[rel=stylesheet]:not([title])").attr("href", assets.resolve(`hydrogen.css`)); @@ -145,7 +146,7 @@ async function buildHtml(doc, version, globalHash, modernOnly, assets) { findThemes(doc, (themeName, theme) => { theme.attr("href", assets.resolve(`themes/${themeName}/bundle.css`)); }); - const pathsJSON = JSON.stringify({ + const configJSON = JSON.stringify(Object.assign({}, baseConfig, { worker: assets.has("worker.js") ? assets.resolve(`worker.js`) : null, downloadSandbox: assets.resolve("download-sandbox.html"), serviceWorker: "sw.js", @@ -154,14 +155,14 @@ async function buildHtml(doc, version, globalHash, modernOnly, assets) { legacyBundle: assets.resolve("olm_legacy.js"), wasmBundle: assets.resolve("olm.js"), } - }); + })); const mainScripts = [ - `` + `` ]; if (!modernOnly) { mainScripts.push( ``, - `` + `` ); } doc("script#main").replaceWith(mainScripts.join(""));