1import fs from 'fs';
2import path from 'path';
3
4import { env } from '../utils/env';
5
6const debug = require('debug')('expo:public-folder') as typeof console.log;
7
8/** @returns the file system path for a user-defined file in the public folder. */
9export function getUserDefinedFile(projectRoot: string, possiblePaths: string[]): string | null {
10  const publicPath = path.join(projectRoot, env.EXPO_PUBLIC_FOLDER);
11
12  for (const possiblePath of possiblePaths) {
13    const fullPath = path.join(publicPath, possiblePath);
14    if (fs.existsSync(fullPath)) {
15      debug(`Found user-defined public file: ` + possiblePath);
16      return fullPath;
17    }
18  }
19
20  return null;
21}
22