microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0502b7a86030ea91bf3320d0f2ad32aff86fa6db

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/ios/iOSPlatform.ts

93lines · 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 runIos = new CommandExecutor(this.projectPath).spawnReactCommand("run-ios", runArguments);
39 const deferred = Q.defer<void>();
40 runIos.on("error", (err: Error) => {
41 deferred.reject(err);
42 });
43 runIos.stderr.on("data", (data: Buffer) => {
44 const dataString = data.toString();
45 if (dataString.indexOf("No devices are booted") !== -1 // No emulators are started
46 || dataString.indexOf("FBSOpenApplicationErrorDomain") !== -1) { // The incorrect emulator is started
47 deferred.reject(new Error("Unable to launch iOS simulator. Try specifying a different target."));
48 }
49 });
50 runIos.on("exit", (code: number) => {
51 if (code !== 0) {
52 const err = new Error(`Command failed with exit code ${code}`);
53 Log.commandFailed(["react-native", "run-ios"].concat(runArguments).join(" "), err);
54 deferred.reject(err);
55 } else {
56 deferred.resolve(void 0);
57 }
58 });
59 return deferred.promise;
60 }
61
62 return new Compiler(this.projectPath).compile().then(() => {
63 return new DeviceDeployer(this.projectPath).deploy();
64 }).then(() => {
65 return new DeviceRunner(this.projectPath).run();
66 });
67 }
68
69 public enableJSDebuggingMode(launchArgs: IRunOptions): Q.Promise<void> {
70 // Configure the app for debugging
71 this.consumeArguments(launchArgs);
72
73 if (this.simulatorTarget.toLowerCase() === IOSPlatform.deviceString) {
74 // Note that currently we cannot automatically switch the device into debug mode.
75 Log.logMessage("Application is running on a device, please shake device and select 'Debug in Chrome' to enable debugging.");
76 return Q.resolve<void>(void 0);
77 }
78
79 return new IOSDebugModeManager(this.projectPath).setSimulatorJSDebuggingModeSetting(/*enable=*/ true)
80 .then(() => {
81 return this.plistBuddy.getBundleId(launchArgs.projectRoot);
82 }).then((bundleId: string) => {
83 // Relaunch the app so the new setting can take effect
84 return new CommandExecutor().execute(`xcrun simctl launch booted ${bundleId}`);
85 });
86 }
87
88 private consumeArguments(launchArgs: IRunOptions): void {
89 this.projectPath = launchArgs.projectRoot;
90 this.simulatorTarget = launchArgs.target || IOSPlatform.simulatorString;
91 this.isSimulator = this.simulatorTarget.toLowerCase() !== IOSPlatform.deviceString;
92 }
93}
94