microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2d4d251e2d19e844359a26043bb117e51dab0ac3

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/ios/iOSPlatform.ts

82lines · 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 "../../utils/commands/log";
7import {CommandExecutor} from "../../utils/commands/commandExecutor";
8import {IMobilePlatform, IDesktopPlatform} from "../platformResolver";
9import {Compiler} from "./compiler";
10import {DeviceDeployer} from "./deviceDeployer";
11import {DeviceRunner} from "./deviceRunner";
12import {IRunOptions} from "../launchArgs";
13import {SimulatorPlist} from "./simulatorPlist";
14import {PlistBuddy} from "./plistBuddy";
15
16export class IOSPlatform implements IMobilePlatform {
17 private static deviceString = "device";
18 private static simulatorString = "simulator";
19
20 private desktopPlatform: IDesktopPlatform;
21
22 private projectPath: string;
23 private simulatorTarget: string;
24 private isSimulator: boolean;
25
26 constructor (desktopPlatform: IDesktopPlatform) {
27 this.desktopPlatform = desktopPlatform;
28 }
29
30 public runApp(launchArgs: IRunOptions): Q.Promise<void> {
31 // Compile, deploy, and launch the app on either a simulator or a device
32 this.consumeArguments(launchArgs);
33
34 if (this.isSimulator) {
35 // React native supports running on the iOS simulator from the command line
36 let runArguments = ["run-ios"];
37 if (this.simulatorTarget.toLowerCase() !== IOSPlatform.simulatorString) {
38 runArguments.push("--simulator");
39 runArguments.push(this.simulatorTarget);
40 }
41
42 return new CommandExecutor(this.projectPath).spawn(this.desktopPlatform.reactNativeCommandName, runArguments);
43 }
44
45 // TODO: This is currently a stub, device debugging is not yet implemented
46 return new Compiler(this.projectPath, this.isSimulator).compile().then(() => {
47 return new DeviceDeployer(this.projectPath).deploy();
48 }).then(() => {
49 return new DeviceRunner(this.projectPath).run();
50 });
51 }
52
53 public enableJSDebuggingMode(launchArgs: IRunOptions): Q.Promise<void> {
54 // Configure the app for debugging
55 this.consumeArguments(launchArgs);
56
57 if (this.simulatorTarget.toLowerCase() === IOSPlatform.deviceString) {
58 // Note that currently we cannot automatically switch the device into debug mode.
59 Log.logMessage("Application is running on a device, please shake device and select 'Debug in Javascript' to enable debugging.");
60 return Q.resolve<void>(void 0);
61 }
62
63 const plistBuddy = new PlistBuddy();
64 // Find the plistFile with the configuration setting
65 return 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
68 return plistBuddy.setPlistProperty(plistFile, ":RCTDevMenu:executorClass", "RCTWebSocketExecutor");
69 }).then(() => {
70 return plistBuddy.getBundleId(launchArgs.projectRoot);
71 }).then((bundleId: string) => {
72 // Relaunch the app so the new setting can take effect
73 return new CommandExecutor().execute(`xcrun simctl launch booted ${bundleId}`);
74 });
75 }
76
77 private consumeArguments(launchArgs: IRunOptions): void {
78 this.projectPath = launchArgs.projectRoot;
79 this.simulatorTarget = launchArgs.target || IOSPlatform.simulatorString;
80 this.isSimulator = this.simulatorTarget.toLowerCase() !== IOSPlatform.deviceString;
81 }
82}