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, 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() {
25    await spawnAsync('fastlane', ['android', 'build', 'build_type:Release'], { stdio: 'inherit' });
26  }
27
28  async uploadBuildAsync(s3Client: S3Client, appVersion: string) {
29    const file = fs.createReadStream(this.getAppPath());
30
31    await s3Client
32      .putObject({
33        Bucket: 'exp-android-apks',
34        Key: `Exponent-${appVersion}.apk`,
35        Body: file,
36        ACL: 'public-read',
37      })
38      .promise();
39  }
40}
41