Skip to content

Commit

Permalink
fix(cli): Make migrator update gradle wrapper files (#5910)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Sep 14, 2022
1 parent 5ef6a38 commit b8b9b1f
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions cli/src/tasks/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const plugins = [
];
const coreVersion = '^4.0.0';
const pluginVersion = '^4.0.0';
const gradleVersion = '7.4.2';

export async function migrateCommand(config: Config): Promise<void> {
if (config === null) {
Expand Down Expand Up @@ -246,7 +247,7 @@ export async function migrateCommand(config: Config): Promise<void> {

// Update gradle-wrapper.properties
await runTask(
`Migrating gradle-wrapper.properties by updating gradle version from 7.0 to 7.4.2.`,
`Migrating gradle-wrapper.properties by updating gradle version from 7.0 to ${gradleVersion}.`,
() => {
return updateGradleWrapper(
join(
Expand Down Expand Up @@ -348,6 +349,24 @@ export async function migrateCommand(config: Config): Promise<void> {
return getCommandOutput('npx', ['cap', 'sync']);
});

try {
await runTask(`Upgrading gradle wrapper files`, () => {
return updateGradleWrapperFiles(config.android.platformDirAbs);
});
} catch (e) {
if (e.includes('EACCES')) {
logger.error(
`gradlew file does not have executable permissions. This can happen if the Android platform was added on a Windows machine. Please run ${c.input(
`chmod +x ./${config.android.platformDir}/gradlew`,
)} and ${c.input(
`cd ${config.android.platformDir} && ./gradlew wrapper --distribution-type all --gradle-version ${gradleVersion} --warning-mode all`,
)} to update the files manually`,
);
} else {
logger.error(`gradle wrapper files were not updated`);
}
}

// Write all breaking changes
await runTask(`Writing breaking changes.`, () => {
return writeBreakingChanges();
Expand Down Expand Up @@ -661,11 +680,29 @@ async function updateGradleWrapper(filename: string) {
'distributionUrl=',
'\n',
// eslint-disable-next-line no-useless-escape
`https\\://services.gradle.org/distributions/gradle-7.4.2-all.zip`,
`https\\://services.gradle.org/distributions/gradle-${gradleVersion}-all.zip`,
);
writeFileSync(filename, replaced, 'utf-8');
}

async function updateGradleWrapperFiles(platformDir: string) {
await runCommand(
`./gradlew`,
[
'wrapper',
'--distribution-type',
'all',
'--gradle-version',
gradleVersion,
'--warning-mode',
'all',
],
{
cwd: platformDir,
},
);
}

async function updateFile(
config: Config,
filename: string,
Expand Down

0 comments on commit b8b9b1f

Please sign in to comment.