amis-rpc-design/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js.map

1 line
8.5 KiB
Plaintext
Raw Normal View History

2023-10-07 19:42:30 +08:00
{"version":3,"names":["runOnAllDevices","args","cmd","adbPath","androidProject","devices","adb","getDevices","length","logger","info","result","tryLaunchEmulator","success","error","chalk","dim","warn","variant","binaryPath","gradleArgs","getTaskNames","appName","mode","tasks","sourceDir","extraParams","push","port","activeArchOnly","architectures","map","device","getCPU","filter","arch","index","array","indexOf","join","debug","execa","stdio","cwd","printRunDoctorTip","createInstallError","undefined","forEach","tryRunAdbReverse","tryInstallAppOnDevice","tryLaunchAppOnDevice","packageName","stderr","toString","message","log","includes","bold","CLIError"],"sources":["../../../src/commands/runAndroid/runOnAllDevices.ts"],"sourcesContent":["/**\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport chalk from 'chalk';\nimport execa from 'execa';\nimport {Config} from '@react-native-community/cli-types';\nimport {\n logger,\n CLIError,\n printRunDoctorTip,\n} from '@react-native-community/cli-tools';\nimport adb from './adb';\nimport tryRunAdbReverse from './tryRunAdbReverse';\nimport tryLaunchAppOnDevice from './tryLaunchAppOnDevice';\nimport tryLaunchEmulator from './tryLaunchEmulator';\nimport tryInstallAppOnDevice from './tryInstallAppOnDevice';\nimport {getTaskNames} from './getTaskNames';\nimport type {Flags} from '.';\n\ntype AndroidProject = NonNullable<Config['project']['android']>;\n\nasync function runOnAllDevices(\n args: Flags,\n cmd: string,\n adbPath: string,\n androidProject: AndroidProject,\n) {\n let devices = adb.getDevices(adbPath);\n if (devices.length === 0) {\n logger.info('Launching emulator...');\n const result = await tryLaunchEmulator(adbPath);\n if (result.success) {\n logger.info('Successfully launched emulator.');\n devices = adb.getDevices(adbPath);\n } else {\n logger.error(\n `Failed to launch emulator. Reason: ${chalk.dim(result.error || '')}.`,\n );\n logger.warn(\n 'Please launch an emulator manually or connect a device. Otherwise app may fail to launch.',\n );\n }\n }\n if (args.variant) {\n logger.warn(\n '\"variant\" flag is deprecated and will be removed in future release. Please switch to \"mode\" flag.',\n );\n }\n\n try {\n if (!args.binaryPath) {\n let gradleArgs = getTaskNames(\n androidProject.appName,\n args.mode || args.variant,\n args.tasks,\n 'install',\n androidProject.sourceDir,\n );\n\n if (args.extraParams) {\n gradleArgs.push(...args.extraParams);\n }\n\n if (args.port != null) {\n gradleArgs.push('-PreactNativeDevServerPort=' + args.port);\n }\n\n if (args.activeArchOnly) {\n const architectures = devices\n .map((device) => {\n return adb.getCPU(adbPath, device);\n })\n .filter(\n (arch, index, array) =>\n arch != null && array.indexOf(arch) === index,\n );\n\n if (architectures.length > 0) {\n logger.info(`Detected architectures ${architectures.join(', ')}`);\n // `reactNativeDebugArchitectures` was renamed to `reactNativeArchitectures` in 0.68.\n // Can be removed when 0.67 no longer needs to be supported.\n gradleArgs.push(\n '-PreactNativeDebugArchitectures=' + architectures.join(','),\n );\n gradleArgs.push(\n '-PreactNativeArchitectures=' + architectures.join(','),\n );\n }\n }\n\n logger.info('Installing the app...');\n logger.debug(\n `Running command \"cd android && ${cmd} ${gradleArgs.join(' ')}\"`,\n );\n\n await execa(cmd, gradleArgs, {\n stdio: ['inherit', 'inherit', 'pipe'],\n cwd: androidProject.sourceDir,\n });\n }\n } catch (error) {\n printRunDoctorTip();\n throw createInstallError(error as any);\n }\n\