Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): remove cordova if not needed via cli #7807

Draft
wants to merge 2 commits into
base: optional-cordova-android
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 40 additions & 15 deletions cli/src/ios/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,53 @@ export async function updateIOS(config: Config, deployment: boolean): Promise<vo
async function updateIOSCocoaPods(config: Config, plugins: Plugin[], deployment: boolean) {
await removePluginsNativeFiles(config);
const cordovaPlugins = plugins.filter((p) => getPluginType(p, platform) === PluginType.Cordova);
if (cordovaPlugins.length > 0) {
// TODO: all the new logic should probably go here
// with an else that removes cordova plugins

const enableCordova = cordovaPlugins.length > 0;

if (enableCordova) {
await copyPluginsNativeFiles(config, cordovaPlugins);
}

if (!(await pathExists(await config.ios.webDirAbs))) {
await copyTask(config, platform);
}

await handleCordovaPluginsJS(cordovaPlugins, config, platform);
await checkPluginDependencies(plugins, platform);
await generateCordovaPodspecs(cordovaPlugins, config);
await installCocoaPodsPlugins(config, plugins, deployment);
await logCordovaManualSteps(cordovaPlugins, config, platform);

if (enableCordova) {
await generateCordovaPodspecs(cordovaPlugins, config);
}

await installCocoaPodsPlugins(config, plugins, deployment, enableCordova);

if (enableCordova) {
await logCordovaManualSteps(cordovaPlugins, config, platform);
}

const incompatibleCordovaPlugins = plugins.filter((p) => getPluginType(p, platform) === PluginType.Incompatible);
printPlugins(incompatibleCordovaPlugins, platform, 'incompatible');
await checkPlatformVersions(config, platform);
}

export async function installCocoaPodsPlugins(config: Config, plugins: Plugin[], deployment: boolean): Promise<void> {
export async function installCocoaPodsPlugins(
config: Config,
plugins: Plugin[],
deployment: boolean,
enableCordova: boolean,
): Promise<void> {
await runTask(`Updating iOS native dependencies with ${c.input(`${await config.ios.podPath} install`)}`, () => {
return updatePodfile(config, plugins, deployment);
return updatePodfile(config, plugins, deployment, enableCordova);
});
}

async function updatePodfile(config: Config, plugins: Plugin[], deployment: boolean): Promise<void> {
const dependenciesContent = await generatePodFile(config, plugins);
async function updatePodfile(
config: Config,
plugins: Plugin[],
deployment: boolean,
enableCordova: boolean,
): Promise<void> {
const dependenciesContent = await generatePodFile(config, plugins, enableCordova);
const relativeCapacitoriOSPath = await getRelativeCapacitoriOSPath(config);
const podfilePath = join(config.ios.nativeProjectDirAbs, 'Podfile');
let podfileContent = await readFile(podfilePath, { encoding: 'utf-8' });
Expand Down Expand Up @@ -123,7 +142,7 @@ async function getRelativeCapacitoriOSPath(config: Config) {
return convertToUnixPath(relative(config.ios.nativeProjectDirAbs, await realpath(dirname(capacitoriOSPath))));
}

async function generatePodFile(config: Config, plugins: Plugin[]): Promise<string> {
async function generatePodFile(config: Config, plugins: Plugin[], enableCordova: boolean): Promise<string> {
const relativeCapacitoriOSPath = await getRelativeCapacitoriOSPath(config);

const capacitorPlugins = plugins.filter((p) => getPluginType(p, platform) === PluginType.Core);
Expand All @@ -141,10 +160,16 @@ async function generatePodFile(config: Config, plugins: Plugin[]): Promise<strin
const cordovaPodlines = cordovaPodfileLines(config, plugins);
pods.concat(cordovaPodlines);

return `
pod 'Capacitor', :path => '${relativeCapacitoriOSPath}'
pod 'CapacitorCordova', :path => '${relativeCapacitoriOSPath}'
${pods.join('').trimEnd()}`;
let podfileString = '\n';
podfileString += ` pod 'Capacitor', :path => '${relativeCapacitoriOSPath}'\n`;

if (enableCordova) {
podfileString += ` pod 'CapacitorCordova', :path => '${relativeCapacitoriOSPath}'\n`;
}

podfileString += pods.join('').trimEnd();

return podfileString;
}

async function getPluginsTask(config: Config) {
Expand Down
Loading