microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
b3a793eee158393d5f6769b11aaccd4cf5927841

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/launcher.ts

54lines · 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";
5import * as path from "path";
6import {MultipleLifetimesAppWorker} from "./appWorker";
7import {Packager} from "./packager";
8import {Log} from "../utils/commands/log";
9import {PlatformResolver} from "./platformResolver";
10import {IRunOptions} from "./launchArgs";
11
12export class Launcher {
13 private projectRootPath: string;
14
15 constructor(projectRootPath: string) {
16 this.projectRootPath = projectRootPath;
17 }
18
19 public launch() {
20 let resolver = new PlatformResolver();
21 let runOptions = this.parseRunOptions();
22 let mobilePlatform = resolver.resolveMobilePlatform(runOptions.platform);
23 if (!mobilePlatform) {
24 Log.logError("The target platform could not be read. Did you forget to add it to the launch.json configuration arguments?");
25 return;
26 }
27
28 let sourcesStoragePath = path.join(this.projectRootPath, ".vscode", ".react");
29 // TODO: We need to remove all the delays, yet make sure things work properly for both Android and iOS
30 Q({})
31 .then(() => Q.delay(new Packager(this.projectRootPath, sourcesStoragePath).start(), 3000))
32 .then(() => Q.delay(mobilePlatform.runApp(runOptions), 3000))
33 .then(() => Q.delay(new MultipleLifetimesAppWorker(sourcesStoragePath).start(), 3000)) // Start the app worker
34 .then(() => mobilePlatform.enableJSDebuggingMode(runOptions))
35 .done(() => { }, reason => {
36 Log.logError("Cannot debug application.", reason);
37 });
38 }
39
40 /**
41 * Parses the launch arguments set in the launch configuration.
42 */
43 private parseRunOptions(): IRunOptions {
44 let result: IRunOptions = { projectRoot: this.projectRootPath };
45
46 if (process.argv.length > 2) {
47 result.platform = process.argv[2].toLowerCase();
48 }
49
50 result.target = process.argv[3];
51 return result;
52 }
53}
54
55