UNPKG

2.14 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7function _child_process() {
8 const data = require("child_process");
9 _child_process = function () {
10 return data;
11 };
12 return data;
13}
14function _os() {
15 const data = _interopRequireDefault(require("os"));
16 _os = function () {
17 return data;
18 };
19 return data;
20}
21function _path() {
22 const data = _interopRequireDefault(require("path"));
23 _path = function () {
24 return data;
25 };
26 return data;
27}
28function _cliTools() {
29 const data = require("@react-native-community/cli-tools");
30 _cliTools = function () {
31 return data;
32 };
33 return data;
34}
35function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
36/**
37 * Copyright (c) Facebook, Inc. and its affiliates.
38 *
39 * This source code is licensed under the MIT license found in the
40 * LICENSE file in the root directory of this source tree.
41 *
42 */
43
44function findAvailableDevice(devices) {
45 for (const key of Object.keys(devices)) {
46 for (const device of devices[key]) {
47 if (device.availability === '(available)' && device.state === 'Booted') {
48 return device;
49 }
50 }
51 }
52 return null;
53}
54
55/**
56 * Starts iOS device syslog tail
57 */
58async function logIOS() {
59 const rawDevices = (0, _child_process().execFileSync)('xcrun', ['simctl', 'list', 'devices', '--json'], {
60 encoding: 'utf8'
61 });
62 const {
63 devices
64 } = JSON.parse(rawDevices);
65 const device = findAvailableDevice(devices);
66 if (device === null) {
67 _cliTools().logger.error('No active iOS device found');
68 return;
69 }
70 tailDeviceLogs(device.udid);
71}
72function tailDeviceLogs(udid) {
73 const logDir = _path().default.join(_os().default.homedir(), 'Library', 'Logs', 'CoreSimulator', udid, 'asl');
74 const log = (0, _child_process().spawnSync)('syslog', ['-w', '-F', 'std', '-d', logDir], {
75 stdio: 'inherit'
76 });
77 if (log.error !== null) {
78 throw log.error;
79 }
80}
81var _default = {
82 name: 'log-ios',
83 description: 'starts iOS device syslog tail',
84 func: logIOS
85};
86exports.default = _default;
87
88//# sourceMappingURL=index.js.map
\No newline at end of file