1import { ExpoConfig } from '@expo/config';
2import { compileModsAsync, ModPlatform } from '@expo/config-plugins';
3import { getPrebuildConfigAsync } from '@expo/prebuild-config';
4
5import { logConfig } from '../config/configAsync';
6import * as Log from '../log';
7import { env } from '../utils/env';
8import {
9  getOrPromptForBundleIdentifier,
10  getOrPromptForPackage,
11} from '../utils/getOrPromptApplicationId';
12
13export async function configureProjectAsync(
14  projectRoot: string,
15  {
16    platforms,
17  }: {
18    platforms: ModPlatform[];
19  }
20): Promise<ExpoConfig> {
21  let bundleIdentifier: string | undefined;
22  if (platforms.includes('ios')) {
23    // Check bundle ID before reading the config because it may mutate the config if the user is prompted to define it.
24    bundleIdentifier = await getOrPromptForBundleIdentifier(projectRoot);
25  }
26  let packageName: string | undefined;
27  if (platforms.includes('android')) {
28    // Check package before reading the config because it may mutate the config if the user is prompted to define it.
29    packageName = await getOrPromptForPackage(projectRoot);
30  }
31
32  let { exp: config } = await getPrebuildConfigAsync(projectRoot, {
33    platforms,
34    packageName,
35    bundleIdentifier,
36  });
37
38  // compile all plugins and mods
39  config = await compileModsAsync(config, {
40    projectRoot,
41    platforms,
42    assertMissingModProviders: false,
43  });
44
45  if (env.EXPO_DEBUG) {
46    Log.log();
47    Log.log('Evaluated config:');
48    logConfig(config);
49    Log.log();
50  }
51
52  return config;
53}
54