xref: /expo/tools/src/CocoaPods.ts (revision 6185d13d)
1import { StdioOptions } from 'child_process';
2
3import { spawnAsync, spawnJSONCommandAsync } from './Utils';
4
5/**
6 * JSON representation of the podspec.
7 */
8export type Podspec = {
9  name: string;
10  version: string;
11  platforms: Record<string, string>;
12  header_dir?: string;
13  source_files: string | string[];
14  exclude_files: string | string[];
15  public_header_files?: string | string[];
16  preserve_paths: string | string[];
17  compiler_flags: string;
18  frameworks: string | string[];
19  vendored_frameworks: string | string[];
20  pod_target_xcconfig: Record<string, string>;
21  xcconfig: Record<string, string>;
22  dependencies: Record<string, any>;
23  info_plist: Record<string, string>;
24  ios?: Podspec;
25  default_subspecs: string | string[];
26  subspecs: Podspec[];
27};
28
29/**
30 * Reads the podspec and returns it in JSON format.
31 */
32export async function readPodspecAsync(podspecPath: string): Promise<Podspec> {
33  return await spawnJSONCommandAsync('pod', ['ipc', 'spec', podspecPath]);
34}
35
36type PodInstallOptions = Partial<{
37  /**
38   * Whether to use `--no-repo-update` flag.
39   */
40  noRepoUpdate: boolean;
41
42  /**
43   * stdio passed to the child process.
44   */
45  stdio: StdioOptions;
46}>;
47
48/**
49 * Installs pods under given project path.
50 */
51export async function podInstallAsync(
52  projectPath: string,
53  options: PodInstallOptions = { noRepoUpdate: false, stdio: 'pipe' }
54): Promise<void> {
55  const args = ['install'];
56
57  if (options.noRepoUpdate) {
58    args.push('--no-repo-update');
59  }
60  await spawnAsync('pod', args, {
61    cwd: projectPath,
62    stdio: options.stdio ?? 'pipe',
63  });
64}
65