Skip to content

Commit

Permalink
fix(cli): create only static pod if needed (#5099)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Oct 6, 2021
1 parent 81a43b1 commit 8304744
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 48 deletions.
9 changes: 9 additions & 0 deletions cli/src/cordova.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,15 @@ export function getIncompatibleCordovaPlugins(platform: string): string[] {
return pluginList;
}

export function needsStaticPod(plugin: Plugin): boolean {
const pluginList = [
'phonegap-plugin-push',
'@havesource/cordova-plugin-push',
'cordova-plugin-firebasex',
];
return pluginList.includes(plugin.id);
}

export async function getCordovaPreferences(config: Config): Promise<any> {
const configXml = join(config.app.rootDir, 'config.xml');
let cordova: any = {};
Expand Down
62 changes: 14 additions & 48 deletions cli/src/ios/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
checkPluginDependencies,
handleCordovaPluginsJS,
logCordovaManualSteps,
needsStaticPod,
} from '../cordova';
import type { Config } from '../definitions';
import { fatal } from '../errors';
Expand Down Expand Up @@ -187,25 +188,20 @@ async function generatePodFile(
});
});
});
const noPodPlugins = cordovaPlugins.filter(filterNoPods);
if (noPodPlugins.length > 0) {
const staticPlugins = cordovaPlugins.filter(needsStaticPod);
const noStaticPlugins = cordovaPlugins.filter(
el => !staticPlugins.includes(el),
);
if (noStaticPlugins.length > 0) {
pods.push(
` pod 'CordovaPlugins', :path => '../capacitor-cordova-ios-plugins'\n`,
);
}
const podPlugins = cordovaPlugins.filter(el => !noPodPlugins.includes(el));
const podSwiftPlugins = podPlugins.filter(filterSwift);
const podObjCPlugins = podPlugins.filter(el => !podSwiftPlugins.includes(el));
if (podObjCPlugins.length > 0) {
if (staticPlugins.length > 0) {
pods.push(
` pod 'CordovaPluginsStatic', :path => '../capacitor-cordova-ios-plugins'\n`,
);
}
if (podSwiftPlugins.length > 0) {
pods.push(
` pod 'CordovaPluginsStaticSwift', :path => '../capacitor-cordova-ios-plugins'\n`,
);
}
const resourcesPlugins = cordovaPlugins.filter(filterResources);
if (resourcesPlugins.length > 0) {
pods.push(
Expand Down Expand Up @@ -238,20 +234,18 @@ async function generateCordovaPodspecs(
cordovaPlugins: Plugin[],
config: Config,
) {
const noPodPlugins = cordovaPlugins.filter(filterNoPods);
const podPlugins = cordovaPlugins.filter(el => !noPodPlugins.includes(el));
const podSwiftPlugins = podPlugins.filter(filterSwift);
const podObjCPlugins = podPlugins.filter(el => !podSwiftPlugins.includes(el));
generateCordovaPodspec(noPodPlugins, config, false, false);
generateCordovaPodspec(podObjCPlugins, config, true, false);
generateCordovaPodspec(podSwiftPlugins, config, true, true);
const staticPlugins = cordovaPlugins.filter(needsStaticPod);
const noStaticPlugins = cordovaPlugins.filter(
el => !staticPlugins.includes(el),
);
generateCordovaPodspec(noStaticPlugins, config, false);
generateCordovaPodspec(staticPlugins, config, true);
}

async function generateCordovaPodspec(
cordovaPlugins: Plugin[],
config: Config,
isStatic: boolean,
isSwift: boolean,
) {
const weakFrameworks: string[] = [];
const linkedFrameworks: string[] = [];
Expand All @@ -268,10 +262,6 @@ async function generateCordovaPodspec(
frameworkDeps.push('s.static_framework = true');
sourcesFolderName += 'static';
}
if (isSwift) {
name += 'Swift';
sourcesFolderName += 'swift';
}
cordovaPlugins.map((plugin: any) => {
const frameworks = getPlatformElement(plugin, platform, 'framework');
frameworks.map((framework: any) => {
Expand Down Expand Up @@ -426,16 +416,9 @@ async function copyPluginsNativeFiles(
const headerFiles = getPlatformElement(p, platform, 'header-file');
const codeFiles = sourceFiles.concat(headerFiles);
const frameworks = getPlatformElement(p, platform, 'framework');
const podFrameworks = frameworks.filter(
(framework: any) => framework.$.type && framework.$.type === 'podspec',
);
const podspecs = getPlatformElement(p, platform, 'podspec');
let sourcesFolderName = 'sources';
if (podFrameworks.length > 0 || podspecs.length > 0) {
if (needsStaticPod(p)) {
sourcesFolderName += 'static';
if (filterSwift(p)) {
sourcesFolderName += 'swift';
}
}
const sourcesFolder = join(
config.ios.cordovaPluginsDirAbs,
Expand Down Expand Up @@ -534,23 +517,6 @@ async function removePluginsNativeFiles(config: Config) {
);
}

function filterNoPods(plugin: Plugin) {
const frameworks = getPlatformElement(plugin, platform, 'framework');
const podFrameworks = frameworks.filter(
(framework: any) => framework.$.type && framework.$.type === 'podspec',
);
const podspecs = getPlatformElement(plugin, platform, 'podspec');
return podFrameworks.length === 0 && podspecs.length === 0;
}

function filterSwift(plugin: Plugin) {
const sourceFiles = getPlatformElement(plugin, platform, 'source-file');
const swiftFiles = sourceFiles.filter(
(sf: any) => sf.$.src && sf.$.src.split('.').pop() === 'swift',
);
return swiftFiles.length > 0;
}

function filterResources(plugin: Plugin) {
const resources = getPlatformElement(plugin, platform, 'resource-file');
return resources.length > 0;
Expand Down

0 comments on commit 8304744

Please sign in to comment.