Skip to content

Commit f4aa63c

Browse files
committed
[LOCAL] Add missing updateTemplateVersion.js
1 parent 63ccefd commit f4aa63c

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

updateTemplateVersion.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { readFileSync, writeFileSync } from "fs";
2+
3+
/**
4+
* Function to get the Nightly version of the package, similar to the one used in React Native.
5+
* Version will look as follows:
6+
* `0.75.0-nightly-20241010-abcd1234`
7+
*/
8+
function getNightlyVersion(originalVersion) {
9+
const version = originalVersion.split("-")[0];
10+
const date = new Date();
11+
const year = date.getFullYear();
12+
const month = date.getMonth() + 1;
13+
const day = date.getDate();
14+
// Get the sha fromt he current commit on github actions
15+
const sha = process.env.GITHUB_SHA.slice(0, 7);
16+
return `${version}-nightly-${year}${month}${day}-${sha}`;
17+
}
18+
19+
if (!process.argv[2]) {
20+
console.error("Please provide a version to update the template to.");
21+
process.exit(1);
22+
}
23+
const targetVersion = process.argv[2];
24+
25+
// We first update version of the template we're about to publish.
26+
const packageJsonData = readFileSync("package.json", "utf8");
27+
const packageJson = JSON.parse(packageJsonData);
28+
if (targetVersion === "nightly") {
29+
packageJson.version = getNightlyVersion(packageJson.version);
30+
} else {
31+
packageJson.version = targetVersion;
32+
}
33+
const updatedPackageJsonData = JSON.stringify(packageJson, null, 2);
34+
writeFileSync("package.json", updatedPackageJsonData, "utf8");
35+
console.log(`Template version updated to ${packageJson.version}`);
36+
37+
// And then we update the version of the dependencies in the template.
38+
// To be `nightly` as well.
39+
const templatePackageJsonData = readFileSync("template/package.json", "utf8");
40+
const templatePackageJson = JSON.parse(templatePackageJsonData);
41+
templatePackageJson.dependencies["react-native"] = targetVersion;
42+
Object.keys(templatePackageJson.devDependencies).forEach((key) => {
43+
if (key.startsWith("@react-native")) {
44+
templatePackageJson.devDependencies[key] = targetVersion;
45+
}
46+
});
47+
const updatedTemplatePackageJsonData = JSON.stringify(
48+
templatePackageJson,
49+
null,
50+
2
51+
);
52+
writeFileSync("template/package.json", updatedTemplatePackageJsonData, "utf8");
53+
54+
console.log(`Project dependencies updated to ${targetVersion}`);

0 commit comments

Comments
 (0)