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( 14 ANDROID_DIR, 15 'app', 16 'build', 17 'outputs', 18 'apk', 19 'versioned', 20 'release', 21 'app-versioned-release.apk' 22 ); 23 } 24 25 getClientUrl(appVersion: string): string { 26 return `https://d1ahtucjixef4r.cloudfront.net/Exponent-${appVersion}.apk`; 27 } 28 29 async getAppVersionAsync(): Promise<string> { 30 return androidAppVersionAsync(); 31 } 32 33 async buildAsync(flavor: ClientBuildFlavor = ClientBuildFlavor.VERSIONED) { 34 await spawnAsync('fastlane', ['android', 'build', 'build_type:Release', `flavor:${flavor}`], { 35 stdio: 'inherit', 36 }); 37 } 38 39 async uploadBuildAsync(s3Client: S3Client, appVersion: string) { 40 const file = fs.createReadStream(this.getAppPath()); 41 42 await s3Client 43 .putObject({ 44 Bucket: 'exp-android-apks', 45 Key: `Exponent-${appVersion}.apk`, 46 Body: file, 47 ACL: 'public-read', 48 }) 49 .promise(); 50 } 51} 52