microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
3677173c6cd3c9a261a8ee5b0db12ffd25ee49a6

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/debugger/ios/iOSPlatform.ts

85lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import * as Q from "q";
5
6import {Log} from "../../common/log";
7import {CommandExecutor} from "../../common/commandExecutor";
8import {IAppPlatform} from "../platformResolver";
9import {Compiler} from "./compiler";
10import {DeviceDeployer} from "./deviceDeployer";
11import {DeviceRunner} from "./deviceRunner";
12import {IRunOptions} from "../launchArgs";
13import {PlistBuddy} from "../../common/ios/plistBuddy";
14import {IOSDebugModeManager} from "../../common/ios/iOSDebugModeManager";
15
16export class IOSPlatform implements IAppPlatform {
17 private static deviceString = "device";
18 private static simulatorString = "simulator";
19
20 private plistBuddy = new PlistBuddy();
21
22 private projectPath: string;
23 private simulatorTarget: string;
24 private isSimulator: boolean;
25
26 public runApp(launchArgs: IRunOptions): Q.Promise<void> {
27 // Compile, deploy, and launch the app on either a simulator or a device
28 this.consumeArguments(launchArgs);
29
30 if (this.isSimulator) {
31 // React native supports running on the iOS simulator from the command line
32 let runArguments: string[] = [];
33 if (this.simulatorTarget.toLowerCase() !== IOSPlatform.simulatorString) {
34 runArguments.push("--simulator");
35 runArguments.push(this.simulatorTarget);
36 }
37
38 const runIosSpawn = new CommandExecutor(this.projectPath).spawnChildReactCommandProcess("run-ios", runArguments);
39 const deferred = Q.defer<void>();
40 runIosSpawn.stderr.on("data", (data: Buffer) => {
41 const dataString = data.toString();
42 if (dataString.indexOf("No devices are booted") !== -1 // No emulators are started
43 || dataString.indexOf("FBSOpenApplicationErrorDomain") !== -1) { // The incorrect emulator is started
44 deferred.reject(new Error("Unable to launch iOS simulator. Try specifying a different target."));
45 }
46 });
47
48 return runIosSpawn.outcome.then(() => {
49 deferred.resolve(void 0); // We resolve deferred when the process ends, in case it wasn't already rejected
50 return deferred.promise; // We return the promise. If an error was detected on stderr, this will be a rejection
51 });
52 }
53
54 return new Compiler(this.projectPath).compile().then(() => {
55 return new DeviceDeployer(this.projectPath).deploy();
56 }).then(() => {
57 return new DeviceRunner(this.projectPath).run();
58 });
59 }
60
61 public enableJSDebuggingMode(launchArgs: IRunOptions): Q.Promise<void> {
62 // Configure the app for debugging
63 this.consumeArguments(launchArgs);
64
65 if (this.simulatorTarget.toLowerCase() === IOSPlatform.deviceString) {
66 // Note that currently we cannot automatically switch the device into debug mode.
67 Log.logMessage("Application is running on a device, please shake device and select 'Debug in Chrome' to enable debugging.");
68 return Q.resolve<void>(void 0);
69 }
70
71 return new IOSDebugModeManager(this.projectPath).setSimulatorJSDebuggingModeSetting(/*enable=*/ true)
72 .then(() => {
73 return this.plistBuddy.getBundleId(launchArgs.projectRoot);
74 }).then((bundleId: string) => {
75 // Relaunch the app so the new setting can take effect
76 return new CommandExecutor().execute(`xcrun simctl launch booted ${bundleId}`);
77 });
78 }
79
80 private consumeArguments(launchArgs: IRunOptions): void {
81 this.projectPath = launchArgs.projectRoot;
82 this.simulatorTarget = launchArgs.target || IOSPlatform.simulatorString;
83 this.isSimulator = this.simulatorTarget.toLowerCase() !== IOSPlatform.deviceString;
84 }
85}
86