Files
react-native/scripts/releases/set-rn-artifacts-version.js
Alex Hunt 5f60ad65ca Rename set-rn-version script, mark as deprecated (#45184)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45184

This is a follow-up to D59055522.

> NOTE:This diff will be followed up by a merge of the set-rn-version script into set-version. (I had considered a rename to version-rn-artifacts, intentionally keeping this script separate and distinct from a future [lerna version + this script] setup — however the current UX and confusion with this naming would be too confusing. It can move into a util 👍🏻.)

- Rename `set-rn-version` to `set-rn-artifacts-version` (more accurate).
- Mark this script as deprecated.
    - For now, there are too many references to this script in CI test jobs to refactor away this entry point, so I am avoiding this — these should later be standardised to `set-version`.

Changelog: [Internal]

Reviewed By: christophpurrer

Differential Revision: D59058085

fbshipit-source-id: 4123ac73b5c7a2e07a1d1b6da61e0ad94fc31f84
2024-06-26 10:14:12 -07:00

138 lines
3.4 KiB
JavaScript
Executable File

/**
* 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.
*
* @flow
* @format
* @oncall react_native
*/
/*::
import type {BuildType, Version} from './utils/version-utils';
*/
const {REPO_ROOT} = require('../consts');
const {getNpmInfo} = require('../npm-utils');
const {parseVersion, validateBuildType} = require('./utils/version-utils');
const {parseArgs} = require('@pkgjs/parseargs');
const {promises: fs} = require('fs');
const path = require('path');
const GRADLE_FILE_PATH = path.join(
REPO_ROOT,
'packages/react-native/ReactAndroid/gradle.properties',
);
const config = {
options: {
'build-type': {
type: 'string',
short: 'b',
},
'to-version': {
type: 'string',
short: 'v',
},
help: {type: 'boolean'},
},
};
/**
* @deprecated This script entry point is deprecated. Please use `set-version`
* instead.
*/
async function main() {
const {
values: {help, 'build-type': buildType, 'to-version': toVersion},
} = parseArgs(config);
if (help) {
console.log(`
Usage: node ./scripts/releases/set-rn-artifacts-version.js [OPTIONS]
Updates relevant native files in the react-native package to materialize
the given release version. This does not update package.json.
Options:
--build-type One of ['dry-run', 'nightly', 'release', 'prealpha'].
--to-version The new version string.
`);
return;
}
if (!validateBuildType(buildType)) {
throw new Error(`Unsupported build type: ${buildType}`);
}
await updateReactNativeArtifacts(
toVersion ?? getNpmInfo(buildType).version,
buildType,
);
}
async function updateReactNativeArtifacts(
version /*: string */,
buildType /*: ?BuildType */,
) {
const versionInfo = parseVersion(version, buildType);
await updateSourceFiles(versionInfo);
await updateGradleFile(versionInfo.version);
}
function updateSourceFiles(
versionInfo /*: Version */,
) /*: Promise<Array<void>>*/ {
const templateData = {version: versionInfo};
return Promise.all([
fs.writeFile(
path.join(
REPO_ROOT,
'packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java',
),
require('./templates/ReactNativeVersion.java-template')(templateData),
),
fs.writeFile(
path.join(REPO_ROOT, 'packages/react-native/React/Base/RCTVersion.m'),
require('./templates/RCTVersion.m-template')(templateData),
),
fs.writeFile(
path.join(
REPO_ROOT,
'packages/react-native/ReactCommon/cxxreact/ReactNativeVersion.h',
),
require('./templates/ReactNativeVersion.h-template')(templateData),
),
fs.writeFile(
path.join(
REPO_ROOT,
'packages/react-native/Libraries/Core/ReactNativeVersion.js',
),
require('./templates/ReactNativeVersion.js-template')(templateData),
),
]);
}
async function updateGradleFile(version /*: string */) /*: Promise<void> */ {
const contents = await fs.readFile(GRADLE_FILE_PATH, 'utf-8');
return fs.writeFile(
GRADLE_FILE_PATH,
contents.replace(/^VERSION_NAME=.*/, `VERSION_NAME=${version}`),
);
}
module.exports = {
updateReactNativeArtifacts,
updateGradleFile,
updateSourceFiles,
};
if (require.main === module) {
// eslint-disable-next-line no-void
void main();
}