microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
fb6c0d0507b286c72b88078fd6d7bc0ff2fa682d

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/ios/iOSPlatform.ts

94lines · modeblame

488f1908Jimmy Thomson10 years ago1// 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
b0061ac6Meena Kunnathur Balakrishnan10 years ago6import {Log} from "../../common/log";
7import {CommandExecutor} from "../../common/commandExecutor";
f8d32439dlebu10 years ago8import {IAppPlatform} from "../platformResolver";
488f1908Jimmy Thomson10 years ago9import {Compiler} from "./compiler";
10import {DeviceDeployer} from "./deviceDeployer";
11import {DeviceRunner} from "./deviceRunner";
12import {IRunOptions} from "../launchArgs";
a9d96b7cdigeff10 years ago13import {PlistBuddy} from "../../common/ios/plistBuddy";
1ed272e1digeff10 years ago14import {IOSDebugModeManager} from "../../common/ios/iOSDebugModeManager";
488f1908Jimmy Thomson10 years ago15
f8d32439dlebu10 years ago16export class IOSPlatform implements IAppPlatform {
bc7a32ceJimmy Thomson10 years ago17private static deviceString = "device";
18private static simulatorString = "simulator";
19
a9d96b7cdigeff10 years ago20private plistBuddy = new PlistBuddy();
21
110558c0Jimmy Thomson10 years ago22private projectPath: string;
23private simulatorTarget: string;
24private isSimulator: boolean;
25
488f1908Jimmy Thomson10 years ago26public runApp(launchArgs: IRunOptions): Q.Promise<void> {
27// Compile, deploy, and launch the app on either a simulator or a device
110558c0Jimmy Thomson10 years ago28this.consumeArguments(launchArgs);
488f1908Jimmy Thomson10 years ago29
110558c0Jimmy Thomson10 years ago30if (this.isSimulator) {
488f1908Jimmy Thomson10 years ago31// React native supports running on the iOS simulator from the command line
f8d32439dlebu10 years ago32let runArguments: string[] = [];
110558c0Jimmy Thomson10 years ago33if (this.simulatorTarget.toLowerCase() !== IOSPlatform.simulatorString) {
488f1908Jimmy Thomson10 years ago34runArguments.push("--simulator");
110558c0Jimmy Thomson10 years ago35runArguments.push(this.simulatorTarget);
488f1908Jimmy Thomson10 years ago36}
37
f7208a21Jimmy Thomson10 years ago38return new CommandExecutor(this.projectPath).spawnReactCommand("run-ios", runArguments).then((runIos) => {
39const deferred = Q.defer<void>();
40runIos.on("error", (err: Error) => {
41deferred.reject(err);
42});
43runIos.stderr.on("data", (data: Buffer) => {
44const dataString = data.toString();
45if (dataString.indexOf("No devices are booted") !== -1 // No emulators are started
46|| dataString.indexOf("FBSOpenApplicationErrorDomain") !== -1) { // The incorrect emulator is started
47deferred.reject(new Error("Unable to launch iOS simulator. Try specifying a different target."));
48}
49});
50runIos.on("exit", (code: number) => {
51if (code !== 0) {
52const err = new Error(`Command failed with exit code ${code}`);
53Log.commandFailed(["react-native", "run-ios"].concat(runArguments).join(" "), err);
54deferred.reject(err);
55} else {
56deferred.resolve(void 0);
57}
58});
59return deferred.promise;
60});
488f1908Jimmy Thomson10 years ago61}
62
bc96b26bJimmy Thomson10 years ago63return new Compiler(this.projectPath).compile().then(() => {
110558c0Jimmy Thomson10 years ago64return new DeviceDeployer(this.projectPath).deploy();
488f1908Jimmy Thomson10 years ago65}).then(() => {
110558c0Jimmy Thomson10 years ago66return new DeviceRunner(this.projectPath).run();
488f1908Jimmy Thomson10 years ago67});
68}
69
70public enableJSDebuggingMode(launchArgs: IRunOptions): Q.Promise<void> {
71// Configure the app for debugging
110558c0Jimmy Thomson10 years ago72this.consumeArguments(launchArgs);
488f1908Jimmy Thomson10 years ago73
110558c0Jimmy Thomson10 years ago74if (this.simulatorTarget.toLowerCase() === IOSPlatform.deviceString) {
488f1908Jimmy Thomson10 years ago75// Note that currently we cannot automatically switch the device into debug mode.
b044f0b9Jimmy Thomson10 years ago76Log.logMessage("Application is running on a device, please shake device and select 'Debug in Chrome' to enable debugging.");
488f1908Jimmy Thomson10 years ago77return Q.resolve<void>(void 0);
78}
79
1ed272e1digeff10 years ago80return new IOSDebugModeManager(this.projectPath).setSimulatorJSDebuggingModeSetting(/*enable=*/ true)
a9d96b7cdigeff10 years ago81.then(() => {
82return this.plistBuddy.getBundleId(launchArgs.projectRoot);
b044f0b9Jimmy Thomson10 years ago83}).then((bundleId: string) => {
84// Relaunch the app so the new setting can take effect
85return new CommandExecutor().execute(`xcrun simctl launch booted ${bundleId}`);
86});
488f1908Jimmy Thomson10 years ago87}
110558c0Jimmy Thomson10 years ago88
89private consumeArguments(launchArgs: IRunOptions): void {
90this.projectPath = launchArgs.projectRoot;
91this.simulatorTarget = launchArgs.target || IOSPlatform.simulatorString;
92this.isSimulator = this.simulatorTarget.toLowerCase() !== IOSPlatform.deviceString;
93}
a9d96b7cdigeff10 years ago94}