1import { ConfigPlugin, IOSConfig, withXcodeProject } from '@expo/config-plugins'; 2import path from 'path'; 3import { XcodeProject } from 'xcode'; 4 5import { STORYBOARD_FILE_PATH } from './withIosSplashScreenStoryboard'; 6 7const debug = require('debug')( 8 'expo:prebuild-config:expo-splash-screen:ios:xcodeproj' 9) as typeof console.log; 10 11export const withIosSplashXcodeProject: ConfigPlugin = (config) => { 12 return withXcodeProject(config, async (config) => { 13 config.modResults = await setSplashStoryboardAsync({ 14 projectName: config.modRequest.projectName!, 15 project: config.modResults, 16 }); 17 return config; 18 }); 19}; 20 21/** 22 * Modifies `.pbxproj` by: 23 * - adding reference for `.storyboard` file 24 */ 25export async function setSplashStoryboardAsync({ 26 projectName, 27 project, 28}: { 29 projectName: string; 30 project: XcodeProject; 31}): Promise<XcodeProject> { 32 // Check if `${projectName}/SplashScreen.storyboard` already exists 33 // Path relative to `ios` directory 34 const storyboardFilePath = path.join(projectName, STORYBOARD_FILE_PATH); 35 if (!project.hasFile(storyboardFilePath)) { 36 debug(`Adding ${storyboardFilePath} to Xcode project`); 37 IOSConfig.XcodeUtils.addResourceFileToGroup({ 38 filepath: storyboardFilePath, 39 groupName: projectName, 40 project, 41 }); 42 } 43 44 return project; 45} 46