amis-rpc-design/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js.map
2023-10-07 19:42:30 +08:00

1 line
16 KiB
Plaintext

{"version":3,"names":["runAndroid","_argv","config","args","link","setPlatform","reactNativeVersion","setVersion","binaryPath","tasks","CLIError","path","isAbsolute","join","root","fs","existsSync","androidProject","getAndroidProject","runPackager","buildAndRun","defaultPort","getAvailableDevicePort","port","adbPath","getAdbPath","devices","adb","getDevices","some","d","includes","toString","process","chdir","sourceDir","cmd","platform","startsWith","selectedTask","interactive","task","promptForTaskSelection","listDevices","deviceId","logger","warn","device","listAndroidDevices","users","checkUsers","length","user","promptForUser","id","connected","runOnSpecificDevice","emulator","info","result","tryLaunchEmulator","readableName","success","chalk","dim","error","runOnAllDevices","buildTask","replace","indexOf","gradleArgs","getTaskNames","appName","mode","variant","push","extraParams","activeArchOnly","architecture","getCPU","build","installAndLaunchOnDevice","selectedDevice","tryRunAdbReverse","tryInstallAppOnDevice","tryLaunchAppOnDevice","packageName","name","description","func","options","default","parse","Number"],"sources":["../../../src/commands/runAndroid/index.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 */\nimport fs from 'fs';\nimport {Config} from '@react-native-community/cli-types';\nimport adb from './adb';\nimport runOnAllDevices from './runOnAllDevices';\nimport tryRunAdbReverse from './tryRunAdbReverse';\nimport tryLaunchAppOnDevice from './tryLaunchAppOnDevice';\nimport tryInstallAppOnDevice from './tryInstallAppOnDevice';\nimport getAdbPath from './getAdbPath';\nimport {logger, CLIError, link} from '@react-native-community/cli-tools';\nimport {getAndroidProject} from '../../config/getAndroidProject';\nimport listAndroidDevices from './listAndroidDevices';\nimport tryLaunchEmulator from './tryLaunchEmulator';\nimport chalk from 'chalk';\nimport path from 'path';\nimport {build, runPackager, BuildFlags, options} from '../buildAndroid';\nimport {promptForTaskSelection} from './listAndroidTasks';\nimport {getTaskNames} from './getTaskNames';\nimport {checkUsers, promptForUser} from './listAndroidUsers';\n\nexport interface Flags extends BuildFlags {\n appId: string;\n appIdSuffix: string;\n mainActivity: string;\n deviceId?: string;\n listDevices?: boolean;\n binaryPath?: string;\n user?: number | string;\n}\n\nexport type AndroidProject = NonNullable<Config['project']['android']>;\n\n/**\n * Starts the app on a connected Android emulator or device.\n */\nasync function runAndroid(_argv: Array<string>, config: Config, args: Flags) {\n link.setPlatform('android');\n\n if (config.reactNativeVersion !== 'unknown') {\n link.setVersion(config.reactNativeVersion);\n }\n\n if (args.binaryPath) {\n if (args.tasks) {\n throw new CLIError(\n 'binary-path and tasks were specified, but they are not compatible. Specify only one',\n );\n }\n\n args.binaryPath = path.isAbsolute(args.binaryPath)\n ? args.binaryPath\n : path.join(config.root, args.binaryPath);\n\n if (args.binaryPath && !fs.existsSync(args.binaryPath)) {\n throw new CLIError(\n 'binary-path was specified, but the file was not found.',\n );\n }\n }\n\n const androidProject = getAndroidProject(config);\n\n await runPackager(args, config);\n return buildAndRun(args, androidProject);\n}\n\nconst defaultPort = 5552;\nasync function getAvailableDevicePort(\n port: number = defaultPort,\n): Promise<number> {\n /**\n * The default value is 5554 for the first virtual device instance running on your machine. A virtual device normally occupies a pair of adjacent ports: a console port and an adb port. The console of the first virtual device running on a particular machine uses console port 5554 and adb port 5555. Subsequent instances use port numbers increasing by two. For example, 5556/5557, 5558/5559, and so on. The range is 5554 to 5682, allowing for 64 concurrent virtual devices.\n */\n const adbPath = getAdbPath();\n const devices = adb.getDevices(adbPath);\n if (port > 5682) {\n throw new CLIError('Failed to launch emulator...');\n }\n if (devices.some((d) => d.includes(port.toString()))) {\n return await getAvailableDevicePort(port + 2);\n }\n return port;\n}\n\n// Builds the app and runs it on a connected emulator / device.\nasync function buildAndRun(args: Flags, androidProject: AndroidProject) {\n process.chdir(androidProject.sourceDir);\n const cmd = process.platform.startsWith('win') ? 'gradlew.bat' : './gradlew';\n\n const adbPath = getAdbPath();\n\n let selectedTask;\n\n if (args.interactive) {\n const task = await promptForTaskSelection(\n 'install',\n androidProject.sourceDir,\n );\n if (task) {\n selectedTask = task;\n }\n }\n\n if (args.listDevices || args.interactive) {\n if (args.deviceId) {\n logger.warn(\n 'Both \"deviceId\" and \"list-devices\" parameters were passed to \"run\" command. We will list available devices and let you choose from one',\n );\n }\n\n const device = await listAndroidDevices();\n if (!device) {\n throw new CLIError(\n `Failed to select device, please try to run app without ${\n args.listDevices ? 'list-devices' : 'interactive'\n } command.`,\n );\n }\n\n if (args.interactive) {\n const users = checkUsers(device.deviceId as string, adbPath);\n if (users && users.length > 1) {\n const user = await promptForUser(users);\n\n if (user) {\n args.user = user.id;\n }\n }\n }\n\n if (device.connected) {\n return runOnSpecificDevice(\n {...args, deviceId: device.deviceId},\n adbPath,\n androidProject,\n selectedTask,\n );\n }\n\n const port = await getAvailableDevicePort();\n const emulator = `emulator-${port}`;\n logger.info('Launching emulator...');\n const result = await tryLaunchEmulator(adbPath, device.readableName, port);\n if (result.success) {\n logger.info('Successfully launched emulator.');\n return runOnSpecificDevice(\n {...args, deviceId: emulator},\n adbPath,\n androidProject,\n selectedTask,\n );\n }\n throw new CLIError(\n `Failed to launch emulator. Reason: ${chalk.dim(result.error || '')}`,\n );\n }\n\n if (args.deviceId) {\n return runOnSpecificDevice(args, adbPath, androidProject, selectedTask);\n } else {\n return runOnAllDevices(args, cmd, adbPath, androidProject);\n }\n}\n\nfunction runOnSpecificDevice(\n args: Flags,\n adbPath: string,\n androidProject: AndroidProject,\n selectedTask?: string,\n) {\n const devices = adb.getDevices(adbPath);\n const {deviceId} = args;\n\n // if coming from run-android command and we have selected task\n // from interactive mode we need to create appropriate build task\n // eg 'installRelease' -> 'assembleRelease'\n const buildTask = selectedTask\n ? [selectedTask.replace('install', 'assemble')]\n : [];\n\n if (devices.length > 0 && deviceId) {\n if (devices.indexOf(deviceId) !== -1) {\n let gradleArgs = getTaskNames(\n androidProject.appName,\n args.mode || args.variant,\n args.tasks ?? buildTask,\n 'install',\n androidProject.sourceDir,\n );\n\n // using '-x lint' in order to ignore linting errors while building the apk\n gradleArgs.push('-x', 'lint');\n if (args.extraParams) {\n gradleArgs.push(...args.extraParams);\n }\n\n if (args.port) {\n gradleArgs.push(`-PreactNativeDevServerPort=${args.port}`);\n }\n\n if (args.activeArchOnly) {\n const architecture = adb.getCPU(adbPath, deviceId);\n\n if (architecture !== null) {\n logger.info(`Detected architecture ${architecture}`);\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(`-PreactNativeDebugArchitectures=${architecture}`);\n gradleArgs.push(`-PreactNativeArchitectures=${architecture}`);\n }\n }\n\n if (!args.binaryPath) {\n build(gradleArgs, androidProject.sourceDir);\n }\n\n installAndLaunchOnDevice(\n args,\n deviceId,\n adbPath,\n androidProject,\n selectedTask,\n );\n } else {\n logger.error(\n `Could not find device with the id: \"${deviceId}\". Please choose one of the following:`,\n ...devices,\n );\n }\n } else {\n logger.error('No Android device or emulator connected.');\n }\n}\n\nfunction installAndLaunchOnDevice(\n args: Flags,\n selectedDevice: string,\n adbPath: string,\n androidProject: AndroidProject,\n selectedTask?: string,\n) {\n tryRunAdbReverse(args.port, selectedDevice);\n\n tryInstallAppOnDevice(\n args,\n adbPath,\n selectedDevice,\n androidProject,\n selectedTask,\n );\n tryLaunchAppOnDevice(\n selectedDevice,\n androidProject.packageName,\n adbPath,\n args,\n );\n}\n\nexport default {\n name: 'run-android',\n description:\n 'builds your app and starts it on a connected Android emulator or device',\n func: runAndroid,\n options: [\n ...options,\n {\n name: '--appId <string>',\n description:\n 'Specify an applicationId to launch after build. If not specified, `package` from AndroidManifest.xml will be used.',\n default: '',\n },\n {\n name: '--appIdSuffix <string>',\n description: 'Specify an applicationIdSuffix to launch after build.',\n default: '',\n },\n {\n name: '--main-activity <string>',\n description: 'Name of the activity to start',\n default: 'MainActivity',\n },\n {\n name: '--deviceId <string>',\n description:\n 'builds your app and starts it on a specific device/simulator with the ' +\n 'given device id (listed by running \"adb devices\" on the command line).',\n },\n {\n name: '--list-devices',\n description:\n 'Lists all available Android devices and simulators and let you choose one to run the app',\n default: false,\n },\n {\n name: '--binary-path <string>',\n description:\n 'Path relative to project root where pre-built .apk binary lives.',\n },\n {\n name: '--user <number>',\n description: 'Id of the User Profile you want to install the app on.',\n parse: Number,\n },\n ],\n};\n\nexport {adb, getAdbPath, listAndroidDevices, tryRunAdbReverse};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;AACA;AACA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;AACA;AACA;AACA;AAA6D;AAxB7D;AACA;AACA;AACA;AACA;AACA;AACA;;AAgCA;AACA;AACA;AACA,eAAeA,UAAU,CAACC,KAAoB,EAAEC,MAAc,EAAEC,IAAW,EAAE;EAC3EC,gBAAI,CAACC,WAAW,CAAC,SAAS,CAAC;EAE3B,IAAIH,MAAM,CAACI,kBAAkB,KAAK,SAAS,EAAE;IAC3CF,gBAAI,CAACG,UAAU,CAACL,MAAM,CAACI,kBAAkB,CAAC;EAC5C;EAEA,IAAIH,IAAI,CAACK,UAAU,EAAE;IACnB,IAAIL,IAAI,CAACM,KAAK,EAAE;MACd,MAAM,KAAIC,oBAAQ,EAChB,qFAAqF,CACtF;IACH;IAEAP,IAAI,CAACK,UAAU,GAAGG,eAAI,CAACC,UAAU,CAACT,IAAI,CAACK,UAAU,CAAC,GAC9CL,IAAI,CAACK,UAAU,GACfG,eAAI,CAACE,IAAI,CAACX,MAAM,CAACY,IAAI,EAAEX,IAAI,CAACK,UAAU,CAAC;IAE3C,IAAIL,IAAI,CAACK,UAAU,IAAI,CAACO,aAAE,CAACC,UAAU,CAACb,I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