@samitouri / QOS-React / commits / eed9ca203c

[ci] Use yargs to parse args to download-experimental-build

ghstack-source-id: 0b222cf61368f1cafdd7b44cdb1a574228cbe403 Pull Request resolved: https://github.com/facebook/react/pull/30375

Lauren Tan committed Jul 18, 2024 at 16:19 UTC eed9ca203c768c3878496a1435ae7c718cf17a92
1 file changed +54 -16
scripts/release/download-experimental-build-ghaction.js
+54 -16
@@ -2,28 +2,66 @@
2
3 'use strict';
4
5 -const {join} = require('path');
6 -const {
7 - addDefaultParamValue,
8 - getPublicPackages,
9 - handleError,
10 -} = require('./utils');
5 +const {join, relative} = require('path');
6 +const {getPublicPackages, handleError} = require('./utils');
7 +const yargs = require('yargs');
8 +const clear = require('clear');
9 +const theme = require('./theme');
10
12 -const downloadBuildArtifacts = require('./shared-commands/download-build-artifacts');
13 -const parseParams = require('./shared-commands/parse-params');
14 -const printSummary = require('./download-experimental-build-commands/print-summary');
11 +const argv = yargs.wrap(yargs.terminalWidth()).options({
12 + releaseChannel: {
13 + alias: 'r',
14 + describe: 'Download the given release channel.',
15 + requiresArg: true,
16 + type: 'string',
17 + choices: ['experimental', 'stable'],
18 + default: 'experimental',
19 + },
20 + commit: {
21 + alias: 'c',
22 + describe: 'Commit hash to download.',
23 + requiresArg: true,
24 + type: 'string',
25 + },
26 + skipTests: {
27 + requiresArg: false,
28 + type: 'boolean',
29 + default: false,
30 + },
31 + allowBrokenCI: {
32 + requiresArg: false,
33 + type: 'boolean',
34 + default: false,
35 + },
36 +}).argv;
37 +
38 +// Inlined from scripts/release/download-experimental-build-commands/print-summary.js
39 +function printSummary(commit) {
40 + const commandPath = relative(
41 + process.env.PWD,
42 + join(__dirname, '../download-experimental-build-ghaction.js')
43 + );
44 +
45 + clear();
46 +
47 + const message = theme`
48 + {caution An experimental build has been downloaded!}
49 +
50 + You can download this build again by running:
51 + {path ${commandPath}} --commit={commit ${commit}}
52 + `;
53 +
54 + console.log(message.replace(/\n +/g, '\n').trim());
55 +}
56
57 const run = async () => {
58 try {
18 - addDefaultParamValue('-r', '--releaseChannel', 'experimental');
19 -
20 - const params = await parseParams();
21 - params.cwd = join(__dirname, '..', '..');
22 - params.packages = await getPublicPackages(true);
59 + argv.cwd = join(__dirname, '..', '..');
60 + argv.packages = await getPublicPackages(true);
61
24 - await downloadBuildArtifacts(params);
62 + console.log(argv);
63
26 - printSummary(params);
64 + printSummary(argv.commit);
65 } catch (error) {
66 handleError(error);
67 }