microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/debugger/launcher.ts
55lines · 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 * as path from "path"; |
| 6 | import {MultipleLifetimesAppWorker} from "./appWorker"; |
| 7 | import {Packager} from "./packager"; |
| 8 | import {Log} from "../utils/commands/log"; |
| 9 | import {PlatformResolver} from "./platformResolver"; |
| 10 | import {IRunOptions} from "./launchArgs"; |
| 11 | |
| 12 | export class Launcher { |
| 13 | private projectRootPath: string; |
| 14 | |
| 15 | constructor(projectRootPath: string) { |
| 16 | this.projectRootPath = projectRootPath; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Parses the launch arguments set in the launch configuration. |
| 21 | */ |
| 22 | private parseRunOptions(): IRunOptions { |
| 23 | let result: IRunOptions = { projectRoot: this.projectRootPath }; |
| 24 | |
| 25 | if (process.argv.length > 2) { |
| 26 | result.platform = process.argv[2].toLowerCase(); |
| 27 | } |
| 28 | |
| 29 | result.target = process.argv[3]; |
| 30 | |
| 31 | return result; |
| 32 | } |
| 33 | |
| 34 | public launch() { |
| 35 | let resolver = new PlatformResolver(); |
| 36 | let runOptions = this.parseRunOptions(); |
| 37 | let desktopPlatform = resolver.resolveDesktopPlatform(); |
| 38 | let mobilePlatform = resolver.resolveMobilePlatform(runOptions.platform, desktopPlatform); |
| 39 | if (!mobilePlatform) { |
| 40 | Log.logError("The target platform could not be read. Did you forget to add it to the launch.json configuration arguments?"); |
| 41 | } else { |
| 42 | let sourcesStoragePath = path.join(this.projectRootPath, ".vscode"); |
| 43 | // TODO: We need to remove all the delays, yet make sure things work properly for both Android and iOS |
| 44 | Q({}) |
| 45 | .then(() => Q.delay(new Packager(this.projectRootPath, desktopPlatform, sourcesStoragePath).start(), 3000)) |
| 46 | .then(() => Q.delay(mobilePlatform.runApp(runOptions), 3000)) |
| 47 | .then(() => Q.delay(new MultipleLifetimesAppWorker(sourcesStoragePath).start(), 3000)) // Start the app worker |
| 48 | .then(() => mobilePlatform.enableJSDebuggingMode(runOptions)) |
| 49 | .done(() => { }, reason => { |
| 50 | Log.logError("Cannot debug application.", reason); |
| 51 | }); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | |