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'
|
|
|
|
*/
|
2022-04-28 14:36:24 +02:00
|
|
|
import {Argument, Option, program} from "commander"
|
2021-11-05 17:11:35 +01:00
|
|
|
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"
|
2022-07-15 09:56:16 +02:00
|
|
|
import {$, cd} from 'zx'
|
2021-01-29 10:38:21 +01:00
|
|
|
|
2022-07-15 09:56:16 +02:00
|
|
|
const log = (...messages) => console.log(chalk.green("\nBUILD:"), ...messages, "\n")
|
2022-02-14 10:19:20 +01:00
|
|
|
|
2022-04-28 14:36:24 +02:00
|
|
|
await program
|
2021-11-05 17:11:35 +01:00
|
|
|
.usage('[options] [test|prod|local|host <url>] ')
|
2022-04-28 14:36:24 +02:00
|
|
|
.addArgument(new Argument("stage")
|
|
|
|
.choices(["test", "prod", "local", "host"])
|
|
|
|
.default("prod")
|
|
|
|
.argOptional())
|
|
|
|
.addArgument(new Argument("host").argOptional())
|
|
|
|
.addOption(new Option('-b, --buildtype <type>', 'gradle build type')
|
|
|
|
.choices(["debugDist", "debug", "release", "releaseTest"])
|
2022-05-17 16:05:58 +02:00
|
|
|
.default("release"))
|
2022-07-15 09:56:16 +02:00
|
|
|
.addOption(new Option('-i, --install', "call adb install after build"))
|
2022-04-28 14:36:24 +02:00
|
|
|
.addOption(new Option('-w --webclient <client>', 'choose web client build')
|
|
|
|
.choices(["make", "dist"])
|
|
|
|
.default("dist"))
|
2022-07-15 09:56:16 +02:00
|
|
|
.action(async (stage, host, {webclient, buildtype}) => {
|
2022-04-28 14:36:24 +02:00
|
|
|
if (stage === "host" && host == null || stage !== "host" && host != null) {
|
|
|
|
program.outputHelp()
|
2021-11-05 17:11:35 +01:00
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
2022-07-15 09:56:16 +02:00
|
|
|
const apk = await buildAndroid({
|
2021-11-05 17:11:35 +01:00
|
|
|
stage: stage ?? 'prod',
|
|
|
|
host: host,
|
|
|
|
webClient: webclient,
|
|
|
|
buildType: buildtype,
|
|
|
|
})
|
2022-07-15 09:56:16 +02:00
|
|
|
|
|
|
|
if (options.install) {
|
|
|
|
await $`adb install ${apk}`
|
|
|
|
// would be cool, but needs to figure out the correct app to start:
|
|
|
|
// await $`adb shell am start -n de.tutao.tutanota/de.tutao.tutanota.MainActivity`
|
|
|
|
}
|
2021-11-05 17:11:35 +01:00
|
|
|
})
|
2022-04-28 14:36:24 +02:00
|
|
|
.parseAsync(process.argv)
|
2019-02-01 11:42:51 +01:00
|
|
|
|
2021-11-05 17:11:35 +01:00
|
|
|
async function buildAndroid({stage, host, buildType, webClient}) {
|
2022-04-28 14:36:24 +02:00
|
|
|
log(`Starting ${stage} 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 {
|
2022-07-15 09:56:16 +02:00
|
|
|
await $`rm -r build/app-android`
|
2021-06-28 13:03:54 +02:00
|
|
|
} catch (e) {
|
|
|
|
// Ignoring the error if the folder is not there
|
2018-12-11 14:55:06 +01:00
|
|
|
}
|
|
|
|
|
2022-07-15 09:56:16 +02:00
|
|
|
const {version} = JSON.parse(await $`cat package.json`.quiet())
|
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}`
|
|
|
|
const outPath = `./build/app-android/${apkName}`
|
2022-07-15 09:56:16 +02:00
|
|
|
cd("./app-android")
|
|
|
|
await $`./gradlew assembleTutao${buildType}`
|
|
|
|
cd("..")
|
|
|
|
await $`mkdir -p build/app-android`
|
|
|
|
await $`mv ${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
|
|
|
|
2022-07-15 09:56:16 +02:00
|
|
|
return outPath
|
|
|
|
}
|