|
| 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 | + * @flow |
| 8 | + * @format |
| 9 | + */ |
| 10 | + |
| 11 | +'use strict'; |
| 12 | + |
| 13 | +/*:: |
| 14 | +import type {BuildType} from './version-utils'; |
| 15 | +import type { ShellString } from 'shelljs'; |
| 16 | +*/ |
| 17 | + |
| 18 | +const {REPO_ROOT} = require('./consts'); |
| 19 | +const {getVersion, validateBuildType} = require('./version-utils'); |
| 20 | +const path = require('path'); |
| 21 | +const {exec} = require('shelljs'); |
| 22 | +const yargs = require('yargs'); |
| 23 | + |
| 24 | +/** |
| 25 | + * This script prepares a release version of react-native and may publish to NPM. |
| 26 | + * It is supposed to run in CI environment, not on a developer's machine. |
| 27 | + * |
| 28 | + * For a dry run, this script will: |
| 29 | + * * Version the commitly of the form `0.0.0-<commitSha>` |
| 30 | + * |
| 31 | + * For a commitly run, this script will: |
| 32 | + * * Version the commitly release of the form `0.0.0-<dateIdentifier>-<commitSha>` |
| 33 | + * * Publish to npm using `nightly` tag |
| 34 | + * |
| 35 | + * For a release run, this script will: |
| 36 | + * * Version the release by the tag version that triggered CI |
| 37 | + * * Publish to npm |
| 38 | + * * using `latest` tag if commit is currently tagged `latest` |
| 39 | + * * or otherwise `{major}.{minor}-stable` |
| 40 | + */ |
| 41 | + |
| 42 | +async function main() { |
| 43 | + const argv = yargs |
| 44 | + .option('t', { |
| 45 | + alias: 'builtType', |
| 46 | + describe: 'The type of build you want to perform.', |
| 47 | + choices: ['dry-run', 'commitly', 'release'], |
| 48 | + default: 'dry-run', |
| 49 | + }) |
| 50 | + .strict().argv; |
| 51 | + |
| 52 | + // $FlowFixMe[prop-missing] |
| 53 | + const buildType = argv.builtType; |
| 54 | + |
| 55 | + if (!validateBuildType(buildType)) { |
| 56 | + throw new Error(`Unsupported build type: ${buildType}`); |
| 57 | + } |
| 58 | + |
| 59 | + const result = await publishNpm(buildType); |
| 60 | + |
| 61 | + if (result && result.code) { |
| 62 | + const version = await getVersion(buildType); |
| 63 | + throw new Error(`Failed to publish hermes-compiler@${version}`); |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +async function publishNpm( |
| 68 | + buildType /*: BuildType */, |
| 69 | +) /*: Promise<ShellString | null> */ { |
| 70 | + if (buildType === 'dry-run') { |
| 71 | + console.log('Skipping `npm publish` because --dry-run is set.'); |
| 72 | + return null; |
| 73 | + } |
| 74 | + |
| 75 | + let tagFlag = ''; |
| 76 | + if (buildType === 'commitly') { |
| 77 | + tagFlag = ` --tag nightly`; |
| 78 | + } |
| 79 | + |
| 80 | + const otp = process.env.NPM_CONFIG_OTP; |
| 81 | + const otpFlag = otp != null ? ` --otp ${otp}` : ''; |
| 82 | + const packagePath = path.join(REPO_ROOT, 'npm', 'hermes-compiler'); |
| 83 | + const options = {cwd: packagePath}; |
| 84 | + |
| 85 | + // return exec(`npm publish${tagFlag}${otpFlag}$`, options); |
| 86 | + |
| 87 | + // Pack npm only for testing to see what will be inlcuded in the package |
| 88 | + return exec('npm pack', options); |
| 89 | +} |
0 commit comments