microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.1.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/debugger/launcher.ts

91lines · 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");
6b6eb911dlebu10 years ago53return extensionMessageSender.sendMessage(em.ExtensionMessage.PREWARM_BUNDLE_CACHE, [runOptions.platform]);
dd442738Jimmy Thomson10 years ago54})
55.then(() => {
56generator.step("mobilePlatform.runApp");
57return mobilePlatform.runApp(runOptions);
58})
59.then(() => {
60generator.step("Starting App Worker");
61return new MultipleLifetimesAppWorker(sourcesStoragePath, runOptions.debugAdapterPort).start();
62}) // Start the app worker
63.then(() => {
64generator.step("mobilePlatform.enableJSDebuggingMode");
65return mobilePlatform.enableJSDebuggingMode(runOptions);
10873e11digeff10 years ago66}).then(() =>
b9356af0Meena Kunnathur Balakrishnan10 years ago67Log.logMessage("Debugging session started successfully."));
dd442738Jimmy Thomson10 years ago68}
bd539474digeff10 years ago69});
10873e11digeff10 years ago70});
71}
72
73private getAppVersion() {
74return JSON.parse(fs.readFileSync(path.join(__dirname, "..", "..", "package.json"), "utf-8")).version;
b3a793eeNisheet Jain10 years ago75}
76
3af9a124unknown10 years ago77/**
fb2bae06Daniel10 years ago78* Parses the launch arguments set in the launch configuration.
3af9a124unknown10 years ago79*/
fb2bae06Daniel10 years ago80private parseRunOptions(): IRunOptions {
24c4c0aaJimmy Thomson10 years ago81const result: IRunOptions = { projectRoot: this.projectRootPath };
5547a16fJimmy Thomson10 years ago82// We expect our debugAdapter to pass in arguments as [platform, debugAdapterPort, target?];
3af9a124unknown10 years ago83
5547a16fJimmy Thomson10 years ago84result.platform = process.argv[2].toLowerCase();
85result.debugAdapterPort = parseInt(process.argv[3], 10) || 9090;
6b6eb911dlebu10 years ago86result.target = process.argv[4];
710f8655digeff10 years ago87result.logCatArguments = process.argv[5];
3af9a124unknown10 years ago88
89return result;
3fb37ad5unknown10 years ago90}
eb113a1fdlebu10 years ago91}