MCPcopy
hub / github.com/ionic-team/capacitor / logiOSPlist

Function logiOSPlist

cli/src/cordova.ts:292–446  ·  view source on GitHub ↗
(configElement: any, config: Config, plugin: Plugin)

Source from the content-addressed store, hash-verified

290}
291
292async function logiOSPlist(configElement: any, config: Config, plugin: Plugin) {
293 let plistPath = resolve(config.ios.nativeTargetDirAbs, 'Info.plist');
294 if (config.app.extConfig.ios?.scheme) {
295 plistPath = resolve(config.ios.nativeProjectDirAbs, `${config.app.extConfig.ios?.scheme}-Info.plist`);
296 }
297 if (!(await pathExists(plistPath))) {
298 plistPath = resolve(config.ios.nativeTargetDirAbs, 'Base.lproj', 'Info.plist');
299 }
300 if (await pathExists(plistPath)) {
301 const xmlMeta = await readXML(plistPath);
302 const data = await readFile(plistPath, { encoding: 'utf-8' });
303 const trimmedPlistData = data.replace(/(\t|\r|\n)/g, '');
304 const plistData = plist.parse(data) as PlistObject;
305 const dict = xmlMeta.plist.dict.pop();
306 if (!dict.key.includes(configElement.$.parent)) {
307 let xml = buildConfigFileXml(configElement);
308 xml = `<key>${configElement.$.parent}</key>${getConfigFileTagContent(xml)}`;
309 logger.warn(`Configuration required for ${c.strong(plugin.id)}.\n` + `Add the following to Info.plist:\n` + xml);
310 } else if (configElement.array || configElement.dict) {
311 if (configElement.array && configElement.array.length > 0 && configElement.array[0].string) {
312 let xml = '';
313 configElement.array[0].string.map((element: any) => {
314 const d = plistData[configElement.$.parent];
315 if (Array.isArray(d) && !d.includes(element)) {
316 xml = xml.concat(`<string>${element}</string>\n`);
317 }
318 });
319 if (xml.length > 0) {
320 logger.warn(
321 `Configuration required for ${c.strong(plugin.id)}.\n` +
322 `Add the following in the existing ${c.strong(configElement.$.parent)} array of your Info.plist:\n` +
323 xml,
324 );
325 }
326 } else {
327 let xml = buildConfigFileXml(configElement);
328 xml = `<key>${configElement.$.parent}</key>${getConfigFileTagContent(xml)}`;
329 xml = `<plist version="1.0"><dict>${xml}</dict></plist>`;
330
331 const parseXmlToSearchable = (childElementsObj: any[], arrayToAddTo: any[]) => {
332 for (const childElement of childElementsObj) {
333 const childElementName = childElement['#name'];
334 const toAdd: {
335 name: string;
336 attrs?: { [key: string]: any } | undefined;
337 children?: any[] | undefined;
338 value?: any | undefined;
339 } = { name: childElementName };
340 if (childElementName === 'key' || childElementName === 'string') {
341 toAdd.value = childElement['_'];
342 } else {
343 if (childElement['$']) {
344 toAdd.attrs = { ...childElement['$'] };
345 }
346 if (childElement['$$']) {
347 toAdd.children = [];
348 parseXmlToSearchable(childElement['$$'], toAdd['children']);
349 }

Callers 1

logCordovaManualStepsFunction · 0.85

Calls 10

readXMLFunction · 0.90
parseXMLFunction · 0.90
readFileFunction · 0.85
buildConfigFileXmlFunction · 0.85
getConfigFileTagContentFunction · 0.85
parseXmlToSearchableFunction · 0.85
doesContainElementsFunction · 0.85
logPossibleMissingItemFunction · 0.85
warnMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected