microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
52bf0a75506c1b3b1cecc9ad89937e596d1bc22a

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/ios/iOSPlatform.ts

76lines · 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";
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";
13import {SimulatorPlist} from "./simulatorPlist";
bc7a32ceJimmy Thomson10 years ago14import {PlistBuddy} from "./plistBuddy";
488f1908Jimmy Thomson10 years ago15
f8d32439dlebu10 years ago16export class IOSPlatform implements IAppPlatform {
bc7a32ceJimmy Thomson10 years ago17private static deviceString = "device";
18private static simulatorString = "simulator";
19
110558c0Jimmy Thomson10 years ago20private projectPath: string;
21private simulatorTarget: string;
22private isSimulator: boolean;
23
488f1908Jimmy Thomson10 years ago24public runApp(launchArgs: IRunOptions): Q.Promise<void> {
25// Compile, deploy, and launch the app on either a simulator or a device
110558c0Jimmy Thomson10 years ago26this.consumeArguments(launchArgs);
488f1908Jimmy Thomson10 years ago27
110558c0Jimmy Thomson10 years ago28if (this.isSimulator) {
488f1908Jimmy Thomson10 years ago29// React native supports running on the iOS simulator from the command line
f8d32439dlebu10 years ago30let runArguments: string[] = [];
110558c0Jimmy Thomson10 years ago31if (this.simulatorTarget.toLowerCase() !== IOSPlatform.simulatorString) {
488f1908Jimmy Thomson10 years ago32runArguments.push("--simulator");
110558c0Jimmy Thomson10 years ago33runArguments.push(this.simulatorTarget);
488f1908Jimmy Thomson10 years ago34}
35
f8d32439dlebu10 years ago36return new CommandExecutor(this.projectPath).spawnAndWaitReactCommand("run-ios", runArguments);
488f1908Jimmy Thomson10 years ago37}
38
39// TODO: This is currently a stub, device debugging is not yet implemented
bc96b26bJimmy Thomson10 years ago40return new Compiler(this.projectPath).compile().then(() => {
110558c0Jimmy Thomson10 years ago41return new DeviceDeployer(this.projectPath).deploy();
488f1908Jimmy Thomson10 years ago42}).then(() => {
110558c0Jimmy Thomson10 years ago43return new DeviceRunner(this.projectPath).run();
488f1908Jimmy Thomson10 years ago44});
45}
46
47public enableJSDebuggingMode(launchArgs: IRunOptions): Q.Promise<void> {
48// Configure the app for debugging
110558c0Jimmy Thomson10 years ago49this.consumeArguments(launchArgs);
488f1908Jimmy Thomson10 years ago50
110558c0Jimmy Thomson10 years ago51if (this.simulatorTarget.toLowerCase() === IOSPlatform.deviceString) {
488f1908Jimmy Thomson10 years ago52// Note that currently we cannot automatically switch the device into debug mode.
afc46a73Jimmy Thomson10 years ago53Log.logMessage("Application is running on a device, please shake device and select 'Debug in Javascript' to enable debugging.");
488f1908Jimmy Thomson10 years ago54return Q.resolve<void>(void 0);
55}
56
bc7a32ceJimmy Thomson10 years ago57const plistBuddy = new PlistBuddy();
488f1908Jimmy Thomson10 years ago58// Find the plistFile with the configuration setting
59return new SimulatorPlist(launchArgs.projectRoot).findPlistFile().then((plistFile: string) => {
60// Set the executorClass to be RCTWebSocketExecutor so on the next startup it will default into debug mode
61// This is approximately equivalent to clicking the "Debug in Chrome" button
bc7a32ceJimmy Thomson10 years ago62return plistBuddy.setPlistProperty(plistFile, ":RCTDevMenu:executorClass", "RCTWebSocketExecutor");
488f1908Jimmy Thomson10 years ago63}).then(() => {
bc7a32ceJimmy Thomson10 years ago64return plistBuddy.getBundleId(launchArgs.projectRoot);
488f1908Jimmy Thomson10 years ago65}).then((bundleId: string) => {
66// Relaunch the app so the new setting can take effect
110558c0Jimmy Thomson10 years ago67return new CommandExecutor().execute(`xcrun simctl launch booted ${bundleId}`);
488f1908Jimmy Thomson10 years ago68});
69}
110558c0Jimmy Thomson10 years ago70
71private consumeArguments(launchArgs: IRunOptions): void {
72this.projectPath = launchArgs.projectRoot;
73this.simulatorTarget = launchArgs.target || IOSPlatform.simulatorString;
74this.isSimulator = this.simulatorTarget.toLowerCase() !== IOSPlatform.deviceString;
75}
488f1908Jimmy Thomson10 years ago76}