|
| 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 strict-local |
| 8 | + * @format |
| 9 | + */ |
| 10 | + |
| 11 | +'use strict'; |
| 12 | + |
| 13 | +/*:: |
| 14 | +import type {PackageJson} from '../shared/monorepoUtils'; |
| 15 | +*/ |
| 16 | + |
| 17 | +const { |
| 18 | + dangerouslyResignGeneratedFile, |
| 19 | + processDotSlashFileInPlace, |
| 20 | + validateAndParseDotSlashFile, |
| 21 | +} = require('./utils/dotslash-utils'); |
| 22 | +const {REPO_ROOT} = require('../shared/consts'); |
| 23 | +const {parseArgs, styleText} = require('util'); |
| 24 | +const path = require('path'); |
| 25 | + |
| 26 | +const FIRST_PARTY_DOTSLASH_FILES = [ |
| 27 | + 'packages/debugger-shell/bin/react-native-devtools', |
| 28 | +]; |
| 29 | + |
| 30 | +const config = { |
| 31 | + allowPositionals: true, |
| 32 | + options: { |
| 33 | + help: {type: 'boolean'}, |
| 34 | + }, |
| 35 | +}; |
| 36 | + |
| 37 | +async function main() { |
| 38 | + const { |
| 39 | + positionals: [version], |
| 40 | + values: {help}, |
| 41 | + /* $FlowFixMe[incompatible-call] Natural Inference rollout. See |
| 42 | + * https://fburl.com/workplace/6291gfvu */ |
| 43 | + } = parseArgs(config); |
| 44 | + |
| 45 | + if (help) { |
| 46 | + console.log(` |
| 47 | + Usage: node ./scripts/releases/write-dotslash-release-asset-urls.js <version> |
| 48 | +
|
| 49 | + Inserts references to release assets URLs into first-party DotSlash files in |
| 50 | + the repo, in preparation for publishing a new release and uploading the |
| 51 | + assets (which happens in a separate step). |
| 52 | +`); |
| 53 | + return; |
| 54 | + } |
| 55 | + |
| 56 | + if (version == null) { |
| 57 | + throw new Error('Missing version argument'); |
| 58 | + } |
| 59 | + |
| 60 | + await writeReleaseAssetUrlsToDotSlashFiles(version); |
| 61 | +} |
| 62 | + |
| 63 | +async function writeReleaseAssetUrlsToDotSlashFiles( |
| 64 | + version /*: string */, |
| 65 | +) /*: Promise<void> */ { |
| 66 | + const releaseTag = `v${version}`; |
| 67 | + for (const filename of FIRST_PARTY_DOTSLASH_FILES) { |
| 68 | + const fullPath = path.join(REPO_ROOT, filename); |
| 69 | + console.log(`Updating ${filename}...`); |
| 70 | + await processDotSlashFileInPlace( |
| 71 | + fullPath, |
| 72 | + (providers, suggestedFilename) => { |
| 73 | + providers = providers.filter(provider => { |
| 74 | + // Remove any existing release asset URLs |
| 75 | + if ( |
| 76 | + (provider.type === 'http' || provider.type == null) && |
| 77 | + provider.url.startsWith( |
| 78 | + 'https://github.com/facebook/react-native/releases/download/', |
| 79 | + ) |
| 80 | + ) { |
| 81 | + console.log(styleText('red', ` -${provider.url}`)); |
| 82 | + return false; |
| 83 | + } |
| 84 | + console.log(styleText('dim', ` ${provider.url}`)); |
| 85 | + return true; |
| 86 | + }); |
| 87 | + if (providers.length === 0) { |
| 88 | + throw new Error( |
| 89 | + 'No usable providers found for asset:', |
| 90 | + suggestedFilename, |
| 91 | + ); |
| 92 | + } |
| 93 | + const url = `https://github.com/facebook/react-native/releases/download/${encodeURIComponent(releaseTag)}/${encodeURIComponent(suggestedFilename)}`; |
| 94 | + console.log(styleText('green', ` +${url}`)); |
| 95 | + providers.unshift({ |
| 96 | + url, |
| 97 | + }); |
| 98 | + console.log('\n'); |
| 99 | + return providers; |
| 100 | + }, |
| 101 | + ); |
| 102 | + await dangerouslyResignGeneratedFile(fullPath); |
| 103 | + await validateAndParseDotSlashFile(fullPath); |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +module.exports = { |
| 108 | + FIRST_PARTY_DOTSLASH_FILES, |
| 109 | + writeReleaseAssetUrlsToDotSlashFiles, |
| 110 | +}; |
| 111 | + |
| 112 | +if (require.main === module) { |
| 113 | + void main(); |
| 114 | +} |
0 commit comments