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