microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/commands/killPort.ts
33lines · modeblame
f1cb0a40lexie0111 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 * as assert from "assert"; | |
| 5 | import * as vscode from "vscode"; | |
| 6 | import { ErrorHelper } from "../../common/error/errorHelper"; | |
| 7 | import { InternalErrorCode } from "../../common/error/internalErrorCode"; | |
| 8 | import { ChildProcess } from "../../common/node/childProcess"; | |
| 9 | import { OutputChannelLogger } from "../log/OutputChannelLogger"; | |
| 10 | import { wait } from "../../common/utils"; | |
7a4506dclexie0111 years ago | 11 | import { ReactNativeCommand } from "./util/reactNativeCommand"; |
f1cb0a40lexie0111 years ago | 12 | |
| 13 | const logger = OutputChannelLogger.getMainChannel(); | |
| 14 | export class killPort extends ReactNativeCommand { | |
| 15 | codeName = "killPort"; | |
| 16 | label = "Kill Port"; | |
| 17 | error = ErrorHelper.getInternalError(InternalErrorCode.FailedToKillPort); | |
| 18 | | |
| 19 | async baseFn(): Promise<void> { | |
| 20 | assert(this.project); | |
| 21 | await wait(); | |
| 22 | await vscode.window | |
| 23 | .showInputBox({ placeHolder: "please enter the port you want to kill" }) | |
| 24 | .then(async value => { | |
| 25 | if (value) { | |
| 26 | const res = await new ChildProcess().exec(`npx kill-port ${value}`); | |
| 27 | logger.info(`killing port ${value}, it may take a while...`); | |
| 28 | const outcome = await res.outcome; | |
| 29 | logger.info(outcome); | |
| 30 | } | |
| 31 | }); | |
| 32 | } | |
| 33 | } |