1import { ModPlatform } from '@expo/config-plugins'; 2import fs from 'fs'; 3import path from 'path'; 4 5import { promptToClearMalformedNativeProjectsAsync } from '../prebuild/clearNativeFolder'; 6import { prebuildAsync } from '../prebuild/prebuildAsync'; 7import { profile } from '../utils/profile'; 8 9export async function ensureNativeProjectAsync( 10 projectRoot: string, 11 { platform, install }: { platform: ModPlatform; install?: boolean } 12) { 13 // If the user has an empty android folder then the project won't build, this can happen when they delete the prebuild files in git. 14 // Check to ensure most of the core files are in place, and prompt to remove the folder if they aren't. 15 await profile(promptToClearMalformedNativeProjectsAsync)(projectRoot, [platform]); 16 17 // If the project doesn't have native code, prebuild it... 18 if (!fs.existsSync(path.join(projectRoot, platform))) { 19 await prebuildAsync(projectRoot, { 20 install: !!install, 21 platforms: [platform], 22 }); 23 } else { 24 return true; 25 } 26 return false; 27} 28