UNPKG

appcenter-cli

Version:

Command line tool for Visual Studio App Center

64 lines (63 loc) 3.81 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const commandline_1 = require("../../../util/commandline"); const interaction_1 = require("../../../util/interaction"); const util_1 = require("util"); const misc_1 = require("../../../util/misc"); const chalk = require("chalk"); const debug = require("debug")("appcenter-cli:commands:codepush:deployments:add"); let CodePushAddCommand = class CodePushAddCommand extends commandline_1.AppCommand { constructor(args) { super(args); } run(client) { return __awaiter(this, void 0, void 0, function* () { const app = this.app; let deployment; try { deployment = yield interaction_1.out.progress("Creating a new CodePush deployment...", client.codePushDeployments.create(app.ownerName, app.appName, this.newDeploymentName.toString())); interaction_1.out.text(`Deployment ${chalk.bold(deployment.name)} has been created for ${this.identifier} with key ${deployment.key}`); return commandline_1.success(); } catch (error) { debug(`Failed to add a new CodePush deployment - ${util_1.inspect(error)}`); if (error.statusCode === 404) { const appNotFoundErrorMsg = `The app ${this.identifier} does not exist. Please double check the name, and provide it in the form owner/appname. \nRun the command ${chalk.bold(`${misc_1.scriptName} apps list`)} to see what apps you have access to.`; return commandline_1.failure(commandline_1.ErrorCodes.NotFound, appNotFoundErrorMsg); } else if (error.statusCode === 409) { const deploymentExistErrorMsg = `A deployment named ${chalk.bold(this.newDeploymentName)} already exists.`; return commandline_1.failure(commandline_1.ErrorCodes.Exception, deploymentExistErrorMsg); } else { return commandline_1.failure(commandline_1.ErrorCodes.Exception, error.response.bodyAsText); } } }); } }; __decorate([ commandline_1.help("New CodePush deployment name"), commandline_1.required, commandline_1.name("new-deployment-name"), commandline_1.position(0) ], CodePushAddCommand.prototype, "newDeploymentName", void 0); CodePushAddCommand = __decorate([ commandline_1.help("Add a new deployment to an app") ], CodePushAddCommand); exports.default = CodePushAddCommand;