diff --git a/packages/cli-hermes/src/profileHermes/index.ts b/packages/cli-hermes/src/profileHermes/index.ts index 6ab7da33b..9fa7727f7 100644 --- a/packages/cli-hermes/src/profileHermes/index.ts +++ b/packages/cli-hermes/src/profileHermes/index.ts @@ -7,7 +7,7 @@ type Options = { raw?: boolean; sourcemapPath?: string; generateSourcemap?: boolean; - port?: string; + port: string; }; async function profileHermes( @@ -43,7 +43,7 @@ export default { func: profileHermes, options: [ { - name: '--filename [string]', + name: '--filename ', description: 'File name of the profile to be downloaded, eg. sampling-profiler-trace8593107139682635366.cpuprofile', }, @@ -53,7 +53,7 @@ export default { 'Pulls the original Hermes tracing profile without any transformation', }, { - name: '--sourcemap-path [string]', + name: '--sourcemap-path ', description: 'The local path to your source map file, eg. /tmp/sourcemap.json', }, @@ -62,9 +62,8 @@ export default { description: 'Generates the JS bundle and source map', }, { - name: '--port [number]', - default: process.env.RCT_METRO_PORT || 8081, - parse: (val: number) => String(val), + name: '--port ', + default: `${process.env.RCT_METRO_PORT || 8081}`, }, ], examples: [ diff --git a/packages/cli/src/commands/bundle/bundleCommandLineArgs.ts b/packages/cli/src/commands/bundle/bundleCommandLineArgs.ts index 51fc1ee7d..b559d098c 100644 --- a/packages/cli/src/commands/bundle/bundleCommandLineArgs.ts +++ b/packages/cli/src/commands/bundle/bundleCommandLineArgs.ts @@ -35,12 +35,12 @@ export default [ 'Path to the root JS file, either absolute or relative to JS root', }, { - name: '--platform [string]', + name: '--platform ', description: 'Either "ios" or "android"', default: 'ios', }, { - name: '--transformer [string]', + name: '--transformer ', description: 'Specify a custom transformer to be used', }, { @@ -63,13 +63,13 @@ export default [ 'File name where to store the resulting bundle, ex. /tmp/groups.bundle', }, { - name: '--bundle-encoding [string]', + name: '--bundle-encoding ', description: 'Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer).', default: 'utf8', }, { - name: '--max-workers [number]', + name: '--max-workers ', description: 'Specifies the maximum number of workers the worker-pool ' + 'will spawn for transforming files. This defaults to the number of the ' + @@ -77,12 +77,12 @@ export default [ parse: (workers: string) => Number(workers), }, { - name: '--sourcemap-output [string]', + name: '--sourcemap-output ', description: 'File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map', }, { - name: '--sourcemap-sources-root [string]', + name: '--sourcemap-sources-root ', description: "Path to make sourcemap's sources entries relative to, ex. /root/dir", }, @@ -92,12 +92,12 @@ export default [ default: false, }, { - name: '--assets-dest [string]', + name: '--assets-dest ', description: 'Directory name where to store assets referenced in the bundle', }, { - name: '--unstable-transform-profile [string]', + name: '--unstable-transform-profile ', description: 'Experimental, transform JS for a specific JS engine. Currently supported: hermes, hermes-canary, default', }, @@ -113,7 +113,7 @@ export default [ default: false, }, { - name: '--config [string]', + name: '--config ', description: 'Path to the CLI configuration file', parse: (val: string) => path.resolve(val), }, diff --git a/packages/cli/src/commands/init/index.ts b/packages/cli/src/commands/init/index.ts index b3d254b5f..e5c766748 100644 --- a/packages/cli/src/commands/init/index.ts +++ b/packages/cli/src/commands/init/index.ts @@ -8,11 +8,11 @@ export default { 'Initialize a new React Native project named in a directory of the same name.', options: [ { - name: '--version [string]', + name: '--version ', description: 'Shortcut for `--template react-native@version`', }, { - name: '--template [string]', + name: '--template ', description: 'Uses a custom template. Valid arguments are the ones supported by `yarn add [package]` or `npm install [package]`, if you are using `--npm` option', }, @@ -21,11 +21,11 @@ export default { description: 'Forces using npm for initialization', }, { - name: '--directory [string]', + name: '--directory ', description: 'Uses a custom directory instead of ``.', }, { - name: '--title [string]', + name: '--title ', description: 'Uses a custom app title name for application', }, { diff --git a/packages/cli/src/commands/link/link.ts b/packages/cli/src/commands/link/link.ts index 7cd384549..e9d43be74 100644 --- a/packages/cli/src/commands/link/link.ts +++ b/packages/cli/src/commands/link/link.ts @@ -98,9 +98,8 @@ export default { parse: (val: string) => val.toLowerCase().split(','), }, { - name: '--all [boolean]', + name: '--all', description: 'Link all native modules and assets', - parse: (val: string) => val.toLowerCase().split(','), }, ], }; diff --git a/packages/cli/src/commands/start/start.ts b/packages/cli/src/commands/start/start.ts index e30bc44fa..4a266ced1 100644 --- a/packages/cli/src/commands/start/start.ts +++ b/packages/cli/src/commands/start/start.ts @@ -15,39 +15,39 @@ export default { description: 'starts the webserver', options: [ { - name: '--port [number]', - parse: (val: string) => Number(val), + name: '--port ', + parse: Number, }, { - name: '--host [string]', + name: '--host ', default: '', }, { - name: '--projectRoot [path]', + name: '--projectRoot ', description: 'Path to a custom project root', parse: (val: string) => path.resolve(val), }, { - name: '--watchFolders [list]', + name: '--watchFolders ', description: 'Specify any additional folders to be added to the watch list', parse: (val: string) => val.split(',').map((folder: string) => path.resolve(folder)), }, { - name: '--assetPlugins [list]', + name: '--assetPlugins ', description: 'Specify any additional asset plugins to be used by the packager by full filepath', parse: (val: string) => val.split(','), }, { - name: '--sourceExts [list]', + name: '--sourceExts ', description: 'Specify any additional source extensions to be used by the packager', parse: (val: string) => val.split(','), }, { - name: '--max-workers [number]', + name: '--max-workers ', description: 'Specifies the maximum number of workers the worker-pool ' + 'will spawn for transforming files. This defaults to the number of the ' + @@ -55,7 +55,7 @@ export default { parse: (workers: string) => Number(workers), }, { - name: '--transformer [string]', + name: '--transformer ', description: 'Specify a custom transformer to be used', }, { @@ -63,7 +63,7 @@ export default { description: 'Removes cached files', }, { - name: '--custom-log-reporter-path, --customLogReporterPath [string]', + name: '--custom-log-reporter-path, --customLogReporterPath ', description: 'Path to a JavaScript file that exports a log reporter as a replacement for TerminalReporter', }, @@ -76,15 +76,15 @@ export default { description: 'Enables https connections to the server', }, { - name: '--key [path]', + name: '--key ', description: 'Path to custom SSL key', }, { - name: '--cert [path]', + name: '--cert ', description: 'Path to custom SSL cert', }, { - name: '--config [string]', + name: '--config ', description: 'Path to the CLI configuration file', parse: (val: string) => path.resolve(val), }, diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 127d51ac4..18039759c 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -9,7 +9,6 @@ import {logger, CLIError} from '@react-native-community/cli-tools'; import {detachedCommands, projectCommands} from './commands'; import init from './commands/init/initCompat'; -import assertRequiredOptions from './tools/assertRequiredOptions'; import loadConfig from './tools/config'; const pkgJson = require('../package.json'); @@ -130,7 +129,6 @@ function attachCommand( command: Command, ...rest: IsDetached extends false ? [Config] : [] ): void { - const options = command.options || []; const cmd = commander .command(command.name) .action(async function handleAction( @@ -141,7 +139,6 @@ function attachCommand( const argv = Array.from(args).slice(0, -1); try { - assertRequiredOptions(options, passedOptions); if (isDetachedCommand(command)) { await command.func(argv, passedOptions); } else { diff --git a/packages/cli/src/tools/assertRequiredOptions.ts b/packages/cli/src/tools/assertRequiredOptions.ts deleted file mode 100644 index 909851a0d..000000000 --- a/packages/cli/src/tools/assertRequiredOptions.ts +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - */ -import {Option} from 'commander'; -import {camelCase} from 'lodash'; -import {CommandOption} from '@react-native-community/cli-types'; - -type PassedOptions = { - [key: string]: unknown; -}; - -// Commander.js has a 2 years old open issue to support <...> syntax -// for options. Until that gets merged, we run the checks manually -// https://github.com/tj/commander.js/issues/230 -export default function assertRequiredOptions( - options: CommandOption[], - passedOptions: PassedOptions, -) { - options.forEach((opt) => { - const option = new Option(opt.name); - - if (!option.required) { - return; - } - - const name = camelCase(option.long); - - if (!passedOptions[name]) { - // Provide commander.js like error message - throw new Error(`Option "${option.long}" is missing`); - } - }); -} diff --git a/packages/platform-android/src/commands/runAndroid/index.ts b/packages/platform-android/src/commands/runAndroid/index.ts index aba543a02..29f351d77 100644 --- a/packages/platform-android/src/commands/runAndroid/index.ts +++ b/packages/platform-android/src/commands/runAndroid/index.ts @@ -318,39 +318,39 @@ export default { func: runAndroid, options: [ { - name: '--root [string]', + name: '--root ', description: '[DEPRECATED - root is discovered automatically] Override the root directory for the android build (which contains the android directory)', default: '', }, { - name: '--variant [string]', + name: '--variant ', description: "Specify your app's build variant", default: 'debug', }, { - name: '--appFolder [string]', + name: '--appFolder ', description: '[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"', }, { - name: '--appId [string]', + name: '--appId ', description: 'Specify an applicationId to launch after build. If not specified, `package` from AndroidManifest.xml will be used.', default: '', }, { - name: '--appIdSuffix [string]', + name: '--appIdSuffix ', description: 'Specify an applicationIdSuffix to launch after build.', default: '', }, { - name: '--main-activity [string]', + name: '--main-activity ', description: 'Name of the activity to start', default: 'MainActivity', }, { - name: '--deviceId [string]', + name: '--deviceId ', description: 'builds your app and starts it on a specific device/simulator with the ' + 'given device id (listed by running "adb devices" on the command line).', @@ -360,18 +360,18 @@ export default { description: 'Do not launch packager while building', }, { - name: '--port [number]', + name: '--port ', default: process.env.RCT_METRO_PORT || 8081, - parse: (val: string) => Number(val), + parse: Number, }, { - name: '--terminal [string]', + name: '--terminal ', description: 'Launches the Metro Bundler in a new window using the specified terminal path.', default: getDefaultUserTerminal(), }, { - name: '--tasks [list]', + name: '--tasks ', description: 'Run custom Gradle tasks. By default it\'s "installDebug"', parse: (val: string) => val.split(','), }, @@ -379,7 +379,6 @@ export default { name: '--no-jetifier', description: '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.', - default: false, }, ], }; diff --git a/packages/platform-ios/src/commands/runIOS/index.ts b/packages/platform-ios/src/commands/runIOS/index.ts index 45d1c23ad..e966619aa 100644 --- a/packages/platform-ios/src/commands/runIOS/index.ts +++ b/packages/platform-ios/src/commands/runIOS/index.ts @@ -557,23 +557,23 @@ export default { ], options: [ { - name: '--simulator [string]', + name: '--simulator ', description: 'Explicitly set simulator to use. Optionally include iOS version between ' + 'parenthesis at the end to match an exact version: "iPhone 6 (10.0)"', default: 'iPhone 12', }, { - name: '--configuration [string]', + name: '--configuration ', description: 'Explicitly set the scheme configuration to use', default: 'Debug', }, { - name: '--scheme [string]', + name: '--scheme ', description: 'Explicitly set Xcode scheme to use', }, { - name: '--project-path [string]', + name: '--project-path ', description: 'Path relative to project root where the Xcode project ' + '(.xcodeproj) lives.', @@ -585,7 +585,7 @@ export default { 'Explicitly set device to use by name. The value is not required if you have a single device connected.', }, { - name: '--udid [string]', + name: '--udid ', description: 'Explicitly set device to use by udid', }, { @@ -597,12 +597,12 @@ export default { description: 'Do not use xcpretty even if installed', }, { - name: '--port [number]', + name: '--port ', default: process.env.RCT_METRO_PORT || 8081, - parse: (val: string) => Number(val), + parse: Number, }, { - name: '--terminal [string]', + name: '--terminal ', description: 'Launches the Metro Bundler in a new window using the specified terminal path.', default: getDefaultUserTerminal,