From df7a1041c4e2d9a5a1ceef247ed00f9f8467df76 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Wed, 5 Jan 2022 17:19:55 +0100 Subject: [PATCH] fix(cli): sync failing if Info.plist is localized (#5333) --- cli/src/cordova.ts | 81 +++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 34 deletions(-) diff --git a/cli/src/cordova.ts b/cli/src/cordova.ts index 7195eb7e68..9acbad61db 100644 --- a/cli/src/cordova.ts +++ b/cli/src/cordova.ts @@ -352,44 +352,57 @@ export async function logCordovaManualSteps( } async function logiOSPlist(configElement: any, config: Config, plugin: Plugin) { - const plistPath = resolve(config.ios.nativeTargetDirAbs, 'Info.plist'); - const xmlMeta = await readXML(plistPath); - const data = await readFile(plistPath, { encoding: 'utf-8' }); - const plistData = plist.parse(data) as PlistObject; - const dict = xmlMeta.plist.dict.pop(); - if (!dict.key.includes(configElement.$.parent)) { - let xml = buildConfigFileXml(configElement); - xml = `${configElement.$.parent}${getConfigFileTagContent(xml)}`; - logger.warn( - `Configuration required for ${c.strong(plugin.id)}.\n` + - `Add the following to Info.plist:\n` + - xml, + let plistPath = resolve(config.ios.nativeTargetDirAbs, 'Info.plist'); + if (!(await pathExists(plistPath))) { + plistPath = resolve( + config.ios.nativeTargetDirAbs, + 'Base.lproj', + 'Info.plist', ); - } else if (configElement.array || configElement.dict) { - if ( - configElement.array && - configElement.array.length > 0 && - configElement.array[0].string - ) { - let xml = ''; - configElement.array[0].string.map((element: any) => { - const d = plistData[configElement.$.parent]; - if (Array.isArray(d) && !d.includes(element)) { - xml = xml.concat(`${element}\n`); + } + if (await pathExists(plistPath)) { + const xmlMeta = await readXML(plistPath); + const data = await readFile(plistPath, { encoding: 'utf-8' }); + const plistData = plist.parse(data) as PlistObject; + const dict = xmlMeta.plist.dict.pop(); + if (!dict.key.includes(configElement.$.parent)) { + let xml = buildConfigFileXml(configElement); + xml = `${configElement.$.parent}${getConfigFileTagContent( + xml, + )}`; + logger.warn( + `Configuration required for ${c.strong(plugin.id)}.\n` + + `Add the following to Info.plist:\n` + + xml, + ); + } else if (configElement.array || configElement.dict) { + if ( + configElement.array && + configElement.array.length > 0 && + configElement.array[0].string + ) { + let xml = ''; + configElement.array[0].string.map((element: any) => { + const d = plistData[configElement.$.parent]; + if (Array.isArray(d) && !d.includes(element)) { + xml = xml.concat(`${element}\n`); + } + }); + if (xml.length > 0) { + logger.warn( + `Configuration required for ${c.strong(plugin.id)}.\n` + + `Add the following in the existing ${c.strong( + configElement.$.parent, + )} array of your Info.plist:\n` + + xml, + ); } - }); - if (xml.length > 0) { - logger.warn( - `Configuration required for ${c.strong(plugin.id)}.\n` + - `Add the following in the existing ${c.strong( - configElement.$.parent, - )} array of your Info.plist:\n` + - xml, - ); + } else { + logPossibleMissingItem(configElement, plugin); } - } else { - logPossibleMissingItem(configElement, plugin); } + } else { + logPossibleMissingItem(configElement, plugin); } }