Skip to content

Commit caf2dbd

Browse files
committed
Update gradle wrapper
1 parent 602ee0f commit caf2dbd

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

scripts/changeGradleVersion.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env node
2+
/*
3+
Updates gradle-wrapper.properties based on REACT_NATIVE_VERSION env var.
4+
- RN < 0.82: Gradle 8.14.1
5+
- RN >= 0.82: Gradle 9.0.0
6+
*/
7+
8+
const fs = require('fs/promises');
9+
const path = require('path');
10+
11+
const GRADLE_WRAPPER_PATH = path.join(
12+
process.cwd(),
13+
'playground',
14+
'android',
15+
'gradle',
16+
'wrapper',
17+
'gradle-wrapper.properties'
18+
);
19+
20+
/**
21+
* Determine the Gradle version based on RN minor version.
22+
*/
23+
function getGradleVersion(rnMinor) {
24+
return rnMinor < 82 ? '8.14.1' : '9.0.0';
25+
}
26+
27+
/**
28+
* Parse RN version string and return the minor version number.
29+
*/
30+
function parseRnMinor(rnVersion) {
31+
const match = String(rnVersion).match(/^\d+\.(\d+)/);
32+
return match ? Number(match[1]) : NaN;
33+
}
34+
35+
/**
36+
* Update gradle-wrapper.properties with the specified Gradle version.
37+
*/
38+
async function updateGradleWrapper(gradleVersion) {
39+
const content = await fs.readFile(GRADLE_WRAPPER_PATH, 'utf8');
40+
41+
const updatedContent = content.replace(
42+
/distributionUrl=https\\:\/\/services\.gradle\.org\/distributions\/gradle-[\d.]+-bin\.zip/,
43+
`distributionUrl=https\\://services.gradle.org/distributions/gradle-${gradleVersion}-bin.zip`
44+
);
45+
46+
await fs.writeFile(GRADLE_WRAPPER_PATH, updatedContent, 'utf8');
47+
return gradleVersion;
48+
}
49+
50+
async function main() {
51+
const rnVersion = process.env.REACT_NATIVE_VERSION;
52+
if (!rnVersion) {
53+
console.log('REACT_NATIVE_VERSION not set; skipping Gradle version update');
54+
return;
55+
}
56+
57+
const rnMinor = parseRnMinor(rnVersion);
58+
if (Number.isNaN(rnMinor)) {
59+
console.error(`Could not parse RN minor version from: ${rnVersion}`);
60+
process.exit(1);
61+
}
62+
63+
const gradleVersion = getGradleVersion(rnMinor);
64+
await updateGradleWrapper(gradleVersion);
65+
66+
console.log(`Updated Gradle version to ${gradleVersion} (RN ${rnVersion}, minor=${rnMinor})`);
67+
}
68+
69+
main().catch((err) => {
70+
console.error('[changeGradleVersion] Error:', err.message);
71+
process.exit(1);
72+
});
73+

scripts/changeReactNativeVersion.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@
33
Updates package.json React Native and React versions based on REACT_NATIVE_VERSION env var.
44
- Fetches the React peer dependency from the npm registry for the specified RN version
55
- Updates package.json dependencies/devDependencies accordingly
6+
- Updates Gradle wrapper version based on RN version
67
*/
78

89
const fs = require('fs/promises');
910
const path = require('path');
1011

12+
const GRADLE_WRAPPER_PATH = path.join(
13+
process.cwd(),
14+
'playground',
15+
'android',
16+
'gradle',
17+
'wrapper',
18+
'gradle-wrapper.properties'
19+
);
20+
1121
/**
1222
* Fetch and compute the versions we need in order to update package.json files.
1323
* Returns an object with:
@@ -86,6 +96,31 @@ function logChanges(packageJsonPath, versions) {
8696
}
8797
}
8898

99+
/**
100+
* Determine the Gradle version based on RN minor version.
101+
* RN < 0.82: Gradle 8.14.1
102+
* RN >= 0.82: Gradle 9.0.0
103+
*/
104+
function getGradleVersion(rnMinor) {
105+
return rnMinor < 82 ? '8.14.1' : '9.0.0';
106+
}
107+
108+
/**
109+
* Update gradle-wrapper.properties with the appropriate Gradle version.
110+
*/
111+
async function updateGradleWrapper(rnMinor) {
112+
const gradleVersion = getGradleVersion(rnMinor);
113+
const content = await fs.readFile(GRADLE_WRAPPER_PATH, 'utf8');
114+
115+
const updatedContent = content.replace(
116+
/distributionUrl=https\\:\/\/services\.gradle\.org\/distributions\/gradle-[\d.]+-bin\.zip/,
117+
`distributionUrl=https\\://services.gradle.org/distributions/gradle-${gradleVersion}-bin.zip`
118+
);
119+
120+
await fs.writeFile(GRADLE_WRAPPER_PATH, updatedContent, 'utf8');
121+
console.log(`Updated Gradle version to ${gradleVersion}`);
122+
}
123+
89124
async function main() {
90125
const rnVersion = process.env.REACT_NATIVE_VERSION;
91126
if (!rnVersion) {
@@ -105,6 +140,9 @@ async function main() {
105140
await updatePackageJsonAt(packageJsonPath, versions);
106141
logChanges(packageJsonPath, versions);
107142
}
143+
144+
// Update Gradle wrapper version
145+
await updateGradleWrapper(versions.rnMinor);
108146
}
109147

110148
main().catch((err) => {

0 commit comments

Comments
 (0)