2024-01-30 14:46:50 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*::
|
2024-02-01 14:02:17 +00:00
|
|
|
import type {BuildType, Version} from './utils/version-utils';
|
2024-01-30 14:46:50 +00:00
|
|
|
*/
|
|
|
|
|
2024-02-16 11:21:25 +00:00
|
|
|
const {REPO_ROOT} = require('../consts');
|
2024-01-30 14:46:50 +00:00
|
|
|
const {getNpmInfo} = require('../npm-utils');
|
2024-02-01 14:02:17 +00:00
|
|
|
const {parseVersion, validateBuildType} = require('./utils/version-utils');
|
2024-01-30 14:46:50 +00:00
|
|
|
const {promises: fs} = require('fs');
|
2024-02-10 05:35:18 +00:00
|
|
|
const path = require('path');
|
2024-11-19 17:47:40 +00:00
|
|
|
const {parseArgs} = require('util');
|
2024-02-10 05:35:18 +00:00
|
|
|
|
|
|
|
const GRADLE_FILE_PATH = path.join(
|
|
|
|
REPO_ROOT,
|
|
|
|
'packages/react-native/ReactAndroid/gradle.properties',
|
|
|
|
);
|
2024-01-30 14:46:50 +00:00
|
|
|
|
|
|
|
const config = {
|
|
|
|
options: {
|
|
|
|
'build-type': {
|
|
|
|
type: 'string',
|
|
|
|
short: 'b',
|
|
|
|
},
|
|
|
|
'to-version': {
|
|
|
|
type: 'string',
|
|
|
|
short: 'v',
|
|
|
|
},
|
|
|
|
help: {type: 'boolean'},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2024-06-26 17:14:12 +00:00
|
|
|
/**
|
|
|
|
* @deprecated This script entry point is deprecated. Please use `set-version`
|
|
|
|
* instead.
|
|
|
|
*/
|
2024-01-30 14:46:50 +00:00
|
|
|
async function main() {
|
|
|
|
const {
|
|
|
|
values: {help, 'build-type': buildType, 'to-version': toVersion},
|
|
|
|
} = parseArgs(config);
|
|
|
|
|
|
|
|
if (help) {
|
|
|
|
console.log(`
|
2024-06-26 17:14:12 +00:00
|
|
|
Usage: node ./scripts/releases/set-rn-artifacts-version.js [OPTIONS]
|
2024-01-30 14:46:50 +00:00
|
|
|
|
2024-06-26 14:59:49 +00:00
|
|
|
Updates relevant native files in the react-native package to materialize
|
|
|
|
the given release version. This does not update package.json.
|
2024-01-30 14:46:50 +00:00
|
|
|
|
|
|
|
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}`);
|
|
|
|
}
|
|
|
|
|
2024-06-26 17:14:12 +00:00
|
|
|
await updateReactNativeArtifacts(
|
2024-01-30 14:46:50 +00:00
|
|
|
toVersion ?? getNpmInfo(buildType).version,
|
|
|
|
buildType,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-06-26 17:14:12 +00:00
|
|
|
async function updateReactNativeArtifacts(
|
2024-01-30 14:46:50 +00:00
|
|
|
version /*: string */,
|
2024-02-20 13:06:03 +00:00
|
|
|
buildType /*: ?BuildType */,
|
2024-01-30 14:46:50 +00:00
|
|
|
) {
|
|
|
|
const versionInfo = parseVersion(version, buildType);
|
|
|
|
|
|
|
|
await updateSourceFiles(versionInfo);
|
|
|
|
await updateGradleFile(versionInfo.version);
|
|
|
|
}
|
|
|
|
|
2024-02-10 05:35:18 +00:00
|
|
|
function updateSourceFiles(
|
|
|
|
versionInfo /*: Version */,
|
|
|
|
) /*: Promise<Array<void>>*/ {
|
2024-01-30 14:46:50 +00:00
|
|
|
const templateData = {version: versionInfo};
|
|
|
|
|
|
|
|
return Promise.all([
|
|
|
|
fs.writeFile(
|
2024-02-10 05:35:18 +00:00
|
|
|
path.join(
|
|
|
|
REPO_ROOT,
|
|
|
|
'packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java',
|
|
|
|
),
|
2024-01-30 14:46:50 +00:00
|
|
|
require('./templates/ReactNativeVersion.java-template')(templateData),
|
|
|
|
),
|
|
|
|
fs.writeFile(
|
2024-02-10 05:35:18 +00:00
|
|
|
path.join(REPO_ROOT, 'packages/react-native/React/Base/RCTVersion.m'),
|
2024-01-30 14:46:50 +00:00
|
|
|
require('./templates/RCTVersion.m-template')(templateData),
|
|
|
|
),
|
|
|
|
fs.writeFile(
|
2024-02-10 05:35:18 +00:00
|
|
|
path.join(
|
|
|
|
REPO_ROOT,
|
|
|
|
'packages/react-native/ReactCommon/cxxreact/ReactNativeVersion.h',
|
|
|
|
),
|
2024-01-30 14:46:50 +00:00
|
|
|
require('./templates/ReactNativeVersion.h-template')(templateData),
|
|
|
|
),
|
|
|
|
fs.writeFile(
|
2024-02-10 05:35:18 +00:00
|
|
|
path.join(
|
|
|
|
REPO_ROOT,
|
|
|
|
'packages/react-native/Libraries/Core/ReactNativeVersion.js',
|
|
|
|
),
|
2024-01-30 14:46:50 +00:00
|
|
|
require('./templates/ReactNativeVersion.js-template')(templateData),
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2024-02-10 05:35:18 +00:00
|
|
|
async function updateGradleFile(version /*: string */) /*: Promise<void> */ {
|
2024-01-30 14:46:50 +00:00
|
|
|
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 = {
|
2024-06-26 17:14:12 +00:00
|
|
|
updateReactNativeArtifacts,
|
2024-02-10 05:35:18 +00:00
|
|
|
updateGradleFile,
|
|
|
|
updateSourceFiles,
|
2024-01-30 14:46:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (require.main === module) {
|
|
|
|
// eslint-disable-next-line no-void
|
|
|
|
void main();
|
|
|
|
}
|