1import fs from 'fs-extra';
2import path from 'path';
3
4import { ANDROID_DIR } from '../Constants';
5import { androidAppVersionAsync } from '../ProjectVersions';
6import { spawnAsync } from '../Utils';
7import { ClientBuilder, ClientBuildFlavor, Platform, S3Client } from './types';
8
9export default class AndroidClientBuilder implements ClientBuilder {
10  platform: Platform = 'android';
11
12  getAppPath(): string {
13    return path.join(ANDROID_DIR, 'app', 'build', 'outputs', 'apk', 'release', 'app-release.apk');
14  }
15
16  getClientUrl(appVersion: string): string {
17    return `https://d1ahtucjixef4r.cloudfront.net/Exponent-${appVersion}.apk`;
18  }
19
20  async getAppVersionAsync(): Promise<string> {
21    return androidAppVersionAsync();
22  }
23
24  async buildAsync(flavor: ClientBuildFlavor = ClientBuildFlavor.VERSIONED) {
25    await spawnAsync('fastlane', ['android', 'build', 'build_type:Release', `flavor:${flavor}`], {
26      stdio: 'inherit',
27    });
28  }
29
30  async uploadBuildAsync(s3Client: S3Client, appVersion: string) {
31    const file = fs.createReadStream(this.getAppPath());
32
33    await s3Client
34      .putObject({
35        Bucket: 'exp-android-apks',
36        Key: `Exponent-${appVersion}.apk`,
37        Body: file,
38        ACL: 'public-read',
39      })
40      .promise();
41  }
42}
43