tutanota/buildSrc/prepareMobileBuild.js

54 lines
1.2 KiB
JavaScript
Raw Normal View History

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"
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) {
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)
}
}
module.exports = prepareFiles
if (require.main === module) {
prepareFiles(process.argv[2])
2019-07-08 11:47:08 +02:00
}