microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
514f9fd68fe2e685a692d7ba98b26a74d1d10d96

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/launcher.ts

57lines · 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 /**
20 * Parses the launch arguments set in the launch configuration.
21 */
22 private parseRunOptions(): IRunOptions {
23 let result: IRunOptions = { projectRoot: this.projectRootPath };
24
25 if (process.argv.length > 2) {
26 result.platform = process.argv[2].toLowerCase();
27 }
28
29 result.target = process.argv[3];
30
31 return result;
32 }
33
34 public launch() {
35 let resolver = new PlatformResolver();
36 let runOptions = this.parseRunOptions();
37 let mobilePlatform = resolver.resolveMobilePlatform(runOptions.platform);
38 if (!mobilePlatform) {
39 Log.logError("The target platform could not be read. Did you forget to add it to the launch.json configuration arguments?");
40 } else {
41 let sourcesStoragePath = path.join(this.projectRootPath, ".vscode", ".react");
42 let packager = new Packager(this.projectRootPath, sourcesStoragePath);
43 Q({})
44 .then(() => packager.start())
45 // 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
46 // and the user needs to Reload JS manually. We prewarm it to prevent that issue
47 .then(() => packager.prewarmBundleCache(runOptions.platform))
48 .then(() => mobilePlatform.runApp(runOptions))
49 .then(() => new MultipleLifetimesAppWorker(sourcesStoragePath).start()) // Start the app worker
50 .then(() => mobilePlatform.enableJSDebuggingMode(runOptions))
51 .done(() => { }, reason => {
52 Log.logError("Cannot debug application.", reason);
53 });
54 }
55 }
56}
57
58