microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/debugger/launcher.ts
54lines · modecode
| 1 | /// <reference path="../typings/vscode-react-native/vscode-react-native" /> |
| 2 | |
| 3 | import * as Q from "q"; |
| 4 | import {DebuggerWorker} from "./debuggerWorker"; |
| 5 | import {Package} from "../utils/node/package"; |
| 6 | import {Packager} from "./packager"; |
| 7 | import {Log} from "../utils/commands/log"; |
| 8 | |
| 9 | export class Launcher { |
| 10 | private debugStrategy: IDebugStrategy; |
| 11 | private projectRootPath: string; |
| 12 | |
| 13 | constructor(projectRootPath: string) { |
| 14 | this.projectRootPath = projectRootPath; |
| 15 | } |
| 16 | |
| 17 | private appPlatform(): string { |
| 18 | let launchArguments = process.argv.slice(2); |
| 19 | return launchArguments[0].toLowerCase(); |
| 20 | } |
| 21 | |
| 22 | private reactNativeProject(): Package { |
| 23 | return new Package(this.projectRootPath); |
| 24 | } |
| 25 | |
| 26 | private createDebugStrategy(): IDebugStrategy { |
| 27 | let platform = this.appPlatform(); |
| 28 | switch (platform) { |
| 29 | // We lazyly load the strategies, because some components might be |
| 30 | // missing on some platforms (like XCode in Windows) |
| 31 | case "ios": |
| 32 | let iosDebugStrategy = require("./ios/iosDebugStrategy"); |
| 33 | return new iosDebugStrategy.IOSDebugStrategy(this.reactNativeProject()); |
| 34 | case "android": |
| 35 | let androidDebugStrategy = require("./android/androidDebugStrategy"); |
| 36 | return new androidDebugStrategy.AndroidDebugStrategy(this.reactNativeProject()); |
| 37 | default: |
| 38 | throw new RangeError("The platform <" + platform + "> is not a valid react-native platform."); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | public launch() { |
| 43 | this.debugStrategy = this.createDebugStrategy(); |
| 44 | |
| 45 | return Q({}) |
| 46 | .then(() => Q.delay(new Packager(this.projectRootPath).start(), 3000)) |
| 47 | .then(() => Q.delay(this.debugStrategy.runApp(), 3000)) |
| 48 | .then(() => Q.delay(new DebuggerWorker(this.projectRootPath).start(), 3000)) // Start the worker |
| 49 | .then(() => this.debugStrategy.enableJSDebuggingMode()) |
| 50 | .done(() => { }, reason => { |
| 51 | Log.logError("Cannot debug application.", reason); |
| 52 | }); |
| 53 | } |
| 54 | } |
| 55 | |