From d0f5dab60ed85b5cf116492fb2a220668cbfae37 Mon Sep 17 00:00:00 2001 From: Ricky Padilla Date: Thu, 22 Aug 2024 17:02:03 -0600 Subject: [PATCH] feat(PSG-5471): make plugin more flexible --- src/app.plugin.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/app.plugin.js b/src/app.plugin.js index 9adb493..b647b23 100644 --- a/src/app.plugin.js +++ b/src/app.plugin.js @@ -44,12 +44,18 @@ function withIosPodfile(configuration) { function withIosAssociatedDomain(configuration) { const associatedDomain = process.env.ASSOCIATED_DOMAIN; if (!associatedDomain) { - throw new Error('ASSOCIATED_DOMAIN environment variable is not set'); + return configuration; } return withEntitlementsPlist(configuration, (config) => { - config.modResults['com.apple.developer.associated-domains'] = [ - `webcredentials:${associatedDomain}`, - ]; + const key = 'com.apple.developer.associated-domains'; + const webCredEntitlement = `webcredentials:${associatedDomain}`; + // Get existing associated domains if they exist + let domains = config.modResults[key] || []; + // Add the new domain only if it's not already present + if (!domains.includes(webCredEntitlement)) { + domains.push(webCredEntitlement); + } + config.modResults[key] = domains; return config; }); } @@ -88,7 +94,7 @@ function withAndroidGradleDependency(configuration) { function withAndroidAssociatedDomain(configuration) { const associatedDomain = process.env.ASSOCIATED_DOMAIN; if (!associatedDomain) { - throw new Error('ASSOCIATED_DOMAIN environment variable is not set'); + return configuration; } // Modify AndroidManifest.xml @@ -124,7 +130,7 @@ function withAndroidAssociatedDomain(configuration) { } let stringsXmlContent = fs.readFileSync(stringsXmlPath, 'utf-8'); // Check if the string already exists - if (!stringsXmlContent.includes('')) { + if (!stringsXmlContent.includes('')) { const newStrings = `${associatedDomain} [{"include": "https://@string/passage_auth_origin/.well-known/assetlinks.json"}]`; // Insert the new strings before the closing tag