const { withDangerousMod } = require('@expo/config-plugins'); const fs = require('fs'); const path = require('path'); const withSigning = (config, options = {}) => { const { teamId = 'X3964MGXHG' } = options; config = withDangerousMod(config, [ 'ios', async (config) => { const platformRoot = config.modRequest.platformProjectRoot; // 1. Inject CODE_SIGN_STYLE and DEVELOPMENT_TEAM into pbxproj const pbxprojPath = path.join(platformRoot, 'app.xcodeproj', 'project.pbxproj'); if (fs.existsSync(pbxprojPath)) { let contents = fs.readFileSync(pbxprojPath, 'utf-8'); const entitlementsLine = 'CODE_SIGN_ENTITLEMENTS = app/app.entitlements;'; const signingBlock = `${entitlementsLine}\n\t\t\t\tCODE_SIGN_STYLE = Automatic;\n\t\t\t\tDEVELOPMENT_TEAM = ${teamId};`; contents = contents.replaceAll(entitlementsLine, signingBlock); fs.writeFileSync(pbxprojPath, contents); } // 2. Set aps-environment to production in entitlements const entitlementsPath = path.join(platformRoot, 'app', 'app.entitlements'); if (fs.existsSync(entitlementsPath)) { let entitlements = fs.readFileSync(entitlementsPath, 'utf-8'); entitlements = entitlements.replace( /aps-environment<\/key>\s*development<\/string>/, 'aps-environment\n\tproduction' ); fs.writeFileSync(entitlementsPath, entitlements); } return config; }, ]); return config; }; module.exports = withSigning;