microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
637e599d4b707fa92106bcd3fbfc075bf8e4625c

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/ios/iOSPlatform.ts

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