Skip to content

Commit

Permalink
fix(cli): Separate Swift plugins from ObjC plugins (#4925)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Aug 16, 2021
1 parent 12c6294 commit 43ce803
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions cli/src/ios/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,18 @@ async function generatePodFile(
);
}
const podPlugins = cordovaPlugins.filter(el => !noPodPlugins.includes(el));
if (podPlugins.length > 0) {
const podSwiftPlugins = podPlugins.filter(filterSwift);
const podObjCPlugins = podPlugins.filter(el => !podSwiftPlugins.includes(el));
if (podObjCPlugins.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 @@ -211,14 +218,18 @@ async function generateCordovaPodspecs(
) {
const noPodPlugins = cordovaPlugins.filter(filterNoPods);
const podPlugins = cordovaPlugins.filter(el => !noPodPlugins.includes(el));
generateCordovaPodspec(noPodPlugins, config, false);
generateCordovaPodspec(podPlugins, config, true);
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);
}

async function generateCordovaPodspec(
cordovaPlugins: Plugin[],
config: Config,
isStatic: boolean,
isSwift: boolean,
) {
const weakFrameworks: string[] = [];
const linkedFrameworks: string[] = [];
Expand All @@ -235,6 +246,10 @@ 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 @@ -396,6 +411,9 @@ async function copyPluginsNativeFiles(
let sourcesFolderName = 'sources';
if (podFrameworks.length > 0 || podspecs.length > 0) {
sourcesFolderName += 'static';
if (filterSwift(p)) {
sourcesFolderName += 'swift';
}
}
const sourcesFolder = join(
config.ios.cordovaPluginsDirAbs,
Expand Down Expand Up @@ -503,6 +521,14 @@ function filterNoPods(plugin: Plugin) {
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 43ce803

Please sign in to comment.