microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/utils/reactNativeCommandExecutor.ts
43lines · 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 {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 | |
| 18 | /** |
| 19 | * Executes a react-native command |
| 20 | * {command} - the react-native command to be executed |
| 21 | */ |
| 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 | |
| 30 | /** |
| 31 | * Starts the React Native packager |
| 32 | */ |
| 33 | public startPackager(): void { |
| 34 | return this.reactNativePackager.start(true, window.createOutputChannel("React-Native")).done(); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Kills the React Native packager invoked by the extension's packager |
| 39 | */ |
| 40 | public stopPackager(): void { |
| 41 | return this.reactNativePackager.stop(window.createOutputChannel("React-Native")); |
| 42 | } |
| 43 | } |
| 44 | |