microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.6.4

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/appcenter/command/commandExecutor.ts

497lines · 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 * as vscode from "vscode";
5import * as Q from "q";
6import * as qs from "qs";
7import * as os from "os";
8
9import { ILogger, LogLevel } from "../../log/LogHelper";
10import Auth from "../../appcenter/auth/auth";
2ceda59emax-mironov8 years ago11import { AppCenterLoginType, ACConstants, AppCenterOS, CurrentAppDeployments, Deployment, ACCommandNames } from "../appCenterConstants";
ef14e11bmax-mironov8 years ago12import { Profile } from "../../appcenter/auth/profile/profile";
bb45fbe6max-mironov8 years ago13import { SettingsHelper } from "../../settingsHelper";
e26df9e4max-mironov8 years ago14import { AppCenterClient, models } from "../api/index";
ff1d5ab0max-mironov8 years ago15import { DefaultApp, ICodePushReleaseParams } from "./commandParams";
640e6e98max-mironov8 years ago16import { AppCenterExtensionManager } from "../appCenterExtensionManager";
6a465861max-mironov8 years ago17import { ACStrings } from "../appCenterStrings";
bf370babSergey Akhalkov8 years ago18import CodePushRelease from "../codepush/release";
a653acfemax-mironov8 years ago19import { ACUtils } from "../helpers/utils";
85a7b4aaannakocheshkova8 years ago20import { updateContents, reactNative, fileUtils } from "../codepush/codepush-sdk/src/index";
a446900cSergey Akhalkov8 years ago21import BundleConfig = reactNative.BundleConfig;
e26df9e4max-mironov8 years ago22import { getQPromisifiedClientResult } from "../api/createClient";
2ceda59emax-mironov8 years ago23import { validRange } from "semver";
24edcbd0max-mironov8 years ago24import { VsCodeUtils, IButtonMessageItem } from "../helpers/vscodeUtils";
bb45fbe6max-mironov8 years ago25
26interface IAppCenterAuth {
640e6e98max-mironov8 years ago27login(appcenterManager: AppCenterExtensionManager): Q.Promise<void>;
6a465861max-mironov8 years ago28logout(appcenterManager: AppCenterExtensionManager): Q.Promise<void>;
a653acfemax-mironov8 years ago29whoAmI(appCenterManager: AppCenterExtensionManager): Q.Promise<void>;
6a465861max-mironov8 years ago30}
31
32interface IAppCenterApps {
2ceda59emax-mironov8 years ago33getCurrentApp(appCenterManager: AppCenterExtensionManager): Q.Promise<void>;
e26df9e4max-mironov8 years ago34setCurrentApp(client: AppCenterClient, appCenterManager: AppCenterExtensionManager): Q.Promise<void>;
4a66f08bmax-mironov8 years ago35setCurrentDeployment(appCenterManager: AppCenterExtensionManager): Q.Promise<void>;
bb45fbe6max-mironov8 years ago36}
37
38interface IAppCenterCodePush {
ef14e11bmax-mironov8 years ago39showMenu(client: AppCenterClient, appCenterManager: AppCenterExtensionManager): Q.Promise<void>;
6a465861max-mironov8 years ago40releaseReact(client: AppCenterClient, appCenterManager: AppCenterExtensionManager): Q.Promise<void>;
2ceda59emax-mironov8 years ago41switchIsMandatoryForRelease(appCenterManager: AppCenterExtensionManager): Q.Promise<void>;
42setTargetBinaryVersionForRelease(appCenterManager: AppCenterExtensionManager): Q.Promise<void>;
bb45fbe6max-mironov8 years ago43}
44
6a465861max-mironov8 years ago45export class AppCenterCommandExecutor implements IAppCenterAuth, IAppCenterCodePush, IAppCenterApps {
bb45fbe6max-mironov8 years ago46private logger: ILogger;
47
48constructor(logger: ILogger) {
49this.logger = logger;
50}
51
640e6e98max-mironov8 years ago52public login(appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
b73e66f1max-mironov8 years ago53const appCenterLoginOptions: string[] = Object.keys(AppCenterLoginType).filter(k => typeof AppCenterLoginType[k as any] === "number");
6a465861max-mironov8 years ago54vscode.window.showQuickPick(appCenterLoginOptions, { placeHolder: ACStrings.SelectLoginTypeMsg })
ef14e11bmax-mironov8 years ago55.then((loginType) => {
56switch (loginType) {
57case (AppCenterLoginType[AppCenterLoginType.Interactive]):
24edcbd0max-mironov8 years ago58const messageItems: IButtonMessageItem[] = [];
59const loginUrl = `${SettingsHelper.getAppCenterLoginEndpoint()}?${qs.stringify({ hostname: os.hostname()})}`;
60messageItems.push({ title : ACStrings.OkBtnLabel,
61url : loginUrl });
62
63return VsCodeUtils.ShowInformationMessage(ACStrings.PleaseLoginViaBrowser, ...messageItems)
64.then((selection: IButtonMessageItem | undefined) => {
65if (selection) {
ef14e11bmax-mironov8 years ago66return vscode.window.showInputBox({ prompt: ACStrings.PleaseProvideToken, ignoreFocusOut: true })
67.then(token => {
68this.loginWithToken(token, appCenterManager);
69});
70} else return Q.resolve(void 0);
71});
72case (AppCenterLoginType[AppCenterLoginType.Token]):
73return vscode.window.showInputBox({ prompt: ACStrings.PleaseProvideToken , ignoreFocusOut: true})
74.then(token => {
75return this.loginWithToken(token, appCenterManager);
76});
77default:
78// User canel login otherwise
79return Q.resolve(void 0);
80}
bb45fbe6max-mironov8 years ago81});
b73e66f1max-mironov8 years ago82return Q.resolve(void 0);
bb45fbe6max-mironov8 years ago83}
84
6a465861max-mironov8 years ago85public logout(appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
2ceda59emax-mironov8 years ago86return Auth.doLogout(appCenterManager.projectRootPath).then(() => {
24edcbd0max-mironov8 years ago87VsCodeUtils.ShowInformationMessage(ACStrings.UserLoggedOutMsg);
ef14e11bmax-mironov8 years ago88return appCenterManager.setupAppCenterStatusBar(null);
89}).catch(() => {
90this.logger.log("An errro occured on logout", LogLevel.Error);
91});
bb45fbe6max-mironov8 years ago92}
93
a653acfemax-mironov8 years ago94public whoAmI(appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
95return Auth.getProfile(appCenterManager.projectRootPath).then((profile: Profile | null) => {
96if (profile && profile.displayName) {
24edcbd0max-mironov8 years ago97VsCodeUtils.ShowInformationMessage(ACStrings.YouAreLoggedInMsg(profile.displayName));
a653acfemax-mironov8 years ago98} else {
24edcbd0max-mironov8 years ago99VsCodeUtils.ShowInformationMessage(ACStrings.UserIsNotLoggedInMsg);
a653acfemax-mironov8 years ago100}
24edcbd0max-mironov8 years ago101return Q.resolve(void 0);
a653acfemax-mironov8 years ago102});
bb45fbe6max-mironov8 years ago103}
104
4a66f08bmax-mironov8 years ago105public setCurrentDeployment(appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
2ceda59emax-mironov8 years ago106this.restoreCurrentApp(appCenterManager.projectRootPath)
107.then((currentApp: DefaultApp) => {
108if (currentApp && currentApp.currentAppDeployments && currentApp.currentAppDeployments.codePushDeployments) {
109const deploymentOptions: string[] = currentApp.currentAppDeployments.codePushDeployments.map((deployment) => {
110return deployment.name;
111});
112vscode.window.showQuickPick(deploymentOptions, { placeHolder: ACStrings.SelectCurrentDeploymentMsg })
113.then((deploymentName) => {
114if (deploymentName) {
115this.saveCurrentApp(
116appCenterManager.projectRootPath,
117currentApp.identifier,
118AppCenterOS[currentApp.os], {
119currentDeploymentName: deploymentName,
120codePushDeployments: currentApp.currentAppDeployments.codePushDeployments,
121},
122currentApp.targetBinaryVersion,
123currentApp.isMandatory
d3db396bmax-mironov8 years ago124);
125VsCodeUtils.ShowInformationMessage(ACStrings.YourCurrentDeploymentMsg(deploymentName));
4a66f08bmax-mironov8 years ago126}
127});
d3db396bmax-mironov8 years ago128} else {
129VsCodeUtils.ShowInformationMessage(ACStrings.NoCurrentAppSetMsg);
4a66f08bmax-mironov8 years ago130}
131});
132return Q.resolve(void 0);
133}
134
2ceda59emax-mironov8 years ago135public getCurrentApp(appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
136this.restoreCurrentApp(appCenterManager.projectRootPath).then((app: DefaultApp) => {
84abb0c7max-mironov8 years ago137if (app) {
24edcbd0max-mironov8 years ago138VsCodeUtils.ShowInformationMessage(ACStrings.YourCurrentAppMsg(app.identifier));
84abb0c7max-mironov8 years ago139} else {
24edcbd0max-mironov8 years ago140VsCodeUtils.ShowInformationMessage(ACStrings.NoCurrentAppSetMsg);
84abb0c7max-mironov8 years ago141}
86466695max-mironov8 years ago142});
6a465861max-mironov8 years ago143return Q.resolve(void 0);
bb45fbe6max-mironov8 years ago144}
640e6e98max-mironov8 years ago145
e26df9e4max-mironov8 years ago146public setCurrentApp(client: AppCenterClient, appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
7574c61amax-mironov8 years ago147vscode.window.withProgress({ location: vscode.ProgressLocation.Window, title: "Get Apps"}, p => {
148return new Promise((resolve, reject) => {
149p.report({message: ACStrings.FetchAppsStatusBarMessage });
150getQPromisifiedClientResult(client.account.apps.list()).then((apps: models.AppResponse[]) => {
151const appsList: models.AppResponse[] = apps;
152const reactNativeApps = appsList.filter(app => app.platform === ACConstants.AppCenterReactNativePlatformName);
153resolve(reactNativeApps);
154});
155});
156}).then((rnApps: models.AppResponse[]) => {
157let options = rnApps.map(app => {
e26df9e4max-mironov8 years ago158return {
159label: `${app.name} (${app.os})`,
160description: app.displayName,
161target: app.name,
162};
163});
164vscode.window.showQuickPick(options, { placeHolder: ACStrings.ProvideCurrentAppPromptMsg })
165.then((selected: {label: string, description: string, target: string}) => {
166if (selected) {
7574c61amax-mironov8 years ago167const selectedApps: models.AppResponse[] = rnApps.filter(app => app.name === selected.target);
e26df9e4max-mironov8 years ago168if (selectedApps && selectedApps.length === 1) {
169const selectedApp: models.AppResponse = selectedApps[0];
170const selectedAppName: string = `${selectedApp.owner.name}/${selectedApp.name}`;
2ceda59emax-mironov8 years ago171const OS: AppCenterOS = AppCenterOS[selectedApp.os.toLowerCase()];
7574c61amax-mironov8 years ago172
173vscode.window.withProgress({ location: vscode.ProgressLocation.Window, title: "Get Deployments"}, p => {
174return new Promise((resolve, reject) => {
175p.report({message: ACStrings.FetchDeploymentsStatusBarMessage });
176getQPromisifiedClientResult(client.codepush.codePushDeployments.list(selectedApp.name, selectedApp.owner.name))
177.then((deployments: models.Deployment[]) => {
ef14e11bmax-mironov8 years ago178resolve(deployments.sort((a, b): any => {
179return a.name < b.name; // sort alphabetically
180}));
7574c61amax-mironov8 years ago181});
182});
ef14e11bmax-mironov8 years ago183})
184.then((appDeployments: models.Deployment[]) => {
185let currentDeployments: CurrentAppDeployments | null = null;
7574c61amax-mironov8 years ago186if (appDeployments.length > 0) {
2ceda59emax-mironov8 years ago187const deployments: Deployment[] = appDeployments.map((d) => {
188return {
189name: d.name,
190};
191});
ef14e11bmax-mironov8 years ago192currentDeployments = {
2ceda59emax-mironov8 years ago193codePushDeployments: deployments,
7574c61amax-mironov8 years ago194currentDeploymentName: appDeployments[0].name, // Select 1st one by default
4a66f08bmax-mironov8 years ago195};
e26df9e4max-mironov8 years ago196}
2ceda59emax-mironov8 years ago197this.saveCurrentApp(
198appCenterManager.projectRootPath,
199selectedAppName,
200OS,
201currentDeployments,
202ACConstants.AppCenterDefaultTargetBinaryVersion,
203ACConstants.AppCenterDefaultIsMandatoryParam)
ef14e11bmax-mironov8 years ago204.then((app: DefaultApp | null) => {
4a66f08bmax-mironov8 years ago205if (app) {
24edcbd0max-mironov8 years ago206return VsCodeUtils.ShowInformationMessage(ACStrings.YourCurrentAppAndDeployemntMsg(selected.target
ef14e11bmax-mironov8 years ago207, app.currentAppDeployments.currentDeploymentName));
208} else {
209this.logger.error("Failed to save current app");
210return Q.resolve(void 0);
4a66f08bmax-mironov8 years ago211}
212});
e26df9e4max-mironov8 years ago213});
214}
bb685befmax-mironov8 years ago215}
216});
217});
7574c61amax-mironov8 years ago218return Q.resolve(void 0);
640e6e98max-mironov8 years ago219}
6a465861max-mironov8 years ago220
221public releaseReact(client: AppCenterClient, appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
fbbc4447Sergey Akhalkov8 years ago222let codePushRelaseParams = <ICodePushReleaseParams>{};
223const projectRootPath: string = appCenterManager.projectRootPath;
9588b66eSergey Akhalkov8 years ago224return Q.Promise<any>((resolve, reject) => {
2ceda59emax-mironov8 years ago225let updateContentsDirectory: string;
226let isMandatory: boolean;
9588b66eSergey Akhalkov8 years ago227vscode.window.withProgress({ location: vscode.ProgressLocation.Window, title: "Get Apps" }, p => {
228return new Promise<DefaultApp>((appResolve, appReject) => {
229p.report({ message: ACStrings.GettingAppInfoMessage });
2ceda59emax-mironov8 years ago230this.restoreCurrentApp(appCenterManager.projectRootPath)
9588b66eSergey Akhalkov8 years ago231.then((currentApp: DefaultApp) => appResolve(<DefaultApp>currentApp))
232.catch(err => appReject(err));
233}).then((currentApp: DefaultApp): any => {
234p.report({ message: ACStrings.DetectingAppVersionMessage });
235if (!currentApp) {
ef14e11bmax-mironov8 years ago236throw new Error(`No current app has been specified.`);
9588b66eSergey Akhalkov8 years ago237}
2ceda59emax-mironov8 years ago238if (!currentApp.os || !reactNative.isValidOS(currentApp.os)) {
ef14e11bmax-mironov8 years ago239throw new Error(`OS must be "android", "ios", or "windows".`);
9588b66eSergey Akhalkov8 years ago240}
241codePushRelaseParams.app = currentApp;
ef14e11bmax-mironov8 years ago242codePushRelaseParams.deploymentName = currentApp.currentAppDeployments.currentDeploymentName;
9588b66eSergey Akhalkov8 years ago243currentApp.os = currentApp.os.toLowerCase();
2ceda59emax-mironov8 years ago244isMandatory = !!currentApp.isMandatory;
245if (currentApp.targetBinaryVersion !== ACConstants.AppCenterDefaultTargetBinaryVersion) {
246return currentApp.targetBinaryVersion;
247} else {
248switch (currentApp.os) {
249case "android": return reactNative.getAndroidAppVersion(projectRootPath);
250case "ios": return reactNative.getiOSAppVersion(projectRootPath);
251case "windows": return reactNative.getWindowsAppVersion(projectRootPath);
252default: throw new Error(`OS must be "android", "ios", or "windows".`);
253}
9588b66eSergey Akhalkov8 years ago254}
255}).then((appVersion: string) => {
192cf71emax-mironov8 years ago256p.report({ message: ACStrings.RunningBundleCommandMessage });
9588b66eSergey Akhalkov8 years ago257codePushRelaseParams.appVersion = appVersion;
258return reactNative.makeUpdateContents(<BundleConfig>{
259os: codePushRelaseParams.app.os,
260projectRootPath: projectRootPath,
261});
262}).then((pathToUpdateContents: string) => {
263p.report({ message: ACStrings.ArchivingUpdateContentsMessage });
264updateContentsDirectory = pathToUpdateContents;
2ceda59emax-mironov8 years ago265this.logger.log(`CodePush updated contents directory path: ${updateContentsDirectory}`, LogLevel.Debug);
9588b66eSergey Akhalkov8 years ago266return updateContents.zip(pathToUpdateContents, projectRootPath);
267}).then((pathToZippedBundle: string) => {
268p.report({ message: ACStrings.ReleasingUpdateContentsMessage });
269codePushRelaseParams.updatedContentZipPath = pathToZippedBundle;
2ceda59emax-mironov8 years ago270codePushRelaseParams.isMandatory = isMandatory;
9588b66eSergey Akhalkov8 years ago271return new Promise<any>((publishResolve, publishReject) => {
bf370babSergey Akhalkov8 years ago272Auth.getProfile(projectRootPath)
273.then((profile: Profile) => {
774e7f5fSergey Akhalkov8 years ago274return profile.accessToken;
275}).then((token: string) => {
276codePushRelaseParams.token = token;
bf370babSergey Akhalkov8 years ago277return CodePushRelease.exec(client, codePushRelaseParams, this.logger);
278}).then((response: any) => publishResolve(response))
9588b66eSergey Akhalkov8 years ago279.catch((error: any) => publishReject(error));
280});
281}).then((response: any) => {
282if (response.succeeded && response.result) {
24edcbd0max-mironov8 years ago283VsCodeUtils.ShowInformationMessage(`Successfully released an update to the "${codePushRelaseParams.deploymentName}" deployment of the "${codePushRelaseParams.app.appName}" app`);
9588b66eSergey Akhalkov8 years ago284resolve(response.result);
285} else {
24edcbd0max-mironov8 years ago286VsCodeUtils.ShowErrorMessage(response.errorMessage);
9588b66eSergey Akhalkov8 years ago287}
288fileUtils.rmDir(codePushRelaseParams.updatedContentZipPath);
289}).catch((error: Error) => {
ef14e11bmax-mironov8 years ago290if (error && error.message) {
24edcbd0max-mironov8 years ago291VsCodeUtils.ShowErrorMessage(`An error occured on doing Code Push release. ${error.message}`);
ef14e11bmax-mironov8 years ago292} else {
24edcbd0max-mironov8 years ago293VsCodeUtils.ShowErrorMessage("An error occured on doing Code Push release");
ef14e11bmax-mironov8 years ago294}
295
9588b66eSergey Akhalkov8 years ago296fileUtils.rmDir(codePushRelaseParams.updatedContentZipPath);
42b1aa55Sergey Akhalkov8 years ago297});
9588b66eSergey Akhalkov8 years ago298});
ff1d5ab0max-mironov8 years ago299});
6a465861max-mironov8 years ago300}
301
ef14e11bmax-mironov8 years ago302public showMenu(client: AppCenterClient, appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
2ceda59emax-mironov8 years ago303return Auth.getProfile(appCenterManager.projectRootPath).then((profile: Profile | null) => {
ef14e11bmax-mironov8 years ago304let defaultApp: DefaultApp | null = null;
305if (profile && profile.defaultApp) {
306defaultApp = profile.defaultApp;
307}
2ceda59emax-mironov8 years ago308let menuPlaceHolederTitle = ACStrings.MenuTitlePlaceholder;
ef14e11bmax-mironov8 years ago309let appCenterMenuOptions = [
310{
2ceda59emax-mironov8 years ago311label: ACStrings.ReleaseReactMenuText(defaultApp),
312description: "",
ef14e11bmax-mironov8 years ago313target: ACCommandNames.CodePushReleaseReact,
314},
315{
2ceda59emax-mironov8 years ago316label: ACStrings.SetCurrentAppMenuText(defaultApp),
317description: "",
ef14e11bmax-mironov8 years ago318target: ACCommandNames.SetCurrentApp,
319},
320{
321label: ACStrings.LogoutMenuLabel,
2ceda59emax-mironov8 years ago322description: "",
ef14e11bmax-mironov8 years ago323target: ACCommandNames.Logout,
324},
325];
326
327// This item is avaliable only if we have specified app already
2ceda59emax-mironov8 years ago328if (defaultApp && defaultApp.currentAppDeployments) {
ef14e11bmax-mironov8 years ago329// Let logout command be always the last one in the list
330appCenterMenuOptions.splice(appCenterMenuOptions.length - 1, 0,
331{
2ceda59emax-mironov8 years ago332label: ACStrings.SetCurrentAppDeploymentText(defaultApp),
333description: "",
ef14e11bmax-mironov8 years ago334target: ACCommandNames.SetCurrentDeployment,
335}
336);
2ceda59emax-mironov8 years ago337appCenterMenuOptions.splice(appCenterMenuOptions.length - 1, 0,
338{
339label: ACStrings.SetCurrentAppTargetBinaryVersionText(defaultApp),
340description: "",
341target: ACCommandNames.SetTargetBinaryVersionForRelease,
342}
343);
344appCenterMenuOptions.splice(appCenterMenuOptions.length - 1, 0,
345{
346label: ACStrings.SetCurrentAppIsMandatoryText(defaultApp),
347description: "",
348target: ACCommandNames.SwitchMandatoryPropertyForRelease,
349}
350);
ef14e11bmax-mironov8 years ago351}
352
353return vscode.window.showQuickPick(appCenterMenuOptions, { placeHolder: menuPlaceHolederTitle })
354.then((selected: {label: string, description: string, target: string}) => {
355if (!selected) {
356// user cancel selection
357return Q.resolve(void 0);
358}
359switch (selected.target) {
360case (ACCommandNames.SetCurrentApp):
361return this.setCurrentApp(client, appCenterManager);
362
363case (ACCommandNames.SetCurrentDeployment):
364return this.setCurrentDeployment(appCenterManager);
365
366case (ACCommandNames.CodePushReleaseReact):
367return this.releaseReact(client, appCenterManager);
368
2ceda59emax-mironov8 years ago369case (ACCommandNames.SetTargetBinaryVersionForRelease):
370return this.setTargetBinaryVersionForRelease(appCenterManager);
371
372case (ACCommandNames.SwitchMandatoryPropertyForRelease):
373return this.switchIsMandatoryForRelease(appCenterManager);
374
ef14e11bmax-mironov8 years ago375case (ACCommandNames.Logout):
376return this.logout(appCenterManager);
377
378default:
379// Ideally shouldn't be there :)
380this.logger.error("Unknown appcenter show menu command");
381return Q.resolve(void 0);
382}
383});
384});
385}
386
2ceda59emax-mironov8 years ago387public switchIsMandatoryForRelease(appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
388this.restoreCurrentApp(appCenterManager.projectRootPath).then((app: DefaultApp) => {
389if (app) {
390const newMandatoryValue = !!!app.isMandatory;
391const osVal: AppCenterOS = AppCenterOS[app.os];
392this.saveCurrentApp(
393appCenterManager.projectRootPath,
394app.identifier,
395osVal, {
396currentDeploymentName: app.currentAppDeployments.currentDeploymentName,
397codePushDeployments: app.currentAppDeployments.codePushDeployments,
398},
399app.targetBinaryVersion,
400newMandatoryValue
401).then(() => {
b1d4af3cmax-mironov8 years ago402VsCodeUtils.ShowInformationMessage(`Changed release to ${newMandatoryValue ? "Mandatory" : "NOT Mandatory"}`);
2ceda59emax-mironov8 years ago403});
404} else {
24edcbd0max-mironov8 years ago405VsCodeUtils.ShowInformationMessage(ACStrings.NoCurrentAppSetMsg);
2ceda59emax-mironov8 years ago406}
407});
408return Q.resolve(void 0);
409}
410
411public setTargetBinaryVersionForRelease(appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
412vscode.window.showInputBox({ prompt: ACStrings.PleaseProvideTargetBinaryVersion, ignoreFocusOut: true })
413.then(appVersion => {
24edcbd0max-mironov8 years ago414if (appVersion === ACConstants.AppCenterDefaultTargetBinaryVersion || (appVersion && !!validRange(appVersion))) {
2ceda59emax-mironov8 years ago415return this.restoreCurrentApp(appCenterManager.projectRootPath).then((app: DefaultApp) => {
416if (app) {
417return this.saveCurrentApp(
418appCenterManager.projectRootPath,
419app.identifier,
420AppCenterOS[app.os], {
421currentDeploymentName: app.currentAppDeployments.currentDeploymentName,
422codePushDeployments: app.currentAppDeployments.codePushDeployments,
423},
424appVersion,
425app.isMandatory
426).then(() => {
24edcbd0max-mironov8 years ago427if (appVersion) {
428VsCodeUtils.ShowInformationMessage(`Changed target binary version to '${appVersion}'`);
429} else {
430VsCodeUtils.ShowInformationMessage(`Changed target binary version to automatically fetched`);
431}
2ceda59emax-mironov8 years ago432});
433} else {
24edcbd0max-mironov8 years ago434VsCodeUtils.ShowInformationMessage(ACStrings.NoCurrentAppSetMsg);
2ceda59emax-mironov8 years ago435return Q.resolve(void 0);
436}
437});
d3db396bmax-mironov8 years ago438} else if (appVersion === undefined) {
439// if user press esc do nothing then
440return Q.resolve(void 0);
2ceda59emax-mironov8 years ago441} else {
24edcbd0max-mironov8 years ago442VsCodeUtils.ShowWarningMessage(ACStrings.InvalidAppVersionParamMsg);
2ceda59emax-mironov8 years ago443return Q.resolve(void 0);
444}
445});
446return Q.resolve(void 0);
447}
448
449private saveCurrentApp(projectRootPath: string,
450currentAppName: string,
451appOS: AppCenterOS,
452currentAppDeployments: CurrentAppDeployments | null,
453targetBinaryVersion: string,
454isMandatory: boolean): Q.Promise<DefaultApp | null> {
455const defaultApp = ACUtils.toDefaultApp(currentAppName, appOS, currentAppDeployments, targetBinaryVersion, isMandatory);
bb685befmax-mironov8 years ago456if (!defaultApp) {
24edcbd0max-mironov8 years ago457VsCodeUtils.ShowWarningMessage(ACStrings.InvalidCurrentAppNameMsg);
e26df9e4max-mironov8 years ago458return Q.resolve(null);
bb685befmax-mironov8 years ago459}
65b8d098max-mironov8 years ago460
2ceda59emax-mironov8 years ago461return Auth.getProfile(projectRootPath).then((profile: Profile | null) => {
ef14e11bmax-mironov8 years ago462if (profile) {
463profile.defaultApp = defaultApp;
2ceda59emax-mironov8 years ago464profile.save(projectRootPath);
ef14e11bmax-mironov8 years ago465return Q.resolve(defaultApp);
466} else {
467// No profile - not logged in?
24edcbd0max-mironov8 years ago468VsCodeUtils.ShowWarningMessage(ACStrings.UserIsNotLoggedInMsg);
ef14e11bmax-mironov8 years ago469return Q.resolve(null);
470}
471});
bb685befmax-mironov8 years ago472}
473
2ceda59emax-mironov8 years ago474private restoreCurrentApp(projectRootPath: string): Q.Promise<DefaultApp | null> {
475return Auth.getProfile(projectRootPath).then((profile: Profile | null) => {
ef14e11bmax-mironov8 years ago476if (profile && profile.defaultApp) {
477return Q.resolve(profile.defaultApp);
bb685befmax-mironov8 years ago478}
ef14e11bmax-mironov8 years ago479return Q.resolve(null);
480});
6a465861max-mironov8 years ago481}
482
ff1d5ab0max-mironov8 years ago483private loginWithToken(token: string | undefined, appCenterManager: AppCenterExtensionManager) {
484if (!token) {
485return;
486}
2ceda59emax-mironov8 years ago487return Auth.doTokenLogin(token, appCenterManager.projectRootPath).then((profile: Profile) => {
84abb0c7max-mironov8 years ago488if (!profile) {
489this.logger.log("Failed to fetch user info from server", LogLevel.Error);
24edcbd0max-mironov8 years ago490VsCodeUtils.ShowWarningMessage(ACStrings.FailedToExecuteLoginMsg);
84abb0c7max-mironov8 years ago491return;
492}
24edcbd0max-mironov8 years ago493VsCodeUtils.ShowInformationMessage(ACStrings.YouAreLoggedInMsg(profile.displayName));
ef14e11bmax-mironov8 years ago494return appCenterManager.setupAppCenterStatusBar(profile);
6a465861max-mironov8 years ago495});
496}
bb45fbe6max-mironov8 years ago497}