Skip to content

Instantly share code, notes, and snippets.

@jpudysz
Created February 1, 2024 17:48
Show Gist options
  • Save jpudysz/15e346ac6f2d986b30b9c4152e5b3909 to your computer and use it in GitHub Desktop.
Save jpudysz/15e346ac6f2d986b30b9c4152e5b3909 to your computer and use it in GitHub Desktop.
Add target to any file in Xcode with Expo config plugin
const { withXcodeProject } = require('@expo/config-plugins')
const findFileReferenceByName = (xcodeProject, fileName) => {
const fileReferences = xcodeProject.hash.project.objects['PBXFileReference']
return Object.fromEntries(
Object
.entries(fileReferences)
.filter(([key, value]) => value.name === `"${fileName}"`)
)
}
const withLiveActivityIntents = (config, { intents }) => {
return withXcodeProject(config, config => {
const xcodeProject = config.modResults
intents.forEach(intent => {
const fileRef = findFileReferenceByName(xcodeProject, intent)
const fileRefUUID = Object.keys(fileRef).at(0)
const fileUUID = xcodeProject.generateUuid()
xcodeProject.addToPbxBuildFileSection({
uuid: fileUUID,
isa: 'PBXBuildFile',
fileRef: fileRefUUID,
basename: intent,
group: 'Sources',
})
xcodeProject.addToPbxSourcesBuildPhase({
uuid: fileUUID,
basename: intent,
group: 'Sources',
target: xcodeProject.getFirstTarget().uuid
})
})
return config
})
}
module.exports = withLiveActivityIntents
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment