forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d96cf6
commit a1d784c
Showing
1 changed file
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const forEachPackage = require('./monorepo/for-each-package'); | ||
const {applyPackageVersions, publishPackage} = require('./npm-utils'); | ||
const updateTemplatePackage = require('./update-template-package'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const {cat, echo, exit} = require('shelljs'); | ||
const yargs = require('yargs'); | ||
|
||
/** | ||
* This script updates core packages to the version of React Native that we are basing on, | ||
* updates internal visionOS packages and releases them. | ||
*/ | ||
if (require.main === module) { | ||
let {argv} = yargs | ||
.option('v', { | ||
alias: 'new-version', | ||
type: 'string', | ||
describe: | ||
'New version of `@callstack/react-native-visionos` to be released', | ||
required: true, | ||
}) | ||
.option('r', { | ||
alias: 'react-native-version', | ||
type: 'string', | ||
describe: | ||
'React Native version that this release is based on. Ex. "0.72.7" or "0.74.0-nightly-20231130-7e5f15b88"', | ||
required: true, | ||
}) | ||
.option('o', { | ||
alias: 'one-time-password', | ||
type: 'string', | ||
describe: 'One time password for npm publish', | ||
required: false, | ||
}); | ||
console.log(argv); | ||
prepareForOOTRelease( | ||
argv.newVersion, | ||
argv.reactNativeVersion, | ||
argv.oneTimePassword, | ||
); | ||
exit(0); | ||
} | ||
|
||
function getPackages() { | ||
const packages = []; | ||
forEachPackage( | ||
(packageAbsolutePath, packageRelativePathFromRoot, packageManifest) => { | ||
packages.push(packageManifest.name); | ||
}, | ||
{includeReactNative: true}, | ||
); | ||
return packages; | ||
} | ||
|
||
function setPackage(version, dependencyVersions) { | ||
const originalPackageJson = JSON.parse( | ||
cat('packages/react-native/package.json'), | ||
); | ||
const packageJson = | ||
dependencyVersions != null | ||
? applyPackageVersions(originalPackageJson, dependencyVersions) | ||
: originalPackageJson; | ||
|
||
packageJson.version = version; | ||
|
||
fs.writeFileSync( | ||
'packages/react-native/package.json', | ||
JSON.stringify(packageJson, null, 2), | ||
'utf-8', | ||
); | ||
} | ||
|
||
function prepareForOOTRelease(newVersion, reactNativeVersion, oneTimePassword) { | ||
const allPackages = getPackages(); | ||
const corePackages = allPackages.filter(packageName => | ||
packageName.startsWith('@react-native/'), | ||
); | ||
const visionOSPackages = allPackages.filter(packageName => | ||
packageName.startsWith('@callstack/'), | ||
); | ||
|
||
const corePackagesVersions = corePackages.reduce( | ||
(acc, pkg) => ({...acc, [pkg]: reactNativeVersion}), | ||
{}, | ||
); | ||
|
||
// Update `packges/react-native` package.json | ||
setPackage(newVersion, corePackagesVersions); | ||
|
||
// Update template package.json | ||
updateTemplatePackage({ | ||
'react-native': reactNativeVersion, | ||
...corePackagesVersions, | ||
...visionOSPackages.reduce((acc, pkg) => ({...acc, [pkg]: newVersion}), {}), | ||
}); | ||
|
||
// Release visionOS packages only if OTP is passed | ||
if (!oneTimePassword) { | ||
return; | ||
} | ||
|
||
const visionOSPackagesPaths = visionOSPackages.map(npmPackage => { | ||
return path.join(__dirname, '..', 'packages', npmPackage); | ||
}); | ||
|
||
const results = visionOSPackagesPaths.map(packagePath => { | ||
const result = publishPackage(packagePath, { | ||
otp: oneTimePassword, | ||
}); | ||
|
||
return result.code; | ||
}); | ||
|
||
if (results.every(Boolean)) { | ||
echo(`Failed to publish ${visionOSPackages.join(', ')} packages to npm`); | ||
return exit(1); | ||
} else { | ||
echo(`Published ${visionOSPackages.join(', ')} to npm ${newVersion}`); | ||
return exit(0); | ||
} | ||
} | ||
|
||
module.exports = prepareForOOTRelease; |