forked from tutao/tutanota
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathandroid.js
114 lines (95 loc) · 3.06 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
/**
* 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 options from "commander"
import fs from "fs"
import {execFileSync} from "child_process"
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 "path"
const log = (...messages) => console.log("\nBUILD:", ...messages, "\n")
options
.usage('[options] [test|prod|local|host <url>] ')
.arguments('[stage] [host]')
.option('-b, --buildtype <type>', 'gradle build type', /^(debugDist|debug|release|releaseTest)$/i, 'release')
.option('-w --webclient <client>', 'choose web client build', /^(make|dist)$/i, 'dist')
.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,
})
})
options.parse(process.argv)
async function buildAndroid({stage, host, buildType, webClient}) {
log(`Starting build with build type: ${buildType}, webclient: ${webClient}, host: ${host}`)
if (webClient === "make") {
await runDevBuild({
stage,
host,
desktop: false,
clean: false,
watch: false,
serve: false
})
} else {
const version = getTutanotaAppVersion()
await buildWebapp(
{
version,
stage,
host,
minify: true,
projectDir: path.resolve("."),
measure
}
)
}
await prepareMobileBuild(webClient)
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
}
log("Starting build: ", buildType)
const {version} = JSON.parse(await fs.promises.readFile("package.json", "utf8"))
const apkName = `tutanota-tutao-${buildType}-${version}.apk`
const apkPath = `app-android/app/build/outputs/apk/tutao/${buildType}/${apkName}`
runCommand('./gradlew', [`assembleTutao${buildType}`], {
cwd: './app-android/',
})
await fs.promises.mkdir("build/app-android", {recursive: true})
const outPath = `./build/app-android/${apkName}`
await fs.promises.rename(apkPath, outPath)
log(`Build complete. The APK is located at: ${outPath}`)
// 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)
}
function runCommand(command, args, options) {
try {
log("command:", `${command} ${args.join(" ")}`)
return execFileSync(command, args, options)
} catch (e) {
// original e contains lots of noise. `e.stack` has enough for debugging
throw new Error(e.stack)
}
}