2022-02-14 10:19:20 +01:00
|
|
|
/**
|
|
|
|
* Utility to create the HTML landing page for the app.
|
|
|
|
*/
|
|
|
|
import fs from "fs-extra"
|
2024-07-30 12:07:58 +02:00
|
|
|
import { renderHtml } from "./LaunchHtml.js"
|
|
|
|
import { mkdir } from "node:fs/promises"
|
2023-04-20 17:14:30 +02:00
|
|
|
import path from "node:path"
|
2022-02-14 10:19:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param env Object with the following keys:
|
|
|
|
* mode: String of value "App" or "Desktop" or "Browser"
|
|
|
|
* dist: Boolean
|
2022-07-15 10:01:02 +02:00
|
|
|
* staticUrl: String defining app base url for non-production environments and the native clients.
|
2022-02-14 10:19:20 +01:00
|
|
|
* versionNumber: String containing the app's version number
|
2024-07-30 10:57:18 +02:00
|
|
|
* @param app App to be built, defaults to mail app {String}
|
2022-02-14 10:19:20 +01:00
|
|
|
* @returns {Promise<Awaited<void>[]>}
|
|
|
|
*/
|
2024-07-30 10:57:18 +02:00
|
|
|
export async function createHtml(env, app = "mail") {
|
2022-02-14 10:19:20 +01:00
|
|
|
let jsFileName
|
|
|
|
let htmlFileName
|
2024-07-30 10:57:18 +02:00
|
|
|
const buildDir = app === "calendar" ? "build-calendar-app" : "build"
|
2022-02-14 10:19:20 +01:00
|
|
|
switch (env.mode) {
|
|
|
|
case "App":
|
|
|
|
jsFileName = "index-app.js"
|
|
|
|
htmlFileName = "index-app.html"
|
|
|
|
break
|
|
|
|
case "Browser":
|
|
|
|
jsFileName = "index.js"
|
|
|
|
htmlFileName = "index.html"
|
|
|
|
break
|
|
|
|
case "Desktop":
|
|
|
|
jsFileName = "index-desktop.js"
|
|
|
|
htmlFileName = "index-desktop.html"
|
|
|
|
}
|
|
|
|
// We need to import bluebird early as it Promise must be replaced before any of our code is executed
|
2024-07-30 12:07:58 +02:00
|
|
|
const imports = [{ src: "polyfill.js" }, { src: jsFileName }]
|
|
|
|
let indexTemplate = await fs.readFile("./buildSrc/index.template.js", "utf8")
|
2024-07-30 10:57:18 +02:00
|
|
|
|
|
|
|
if (app === "calendar") indexTemplate = indexTemplate.replaceAll("app.js", "calendar-app.js")
|
2022-02-14 10:19:20 +01:00
|
|
|
|
|
|
|
const index = `window.whitelabelCustomizations = null
|
|
|
|
window.env = ${JSON.stringify(env, null, 2)}
|
|
|
|
${indexTemplate}`
|
2024-07-30 10:57:18 +02:00
|
|
|
return Promise.all([
|
2024-07-30 12:07:58 +02:00
|
|
|
_writeFile(`./${buildDir}/${jsFileName}`, index),
|
|
|
|
renderHtml(imports, env).then((content) => _writeFile(`./${buildDir}/${htmlFileName}`, content)),
|
2024-07-30 10:57:18 +02:00
|
|
|
])
|
2022-02-14 10:19:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async function _writeFile(targetFile, content) {
|
2024-07-30 12:07:58 +02:00
|
|
|
await mkdir(path.dirname(targetFile), { recursive: true })
|
2022-12-27 15:37:40 +01:00
|
|
|
await fs.writeFile(targetFile, content, "utf-8")
|
|
|
|
}
|