microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/commands/publishToExpHost.ts
71lines · 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 * as XDL from "../exponent/xdlInterface"; |
| 11 | import { RunExponent } from "./runExponent"; |
| 12 | import { loginToExponent } from "./util"; |
| 13 | import { ReactNativeCommand } from "./util/reactNativeCommand"; |
| 14 | |
| 15 | nls.config({ |
| 16 | messageFormat: nls.MessageFormat.bundle, |
| 17 | bundleFormat: nls.BundleFormat.standalone, |
| 18 | })(); |
| 19 | const localize = nls.loadMessageBundle(); |
| 20 | |
| 21 | const logger = OutputChannelLogger.getMainChannel(); |
| 22 | |
| 23 | export class PublishToExpHost extends ReactNativeCommand { |
| 24 | codeName = "publishToExpHost"; |
| 25 | label = "Publish To Expo Host"; |
| 26 | error = ErrorHelper.getInternalError(InternalErrorCode.FailedToPublishToExpHost); |
| 27 | |
| 28 | async baseFn(): Promise<void> { |
| 29 | if (!(await this.executePublishToExpHost())) { |
| 30 | logger.warning( |
| 31 | localize( |
| 32 | "ExponentPublishingWasUnsuccessfulMakeSureYoureLoggedInToExpo", |
| 33 | "Publishing was unsuccessful. Please make sure you are logged in Expo and your project is a valid Expo project", |
| 34 | ), |
| 35 | ); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | private async executePublishToExpHost(): Promise<boolean> { |
| 40 | assert(this.project); |
| 41 | |
| 42 | logger.info( |
| 43 | localize( |
| 44 | "PublishingAppToExponentServer", |
| 45 | "Publishing app to Expo server. This might take a moment.", |
| 46 | ), |
| 47 | ); |
| 48 | |
| 49 | const user = await loginToExponent(this.project); |
| 50 | |
| 51 | logger.debug(`Publishing as ${user.username}...`); |
| 52 | |
| 53 | await RunExponent.prototype.baseFn.bind(this)(); |
| 54 | const response = await XDL.publish(this.project.getWorkspaceFolderUri().fsPath); |
| 55 | |
| 56 | if (response.err || !response.url) { |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | const publishedOutput = localize( |
| 61 | "ExpoAppSuccessfullyPublishedTo", |
| 62 | "Expo app successfully published to {0}", |
| 63 | response.url, |
| 64 | ); |
| 65 | |
| 66 | logger.info(publishedOutput); |
| 67 | |
| 68 | void vscode.window.showInformationMessage(publishedOutput); |
| 69 | return true; |
| 70 | } |
| 71 | } |
| 72 | |