Skip to content

Commit

Permalink
Merge branch 'main' into RDMR-129
Browse files Browse the repository at this point in the history
  • Loading branch information
markemer authored Dec 17, 2024
2 parents fa28dee + 9fe2256 commit 267d623
Showing 1 changed file with 38 additions and 46 deletions.
84 changes: 38 additions & 46 deletions cli/src/tasks/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { writeFileSync, readFileSync, existsSync } from 'fs-extra';
import { join } from 'path';
import rimraf from 'rimraf';
import { coerce, gt, gte, lt } from 'semver';
import { coerce, gte, lt } from 'semver';

import { getAndroidPlugins } from '../android/common';
import c from '../colors';
Expand Down Expand Up @@ -44,9 +44,9 @@ const plugins = [
'@capacitor/text-zoom',
'@capacitor/toast',
];
const coreVersion = '^6.0.0';
const pluginVersion = '^6.0.0';
const gradleVersion = '8.2.1';
const coreVersion = 'next';
const pluginVersion = 'next';
const gradleVersion = '8.11.1';
let installFailed = false;

export async function migrateCommand(config: Config, noprompt: boolean, packagemanager: string): Promise<void> {
Expand All @@ -55,14 +55,14 @@ export async function migrateCommand(config: Config, noprompt: boolean, packagem
}

const capMajor = await checkCapacitorMajorVersion(config);
if (capMajor < 5) {
fatal('Migrate can only be used on capacitor 5 and above, please use the CLI in Capacitor 5 to upgrade to 5 first');
if (capMajor < 6) {
fatal('Migrate can only be used on Capacitor 6, please use the CLI in Capacitor 6 to upgrade to 6 first');
}

const jdkMajor = await checkJDKMajorVersion();

if (jdkMajor < 17) {
logger.warn('Capacitor 6 requires JDK 17 or higher. Some steps may fail.');
if (jdkMajor < 21) {
logger.warn('Capacitor 7 requires JDK 21 or higher. Some steps may fail.');
}

const variablesAndClasspaths:
Expand All @@ -89,7 +89,7 @@ export async function migrateCommand(config: Config, noprompt: boolean, packagem

const { migrateconfirm } = noprompt
? { migrateconfirm: 'y' }
: await logPrompt(`Capacitor 6 sets a deployment target of iOS 13 and Android 14 (SDK 34). \n`, {
: await logPrompt(`Capacitor 7 sets a deployment target of iOS 14 and Android 15 (SDK 35). \n`, {
type: 'text',
name: 'migrateconfirm',
message: `Are you sure you want to migrate? (Y/n)`,
Expand Down Expand Up @@ -147,9 +147,19 @@ export async function migrateCommand(config: Config, noprompt: boolean, packagem
// Update iOS Projects
if (allDependencies['@capacitor/ios'] && existsSync(config.ios.platformDirAbs)) {
// ios template changes
// Remove NSLocationAlwaysUsageDescription
await runTask(`Migrating Info.plist by removing NSLocationAlwaysUsageDescription key.`, () => {
return removeKey(join(config.ios.nativeTargetDirAbs, 'Info.plist'), 'NSLocationAlwaysUsageDescription');
// Set deployment target to 14.0
await runTask(`Migrating deployment target to 14.0.`, () => {
return updateFile(
config,
join(config.ios.nativeXcodeProjDirAbs, 'project.pbxproj'),
'IPHONEOS_DEPLOYMENT_TARGET = ',
';',
'14.0',
);
});
// Update Podfile to 14.0
await runTask(`Migrating Podfile to 14.0.`, () => {
return updateFile(config, join(config.ios.nativeProjectDirAbs, 'Podfile'), `platform :ios, '`, `'`, '14.0');
});
}

Expand All @@ -166,8 +176,12 @@ export async function migrateCommand(config: Config, noprompt: boolean, packagem
join(config.android.platformDirAbs, 'gradle', 'wrapper', 'gradle-wrapper.properties'),
);

if (!installFailed && gt(gradleVersion, gradleWrapperVersion)) {
if (!installFailed && gte(gradleVersion, gradleWrapperVersion)) {
try {
await runTask(`Upgrading gradle wrapper`, () => {
return updateGradleWrapperFiles(config.android.platformDirAbs);
});
// Run twice as first time it only updates the wrapper properties file
await runTask(`Upgrading gradle wrapper files`, () => {
return updateGradleWrapperFiles(config.android.platformDirAbs);
});
Expand All @@ -191,28 +205,6 @@ export async function migrateCommand(config: Config, noprompt: boolean, packagem
return updateBuildGradle(join(config.android.platformDirAbs, 'build.gradle'), variablesAndClasspaths);
});

// Replace deprecated compileSdkVersion
await runTask('Replacing deprecated compileSdkVersion from build.gradle', () => {
return (async (): Promise<void> => {
const buildGradleFilename = join(config.android.platformDirAbs, 'app', 'build.gradle');
const buildGradleText = readFile(buildGradleFilename);

if (!buildGradleText) {
logger.error(`Could not read ${buildGradleFilename}. Check its permissions and if it exists.`);
return;
}
const compileSdk = `compileSdkVersion rootProject.ext.compileSdkVersion`;
if (buildGradleText.includes(compileSdk)) {
const buildGradleReplaced = buildGradleText.replace(
compileSdk,
`compileSdk rootProject.ext.compileSdkVersion`,
);

writeFileSync(buildGradleFilename, buildGradleReplaced, 'utf-8');
}
})();
});

// Variables gradle
await runTask(`Migrating variables.gradle file.`, () => {
return (async (): Promise<void> => {
Expand Down Expand Up @@ -261,11 +253,11 @@ export async function migrateCommand(config: Config, noprompt: boolean, packagem
}
}
const pluginVariables: { [key: string]: string } = {
firebaseMessagingVersion: '23.3.1',
playServicesLocationVersion: '21.1.0',
androidxBrowserVersion: '1.7.0',
androidxMaterialVersion: '1.10.0',
androidxExifInterfaceVersion: '1.3.6',
firebaseMessagingVersion: '24.1.0',
playServicesLocationVersion: '21.3.0',
androidxBrowserVersion: '1.8.0',
androidxMaterialVersion: '1.12.0',
androidxExifInterfaceVersion: '1.3.7',
androidxCoreKTXVersion: '1.12.0',
googleMapsPlayServicesVersion: '18.2.0',
googleMapsUtilsVersion: '3.8.2',
Expand Down Expand Up @@ -360,11 +352,11 @@ async function installLatestLibs(dependencyManager: string, runInstall: boolean,

async function writeBreakingChanges() {
const breaking = [
'@capacitor/camera',
'@capacitor/filesystem',
'@capacitor/geolocation',
'@capacitor/google-maps',
'@capacitor/local-notifications',
'@capacitor/app',
'@capacitor/device',
'@capacitor/haptics',
'@capacitor/splash-screen',
'@capacitor/statusbar',
];
const broken = [];
for (const lib of breaking) {
Expand All @@ -374,7 +366,7 @@ async function writeBreakingChanges() {
}
if (broken.length > 0) {
logger.info(
`IMPORTANT: Review https://capacitorjs.com/docs/next/updating/6-0#plugins for breaking changes in these plugins that you use: ${broken.join(
`IMPORTANT: Review https://capacitorjs.com/docs/next/updating/7-0#plugins for breaking changes in these plugins that you use: ${broken.join(
', ',
)}.`,
);
Expand Down

0 comments on commit 267d623

Please sign in to comment.