1import { getConfig } from '@expo/config';
2
3import { queryAndGenerateAsync, selectAndGenerateAsync } from './generate';
4import { Options } from './resolveOptions';
5import { DestinationResolutionProps } from './templates';
6import { findUpProjectRootOrAssert } from '../utils/findUp';
7import { setNodeEnv } from '../utils/nodeEnv';
8
9export async function customizeAsync(files: string[], options: Options, extras: any[]) {
10  setNodeEnv('development');
11  // Locate the project root based on the process current working directory.
12  // This enables users to run `npx expo customize` from a subdirectory of the project.
13  const projectRoot = findUpProjectRootOrAssert(process.cwd());
14
15  require('@expo/env').load(projectRoot);
16
17  // Get the static path (defaults to 'web/')
18  // Doesn't matter if expo is installed or which mode is used.
19  const { exp } = getConfig(projectRoot, {
20    skipSDKVersionRequirement: true,
21  });
22
23  // Create the destination resolution props which are used in both
24  // the query and select functions.
25  const props: DestinationResolutionProps = {
26    webStaticPath: exp.web?.staticPath ?? 'web',
27  };
28
29  // If the user provided files, we'll generate them without prompting.
30  if (files.length) {
31    return queryAndGenerateAsync(projectRoot, {
32      files,
33      props,
34      extras,
35    });
36  }
37
38  // Otherwise, we'll prompt the user to select which files to generate.
39  await selectAndGenerateAsync(projectRoot, {
40    props,
41    extras,
42  });
43}
44