tutanota/buildSrc/prepareMobileBuild.js

42 lines
1.2 KiB
JavaScript
Raw Normal View History

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"
import { fileURLToPath } from "node:url"
2022-05-10 12:07:23 +02:00
import "zx/globals"
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-01-29 10:38:21 +01:00
/**
* Removes source maps, icons, HTML files which are not needed for mobile apps.
*/
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)) {
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)) {
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)
}
}