microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/appcenter/codepush/release.ts
40lines · 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 { AppCenterClient, models } from "../api/index"; |
| 5 | import { ILogger, LogLevel } from "../../log/LogHelper"; |
| 6 | import { ICodePushReleaseParams } from "../command/commandParams"; |
| 7 | import * as Q from "q"; |
| 8 | import { CommandResult, success, failure, ErrorCodes } from "../command/commandResult"; |
| 9 | import { appcenterCodePushRelease } from "./release-strategy/appcenterCodePushRelease"; |
| 10 | import { legacyCodePushRelease } from "./release-strategy/legacyCodePushRelease"; |
| 11 | import { SettingsHelper } from "../../settingsHelper"; |
| 12 | |
| 13 | // Use old service endpoint unless we will fix issue with 1MB payload limitation for new one |
| 14 | const useLegacyCodePushServer: boolean = SettingsHelper.getLegacyCodePushServiceEnabled(); |
| 15 | |
| 16 | export default class CodePushRelease { |
| 17 | public static exec(client: AppCenterClient, params: ICodePushReleaseParams, logger: ILogger): Q.Promise<CommandResult> { |
| 18 | return ((): Q.Promise<CodePushRelease> => { |
| 19 | if (useLegacyCodePushServer) { |
| 20 | return legacyCodePushRelease(params, <string>params.token, SettingsHelper.getLegacyCodePushEndpoint()); |
| 21 | } else { |
| 22 | return appcenterCodePushRelease(client, params); |
| 23 | } |
| 24 | })().then((result: models.CodePushRelease) => { |
| 25 | return success(result); |
| 26 | }).catch((error) => { |
| 27 | if (error && error.reposnse && error.response.statusCode === 409) { |
| 28 | logger.log(error.response.body, LogLevel.Error); |
| 29 | return failure(ErrorCodes.Exception, error.response.body); |
| 30 | } |
| 31 | |
| 32 | logger.log("An error occured on doing Code Push release", LogLevel.Error); |
| 33 | if (typeof error === "string") { |
| 34 | return failure(ErrorCodes.Exception, error); |
| 35 | } else { |
| 36 | return failure(ErrorCodes.Exception, "An error occured on doing Code Push release"); |
| 37 | } |
| 38 | }); |
| 39 | } |
| 40 | } |