2023-04-20 17:14:30 +02:00
|
|
|
import fs from "node:fs"
|
2022-12-27 15:37:40 +01:00
|
|
|
import { program } from "commander"
|
2024-09-03 18:03:05 +02:00
|
|
|
import { glob } from "glob"
|
2023-04-20 17:14:30 +02:00
|
|
|
import { fileURLToPath } from "node:url"
|
2022-05-10 12:07:23 +02:00
|
|
|
import "zx/globals"
|
2021-09-09 15:08:09 +02:00
|
|
|
|
|
|
|
|
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
2022-12-27 15:37:40 +01:00
|
|
|
program.usage("make|dist").arguments("<target>").action(prepareMobileBuild).parse(process.argv)
|
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.
|
|
|
|
|
*/
|
2024-07-16 16:54:03 +02:00
|
|
|
export async function prepareMobileBuild(buildType, app) {
|
2019-07-08 10:37:01 +02:00
|
|
|
console.log("prepare mobile build for build type", buildType)
|
|
|
|
|
let prefix
|
2023-10-11 16:36:12 +02:00
|
|
|
if (["dist", "make"].includes(buildType)) {
|
2024-07-16 16:54:03 +02:00
|
|
|
prefix = app === "mail" ? "build/" : "build-calendar-app/"
|
2023-10-11 16:36:12 +02:00
|
|
|
} else {
|
|
|
|
|
throw new Error("Unknown build type " + buildType)
|
2019-07-08 10:37:01 +02:00
|
|
|
}
|
|
|
|
|
|
2023-09-14 11:58:55 +02:00
|
|
|
const wasmpath = prefix + "wasm"
|
|
|
|
|
if (fs.existsSync(wasmpath)) {
|
2023-09-18 14:27:47 +02:00
|
|
|
console.log("unlinking ", wasmpath)
|
|
|
|
|
fs.rmSync(wasmpath, { force: true, recursive: true })
|
2023-09-14 11:58:55 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-08 10:37:01 +02:00
|
|
|
const maps = glob.sync(prefix + "*.js.map")
|
|
|
|
|
for (let file of maps) {
|
|
|
|
|
console.log("unlinking ", file)
|
|
|
|
|
fs.unlinkSync(file)
|
|
|
|
|
}
|
|
|
|
|
const indexHtmlPath = prefix + "index.html"
|
|
|
|
|
if (fs.existsSync(indexHtmlPath)) {
|
|
|
|
|
fs.unlinkSync(indexHtmlPath)
|
|
|
|
|
console.log("rm ", indexHtmlPath)
|
|
|
|
|
} else {
|
|
|
|
|
console.log("no file at", indexHtmlPath)
|
|
|
|
|
}
|
|
|
|
|
}
|