-
Notifications
You must be signed in to change notification settings - Fork 525
/
android.js
161 lines (130 loc) · 4.97 KB
/
android.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/**
* 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'
*/
import { Argument, Option, program } from "commander"
import { runDevBuild } from "./buildSrc/DevBuild.js"
import { prepareMobileBuild } from "./buildSrc/prepareMobileBuild.js"
import { buildWebapp } from "./buildSrc/buildWebapp.js"
import { getTutanotaAppVersion, measure } from "./buildSrc/buildUtils.js"
import path from "node:path"
import { $, cd } from "zx"
const log = (...messages) => console.log(chalk.green("\nBUILD:"), ...messages, "\n")
await program
.usage("[options] [test|prod|local|host <url>] ")
.addArgument(new Argument("stage").choices(["test", "prod", "local", "host"]).default("prod").argOptional())
.addArgument(new Argument("host").argOptional())
.addOption(new Option("-a, --app <type>", "app to build").choices(["mail", "calendar"]).default("mail"))
.addOption(new Option("-b, --buildtype <type>", "gradle build type").choices(["debugDist", "debug", "release", "releaseTest"]).default("release"))
.addOption(new Option("-i, --install", "call adb install after build"))
.addOption(new Option("-w --webclient <client>", "choose web client build").choices(["make", "dist"]).default("dist"))
.option("-e, --existing", "Use existing prebuilt web client files")
.action(async (stage, host, { webclient, buildtype, install, existing, app }) => {
if ((stage === "host" && host == null) || (stage !== "host" && host != null)) {
program.outputHelp()
process.exit(1)
}
const apk = await buildAndroid({
stage: stage ?? "prod",
host: host,
webClient: webclient,
existing,
buildType: buildtype,
app,
})
if (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`
}
})
.parseAsync(process.argv)
async function buildCalendarBundle({ buildType }) {
const { version } = JSON.parse(await $`cat package.json`.quiet())
const bundleName = `calendar-tutao-${buildType}-${version}.aab`
const bundlePath = `app-android/calendar/build/outputs/bundle/tutao${buildType.charAt(0).toUpperCase() + buildType.slice(1)}/${bundleName}`
const outPath = `./build-calendar-app/app-android/${bundleName}`
cd("./app-android")
await $`./gradlew :calendar:bundleTutao${buildType}`
cd("..")
await $`mkdir -p build-calendar-app/app-android`
await $`mv ${bundlePath} ${outPath}`
log(`Build complete. The AAB is located at: ${outPath}`)
return outPath
}
async function buildCalendarApk({ buildType }) {
const { version } = JSON.parse(await $`cat package.json`.quiet())
const bundleName = `calendar-tutao-${buildType}-${version}`
const bundlePath = `app-android/calendar/build/outputs/apk/tutao/${buildType}/${bundleName}`
const outPath = `./build-calendar-app/app-android/${bundleName}`
cd("./app-android")
await $`if [ -f .${outPath}.aab ]; then mkdir ../temp; mv .${outPath}.aab ../temp/${bundleName}.aab; fi`
await $`./gradlew :calendar:assembleTutao${buildType}`
cd("..")
await $`mkdir -p build-calendar-app/app-android`
await $`mv ${bundlePath}.apk ${outPath}.apk`
await $`if [ -f ./temp/${bundleName}.aab ]; then mv ./temp/${bundleName}.aab ${outPath}.aab; rm -d ./temp; fi`
log(`Build complete. The APK is located at: ${outPath}`)
return outPath
}
async function buildMailApk({ buildType }) {
const { version } = JSON.parse(await $`cat package.json`.quiet())
const apkName = `tutanota-app-tutao-${buildType}-${version}.apk`
const apkPath = `app-android/app/build/outputs/apk/tutao/${buildType}/${apkName}`
const outPath = `./build/app-android/${apkName}`
cd("./app-android")
await $`./gradlew :app:assembleTutao${buildType}`
cd("..")
await $`mkdir -p build/app-android`
await $`mv ${apkPath} ${outPath}`
log(`Build complete. The APK is located at: ${outPath}`)
return outPath
}
async function buildAndroid({ stage, host, buildType, existing, webClient, app }) {
log(`Starting ${stage} build with build type: ${buildType}, webclient: ${webClient}, host: ${host}`)
if (!existing) {
if (webClient === "make") {
await runDevBuild({
stage,
host,
desktop: false,
clean: false,
watch: false,
serve: false,
app,
})
} else {
const version = await getTutanotaAppVersion()
await buildWebapp({
version,
stage,
host,
minify: true,
projectDir: path.resolve("."),
measure,
app,
})
}
} else {
console.log("skipped webapp build")
}
await prepareMobileBuild(webClient, app)
const buildDir = app === "mail" ? "build" : "build-calendar-app"
try {
await $`rm -r ${buildDir}/app-android`
} catch (e) {
// Ignoring the error if the folder is not there
}
if (app === "mail") {
return await buildMailApk({ buildType })
} else {
await buildCalendarBundle({ buildType })
return await buildCalendarApk({ buildType })
}
}