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

Function copyPluginsNativeFiles

cli/src/ios/update.ts:588–663  ·  view source on GitHub ↗
(config: Config, cordovaPlugins: Plugin[])

Source from the content-addressed store, hash-verified

586}
587
588async function copyPluginsNativeFiles(config: Config, cordovaPlugins: Plugin[]) {
589 const isSPM = (await config.ios.packageManager) === 'SPM';
590 for (const p of cordovaPlugins) {
591 const platformTag = getPluginPlatform(p, platform);
592 if (isSPM && platformTag.$?.package) {
593 continue;
594 }
595 const sourceFiles = getPlatformElement(p, platform, 'source-file');
596 const headerFiles = getPlatformElement(p, platform, 'header-file');
597 const codeFiles = sourceFiles.concat(headerFiles);
598 const frameworks = getPlatformElement(p, platform, 'framework');
599 let sourcesFolderName = 'sources';
600 if (!isSPM && needsStaticPod(p)) {
601 sourcesFolderName += 'static';
602 }
603 const sourcesFolder = join(config.ios.cordovaPluginsDirAbs, sourcesFolderName, p.name);
604 for (const codeFile of codeFiles) {
605 let fileName = codeFile.$.src.split('/').pop();
606 const fileExt = codeFile.$.src.split('.').pop();
607 if (fileExt === 'a' && !fileName.startsWith('lib')) {
608 fileName = 'lib' + fileName;
609 }
610 let destFolder = sourcesFolderName;
611 if (!isSPM && codeFile.$['compiler-flags'] && codeFile.$['compiler-flags'] === '-fno-objc-arc') {
612 destFolder = 'noarc';
613 }
614 const filePath = getFilePath(config, p, codeFile.$.src);
615 const fileDest = join(config.ios.cordovaPluginsDirAbs, destFolder, p.name, fileName);
616 await copy(filePath, fileDest);
617 if (!codeFile.$.framework) {
618 let fileContent = await readFile(fileDest, { encoding: 'utf-8' });
619 if (fileExt === 'swift') {
620 fileContent = 'import Cordova\n' + fileContent;
621 await writeFile(fileDest, fileContent, { encoding: 'utf-8' });
622 } else {
623 if (fileContent.includes('@import Firebase;')) {
624 fileContent = fileContent.replace('@import Firebase;', '#import <Firebase/Firebase.h>');
625 await writeFile(fileDest, fileContent, { encoding: 'utf-8' });
626 }
627 if (
628 fileContent.includes('[NSBundle bundleForClass:[self class]]') ||
629 fileContent.includes('[NSBundle bundleForClass:[CDVCapture class]]')
630 ) {
631 const bundleName = isSPM ? 'SWIFTPM_MODULE_BUNDLE' : '[NSBundle mainBundle]';
632 fileContent = fileContent.replace('[NSBundle bundleForClass:[self class]]', bundleName);
633 fileContent = fileContent.replace('[NSBundle bundleForClass:[CDVCapture class]]', bundleName);
634 await writeFile(fileDest, fileContent, { encoding: 'utf-8' });
635 }
636 if (isSPM && fileContent.includes('[NSBundle mainBundle] URLForResource')) {
637 fileContent = fileContent.replace(
638 '[NSBundle mainBundle] URLForResource',
639 'SWIFTPM_MODULE_BUNDLE URLForResource',
640 );
641 await writeFile(fileDest, fileContent, { encoding: 'utf-8' });
642 }
643 if (fileContent.includes('[self.webView superview]') || fileContent.includes('self.webView.superview')) {
644 fileContent = fileContent.replace(/\[self.webView superview\]/g, 'self.viewController.view');
645 fileContent = fileContent.replace(/self.webView.superview/g, 'self.viewController.view');

Callers 1

updatePluginFilesFunction · 0.70

Calls 6

getPluginPlatformFunction · 0.90
getPlatformElementFunction · 0.90
needsStaticPodFunction · 0.90
getFilePathFunction · 0.90
copyFunction · 0.90
readFileFunction · 0.85

Tested by

no test coverage detected