microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
d976d077829ddbbeb18bfcab2945dd399d76173c

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/launcher.ts

56lines · 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 "../common/packager";
8import {Log} from "../common/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 } else {
26 let sourcesStoragePath = path.join(this.projectRootPath, ".vscode", ".react");
27 let packager = new Packager(this.projectRootPath, sourcesStoragePath);
28 Q({})
29 .then(() => packager.start())
30 // We've seen that if we don't prewarm the bundle cache, the app fails on the first attempt to connect to the debugger logic
31 // and the user needs to Reload JS manually. We prewarm it to prevent that issue
32 .then(() => packager.prewarmBundleCache(runOptions.platform))
33 .then(() => mobilePlatform.runApp(runOptions))
34 .then(() => new MultipleLifetimesAppWorker(sourcesStoragePath, runOptions.debugAdapterPort).start()) // Start the app worker
35 .then(() => mobilePlatform.enableJSDebuggingMode(runOptions))
36 .done(() => { }, reason => {
37 Log.logError("Cannot debug application.", reason);
38 });
39 }
40 }
41
42 /**
43 * Parses the launch arguments set in the launch configuration.
44 */
45 private parseRunOptions(): IRunOptions {
46 let result: IRunOptions = { projectRoot: this.projectRootPath };
47 // We expect our debugAdapter to pass in arguments as [platform, debugAdapterPort, target?];
48
49 result.platform = process.argv[2].toLowerCase();
50 result.debugAdapterPort = parseInt(process.argv[3], 10) || 9090;
51 result.target = process.argv[4];
52
53 return result;
54 }
55}
56
57