microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.1.4

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/launcher.ts

94lines · 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
24c4c0aaJimmy Thomson10 years ago4import * as fs from "fs";
4677921cdigeff10 years ago5import * as path from "path";
bd539474digeff10 years ago6import * as Q from "q";
4677921cdigeff10 years ago7import {MultipleLifetimesAppWorker} from "./appWorker";
c2bf3c4fdigeff10 years ago8import {Log} from "../common/log/log";
9import {ErrorHelper} from "../common/error/errorHelper";
10import {InternalErrorCode} from "../common/error/internalErrorCode";
2743f19cdlebu10 years ago11import {ScriptImporter} from "./scriptImporter";
f5ea0577unknown10 years ago12import {PlatformResolver} from "./platformResolver";
2d3a052eMeena Kunnathur Balakrishnan10 years ago13import {TelemetryHelper} from "../common/telemetryHelper";
acf08bc2dlebu10 years ago14import {IRunOptions} from "../common/launchArgs";
2743f19cdlebu10 years ago15import * as em from "../common/extensionMessaging";
47958817digeff10 years ago16import {EntryPointHandler} from "../common/entryPointHandler";
3fb37ad5unknown10 years ago17
18export class Launcher {
19private projectRootPath: string;
20
21constructor(projectRootPath: string) {
22this.projectRootPath = projectRootPath;
23}
24
10873e11digeff10 years ago25public launch(): void {
24c4c0aaJimmy Thomson10 years ago26// Enable telemetry
c2bf3c4fdigeff10 years ago27new EntryPointHandler(true).runApp("react-native-debug-process", () => this.getAppVersion(),
28ErrorHelper.getInternalError(InternalErrorCode.DebuggingFailed), () => {
bd539474digeff10 years ago29return TelemetryHelper.generate("launch", (generator) => {
dd442738Jimmy Thomson10 years ago30const resolver = new PlatformResolver();
31const runOptions = this.parseRunOptions();
32const mobilePlatform = resolver.resolveMobilePlatform(runOptions.platform);
33if (!mobilePlatform) {
10873e11digeff10 years ago34throw new RangeError("The target platform could not be read. Did you forget to add it to the launch.json configuration arguments?");
dd442738Jimmy Thomson10 years ago35} else {
24c4c0aaJimmy Thomson10 years ago36const sourcesStoragePath = path.join(this.projectRootPath, ".vscode", ".react");
eb113a1fdlebu10 years ago37let extensionMessageSender = new em.ExtensionMessageSender();
bd539474digeff10 years ago38return Q({})
39.then(() => {
40generator.step("startPackager");
6b6eb911dlebu10 years ago41return extensionMessageSender.sendMessage(em.ExtensionMessage.START_PACKAGER);
2743f19cdlebu10 years ago42})
43.then(() => {
44let scriptImporter = new ScriptImporter(sourcesStoragePath);
45return scriptImporter.downloadDebuggerWorker(sourcesStoragePath).then(() => {
46Log.logMessage("Downloaded debuggerWorker.js (Logic to run the React Native app) from the Packager.");
47});
bd539474digeff10 years ago48})
dd442738Jimmy Thomson10 years ago49// 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
50// and the user needs to Reload JS manually. We prewarm it to prevent that issue
51.then(() => {
52generator.step("prewarmBundleCache");
88dd805aDaniel Lebu10 years ago53Log.logMessage("Prewarming bundle cache. This may take a while ...");
6b6eb911dlebu10 years ago54return extensionMessageSender.sendMessage(em.ExtensionMessage.PREWARM_BUNDLE_CACHE, [runOptions.platform]);
dd442738Jimmy Thomson10 years ago55})
56.then(() => {
57generator.step("mobilePlatform.runApp");
8a34309cDaniel Lebu10 years ago58Log.logMessage("Building and running application.");
dd442738Jimmy Thomson10 years ago59return mobilePlatform.runApp(runOptions);
60})
61.then(() => {
62generator.step("Starting App Worker");
8a34309cDaniel Lebu10 years ago63Log.logMessage("Starting debugger app worker.");
dd442738Jimmy Thomson10 years ago64return new MultipleLifetimesAppWorker(sourcesStoragePath, runOptions.debugAdapterPort).start();
65}) // Start the app worker
66.then(() => {
67generator.step("mobilePlatform.enableJSDebuggingMode");
68return mobilePlatform.enableJSDebuggingMode(runOptions);
10873e11digeff10 years ago69}).then(() =>
b9356af0Meena Kunnathur Balakrishnan10 years ago70Log.logMessage("Debugging session started successfully."));
dd442738Jimmy Thomson10 years ago71}
bd539474digeff10 years ago72});
10873e11digeff10 years ago73});
74}
75
76private getAppVersion() {
77return JSON.parse(fs.readFileSync(path.join(__dirname, "..", "..", "package.json"), "utf-8")).version;
b3a793eeNisheet Jain10 years ago78}
79
3af9a124unknown10 years ago80/**
fb2bae06Daniel10 years ago81* Parses the launch arguments set in the launch configuration.
3af9a124unknown10 years ago82*/
fb2bae06Daniel10 years ago83private parseRunOptions(): IRunOptions {
24c4c0aaJimmy Thomson10 years ago84const result: IRunOptions = { projectRoot: this.projectRootPath };
5547a16fJimmy Thomson10 years ago85// We expect our debugAdapter to pass in arguments as [platform, debugAdapterPort, target?];
3af9a124unknown10 years ago86
5547a16fJimmy Thomson10 years ago87result.platform = process.argv[2].toLowerCase();
88result.debugAdapterPort = parseInt(process.argv[3], 10) || 9090;
6b6eb911dlebu10 years ago89result.target = process.argv[4];
710f8655digeff10 years ago90result.logCatArguments = process.argv[5];
3af9a124unknown10 years ago91
92return result;
3fb37ad5unknown10 years ago93}
88dd805aDaniel Lebu10 years ago94}