1import fs from 'fs-extra';
2import path from 'path';
3
4import { podInstallAsync } from '../CocoaPods';
5import { EXPO_DIR, IOS_DIR } from '../Constants';
6import { iosAppVersionAsync } from '../ProjectVersions';
7import { spawnAsync } from '../Utils';
8import { ClientBuilder, ClientBuildFlavor, Platform } from './types';
9
10export default class IosClientBuilder implements ClientBuilder {
11  platform: Platform = 'ios';
12
13  getAppPath(): string {
14    return path.join(
15      IOS_DIR,
16      'simulator-build',
17      'Build',
18      'Products',
19      'Release-iphonesimulator',
20      'Expo Go.app'
21    );
22  }
23
24  getClientUrl(appVersion: string): string {
25    return `https://dpq5q02fu5f55.cloudfront.net/Exponent-${appVersion}.tar.gz`;
26  }
27
28  async getAppVersionAsync(): Promise<string> {
29    return await iosAppVersionAsync();
30  }
31
32  async buildAsync(flavor: ClientBuildFlavor = ClientBuildFlavor.VERSIONED) {
33    await podInstallAsync(IOS_DIR, {
34      stdio: 'inherit',
35    });
36    await spawnAsync('fastlane', ['ios', 'create_simulator_build', `flavor:${flavor}`], {
37      stdio: 'inherit',
38    });
39  }
40
41  async uploadBuildAsync(s3Client, appVersion: string) {
42    const tempAppPath = path.join(EXPO_DIR, 'temp-app.tar.gz');
43
44    await spawnAsync('tar', ['-zcvf', tempAppPath, '-C', this.getAppPath(), '.'], {
45      stdio: ['ignore', 'ignore', 'inherit'], // only stderr
46    });
47
48    const file = fs.createReadStream(tempAppPath);
49
50    await s3Client
51      .putObject({
52        Bucket: 'exp-ios-simulator-apps',
53        Key: `Exponent-${appVersion}.tar.gz`,
54        Body: file,
55        ACL: 'public-read',
56      })
57      .promise();
58
59    await fs.remove(tempAppPath);
60  }
61}
62