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"
|
2021-01-29 10:38:21 +01: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.
|
|
|
|
|
*/
|
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"
|
2023-02-08 14:37:08 +01:00
|
|
|
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))
|
2020-12-22 16:20:03 +01:00
|
|
|
if (doDiscard) {
|
2019-07-10 15:49:40 +02:00
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|