Skip to content

Commit 24b6074

Browse files
committed
feat: implement OOT release script
1 parent 3d96cf6 commit 24b6074

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed

scripts/prepare-for-oot-release.js

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
*/
9+
10+
'use strict';
11+
12+
const forEachPackage = require('./monorepo/for-each-package');
13+
const {applyPackageVersions, publishPackage} = require('./npm-utils');
14+
const updateTemplatePackage = require('./update-template-package');
15+
const fs = require('fs');
16+
const path = require('path');
17+
const {cat, echo, exit} = require('shelljs');
18+
const yargs = require('yargs');
19+
20+
/**
21+
* This script updates core packages to the version of React Native that we are basing on,
22+
* updates internal visionOS packages and releases them.
23+
*/
24+
if (require.main === module) {
25+
let {argv} = yargs
26+
.option('v', {
27+
alias: 'new-version',
28+
type: 'string',
29+
describe:
30+
'New version of `@callstack/react-native-visionos` to be released',
31+
required: true,
32+
})
33+
.option('r', {
34+
alias: 'react-native-version',
35+
type: 'string',
36+
describe:
37+
'React Native version that this release is based on. Ex. "0.72.7" or "0.74.0-nightly-20231130-7e5f15b88"',
38+
required: true,
39+
})
40+
.option('t', {
41+
alias: 'tag',
42+
type: 'string',
43+
describe: 'Tag to be used for publishing packages',
44+
required: false,
45+
})
46+
.option('o', {
47+
alias: 'one-time-password',
48+
type: 'string',
49+
describe: 'One time password for npm publish',
50+
required: false,
51+
});
52+
53+
prepareForOOTRelease(
54+
argv.newVersion,
55+
argv.reactNativeVersion,
56+
argv.oneTimePassword,
57+
argv.tag,
58+
);
59+
exit(0);
60+
}
61+
62+
function getPackages() {
63+
const packages = {};
64+
forEachPackage(
65+
(packageAbsolutePath, packageRelativePathFromRoot, packageManifest) => {
66+
packages[packageManifest.name] = packageRelativePathFromRoot;
67+
},
68+
{includeReactNative: true},
69+
);
70+
return packages;
71+
}
72+
73+
function setPackage(packagePath, version, dependencyVersions) {
74+
const originalPackageJson = JSON.parse(cat(`${packagePath}/package.json`));
75+
const packageJson =
76+
dependencyVersions != null
77+
? applyPackageVersions(originalPackageJson, dependencyVersions)
78+
: originalPackageJson;
79+
80+
packageJson.version = version;
81+
82+
fs.writeFileSync(
83+
`${packagePath}/package.json`,
84+
JSON.stringify(packageJson, null, 2),
85+
'utf-8',
86+
);
87+
}
88+
89+
function prepareForOOTRelease(
90+
newVersion,
91+
reactNativeVersion,
92+
oneTimePassword,
93+
tag = 'latest',
94+
) {
95+
const allPackages = getPackages();
96+
const corePackages = Object.keys(allPackages).filter(packageName =>
97+
packageName.startsWith('@react-native/'),
98+
);
99+
const visionOSPackages = Object.keys(allPackages).filter(packageName =>
100+
packageName.startsWith('@callstack/'),
101+
);
102+
103+
const corePackagesVersions = corePackages.reduce(
104+
(acc, pkg) => ({...acc, [pkg]: reactNativeVersion}),
105+
{},
106+
);
107+
108+
// Update `packges/react-native` package.json and all visionOS packages
109+
visionOSPackages.forEach(pkg => {
110+
echo(`Setting ${pkg} version to ${newVersion} `);
111+
setPackage(allPackages[pkg], newVersion, corePackagesVersions);
112+
});
113+
114+
// Update template package.json
115+
updateTemplatePackage({
116+
'react-native': reactNativeVersion,
117+
...corePackagesVersions,
118+
...visionOSPackages.reduce((acc, pkg) => ({...acc, [pkg]: newVersion}), {}),
119+
});
120+
echo(`Updating template and it's dependencies to ${reactNativeVersion}`);
121+
122+
// Release visionOS packages only if OTP is passed
123+
if (!oneTimePassword) {
124+
return;
125+
}
126+
127+
const results = visionOSPackages
128+
.map(npmPackage => {
129+
return path.join(__dirname, '..', allPackages[npmPackage]);
130+
})
131+
.map(packagePath => {
132+
echo(`Releasing ${packagePath}`);
133+
const result = publishPackage(packagePath, {
134+
tag,
135+
otp: oneTimePassword,
136+
});
137+
138+
return result.code;
139+
});
140+
141+
if (results.every(Boolean)) {
142+
echo(`Failed to publish ${visionOSPackages.join(', ')} packages to npm`);
143+
return exit(1);
144+
} else {
145+
echo(
146+
`Published ${visionOSPackages.join(
147+
', ',
148+
)} to npm with version: ${newVersion}`,
149+
);
150+
return exit(0);
151+
}
152+
}
153+
154+
module.exports = prepareForOOTRelease;

0 commit comments

Comments
 (0)