2022-02-14 10:19:20 +01:00
|
|
|
/**
|
|
|
|
* Build script for android app.
|
|
|
|
*
|
|
|
|
* Besides options below this script may require signing parameters passed as environment variables:
|
|
|
|
* 'APK_SIGN_ALIAS'
|
|
|
|
* 'APK_SIGN_STORE_PASS'
|
|
|
|
* 'APK_SIGN_KEY_PASS'
|
|
|
|
* 'APK_SIGN_STORE'
|
|
|
|
* 'ANDROID_HOME'
|
|
|
|
*/
|
2021-01-29 10:38:21 +01:00
|
|
|
import options from "commander"
|
|
|
|
import fs from "fs"
|
2021-11-05 17:11:35 +01:00
|
|
|
import {execFileSync} from "child_process"
|
|
|
|
import {runDevBuild} from "./buildSrc/DevBuild.js"
|
2021-09-09 15:08:09 +02:00
|
|
|
import {prepareMobileBuild} from "./buildSrc/prepareMobileBuild.js"
|
2022-02-14 10:19:20 +01:00
|
|
|
import {buildWebapp} from "./buildSrc/buildWebapp.js"
|
|
|
|
import {getTutanotaAppVersion, measure} from "./buildSrc/buildUtils.js"
|
|
|
|
import path from "path"
|
2021-01-29 10:38:21 +01:00
|
|
|
|
2021-11-05 17:11:35 +01:00
|
|
|
const log = (...messages) => console.log("\nBUILD:", ...messages, "\n")
|
2018-12-11 14:55:06 +01:00
|
|
|
|
2022-02-14 10:19:20 +01:00
|
|
|
|
2018-12-11 14:55:06 +01:00
|
|
|
options
|
2021-11-05 17:11:35 +01:00
|
|
|
.usage('[options] [test|prod|local|host <url>] ')
|
|
|
|
.arguments('[stage] [host]')
|
2018-12-11 15:23:03 +01:00
|
|
|
.option('-b, --buildtype <type>', 'gradle build type', /^(debugDist|debug|release|releaseTest)$/i, 'release')
|
2019-02-27 11:16:51 +01:00
|
|
|
.option('-w --webclient <client>', 'choose web client build', /^(make|dist)$/i, 'dist')
|
2021-11-05 17:11:35 +01:00
|
|
|
.action((stage, host, options) => {
|
|
|
|
if (!["test", "prod", "local", "host", undefined].includes(stage)
|
|
|
|
|| (stage !== "host" && host)
|
|
|
|
|| (stage === "host" && !host)) {
|
|
|
|
options.outputHelp()
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
const {webclient, buildtype} = options
|
|
|
|
|
|
|
|
buildAndroid({
|
|
|
|
stage: stage ?? 'prod',
|
|
|
|
host: host,
|
|
|
|
webClient: webclient,
|
|
|
|
buildType: buildtype,
|
|
|
|
})
|
|
|
|
})
|
2018-12-11 14:55:06 +01:00
|
|
|
|
2021-11-05 17:11:35 +01:00
|
|
|
options.parse(process.argv)
|
2021-06-28 13:03:54 +02:00
|
|
|
|
2019-02-01 11:42:51 +01:00
|
|
|
|
2021-11-05 17:11:35 +01:00
|
|
|
async function buildAndroid({stage, host, buildType, webClient}) {
|
2021-06-28 13:03:54 +02:00
|
|
|
log(`Starting build with build type: ${buildType}, webclient: ${webClient}, host: ${host}`)
|
2018-12-11 14:55:06 +01:00
|
|
|
|
2021-11-05 17:11:35 +01:00
|
|
|
if (webClient === "make") {
|
|
|
|
await runDevBuild({
|
|
|
|
stage,
|
|
|
|
host,
|
|
|
|
desktop: false,
|
|
|
|
clean: false,
|
|
|
|
watch: false,
|
|
|
|
serve: false
|
|
|
|
})
|
|
|
|
} else {
|
2022-03-02 18:21:01 +01:00
|
|
|
const version = getTutanotaAppVersion()
|
2022-02-14 10:19:20 +01:00
|
|
|
await buildWebapp(
|
|
|
|
{
|
|
|
|
version,
|
|
|
|
stage,
|
|
|
|
host,
|
|
|
|
minify: true,
|
|
|
|
projectDir: path.resolve("."),
|
|
|
|
measure
|
|
|
|
}
|
|
|
|
)
|
2021-11-05 17:11:35 +01:00
|
|
|
}
|
2018-12-11 14:55:06 +01:00
|
|
|
|
2021-09-09 15:08:09 +02:00
|
|
|
await prepareMobileBuild(webClient)
|
2018-12-11 14:55:06 +01:00
|
|
|
|
2021-06-28 13:03:54 +02:00
|
|
|
try {
|
|
|
|
log("cleaning 'build/app-android'")
|
|
|
|
await fs.promises.rm("build/app-android", {recursive: true})
|
|
|
|
} catch (e) {
|
|
|
|
// Ignoring the error if the folder is not there
|
2018-12-11 14:55:06 +01:00
|
|
|
}
|
|
|
|
|
2021-06-28 13:03:54 +02:00
|
|
|
log("Starting build: ", buildType)
|
|
|
|
|
2021-09-08 17:07:12 +02:00
|
|
|
const {version} = JSON.parse(await fs.promises.readFile("package.json", "utf8"))
|
2021-09-09 15:08:09 +02:00
|
|
|
const apkName = `tutanota-tutao-${buildType}-${version}.apk`
|
|
|
|
const apkPath = `app-android/app/build/outputs/apk/tutao/${buildType}/${apkName}`
|
2021-09-08 17:07:12 +02:00
|
|
|
|
2021-09-09 15:08:09 +02:00
|
|
|
runCommand('./gradlew', [`assembleTutao${buildType}`], {
|
|
|
|
cwd: './app-android/',
|
|
|
|
})
|
2021-06-28 13:03:54 +02:00
|
|
|
|
|
|
|
await fs.promises.mkdir("build/app-android", {recursive: true})
|
|
|
|
|
2021-09-09 15:08:09 +02:00
|
|
|
const outPath = `./build/app-android/${apkName}`
|
|
|
|
await fs.promises.rename(apkPath, outPath)
|
2021-06-28 13:03:54 +02:00
|
|
|
|
|
|
|
log(`Build complete. The APK is located at: ${outPath}`)
|
2021-11-05 17:11:35 +01:00
|
|
|
|
|
|
|
// runDevBuild spawns some child processes from the BuildServerClient,
|
|
|
|
// ideally we would detach from them inside as needed but for now we just hard exit
|
|
|
|
process.exit(0)
|
2018-12-11 14:55:06 +01:00
|
|
|
}
|
2021-06-18 11:10:33 +02:00
|
|
|
|
2021-06-28 13:03:54 +02:00
|
|
|
function runCommand(command, args, options) {
|
2021-06-18 11:10:33 +02:00
|
|
|
try {
|
2021-06-28 13:03:54 +02:00
|
|
|
log("command:", `${command} ${args.join(" ")}`)
|
|
|
|
return execFileSync(command, args, options)
|
2021-06-18 11:10:33 +02:00
|
|
|
} catch (e) {
|
2021-06-28 13:03:54 +02:00
|
|
|
// original e contains lots of noise. `e.stack` has enough for debugging
|
|
|
|
throw new Error(e.stack)
|
2021-06-18 11:10:33 +02:00
|
|
|
}
|
2021-11-05 17:11:35 +01:00
|
|
|
}
|