import fs from 'fs-extra' ; import path from 'path' ; import { ConfigPlugin , XcodeProject } from '../Plugin.types' ; import { withXcodeProject } from '../plugins/ios-plugins' ; import { addBuildSourceFileToGroup , getProjectName } from './utils/Xcodeproj' ; param config param props . filePath param props . contents param props . overwrite returns export const withBuildSourceFile = ( config , { filePath , contents , overwrite } ) => { return withXcodeProject ( config , config => { const projectName = getProjectName ( config . modRequest . projectRoot ) ; config . modResults = createBuildSourceFile ( { project : config . modResults , nativeProjectRoot : config . modRequest . platformProjectRoot , fileContents : contents , filePath : path . join ( projectName , filePath ) , overwrite } ) ; return config ; } ) ; } ; param nativeProjectRoot param filePath param fileContents param overwrite export function createBuildSourceFile ( { project , nativeProjectRoot , filePath , fileContents , overwrite , } ) { const absoluteFilePath = path . join ( nativeProjectRoot , filePath ) ; if ( overwrite || ! fs . existsSync ( absoluteFilePath ) ) { fs . writeFileSync ( absoluteFilePath , fileContents , 'utf8' ) ; } const groupName = path . dirname ( filePath ) ; if ( ! project . hasFile ( filePath ) ) { project = addBuildSourceFileToGroup ( { filepath : filePath , groupName , project } ) ; } return project ; }