2019-07-08 10:37:01 +02:00
|
|
|
const fs = require("fs")
|
2019-07-08 11:47:08 +02:00
|
|
|
const glob = require("glob")
|
2019-07-08 10:37:01 +02:00
|
|
|
|
|
|
|
|
function prepareFiles(buildType) {
|
|
|
|
|
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"
|
2020-12-22 11:12:18 +01:00
|
|
|
const imagesToKeep = [
|
|
|
|
|
"ionicons.ttf", "logo-solo-red.png"
|
|
|
|
|
]
|
2019-07-08 10:37:01 +02:00
|
|
|
if (fs.existsSync(imagesPath)) {
|
|
|
|
|
const imageFiles = glob.sync(prefix + "images/*")
|
|
|
|
|
for (let file of imageFiles) {
|
2020-12-22 16:20:03 +01:00
|
|
|
const doDiscard = !imagesToKeep.find(name => file.endsWith(name))
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = prepareFiles
|
|
|
|
|
|
|
|
|
|
if (require.main === module) {
|
|
|
|
|
prepareFiles(process.argv[2])
|
2019-07-08 11:47:08 +02:00
|
|
|
}
|