xref: /expo/tools/src/CocoaPods.ts (revision 75e080d0)
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  preserve_paths: string | string[];
16  compiler_flags: string;
17  frameworks: string | string[];
18  pod_target_xcconfig: Record<string, string>;
19  xcconfig: Record<string, string>;
20  dependencies: Record<string, any>;
21  info_plist: Record<string, string>;
22  ios?: Podspec;
23};
24
25/**
26 * Reads the podspec and returns it in JSON format.
27 */
28export async function readPodspecAsync(podspecPath: string): Promise<Podspec> {
29  return await spawnJSONCommandAsync('pod', ['ipc', 'spec', podspecPath]);
30}
31
32type PodInstallOptions = Partial<{
33  /**
34   * Whether to use `--no-repo-update` flag.
35   */
36  noRepoUpdate: boolean;
37
38  /**
39   * stdio passed to the child process.
40   */
41  stdio: StdioOptions;
42}>;
43
44/**
45 * Installs pods under given project path.
46 */
47export async function podInstallAsync(
48  projectPath: string,
49  options: PodInstallOptions = { noRepoUpdate: false, stdio: 'pipe' }
50): Promise<void> {
51  const args = ['install'];
52
53  if (options.noRepoUpdate) {
54    args.push('--no-repo-update');
55  }
56  await spawnAsync('pod', args, {
57    cwd: projectPath,
58    stdio: options.stdio ?? 'pipe',
59  });
60}
61