{"version":3,"names":["buildIOS","_","ctx","args","project","ios","CLIError","xcodeProject","sourceDir","process","chdir","configuration","logger","warn","mode","projectInfo","getProjectInfo","checkIfConfigurationExists","inferredSchemeName","path","basename","name","extname","scheme","interactive","selection","selectFromInteractiveMode","modifiedArgs","getConfigurationScheme","info","isWorkspace","chalk","bold","extendedArgs","packager","device","udid","simulator","buildProject","undefined","fallbackSimulators","selectedSimulator","getDestinationSimulator","error","devices","listIOSDevices","find","d","printFoundDevices","physicalDevices","filter","type","matchingDevice","deviceName","firstIOSDevice","deviceByName","formattedDeviceName","String","version","map","join","iosBuildOptions","description","default","env","RCT_METRO_PORT","parse","Number","getDefaultUserTerminal","val","split","func","examples","desc","cmd","options"],"sources":["../../../src/commands/buildIOS/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 */\n\nimport path from 'path';\nimport chalk from 'chalk';\nimport {Config} from '@react-native-community/cli-types';\nimport {\n logger,\n CLIError,\n getDefaultUserTerminal,\n} from '@react-native-community/cli-tools';\nimport {Device} from '../../types';\nimport {BuildFlags, buildProject} from './buildProject';\nimport {getDestinationSimulator} from '../../tools/getDestinationSimulator';\nimport {selectFromInteractiveMode} from '../../tools/selectFromInteractiveMode';\nimport {getProjectInfo} from '../../tools/getProjectInfo';\nimport {checkIfConfigurationExists} from '../../tools/checkIfConfigurationExists';\nimport {getConfigurationScheme} from '../../tools/getConfigurationScheme';\nimport listIOSDevices from '../../tools/listIOSDevices';\n\nexport interface FlagsT extends BuildFlags {\n configuration?: string;\n simulator?: string;\n device?: string | true;\n udid?: string;\n scheme?: string;\n}\n\nasync function buildIOS(_: Array, ctx: Config, args: FlagsT) {\n if (!ctx.project.ios) {\n throw new CLIError(\n 'iOS project folder not found. Are you sure this is a React Native project?',\n );\n }\n\n const {xcodeProject, sourceDir} = ctx.project.ios;\n\n if (!xcodeProject) {\n throw new CLIError(\n `Could not find Xcode project files in \"${sourceDir}\" folder`,\n );\n }\n\n process.chdir(sourceDir);\n\n if (args.configuration) {\n logger.warn('--configuration has been deprecated. Use --mode instead.');\n logger.warn(\n 'Parameters were automatically reassigned to --mode on this run.',\n );\n args.mode = args.configuration;\n }\n\n const projectInfo = getProjectInfo();\n\n if (args.mode) {\n checkIfConfigurationExists(projectInfo, args.mode);\n }\n\n const inferredSchemeName = path.basename(\n xcodeProject.name,\n path.extname(xcodeProject.name),\n );\n\n let scheme = args.scheme || inferredSchemeName;\n let mode = args.mode;\n\n if (args.interactive) {\n const selection = await selectFromInteractiveMode({scheme, mode});\n\n if (selection.scheme) {\n scheme = selection.scheme;\n }\n\n if (selection.mode) {\n mode = selection.mode;\n }\n }\n\n const modifiedArgs = {...args, scheme, mode};\n\n args.mode = getConfigurationScheme(\n {scheme: args.scheme, mode: args.mode},\n sourceDir,\n );\n\n logger.info(\n `Found Xcode ${\n xcodeProject.isWorkspace ? 'workspace' : 'project'\n } \"${chalk.bold(xcodeProject.name)}\"`,\n );\n\n const extendedArgs = {\n ...modifiedArgs,\n packager: false,\n };\n\n // // No need to load all available devices\n if (!args.device && !args.udid) {\n if (!args.simulator) {\n return buildProject(xcodeProject, undefined, scheme, extendedArgs);\n }\n\n /**\n * If provided simulator does not exist, try simulators in following order\n * - iPhone 14\n * - iPhone 13\n * - iPhone 12\n * - iPhone 11\n */\n const fallbackSimulators = [\n 'iPhone 14',\n 'iPhone 13',\n 'iPhone 12',\n 'iPhone 11',\n ];\n\n const selectedSimulator = getDestinationSimulator(args, fallbackSimulators);\n\n return buildProject(\n xcodeProject,\n selectedSimulator.udid,\n scheme,\n extendedArgs,\n );\n }\n\n if (args.device && args.udid) {\n return logger.error(\n 'The `device` and `udid` options are mutually exclusive.',\n );\n }\n\n const devices = await listIOSDevices();\n\n if (args.udid) {\n const device = devices.find((d) => d.udid === args.udid);\n if (!device) {\n return logger.error(\n `Could not find a device with udid: \"${chalk.bold(\n args.udid,\n )}\". ${printFoundDevices(devices)}`,\n );\n }\n\n return buildProject(xcodeProject, device.udid, scheme, extendedArgs);\n } else {\n const physicalDevices = devices.filter((d) => d.type !== 'simulator');\n const device = matchingDevice(physicalDevices, args.device);\n if (device) {\n return buildProject(xcodeProject, device.udid, scheme, extendedArgs);\n }\n }\n}\n\nfunction matchingDevice(\n devices: Array,\n deviceName: string | true | undefined,\n) {\n if (deviceName === true) {\n const firstIOSDevice = devices.find((d) => d.type === 'device')!;\n if (firstIOSDevice) {\n logger.info(\n `Using first available device named \"${chalk.bold(\n firstIOSDevice.name,\n )}\" due to lack of name supplied.`,\n );\n return firstIOSDevice;\n } else {\n logger.error('No iOS devices connected.');\n return undefined;\n }\n }\n const deviceByName = devices.find(\n (device) =>\n device.name === deviceName || formattedDeviceName(device) === deviceName,\n );\n if (!deviceByName) {\n logger.error(\n `Could not find a device named: \"${chalk.bold(\n String(deviceName),\n )}\". ${printFoundDevices(devices)}`,\n );\n }\n return deviceByName;\n}\n\nfunction formattedDeviceName(simulator: Device) {\n return simulator.version\n ? `${simulator.name} (${simulator.version})`\n : simulator.name;\n}\n\nfunction printFoundDevices(devices: Array) {\n return [\n 'Available devices:',\n ...devices.map((device) => ` - ${device.name} (${device.udid})`),\n ].join('\\n');\n}\n\nexport const iosBuildOptions = [\n {\n name: '--simulator ',\n description:\n 'Explicitly set simulator to use. Optionally include iOS version between ' +\n 'parenthesis at the end to match an exact version: \"iPhone 6 (10.0)\"',\n },\n {\n name: '--mode ',\n description:\n 'Explicitly set the scheme configuration to use. This option is case sensitive.',\n },\n {\n name: '--configuration ',\n description: '[Deprecated] Explicitly set the scheme configuration to use',\n },\n {\n name: '--scheme ',\n description: 'Explicitly set Xcode scheme to use',\n },\n {\n name: '--device [string]',\n description:\n 'Explicitly set device to use by name. The value is not required if you have a single device connected.',\n },\n {\n name: '--destination ',\n description: 'Explicitly extend distination e.g. \"arch=x86_64\"',\n },\n {\n name: '--udid ',\n description: 'Explicitly set device to use by udid',\n },\n {\n name: '--verbose',\n description: 'Do not use xcbeautify or xcpretty even if installed',\n },\n {\n name: '--port ',\n default: process.env.RCT_METRO_PORT || 8081,\n parse: Number,\n },\n {\n name: '--terminal ',\n description:\n 'Launches the Metro Bundler in a new window using the specified terminal path.',\n default: getDefaultUserTerminal(),\n },\n {\n name: '--xcconfig [string]',\n description: 'Explicitly set xcconfig to use',\n },\n {\n name: '--buildFolder ',\n description:\n 'Location for iOS build artifacts. Corresponds to Xcode\\'s \"-derivedDataPath\".',\n },\n {\n name: '--extra-params ',\n description: 'Custom params that will be passed to xcodebuild command.',\n parse: (val: string) => val.split(' '),\n },\n];\n\nexport default {\n name: 'build-ios',\n description: 'builds your app on iOS simulator',\n func: buildIOS,\n examples: [\n {\n desc: 'Build the app for the IOS simulator',\n cmd: 'react-native build-ios',\n },\n {\n desc: 'Build the app for all IOS devices',\n cmd: 'react-native build-ios --mode \"Release\"',\n },\n {\n desc: 'Build the app for a specific IOS device',\n cmd: 'react-native build-ios --simulator \"IPhone 11\"',\n },\n ],\n options: [\n ...iosBuildOptions,\n {\n name: '--interactive',\n description:\n 'Explicitly select which scheme and configuration to use before running a build',\n },\n ],\n};\n"],"mappings":";;;;;;AAQA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AAAwD;AAvBxD;AACA;AACA;AACA;AACA;AACA;AACA;;AA2BA,eAAeA,QAAQ,CAACC,CAAgB,EAAEC,GAAW,EAAEC,IAAY,EAAE;EACnE,IAAI,CAACD,GAAG,CAACE,OAAO,CAACC,GAAG,EAAE;IACpB,MAAM,KAAIC,oBAAQ,EAChB,4EAA4E,CAC7E;EACH;EAEA,MAAM;IAACC,YAAY;IAAEC;EAAS,CAAC,GAAGN,GAAG,CAACE,OAAO,CAACC,GAAG;EAEjD,IAAI,CAACE,YAAY,EAAE;IACjB,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