-
Notifications
You must be signed in to change notification settings - Fork 546
/
Copy pathprepareMobileBuild.js
56 lines (51 loc) · 1.6 KB
/
prepareMobileBuild.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import fs from "node:fs"
import { program } from "commander"
import { glob } from "glob"
import { fileURLToPath } from "node:url"
import "zx/globals"
if (process.argv[1] === fileURLToPath(import.meta.url)) {
program.usage("make|dist").arguments("<target>").action(prepareMobileBuild).parse(process.argv)
}
/**
* Removes source maps, icons, HTML files which are not needed for mobile apps.
*/
export async function prepareMobileBuild(buildType, app) {
console.log("prepare mobile build for build type", buildType)
let prefix
if (["dist", "make"].includes(buildType)) {
prefix = app === "mail" ? "build/" : "build-calendar-app/"
} else {
throw new Error("Unknown build type " + buildType)
}
const wasmpath = prefix + "wasm"
if (fs.existsSync(wasmpath)) {
console.log("unlinking ", wasmpath)
fs.rmSync(wasmpath, { force: true, recursive: true })
}
const imagesPath = prefix + "images"
const imagesToKeep = ["font.ttf", "logo-solo-red.png"]
if (fs.existsSync(imagesPath)) {
const imageFiles = await globby(prefix + "images/*")
for (let file of imageFiles) {
const doDiscard = !imagesToKeep.some((name) => file.endsWith(name))
if (doDiscard) {
console.log("unlinking ", file)
fs.unlinkSync(file)
}
}
} 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)
}
}