microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/commands/openRNUpgradeHelper.ts
59lines · 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 assert from "assert"; |
| 5 | import * as nls from "vscode-nls"; |
| 6 | import * as vscode from "vscode"; |
| 7 | import { OutputChannelLogger } from "../log/OutputChannelLogger"; |
| 8 | import { ErrorHelper } from "../../common/error/errorHelper"; |
| 9 | import { InternalErrorCode } from "../../common/error/internalErrorCode"; |
| 10 | import { wait } from "../../common/utils"; |
| 11 | import { Command } from "./util/command"; |
| 12 | |
| 13 | nls.config({ |
| 14 | messageFormat: nls.MessageFormat.bundle, |
| 15 | bundleFormat: nls.BundleFormat.standalone, |
| 16 | })(); |
| 17 | const localize = nls.loadMessageBundle(); |
| 18 | const logger = OutputChannelLogger.getMainChannel(); |
| 19 | |
| 20 | export class OpenRNUpgradeHelper extends Command { |
| 21 | codeName = "openRNUpgradeHelper"; |
| 22 | label = "Open react native upgrade helper in web page"; |
| 23 | error = ErrorHelper.getInternalError(InternalErrorCode.FailedToOpenRNUpgradeHelper); |
| 24 | |
| 25 | async baseFn(): Promise<void> { |
| 26 | assert(this.project); |
| 27 | const RNUrl = |
| 28 | "https://react-native-community.github.io/upgrade-helper/?package=react-native"; |
| 29 | const RNWUrl = |
| 30 | "https://react-native-community.github.io/upgrade-helper/?package=react-native-windows&language=cpp"; |
| 31 | const RNMUrl = |
| 32 | "https://react-native-community.github.io/upgrade-helper/?package=react-native-macos"; |
| 33 | |
| 34 | await wait(); |
| 35 | const item = await vscode.window.showQuickPick( |
| 36 | ["React Native", "React Native Windows", "React Native MacOS"], |
| 37 | { |
| 38 | placeHolder: "Select type for your react native project", |
| 39 | }, |
| 40 | ); |
| 41 | |
| 42 | logger.info( |
| 43 | localize("OpenInWebBrowser", "Open react native upgrade helper in web browser."), |
| 44 | ); |
| 45 | |
| 46 | switch (item) { |
| 47 | case "React Native": |
| 48 | await vscode.env.openExternal(vscode.Uri.parse(RNUrl)); |
| 49 | break; |
| 50 | case "React Native Windows": |
| 51 | await vscode.env.openExternal(vscode.Uri.parse(RNWUrl)); |
| 52 | break; |
| 53 | case "React Native MacOS": |
| 54 | await vscode.env.openExternal(vscode.Uri.parse(RNMUrl)); |
| 55 | break; |
| 56 | default: |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |