microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/utils/reactNativeCommandExecutor.ts
43lines · modeblame
bef522ffMeena Kunnathur Balakrishnan10 years ago | 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 {CommandExecutor} from "./commands/commandExecutor"; | |
| 5 | import {PlatformResolver} from "./../debugger/platformResolver"; | |
| 6 | import {Packager} from "./../debugger/packager"; | |
| 7 | import {window} from "vscode"; | |
| 8 | | |
| 9 | export class ReactNativeCommandExecutor { | |
| 10 | private reactNativePackager: Packager; | |
| 11 | private workspaceRoot: string; | |
| 12 | | |
| 13 | constructor(workspaceRoot: string) { | |
| 14 | this.workspaceRoot = workspaceRoot; | |
| 15 | this.reactNativePackager = new Packager(workspaceRoot); | |
| 16 | } | |
| 17 | | |
0904a0d7Meena Kunnathur Balakrishnan10 years ago | 18 | /** |
| 19 | * Executes a react-native command | |
| 20 | * {command} - the react-native command to be executed | |
| 21 | */ | |
bef522ffMeena Kunnathur Balakrishnan10 years ago | 22 | public executeReactNativeCommand(command: string): void { |
| 23 | let resolver = new PlatformResolver(); | |
| 24 | let desktopPlatform = resolver.resolveDesktopPlatform(); | |
| 25 | | |
| 26 | // Invoke "react-native" with the command passed | |
| 27 | return new CommandExecutor(this.workspaceRoot).spawn(desktopPlatform.reactNativeCommandName, [command], {}, window.createOutputChannel("React-Native")).done(); | |
| 28 | } | |
| 29 | | |
0904a0d7Meena Kunnathur Balakrishnan10 years ago | 30 | /** |
| 31 | * Starts the React Native packager | |
| 32 | */ | |
bef522ffMeena Kunnathur Balakrishnan10 years ago | 33 | public startPackager(): void { |
088101adMeena Kunnathur Balakrishnan10 years ago | 34 | return this.reactNativePackager.start(true, window.createOutputChannel("React-Native")).done(); |
bef522ffMeena Kunnathur Balakrishnan10 years ago | 35 | } |
| 36 | | |
0904a0d7Meena Kunnathur Balakrishnan10 years ago | 37 | /** |
| 38 | * Kills the React Native packager invoked by the extension's packager | |
| 39 | */ | |
bef522ffMeena Kunnathur Balakrishnan10 years ago | 40 | public stopPackager(): void { |
| 41 | return this.reactNativePackager.stop(window.createOutputChannel("React-Native")); | |
| 42 | } | |
| 43 | } |