microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
ea8a5f88eea22e059c668cbca7ca4bc4bfa20dbe

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/launcher.ts

56lines · modeblame

a31b007cunknown10 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
3fb37ad5unknown10 years ago4import * as Q from "q";
4677921cdigeff10 years ago5import * as path from "path";
6import {MultipleLifetimesAppWorker} from "./appWorker";
3fb37ad5unknown10 years ago7import {Packager} from "./packager";
bedf110funknown10 years ago8import {Log} from "../utils/commands/log";
f5ea0577unknown10 years ago9import {PlatformResolver} from "./platformResolver";
fb2bae06Daniel10 years ago10import {IRunOptions} from "./launchArgs";
3fb37ad5unknown10 years ago11
12export class Launcher {
13private projectRootPath: string;
14
15constructor(projectRootPath: string) {
16this.projectRootPath = projectRootPath;
17}
18
b3a793eeNisheet Jain10 years ago19public launch() {
20let resolver = new PlatformResolver();
21let runOptions = this.parseRunOptions();
22let mobilePlatform = resolver.resolveMobilePlatform(runOptions.platform);
23if (!mobilePlatform) {
24Log.logError("The target platform could not be read. Did you forget to add it to the launch.json configuration arguments?");
3af9a124unknown10 years ago25} else {
4e7a6f0edlebu10 years ago26let sourcesStoragePath = path.join(this.projectRootPath, ".vscode", ".react");
418d8ac5digeff10 years ago27let packager = new Packager(this.projectRootPath, sourcesStoragePath);
3af9a124unknown10 years ago28Q({})
418d8ac5digeff10 years ago29.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).start()) // Start the app worker
e639e7a4Daniel10 years ago35.then(() => mobilePlatform.enableJSDebuggingMode(runOptions))
3af9a124unknown10 years ago36.done(() => { }, reason => {
37Log.logError("Cannot debug application.", reason);
38});
b3a793eeNisheet Jain10 years ago39}
40}
41
3af9a124unknown10 years ago42/**
fb2bae06Daniel10 years ago43* Parses the launch arguments set in the launch configuration.
3af9a124unknown10 years ago44*/
fb2bae06Daniel10 years ago45private parseRunOptions(): IRunOptions {
46let result: IRunOptions = { projectRoot: this.projectRootPath };
3af9a124unknown10 years ago47
48if (process.argv.length > 2) {
fb2bae06Daniel10 years ago49result.platform = process.argv[2].toLowerCase();
3af9a124unknown10 years ago50}
51
fb2bae06Daniel10 years ago52result.target = process.argv[3];
3af9a124unknown10 years ago53return result;
3fb37ad5unknown10 years ago54}
55}
fb2bae06Daniel10 years ago56