Skip to content

Commit b52fc00

Browse files
authored
feat: respect required/optional option values (#1328)
* validate options * Update index.ts
1 parent c5ca3b6 commit b52fc00

File tree

9 files changed

+51
-95
lines changed

9 files changed

+51
-95
lines changed

packages/cli-hermes/src/profileHermes/index.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type Options = {
77
raw?: boolean;
88
sourcemapPath?: string;
99
generateSourcemap?: boolean;
10-
port?: string;
10+
port: string;
1111
};
1212

1313
async function profileHermes(
@@ -43,7 +43,7 @@ export default {
4343
func: profileHermes,
4444
options: [
4545
{
46-
name: '--filename [string]',
46+
name: '--filename <string>',
4747
description:
4848
'File name of the profile to be downloaded, eg. sampling-profiler-trace8593107139682635366.cpuprofile',
4949
},
@@ -53,7 +53,7 @@ export default {
5353
'Pulls the original Hermes tracing profile without any transformation',
5454
},
5555
{
56-
name: '--sourcemap-path [string]',
56+
name: '--sourcemap-path <string>',
5757
description:
5858
'The local path to your source map file, eg. /tmp/sourcemap.json',
5959
},
@@ -62,9 +62,8 @@ export default {
6262
description: 'Generates the JS bundle and source map',
6363
},
6464
{
65-
name: '--port [number]',
66-
default: process.env.RCT_METRO_PORT || 8081,
67-
parse: (val: number) => String(val),
65+
name: '--port <number>',
66+
default: `${process.env.RCT_METRO_PORT || 8081}`,
6867
},
6968
],
7069
examples: [

packages/cli/src/commands/bundle/bundleCommandLineArgs.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ export default [
3535
'Path to the root JS file, either absolute or relative to JS root',
3636
},
3737
{
38-
name: '--platform [string]',
38+
name: '--platform <string>',
3939
description: 'Either "ios" or "android"',
4040
default: 'ios',
4141
},
4242
{
43-
name: '--transformer [string]',
43+
name: '--transformer <string>',
4444
description: 'Specify a custom transformer to be used',
4545
},
4646
{
@@ -63,26 +63,26 @@ export default [
6363
'File name where to store the resulting bundle, ex. /tmp/groups.bundle',
6464
},
6565
{
66-
name: '--bundle-encoding [string]',
66+
name: '--bundle-encoding <string>',
6767
description:
6868
'Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer).',
6969
default: 'utf8',
7070
},
7171
{
72-
name: '--max-workers [number]',
72+
name: '--max-workers <number>',
7373
description:
7474
'Specifies the maximum number of workers the worker-pool ' +
7575
'will spawn for transforming files. This defaults to the number of the ' +
7676
'cores available on your machine.',
7777
parse: (workers: string) => Number(workers),
7878
},
7979
{
80-
name: '--sourcemap-output [string]',
80+
name: '--sourcemap-output <string>',
8181
description:
8282
'File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map',
8383
},
8484
{
85-
name: '--sourcemap-sources-root [string]',
85+
name: '--sourcemap-sources-root <string>',
8686
description:
8787
"Path to make sourcemap's sources entries relative to, ex. /root/dir",
8888
},
@@ -92,12 +92,12 @@ export default [
9292
default: false,
9393
},
9494
{
95-
name: '--assets-dest [string]',
95+
name: '--assets-dest <string>',
9696
description:
9797
'Directory name where to store assets referenced in the bundle',
9898
},
9999
{
100-
name: '--unstable-transform-profile [string]',
100+
name: '--unstable-transform-profile <string>',
101101
description:
102102
'Experimental, transform JS for a specific JS engine. Currently supported: hermes, hermes-canary, default',
103103
},
@@ -113,7 +113,7 @@ export default [
113113
default: false,
114114
},
115115
{
116-
name: '--config [string]',
116+
name: '--config <string>',
117117
description: 'Path to the CLI configuration file',
118118
parse: (val: string) => path.resolve(val),
119119
},

packages/cli/src/commands/init/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ export default {
88
'Initialize a new React Native project named <projectName> in a directory of the same name.',
99
options: [
1010
{
11-
name: '--version [string]',
11+
name: '--version <string>',
1212
description: 'Shortcut for `--template react-native@version`',
1313
},
1414
{
15-
name: '--template [string]',
15+
name: '--template <string>',
1616
description:
1717
'Uses a custom template. Valid arguments are the ones supported by `yarn add [package]` or `npm install [package]`, if you are using `--npm` option',
1818
},
@@ -21,11 +21,11 @@ export default {
2121
description: 'Forces using npm for initialization',
2222
},
2323
{
24-
name: '--directory [string]',
24+
name: '--directory <string>',
2525
description: 'Uses a custom directory instead of `<projectName>`.',
2626
},
2727
{
28-
name: '--title [string]',
28+
name: '--title <string>',
2929
description: 'Uses a custom app title name for application',
3030
},
3131
{

packages/cli/src/commands/link/link.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ export default {
9898
parse: (val: string) => val.toLowerCase().split(','),
9999
},
100100
{
101-
name: '--all [boolean]',
101+
name: '--all',
102102
description: 'Link all native modules and assets',
103-
parse: (val: string) => val.toLowerCase().split(','),
104103
},
105104
],
106105
};

packages/cli/src/commands/start/start.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,55 +15,55 @@ export default {
1515
description: 'starts the webserver',
1616
options: [
1717
{
18-
name: '--port [number]',
19-
parse: (val: string) => Number(val),
18+
name: '--port <number>',
19+
parse: Number,
2020
},
2121
{
22-
name: '--host [string]',
22+
name: '--host <string>',
2323
default: '',
2424
},
2525
{
26-
name: '--projectRoot [path]',
26+
name: '--projectRoot <path>',
2727
description: 'Path to a custom project root',
2828
parse: (val: string) => path.resolve(val),
2929
},
3030
{
31-
name: '--watchFolders [list]',
31+
name: '--watchFolders <list>',
3232
description:
3333
'Specify any additional folders to be added to the watch list',
3434
parse: (val: string) =>
3535
val.split(',').map<string>((folder: string) => path.resolve(folder)),
3636
},
3737
{
38-
name: '--assetPlugins [list]',
38+
name: '--assetPlugins <list>',
3939
description:
4040
'Specify any additional asset plugins to be used by the packager by full filepath',
4141
parse: (val: string) => val.split(','),
4242
},
4343
{
44-
name: '--sourceExts [list]',
44+
name: '--sourceExts <list>',
4545
description:
4646
'Specify any additional source extensions to be used by the packager',
4747
parse: (val: string) => val.split(','),
4848
},
4949
{
50-
name: '--max-workers [number]',
50+
name: '--max-workers <number>',
5151
description:
5252
'Specifies the maximum number of workers the worker-pool ' +
5353
'will spawn for transforming files. This defaults to the number of the ' +
5454
'cores available on your machine.',
5555
parse: (workers: string) => Number(workers),
5656
},
5757
{
58-
name: '--transformer [string]',
58+
name: '--transformer <string>',
5959
description: 'Specify a custom transformer to be used',
6060
},
6161
{
6262
name: '--reset-cache, --resetCache',
6363
description: 'Removes cached files',
6464
},
6565
{
66-
name: '--custom-log-reporter-path, --customLogReporterPath [string]',
66+
name: '--custom-log-reporter-path, --customLogReporterPath <string>',
6767
description:
6868
'Path to a JavaScript file that exports a log reporter as a replacement for TerminalReporter',
6969
},
@@ -76,15 +76,15 @@ export default {
7676
description: 'Enables https connections to the server',
7777
},
7878
{
79-
name: '--key [path]',
79+
name: '--key <path>',
8080
description: 'Path to custom SSL key',
8181
},
8282
{
83-
name: '--cert [path]',
83+
name: '--cert <path>',
8484
description: 'Path to custom SSL cert',
8585
},
8686
{
87-
name: '--config [string]',
87+
name: '--config <string>',
8888
description: 'Path to the CLI configuration file',
8989
parse: (val: string) => path.resolve(val),
9090
},

packages/cli/src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {logger, CLIError} from '@react-native-community/cli-tools';
99

1010
import {detachedCommands, projectCommands} from './commands';
1111
import init from './commands/init/initCompat';
12-
import assertRequiredOptions from './tools/assertRequiredOptions';
1312
import loadConfig from './tools/config';
1413

1514
const pkgJson = require('../package.json');
@@ -130,7 +129,6 @@ function attachCommand<IsDetached extends boolean>(
130129
command: Command<IsDetached>,
131130
...rest: IsDetached extends false ? [Config] : []
132131
): void {
133-
const options = command.options || [];
134132
const cmd = commander
135133
.command(command.name)
136134
.action(async function handleAction(
@@ -141,7 +139,6 @@ function attachCommand<IsDetached extends boolean>(
141139
const argv = Array.from(args).slice(0, -1);
142140

143141
try {
144-
assertRequiredOptions(options, passedOptions);
145142
if (isDetachedCommand(command)) {
146143
await command.func(argv, passedOptions);
147144
} else {

packages/cli/src/tools/assertRequiredOptions.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

packages/platform-android/src/commands/runAndroid/index.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,39 +318,39 @@ export default {
318318
func: runAndroid,
319319
options: [
320320
{
321-
name: '--root [string]',
321+
name: '--root <string>',
322322
description:
323323
'[DEPRECATED - root is discovered automatically] Override the root directory for the android build (which contains the android directory)',
324324
default: '',
325325
},
326326
{
327-
name: '--variant [string]',
327+
name: '--variant <string>',
328328
description: "Specify your app's build variant",
329329
default: 'debug',
330330
},
331331
{
332-
name: '--appFolder [string]',
332+
name: '--appFolder <string>',
333333
description:
334334
'[DEPRECATED – use "project.android.appName" in react-native.config.js] Specify a different application folder name for the android source. If not, we assume is "app"',
335335
},
336336
{
337-
name: '--appId [string]',
337+
name: '--appId <string>',
338338
description:
339339
'Specify an applicationId to launch after build. If not specified, `package` from AndroidManifest.xml will be used.',
340340
default: '',
341341
},
342342
{
343-
name: '--appIdSuffix [string]',
343+
name: '--appIdSuffix <string>',
344344
description: 'Specify an applicationIdSuffix to launch after build.',
345345
default: '',
346346
},
347347
{
348-
name: '--main-activity [string]',
348+
name: '--main-activity <string>',
349349
description: 'Name of the activity to start',
350350
default: 'MainActivity',
351351
},
352352
{
353-
name: '--deviceId [string]',
353+
name: '--deviceId <string>',
354354
description:
355355
'builds your app and starts it on a specific device/simulator with the ' +
356356
'given device id (listed by running "adb devices" on the command line).',
@@ -360,26 +360,25 @@ export default {
360360
description: 'Do not launch packager while building',
361361
},
362362
{
363-
name: '--port [number]',
363+
name: '--port <number>',
364364
default: process.env.RCT_METRO_PORT || 8081,
365-
parse: (val: string) => Number(val),
365+
parse: Number,
366366
},
367367
{
368-
name: '--terminal [string]',
368+
name: '--terminal <string>',
369369
description:
370370
'Launches the Metro Bundler in a new window using the specified terminal path.',
371371
default: getDefaultUserTerminal(),
372372
},
373373
{
374-
name: '--tasks [list]',
374+
name: '--tasks <list>',
375375
description: 'Run custom Gradle tasks. By default it\'s "installDebug"',
376376
parse: (val: string) => val.split(','),
377377
},
378378
{
379379
name: '--no-jetifier',
380380
description:
381381
'Do not run "jetifier" – the AndroidX transition tool. By default it runs before Gradle to ease working with libraries that don\'t support AndroidX yet. See more at: https://www.npmjs.com/package/jetifier.',
382-
default: false,
383382
},
384383
],
385384
};

0 commit comments

Comments
 (0)