tutanota/buildSrc/prepareMobileBuild.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

import fs from "node:fs"
2022-12-27 15:37:40 +01:00
import { program } from "commander"
2021-01-29 10:38:21 +01: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.
*/
2022-05-10 12:07:23 +02:00
export async function prepareMobileBuild(buildType) {
2019-07-08 10:37:01 +02:00
console.log("prepare mobile build for build type", buildType)
let prefix
switch (buildType) {
case "dist":
prefix = "build/dist/"
break
2019-07-24 11:24:46 +02:00
case "make":
2019-07-08 10:37:01 +02:00
prefix = "build/"
break
default:
throw new Error("Unknown build type " + buildType)
}
const imagesPath = prefix + "images"
const imagesToKeep = ["font.ttf", "logo-solo-red.png"]
2019-07-08 10:37:01 +02:00
if (fs.existsSync(imagesPath)) {
2022-05-10 12:07:23 +02:00
const imageFiles = await globby(prefix + "images/*")
2019-07-08 10:37:01 +02:00
for (let file of imageFiles) {
2022-12-27 15:37:40 +01:00
const doDiscard = !imagesToKeep.find((name) => file.endsWith(name))
if (doDiscard) {
console.log("unlinking ", file)
fs.unlinkSync(file)
}
2019-07-08 10:37:01 +02:00
}
} else {
console.log("No folder at", imagesPath)
}
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)
}
}