microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.6.5

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/appcenter/appCenterCommandPalleteHandler.ts

106lines · modeblame

bb45fbe6max-mironov8 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import { ILogger, LogLevel } from "../log/LogHelper";
5import * as Q from "q";
6import { AppCenterCommandExecutor } from "./command/commandExecutor";
7import Auth from "../appcenter/auth/auth";
8import { AppCenterClient } from "./api/index";
a653acfemax-mironov8 years ago9import { Profile } from "./auth/profile/profile";
bb45fbe6max-mironov8 years ago10import { AppCenterClientFactory, createAppCenterClient } from "./api/createClient";
11import { SettingsHelper } from "../settingsHelper";
640e6e98max-mironov8 years ago12import { AppCenterCommandType } from "./appCenterConstants";
13import { AppCenterExtensionManager } from "./appCenterExtensionManager";
6a465861max-mironov8 years ago14import { ACStrings } from "./appCenterStrings";
a653acfemax-mironov8 years ago15import { ACUtils } from "./helpers/utils";
16import { VsCodeUtils } from "./helpers/vscodeUtils";
bb45fbe6max-mironov8 years ago17
18export class AppCenterCommandPalleteHandler {
19private commandExecutor: AppCenterCommandExecutor;
20private client: AppCenterClient;
21private logger: ILogger;
22private clientFactory: AppCenterClientFactory;
18c1b13amax-mironov8 years ago23private appCenterManager: AppCenterExtensionManager;
bb45fbe6max-mironov8 years ago24
25constructor(logger: ILogger) {
26this.commandExecutor = new AppCenterCommandExecutor(logger);
27this.clientFactory = createAppCenterClient();
28this.logger = logger;
29}
30
18c1b13amax-mironov8 years ago31public set AppCenterManager(manager: AppCenterExtensionManager) {
32this.appCenterManager = manager;
33}
34
35public run(command: AppCenterCommandType): Q.Promise<void> {
e96aa5fcmax-mironov8 years ago36return ACUtils.isCodePushProject(this.appCenterManager.projectRootPath).then((isCodePush: boolean) => {
37if (!isCodePush) {
38VsCodeUtils.ShowWarningMessage(ACStrings.NoCodePushDetectedMsg);
24edcbd0max-mironov8 years ago39return Q.resolve(void 0);
e96aa5fcmax-mironov8 years ago40} else {
41// Login is special case
42if (command === AppCenterCommandType.Login) {
43return this.commandExecutor.login(this.appCenterManager);
44}
45
46return Auth.getProfile(this.appCenterManager.projectRootPath).then((profile: Profile) => {
47if (!profile) {
48VsCodeUtils.ShowWarningMessage(ACStrings.UserIsNotLoggedInMsg);
49return Q.resolve(void 0);
50} else {
51const clientOrNull: AppCenterClient | null = this.resolveAppCenterClient(profile);
52if (clientOrNull) {
53this.client = clientOrNull;
bb45fbe6max-mironov8 years ago54
e96aa5fcmax-mironov8 years ago55switch (command) {
56case (AppCenterCommandType.Logout):
57return this.commandExecutor.logout(this.appCenterManager);
bb45fbe6max-mironov8 years ago58
e96aa5fcmax-mironov8 years ago59case (AppCenterCommandType.Whoami):
60return this.commandExecutor.whoAmI(this.appCenterManager);
bb45fbe6max-mironov8 years ago61
e96aa5fcmax-mironov8 years ago62case (AppCenterCommandType.SetCurrentApp):
63return this.commandExecutor.setCurrentApp(this.client, this.appCenterManager);
640e6e98max-mironov8 years ago64
e96aa5fcmax-mironov8 years ago65case (AppCenterCommandType.GetCurrentApp):
66return this.commandExecutor.getCurrentApp(this.appCenterManager);
6a465861max-mironov8 years ago67
e96aa5fcmax-mironov8 years ago68case (AppCenterCommandType.SetCurrentDeployment):
69return this.commandExecutor.setCurrentDeployment(this.appCenterManager);
4a66f08bmax-mironov8 years ago70
e96aa5fcmax-mironov8 years ago71case (AppCenterCommandType.CodePushReleaseReact):
72return this.commandExecutor.releaseReact(this.client, this.appCenterManager);
6a465861max-mironov8 years ago73
e96aa5fcmax-mironov8 years ago74case (AppCenterCommandType.ShowMenu):
75return this.commandExecutor.showMenu(this.client, this.appCenterManager);
ef14e11bmax-mironov8 years ago76
e96aa5fcmax-mironov8 years ago77case (AppCenterCommandType.SwitchMandatoryPropForRelease):
78return this.commandExecutor.switchIsMandatoryForRelease(this.appCenterManager);
2ceda59emax-mironov8 years ago79
e96aa5fcmax-mironov8 years ago80case (AppCenterCommandType.SetTargetBinaryVersionForRelease):
81return this.commandExecutor.setTargetBinaryVersionForRelease(this.appCenterManager);
2ceda59emax-mironov8 years ago82
e96aa5fcmax-mironov8 years ago83default:
84throw new Error("Unknown App Center command!");
85}
86} else {
87this.logger.log("Failed to get App Center client", LogLevel.Error);
88throw new Error("Failed to get App Center client!");
89}
bb45fbe6max-mironov8 years ago90}
e96aa5fcmax-mironov8 years ago91});
92}
bb45fbe6max-mironov8 years ago93});
94}
95
a653acfemax-mironov8 years ago96private resolveAppCenterClient(profile: Profile): AppCenterClient | null {
bb45fbe6max-mironov8 years ago97if (!this.client) {
a653acfemax-mironov8 years ago98if (profile) {
99return this.clientFactory.fromProfile(profile, SettingsHelper.getAppCenterAPIEndpoint());
bb45fbe6max-mironov8 years ago100} else {
a653acfemax-mironov8 years ago101throw new Error("No App Center user specified!");
bb45fbe6max-mironov8 years ago102}
103}
104return this.client;
105}
106}