{"version":3,"names":["logIOS","_argv","_ctx","args","simulators","getSimulators","bootedSimulators","Object","keys","devices","map","key","reduce","acc","val","concat","filter","state","listIOSDevices","availableSimulators","type","isAvailable","length","logger","error","bootedAndAvailableSimulators","booted","available","find","udid","interactive","prompt","name","message","choices","simulator","title","value","tailDeviceLogs","logDir","path","join","os","homedir","log","spawnSync","stdio","description","func","options"],"sources":["../../../src/commands/logIOS/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 {spawnSync} from 'child_process';\nimport os from 'os';\nimport path from 'path';\nimport {logger, prompt} from '@react-native-community/cli-tools';\nimport listIOSDevices from '../../tools/listIOSDevices';\nimport getSimulators from '../../tools/getSimulators';\nimport {Config} from '@react-native-community/cli-types';\n\n/**\n * Starts iOS device syslog tail\n */\n\ntype Args = {\n interactive: boolean;\n};\n\nasync function logIOS(_argv: Array, _ctx: Config, args: Args) {\n // Here we're using two command because first command `xcrun simctl list --json devices` outputs `state` but doesn't return `available`. But second command `xcrun xcdevice list` outputs `available` but doesn't output `state`. So we need to connect outputs of both commands.\n const simulators = getSimulators();\n const bootedSimulators = Object.keys(simulators.devices)\n .map((key) => simulators.devices[key])\n .reduce((acc, val) => acc.concat(val), [])\n .filter(({state}) => state === 'Booted');\n\n const devices = await listIOSDevices();\n const availableSimulators = devices.filter(\n ({type, isAvailable}) => type === 'simulator' && isAvailable,\n );\n\n if (availableSimulators.length === 0) {\n logger.error('No simulators detected. Install simulators via Xcode.');\n return;\n }\n\n const bootedAndAvailableSimulators = bootedSimulators.map((booted) => {\n const available = availableSimulators.find(\n ({udid}) => udid === booted.udid,\n );\n return {...available, ...booted};\n });\n\n if (bootedAndAvailableSimulators.length === 0) {\n logger.error('No booted and available iOS simulators found.');\n return;\n }\n\n if (args.interactive && bootedAndAvailableSimulators.length > 1) {\n const {udid} = await prompt({\n type: 'select',\n name: 'udid',\n message: 'Select iOS simulators to tail logs from',\n choices: bootedAndAvailableSimulators.map((simulator) => ({\n title: simulator.name,\n value: simulator.udid,\n })),\n });\n\n tailDeviceLogs(udid);\n } else {\n tailDeviceLogs(bootedAndAvailableSimulators[0].udid);\n }\n}\n\nfunction tailDeviceLogs(udid: string) {\n const logDir = path.join(\n os.homedir(),\n 'Library',\n 'Logs',\n 'CoreSimulator',\n udid,\n 'asl',\n );\n\n const log = spawnSync('syslog', ['-w', '-F', 'std', '-d', logDir], {\n stdio: 'inherit',\n });\n\n if (log.error !== null) {\n throw log.error;\n }\n}\n\nexport default {\n name: 'log-ios',\n description: 'starts iOS device syslog tail',\n func: logIOS,\n options: [\n {\n name: '--interactive',\n description:\n 'Explicitly select simulator to tail logs from. By default it will tail logs from the first booted and available simulator.',\n },\n ],\n};\n"],"mappings":";;;;;;AAQA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;AACA;AAAsD;AAbtD;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA;AACA;AACA;;AAMA,eAAeA,MAAM,CAACC,KAAoB,EAAEC,IAAY,EAAEC,IAAU,EAAE;EACpE;EACA,MAAMC,UAAU,GAAG,IAAAC,sBAAa,GAAE;EAClC,MAAMC,gBAAgB,GAAGC,MAAM,CAACC,IAAI,CAACJ,UAAU,CAACK,OAAO,CAAC,CACrDC,GAAG,CAAEC,GAAG,IAAKP,UAAU,CAACK,OAAO,CAACE,GAAG,CAAC,CAAC,CACrCC,MAAM,CAAC,CAACC,GAAG,EAAEC,GAAG,KAAKD,GAAG,CAACE,MAAM,CAACD,GAAG,CAAC,EAAE,EAAE,CAAC,CACzCE,MAAM,CAAC,CAAC;IAACC;EAAK,CAAC,KAAKA,KAAK,KAAK,QAAQ,CAAC;EAE1C,MAAMR,OAAO,GAA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