UNPKG

appcenter-cli

Version:

Command line tool for Visual Studio App Center

125 lines (124 loc) 7.39 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 codepush_release_command_base_1 = require("./lib/codepush-release-command-base"); const interaction_1 = require("../../util/interaction"); const util_1 = require("util"); const path = require("path"); const fs = require("fs"); const validation_utils_1 = require("./lib/validation-utils"); const cordova_utils_1 = require("./lib/cordova-utils"); const childProcess = require("child_process"); const chalk = require("chalk"); const debug = require("debug")("appcenter-cli:commands:codepush:release-cordova"); let CodePushReleaseCordovaCommand = class CodePushReleaseCordovaCommand extends codepush_release_command_base_1.default { run(client) { return __awaiter(this, void 0, void 0, function* () { if (!(yield validation_utils_1.isValidDeployment(client, this.app, this.specifiedDeploymentName))) { return commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, `Deployment "${this.specifiedDeploymentName}" does not exist.`); } else { this.deploymentName = this.specifiedDeploymentName; } const appInfo = yield interaction_1.out.progress("Getting app info...", client.apps.get(this.app.ownerName, this.app.appName)); this.os = appInfo.os.toLowerCase(); this.platform = appInfo.platform.toLowerCase(); if (!cordova_utils_1.isValidOS(this.os)) { return commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, `Platform must be either "ios" or "android".`); } if (!cordova_utils_1.isValidPlatform(this.platform)) { return commandline_1.failure(commandline_1.ErrorCodes.Exception, `Platform must be "Cordova".`); } if (this.specifiedTargetBinaryVersion) { this.targetBinaryVersion = this.specifiedTargetBinaryVersion; } else { this.targetBinaryVersion = yield cordova_utils_1.getCordovaProjectAppVersion(); } if (!validation_utils_1.isValidRange(this.targetBinaryVersion)) { return commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, "Invalid binary version(s) for a release."); } const cordovaCommand = this.getCordovaCommand(); let cordovaCLI; try { cordovaCLI = cordova_utils_1.getCordovaOrPhonegapCLI(); } catch (e) { return commandline_1.failure(commandline_1.ErrorCodes.Exception, `Unable to ${cordovaCommand} project. Please ensure that either the Cordova or PhoneGap CLI is installed.`); } interaction_1.out.text(chalk.cyan(`Running "${cordovaCLI} ${cordovaCommand}" command:\n`)); try { childProcess.execSync([cordovaCLI, cordovaCommand, this.os, "--verbose"].join(" "), { stdio: "inherit" }); } catch (error) { debug(`Failed to release a CodePush update - ${util_1.inspect(error)}`); return commandline_1.failure(commandline_1.ErrorCodes.Exception, `Unable to ${cordovaCommand} project. Please ensure that the CWD represents a Cordova project and that the "${this.os}" platform was added by running "${cordovaCLI} platform add ${this.os}".`); } try { this.updateContentsPath = this.getOutputFolder(); } catch (error) { debug(`Failed to release a CodePush update - ${util_1.inspect(error)}`); return commandline_1.failure(commandline_1.ErrorCodes.Exception, `No output folder found. Please ensure that the CWD represents a Cordova project and that the "${this.os}" platform was added by running "${cordovaCLI} platform add ${this.os}".`); } interaction_1.out.text(chalk.cyan("\nReleasing update contents to CodePush:\n")); return yield this.release(client); }); } getOutputFolder() { const projectRoot = process.cwd(); const platformFolder = path.join(projectRoot, "platforms", this.os); if (this.os === "ios") { return path.join(platformFolder, "www"); } else if (this.os === "android") { // Since cordova-android 7 assets directory moved to android/app/src/main/assets instead of android/assets const outputFolderVer7 = path.join(platformFolder, "app", "src", "main", "assets", "www"); const outputFolderPre7 = path.join(platformFolder, "assets", "www"); if (fs.existsSync(outputFolderVer7)) { return outputFolderVer7; } else if (fs.existsSync(outputFolderPre7)) { return outputFolderPre7; } } throw new Error(`${this.os} output folder does not exists`); } getCordovaCommand() { return this.build ? (this.isReleaseBuildType ? "build --release" : "build") : "prepare"; } }; __decorate([ commandline_1.help(`Invoke "cordova build" instead of "cordova prepare"`), commandline_1.shortName("b"), commandline_1.longName("build") ], CodePushReleaseCordovaCommand.prototype, "build", void 0); __decorate([ commandline_1.help('If "build" option is true specifies whether perform a release build'), commandline_1.longName("is-release-build-type") ], CodePushReleaseCordovaCommand.prototype, "isReleaseBuildType", void 0); __decorate([ commandline_1.help("Semver expression that specifies the binary app version(s) this release is targeting (e.g. 1.1.0, ~1.2.3)"), commandline_1.shortName("t"), commandline_1.longName("target-binary-version"), commandline_1.hasArg ], CodePushReleaseCordovaCommand.prototype, "specifiedTargetBinaryVersion", void 0); CodePushReleaseCordovaCommand = __decorate([ commandline_1.help("Release a Cordova update to an app deployment") ], CodePushReleaseCordovaCommand); exports.default = CodePushReleaseCordovaCommand;