microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/debugger/launcher.ts
53lines · 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 | |
| 4 | import * as fs from "fs"; |
| 5 | import * as path from "path"; |
| 6 | |
| 7 | import {MultipleLifetimesAppWorker} from "./appWorker"; |
| 8 | import {ErrorHelper} from "../common/error/errorHelper"; |
| 9 | import {InternalErrorCode} from "../common/error/internalErrorCode"; |
| 10 | import {ScriptImporter} from "./scriptImporter"; |
| 11 | import {TelemetryHelper} from "../common/telemetryHelper"; |
| 12 | import {Log} from "../common/log/log"; |
| 13 | import {RemoteExtension} from "../common/remoteExtension"; |
| 14 | import {EntryPointHandler, ProcessType} from "../common/entryPointHandler"; |
| 15 | |
| 16 | export class Launcher { |
| 17 | private workspaceRootPath: string; |
| 18 | private projectRootPath: string; |
| 19 | private remoteExtension: RemoteExtension; |
| 20 | |
| 21 | constructor(workspaceRootPath: string, projectRootPath: string) { |
| 22 | this.workspaceRootPath = workspaceRootPath; |
| 23 | this.projectRootPath = projectRootPath; |
| 24 | this.remoteExtension = RemoteExtension.atProjectRootPath(this.projectRootPath); |
| 25 | } |
| 26 | |
| 27 | public launch(): void { |
| 28 | const debugAdapterPort = parseInt(process.argv[2], 10) || 9090; |
| 29 | // Enable telemetry |
| 30 | new EntryPointHandler(ProcessType.Debugee).runApp("react-native-debug-process", () => this.getAppVersion(), |
| 31 | ErrorHelper.getInternalError(InternalErrorCode.DebuggingFailed), this.projectRootPath, () => { |
| 32 | return TelemetryHelper.generate("launch", (generator) => { |
| 33 | const sourcesStoragePath = path.join(this.workspaceRootPath, ".vscode", ".react"); |
| 34 | return this.remoteExtension.getPackagerPort().then(packagerPort => { |
| 35 | let scriptImporter = new ScriptImporter(packagerPort, sourcesStoragePath); |
| 36 | return scriptImporter.downloadDebuggerWorker(sourcesStoragePath).then(() => { |
| 37 | Log.logMessage("Downloaded debuggerWorker.js (Logic to run the React Native app) from the Packager."); |
| 38 | }).then(() => { |
| 39 | generator.step("Starting App Worker"); |
| 40 | Log.logMessage("Starting debugger app worker."); |
| 41 | return new MultipleLifetimesAppWorker(packagerPort, sourcesStoragePath, debugAdapterPort).start(); |
| 42 | }).then(() => |
| 43 | Log.logMessage("Debugging session started successfully.")); |
| 44 | }); |
| 45 | }); |
| 46 | } |
| 47 | ); |
| 48 | } |
| 49 | |
| 50 | private getAppVersion() { |
| 51 | return JSON.parse(fs.readFileSync(path.join(__dirname, "..", "..", "package.json"), "utf-8")).version; |
| 52 | } |
| 53 | } |
| 54 | |