Skip to content

Commit a1d784c

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

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed

scripts/prepare-for-oot-release.js

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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('o', {
41+
alias: 'one-time-password',
42+
type: 'string',
43+
describe: 'One time password for npm publish',
44+
required: false,
45+
});
46+
console.log(argv);
47+
prepareForOOTRelease(
48+
argv.newVersion,
49+
argv.reactNativeVersion,
50+
argv.oneTimePassword,
51+
);
52+
exit(0);
53+
}
54+
55+
function getPackages() {
56+
const packages = [];
57+
forEachPackage(
58+
(packageAbsolutePath, packageRelativePathFromRoot, packageManifest) => {
59+
packages.push(packageManifest.name);
60+
},
61+
{includeReactNative: true},
62+
);
63+
return packages;
64+
}
65+
66+
function setPackage(version, dependencyVersions) {
67+
const originalPackageJson = JSON.parse(
68+
cat('packages/react-native/package.json'),
69+
);
70+
const packageJson =
71+
dependencyVersions != null
72+
? applyPackageVersions(originalPackageJson, dependencyVersions)
73+
: originalPackageJson;
74+
75+
packageJson.version = version;
76+
77+
fs.writeFileSync(
78+
'packages/react-native/package.json',
79+
JSON.stringify(packageJson, null, 2),
80+
'utf-8',
81+
);
82+
}
83+
84+
function prepareForOOTRelease(newVersion, reactNativeVersion, oneTimePassword) {
85+
const allPackages = getPackages();
86+
const corePackages = allPackages.filter(packageName =>
87+
packageName.startsWith('@react-native/'),
88+
);
89+
const visionOSPackages = allPackages.filter(packageName =>
90+
packageName.startsWith('@callstack/'),
91+
);
92+
93+
const corePackagesVersions = corePackages.reduce(
94+
(acc, pkg) => ({...acc, [pkg]: reactNativeVersion}),
95+
{},
96+
);
97+
98+
// Update `packges/react-native` package.json
99+
setPackage(newVersion, corePackagesVersions);
100+
101+
// Update template package.json
102+
updateTemplatePackage({
103+
'react-native': reactNativeVersion,
104+
...corePackagesVersions,
105+
...visionOSPackages.reduce((acc, pkg) => ({...acc, [pkg]: newVersion}), {}),
106+
});
107+
108+
// Release visionOS packages only if OTP is passed
109+
if (!oneTimePassword) {
110+
return;
111+
}
112+
113+
const visionOSPackagesPaths = visionOSPackages.map(npmPackage => {
114+
return path.join(__dirname, '..', 'packages', npmPackage);
115+
});
116+
117+
const results = visionOSPackagesPaths.map(packagePath => {
118+
const result = publishPackage(packagePath, {
119+
otp: oneTimePassword,
120+
});
121+
122+
return result.code;
123+
});
124+
125+
if (results.every(Boolean)) {
126+
echo(`Failed to publish ${visionOSPackages.join(', ')} packages to npm`);
127+
return exit(1);
128+
} else {
129+
echo(`Published ${visionOSPackages.join(', ')} to npm ${newVersion}`);
130+
return exit(0);
131+
}
132+
}
133+
134+
module.exports = prepareForOOTRelease;

0 commit comments

Comments
 (0)