Created
February 1, 2024 17:48
-
-
Save jpudysz/15e346ac6f2d986b30b9c4152e5b3909 to your computer and use it in GitHub Desktop.
Add target to any file in Xcode with Expo config plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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