UNPKG

4.27 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.ensureSimulatorAppRunningAsync = ensureSimulatorAppRunningAsync;
7exports.isSimulatorAppRunningAsync = isSimulatorAppRunningAsync;
8exports.killAllAsync = killAllAsync;
9exports.openSimulatorAppAsync = openSimulatorAppAsync;
10exports.waitForSimulatorAppToStart = waitForSimulatorAppToStart;
11function osascript() {
12 const data = _interopRequireWildcard(require("@expo/osascript"));
13 osascript = function () {
14 return data;
15 };
16 return data;
17}
18function _spawnAsync() {
19 const data = _interopRequireDefault(require("@expo/spawn-async"));
20 _spawnAsync = function () {
21 return data;
22 };
23 return data;
24}
25function _child_process() {
26 const data = require("child_process");
27 _child_process = function () {
28 return data;
29 };
30 return data;
31}
32function _util() {
33 const data = require("util");
34 _util = function () {
35 return data;
36 };
37 return data;
38}
39function _internal() {
40 const data = require("../../internal");
41 _internal = function () {
42 return data;
43 };
44 return data;
45}
46function _waitForActionAsync() {
47 const data = require("./waitForActionAsync");
48 _waitForActionAsync = function () {
49 return data;
50 };
51 return data;
52}
53function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
54function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
55function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
56const execAsync = (0, _util().promisify)(_child_process().exec);
57async function waitForSimulatorAppToStart() {
58 return (0, _waitForActionAsync().waitForActionAsync)({
59 interval: 50,
60 action: isSimulatorAppRunningAsync
61 });
62}
63
64/**
65 * I think the app can be open while no simulators are booted.
66 */
67async function isSimulatorAppRunningAsync() {
68 try {
69 const zeroMeansNo = (await osascript().execAsync('tell app "System Events" to count processes whose name is "Simulator"')).trim();
70 if (zeroMeansNo === '0') {
71 return false;
72 }
73 } catch (error) {
74 if (error.message.includes('Application isn’t running')) {
75 return false;
76 }
77 throw error;
78 }
79 return true;
80}
81async function ensureSimulatorAppRunningAsync({
82 udid
83}) {
84 // Yes, simulators can be booted even if the app isn't running, obviously we'd never want this.
85 if (!(await isSimulatorAppRunningAsync())) {
86 _internal().Logger.global.info(`\u203A Opening the iOS simulator, this might take a moment.`);
87
88 // In theory this would ensure the correct simulator is booted as well.
89 // This isn't theory though, this is Xcode.
90 await openSimulatorAppAsync({
91 udid
92 });
93 if (!(await waitForSimulatorAppToStart())) {
94 throw new (_waitForActionAsync().TimeoutError)(`Simulator app did not open fast enough. Try opening Simulator first, then running your app.`);
95 }
96 }
97}
98async function openSimulatorAppAsync({
99 udid
100}) {
101 const args = ['open', '-a', 'Simulator'];
102 if (udid) {
103 // This has no effect if the app is already running.
104 args.push('--args', '-CurrentDeviceUDID', udid);
105 }
106 await execAsync(args.join(' '));
107}
108async function killAllAsync() {
109 return await (0, _spawnAsync().default)('killAll', ['Simulator']);
110}
111//# sourceMappingURL=ensureSimulatorAppRunningAsync.js.map
\No newline at end of file