microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/debugger/launcher.ts
52lines · 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 Q from "q"; |
| 5 | import {DebuggerWorker} from "./debuggerWorker"; |
| 6 | import {Packager} from "./packager"; |
| 7 | import {Log} from "../utils/commands/log"; |
| 8 | import {PlatformResolver} from "./platformResolver"; |
| 9 | import {IRunOptions} from "./launchArgs"; |
| 10 | |
| 11 | export class Launcher { |
| 12 | private projectRootPath: string; |
| 13 | |
| 14 | constructor(projectRootPath: string) { |
| 15 | this.projectRootPath = projectRootPath; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Parses the launch arguments set in the launch configuration. |
| 20 | */ |
| 21 | private parseRunOptions(): IRunOptions { |
| 22 | let result: IRunOptions = { projectRoot: this.projectRootPath }; |
| 23 | |
| 24 | if (process.argv.length > 2) { |
| 25 | result.platform = process.argv[2].toLowerCase(); |
| 26 | } |
| 27 | |
| 28 | result.target = process.argv[3]; |
| 29 | |
| 30 | return result; |
| 31 | } |
| 32 | |
| 33 | public launch() { |
| 34 | let resolver = new PlatformResolver(); |
| 35 | let runOptions = this.parseRunOptions(); |
| 36 | let desktopPlatform = resolver.resolveDesktopPlatform(); |
| 37 | let mobilePlatform = resolver.resolveMobilePlatform(runOptions.platform, desktopPlatform); |
| 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 | Q({}) |
| 42 | .then(() => Q.delay(new Packager(this.projectRootPath, desktopPlatform).start(), 3000)) |
| 43 | .then(() => Q.delay(mobilePlatform.runApp(runOptions), 3000)) |
| 44 | .then(() => Q.delay(new DebuggerWorker(this.projectRootPath).start(), 3000)) // Start the worker |
| 45 | .then(() => mobilePlatform.enableJSDebuggingMode(runOptions)) |
| 46 | .done(() => { }, reason => { |
| 47 | Log.logError("Cannot debug application.", reason); |
| 48 | }); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | |