2023-04-20 17:14:30 +02:00
|
|
|
import fs from "node:fs"
|
2025-07-21 15:26:41 +02:00
|
|
|
import { Option, program } from "commander"
|
2023-04-20 17:14:30 +02:00
|
|
|
import { fileURLToPath } from "node:url"
|
2025-07-21 13:22:07 +02:00
|
|
|
import path from "node:path"
|
2021-09-09 15:08:09 +02:00
|
|
|
|
2025-07-21 15:26:41 +02:00
|
|
|
const TAG = "prepareMobileBuild:"
|
|
|
|
|
|
2021-09-09 15:08:09 +02:00
|
|
|
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
2025-07-21 15:26:41 +02:00
|
|
|
program
|
|
|
|
|
.description("Prepare built web code for mobile app build")
|
|
|
|
|
.addOption(new Option("--app <app>", "which app to prepare build for").choices(["mail", "calendar"]))
|
|
|
|
|
.parse(process.argv)
|
|
|
|
|
await prepareMobileBuild(program.opts())
|
2021-09-09 15:08:09 +02:00
|
|
|
}
|
2021-01-29 10:38:21 +01:00
|
|
|
|
2021-09-09 15:08:09 +02:00
|
|
|
/**
|
|
|
|
|
* Removes source maps, icons, HTML files which are not needed for mobile apps.
|
2025-07-21 15:26:41 +02:00
|
|
|
* @param opts {object}
|
|
|
|
|
* @param opts.app {"mail"|"calendar"}
|
2021-09-09 15:08:09 +02:00
|
|
|
*/
|
2025-07-21 15:26:41 +02:00
|
|
|
export async function prepareMobileBuild({ app }) {
|
|
|
|
|
if (app !== "mail" && app !== "calendar") {
|
|
|
|
|
throw new Error("Required option app: " + app)
|
|
|
|
|
}
|
|
|
|
|
console.log(TAG, "prepare mobile build for app", app)
|
|
|
|
|
const prefix = app === "mail" ? "build/" : "build-calendar-app/"
|
|
|
|
|
if (!fs.existsSync(prefix)) {
|
|
|
|
|
throw new Error(`Prefix dir does not exist, likely an error!: ${prefix}`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
removeWasm(prefix)
|
|
|
|
|
removeSourceMaps(prefix)
|
|
|
|
|
|
|
|
|
|
const indexHtmlPath = prefix + "index.html"
|
|
|
|
|
if (fs.existsSync(indexHtmlPath)) {
|
|
|
|
|
fs.unlinkSync(indexHtmlPath)
|
|
|
|
|
console.log(TAG, "rm", indexHtmlPath)
|
2023-10-11 16:36:12 +02:00
|
|
|
} else {
|
2025-07-21 15:26:41 +02:00
|
|
|
console.log(TAG, "no file at", indexHtmlPath)
|
2019-07-08 10:37:01 +02:00
|
|
|
}
|
2025-07-21 15:26:41 +02:00
|
|
|
}
|
2019-07-08 10:37:01 +02:00
|
|
|
|
2025-07-21 15:26:41 +02:00
|
|
|
/** @param prefix {string} */
|
|
|
|
|
function removeWasm(prefix) {
|
|
|
|
|
const wasmpath = path.join(prefix, "wasm")
|
2023-09-14 11:58:55 +02:00
|
|
|
if (fs.existsSync(wasmpath)) {
|
2025-07-21 15:26:41 +02:00
|
|
|
console.log(TAG, "rm", wasmpath)
|
2023-09-18 14:27:47 +02:00
|
|
|
fs.rmSync(wasmpath, { force: true, recursive: true })
|
2023-09-14 11:58:55 +02:00
|
|
|
}
|
2025-07-21 15:26:41 +02:00
|
|
|
}
|
2023-09-14 11:58:55 +02:00
|
|
|
|
2025-07-21 15:26:41 +02:00
|
|
|
/** @param prefix {string} */
|
|
|
|
|
function removeSourceMaps(prefix) {
|
2025-07-21 13:22:07 +02:00
|
|
|
for (let file of fs.readdirSync(prefix)) {
|
|
|
|
|
if (file.endsWith(".js.map")) {
|
2025-07-21 15:26:41 +02:00
|
|
|
console.log(TAG, "rm", file)
|
2025-07-21 13:22:07 +02:00
|
|
|
fs.unlinkSync(path.join(prefix, file))
|
|
|
|
|
}
|
2019-07-08 10:37:01 +02:00
|
|
|
}
|
|
|
|
|
}
|