Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 949
feat: add invoking CLI's scripts for launching Metro in run-ios command#2021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
a0e33d1d8421f9e7f8e491c28857797192e91750c51549486d8f091aa4e0c8143604ae8e5d088cba278d9810c4c3b3a7b95277063732308dFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -13,13 +13,22 @@ import tryRunAdbReverse from './tryRunAdbReverse'; | ||
| import tryLaunchAppOnDevice from './tryLaunchAppOnDevice'; | ||
| import tryInstallAppOnDevice from './tryInstallAppOnDevice'; | ||
| import getAdbPath from './getAdbPath'; | ||
| import {logger, CLIError, link} from '@react-native-community/cli-tools'; | ||
| import { | ||
| logger, | ||
| CLIError, | ||
| link, | ||
| getDefaultUserTerminal, | ||
| isPackagerRunning, | ||
| logAlreadyRunningBundler, | ||
| startServerInNewWindow, | ||
| handlePortUnavailable, | ||
| } from '@react-native-community/cli-tools'; | ||
| import {getAndroidProject} from '../../config/getAndroidProject'; | ||
| import listAndroidDevices from './listAndroidDevices'; | ||
| import tryLaunchEmulator from './tryLaunchEmulator'; | ||
| import chalk from 'chalk'; | ||
| import path from 'path'; | ||
| import {build, runPackager, BuildFlags, options} from '../buildAndroid'; | ||
| import {build, BuildFlags, options} from '../buildAndroid'; | ||
| import {promptForTaskSelection} from './listAndroidTasks'; | ||
| import {getTaskNames} from './getTaskNames'; | ||
| import {checkUsers, promptForUser} from './listAndroidUsers'; | ||
| @@ -28,6 +37,9 @@ export interface Flags extends BuildFlags { | ||
| appId: string; | ||
| appIdSuffix: string; | ||
| mainActivity: string; | ||
| port: number; | ||
| terminal?: string; | ||
| packager?: boolean; | ||
| deviceId?: string; | ||
| listDevices?: boolean; | ||
| binaryPath?: string; | ||
| @@ -42,6 +54,35 @@ export type AndroidProject = NonNullable<Config['project']['android']>; | ||
| async function runAndroid(_argv: Array<string>, config: Config, args: Flags) { | ||
| link.setPlatform('android'); | ||
| let {packager, port} = args; | ||
| const packagerStatus = await isPackagerRunning(port); | ||
| if ( | ||
| typeof packagerStatus === 'object' && | ||
| packagerStatus.status === 'running' | ||
| ) { | ||
| if (packagerStatus.root === config.root) { | ||
| packager = false; | ||
| logAlreadyRunningBundler(port); | ||
| } else { | ||
| const result = await handlePortUnavailable(port, config.root, packager); | ||
| [port, packager] = [result.port, result.packager]; | ||
| } | ||
| } else if (packagerStatus === 'unrecognized') { | ||
| const result = await handlePortUnavailable(port, config.root, packager); | ||
| [port, packager] = [result.port, result.packager]; | ||
| } | ||
| if (packager) { | ||
| await startServerInNewWindow( | ||
| ||
| port, | ||
| config.root, | ||
| config.reactNativePath, | ||
| args.terminal, | ||
| ); | ||
| } | ||
| if (config.reactNativeVersion !== 'unknown') { | ||
| link.setVersion(config.reactNativeVersion); | ||
| } | ||
| @@ -66,7 +107,6 @@ async function runAndroid(_argv: Array<string>, config: Config, args: Flags) { | ||
| const androidProject = getAndroidProject(config); | ||
| await runPackager(args, config); | ||
| return buildAndRun(args, androidProject); | ||
| } | ||
| @@ -269,6 +309,21 @@ export default { | ||
| func: runAndroid, | ||
| options: [ | ||
| ...options, | ||
| { | ||
| name: '--no-packager', | ||
| description: 'Do not launch packager while running the app', | ||
| }, | ||
| { | ||
| name: '--port <number>', | ||
| default: process.env.RCT_METRO_PORT || 8081, | ||
| parse: Number, | ||
| }, | ||
| { | ||
| name: '--terminal <string>', | ||
| description: | ||
| 'Launches the Metro Bundler in a new window using the specified terminal path.', | ||
| default: getDefaultUserTerminal(), | ||
| }, | ||
| { | ||
| name: '--appId <string>', | ||
| description: | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.