microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
b4683d60d2ce52828fca73ad1093856d8a898640

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/ios/iOSPlatform.ts

82lines · 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
afc46a73Jimmy Thomson10 years ago6import {Log} from "../../utils/commands/log";
488f1908Jimmy Thomson10 years ago7import {CommandExecutor} from "../../utils/commands/commandExecutor";
bc7a32ceJimmy Thomson10 years ago8import {IMobilePlatform, IDesktopPlatform} from "../platformResolver";
488f1908Jimmy Thomson10 years ago9import {Compiler} from "./compiler";
10import {DeviceDeployer} from "./deviceDeployer";
11import {DeviceRunner} from "./deviceRunner";
12import {IRunOptions} from "../launchArgs";
13import {SimulatorPlist} from "./simulatorPlist";
bc7a32ceJimmy Thomson10 years ago14import {PlistBuddy} from "./plistBuddy";
488f1908Jimmy Thomson10 years ago15
16export class IOSPlatform implements IMobilePlatform {
bc7a32ceJimmy Thomson10 years ago17private static deviceString = "device";
18private static simulatorString = "simulator";
19
20private desktopPlatform: IDesktopPlatform;
21
110558c0Jimmy Thomson10 years ago22private projectPath: string;
23private simulatorTarget: string;
24private isSimulator: boolean;
25
bc7a32ceJimmy Thomson10 years ago26constructor (desktopPlatform: IDesktopPlatform) {
27this.desktopPlatform = desktopPlatform;
28}
29
488f1908Jimmy Thomson10 years ago30public runApp(launchArgs: IRunOptions): Q.Promise<void> {
31// Compile, deploy, and launch the app on either a simulator or a device
110558c0Jimmy Thomson10 years ago32this.consumeArguments(launchArgs);
488f1908Jimmy Thomson10 years ago33
110558c0Jimmy Thomson10 years ago34if (this.isSimulator) {
488f1908Jimmy Thomson10 years ago35// React native supports running on the iOS simulator from the command line
36let runArguments = ["run-ios"];
110558c0Jimmy Thomson10 years ago37if (this.simulatorTarget.toLowerCase() !== IOSPlatform.simulatorString) {
488f1908Jimmy Thomson10 years ago38runArguments.push("--simulator");
110558c0Jimmy Thomson10 years ago39runArguments.push(this.simulatorTarget);
488f1908Jimmy Thomson10 years ago40}
41
110558c0Jimmy Thomson10 years ago42return new CommandExecutor(this.projectPath).spawn(this.desktopPlatform.reactNativeCommandName, runArguments);
488f1908Jimmy Thomson10 years ago43}
44
45// TODO: This is currently a stub, device debugging is not yet implemented
110558c0Jimmy Thomson10 years ago46return new Compiler(this.projectPath, this.isSimulator).compile().then(() => {
47return new DeviceDeployer(this.projectPath).deploy();
488f1908Jimmy Thomson10 years ago48}).then(() => {
110558c0Jimmy Thomson10 years ago49return new DeviceRunner(this.projectPath).run();
488f1908Jimmy Thomson10 years ago50});
51}
52
53public enableJSDebuggingMode(launchArgs: IRunOptions): Q.Promise<void> {
54// Configure the app for debugging
110558c0Jimmy Thomson10 years ago55this.consumeArguments(launchArgs);
488f1908Jimmy Thomson10 years ago56
110558c0Jimmy Thomson10 years ago57if (this.simulatorTarget.toLowerCase() === IOSPlatform.deviceString) {
488f1908Jimmy Thomson10 years ago58// Note that currently we cannot automatically switch the device into debug mode.
afc46a73Jimmy Thomson10 years ago59Log.logMessage("Application is running on a device, please shake device and select 'Debug in Javascript' to enable debugging.");
488f1908Jimmy Thomson10 years ago60return Q.resolve<void>(void 0);
61}
62
bc7a32ceJimmy Thomson10 years ago63const plistBuddy = new PlistBuddy();
488f1908Jimmy Thomson10 years ago64// Find the plistFile with the configuration setting
65return new SimulatorPlist(launchArgs.projectRoot).findPlistFile().then((plistFile: string) => {
66// Set the executorClass to be RCTWebSocketExecutor so on the next startup it will default into debug mode
67// This is approximately equivalent to clicking the "Debug in Chrome" button
bc7a32ceJimmy Thomson10 years ago68return plistBuddy.setPlistProperty(plistFile, ":RCTDevMenu:executorClass", "RCTWebSocketExecutor");
488f1908Jimmy Thomson10 years ago69}).then(() => {
bc7a32ceJimmy Thomson10 years ago70return plistBuddy.getBundleId(launchArgs.projectRoot);
488f1908Jimmy Thomson10 years ago71}).then((bundleId: string) => {
72// Relaunch the app so the new setting can take effect
110558c0Jimmy Thomson10 years ago73return new CommandExecutor().execute(`xcrun simctl launch booted ${bundleId}`);
488f1908Jimmy Thomson10 years ago74});
75}
110558c0Jimmy Thomson10 years ago76
77private consumeArguments(launchArgs: IRunOptions): void {
78this.projectPath = launchArgs.projectRoot;
79this.simulatorTarget = launchArgs.target || IOSPlatform.simulatorString;
80this.isSimulator = this.simulatorTarget.toLowerCase() !== IOSPlatform.deviceString;
81}
488f1908Jimmy Thomson10 years ago82}