microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.11.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

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
4import * as assert from "assert";
5import * as nls from "vscode-nls";
6import * as vscode from "vscode";
7import { OutputChannelLogger } from "../log/OutputChannelLogger";
8import { ErrorHelper } from "../../common/error/errorHelper";
9import { InternalErrorCode } from "../../common/error/internalErrorCode";
10import * as XDL from "../exponent/xdlInterface";
11import { RunExponent } from "./runExponent";
12import { loginToExponent } from "./util";
13import { ReactNativeCommand } from "./util/reactNativeCommand";
14
15nls.config({
16 messageFormat: nls.MessageFormat.bundle,
17 bundleFormat: nls.BundleFormat.standalone,
18})();
19const localize = nls.loadMessageBundle();
20
21const logger = OutputChannelLogger.getMainChannel();
22
23export 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