Last active
May 11, 2024 07:52
-
-
Save kyaroru/99cd2c25ef14c2b7a6ffe9f4de2c50f4 to your computer and use it in GitHub Desktop.
Example of expo config plugin for modifying Podfile
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
import { ConfigPlugin, withDangerousMod } from '@expo/config-plugins' | |
import { | |
MergeResults, | |
mergeContents, | |
removeContents, | |
} from '@expo/config-plugins/build/utils/generateCode' | |
import path from 'path' | |
import fs from 'fs-extra' | |
const debug = require('debug')('file-viewer-plugin') as typeof console.log | |
export function addExcludedArm64(src: string): MergeResults { | |
return mergeContents({ | |
tag: 'add-arm64', | |
src, | |
newSrc: ` | |
installer.pods_project.build_configurations.each do |config| | |
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" | |
end`, | |
anchor: /__apply_Xcode_12_5_M1_post_install_workaround\(installer\)/, | |
offset: 1, | |
comment: '#', | |
}) | |
} | |
const withExcludedArm64: ConfigPlugin = config => { | |
return withDangerousMod(config, [ | |
'ios', | |
async config => { | |
const filePath = path.join(config.modRequest.platformProjectRoot, 'Podfile') | |
const contents = await fs.readFile(filePath, 'utf-8') | |
let results: MergeResults | |
if (contents.indexOf('config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"') > -1) { | |
return config | |
} | |
else { | |
try { | |
results = addExcludedArm64(contents) | |
} catch (error: any) { | |
if (error.code === 'ERR_NO_MATCH') { | |
throw new Error( | |
`Cannot add arm64 from project's ios/Podfile because it's malformed. Please report this with a copy of your project Podfile.` | |
) | |
} | |
throw error | |
} | |
if (results.didMerge || results.didClear) { | |
await fs.writeFile(filePath, results.contents) | |
} | |
return config | |
} | |
}, | |
]) | |
} | |
const initPlugin: ConfigPlugin = config => { | |
config = withExcludedArm64(config) | |
return config | |
} | |
export default initPlugin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment