UNPKG

dce-dev-wizard

Version:

Wizard for managing development apps at Harvard DCE.

119 lines 5.08 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var clear_1 = __importDefault(require("clear")); // Import helpers var showChooser_1 = __importDefault(require("../helpers/showChooser")); var getDeploymentConfig_1 = __importDefault(require("../operations/getDeploymentConfig")); var print_1 = __importDefault(require("../helpers/print")); var prompt_1 = __importDefault(require("../helpers/prompt")); var exec_1 = __importDefault(require("../helpers/exec")); // Import shared constants var BRANCH_VERSION_SEPARATOR_1 = __importDefault(require("../constants/BRANCH_VERSION_SEPARATOR")); /** * Show and/or modify the deployed tag version * @author Gabe Abrams * @param deployment the currently selected deployment */ var changeVersion = function (deployment) { var _a; // Show loading indicator (0, clear_1.default)(); console.log('Loading current version...\n'); // Get environment variables var deployConfig = (0, getDeploymentConfig_1.default)(deployment); // Get last part of the app image var parts = deployConfig.appImage.split(':'); var branchAndVersion = parts[parts.length - 1]; var appImagePrefix = deployConfig.appImage.substring(0, deployConfig.appImage.length - branchAndVersion.length); // Get the unprocessed branch name and version var branchVersionParts = branchAndVersion.split(BRANCH_VERSION_SEPARATOR_1.default); var unprocessedBranchName = branchVersionParts[0]; var versionNumber = ((_a = branchVersionParts[1]) !== null && _a !== void 0 ? _a : ''); // Process branch name var processedBranchName = unprocessedBranchName.replace('-', '/'); // Version cannot be changed message if (processedBranchName !== 'main' && processedBranchName !== 'master') { (0, clear_1.default)(); print_1.default.subtitle('Cannot Change Version'); console.log(''); console.log("Current branch: ".concat(processedBranchName)); console.log(''); console.log('Note: to change the version, first change the branch to either "main" or "master"'); console.log(''); print_1.default.enterToContinue(); return; } // Print status (0, clear_1.default)(); print_1.default.subtitle("Current version: ".concat(versionNumber !== null && versionNumber !== void 0 ? versionNumber : '[Most Recent Build]')); console.log(''); // Choose an operation var tag = (0, showChooser_1.default)('Choose an operation:', [ { description: 'Change Version Number', tag: 'C', }, { description: 'Use [Most Recent Build] Instead of Specific Version', tag: 'U', }, { description: 'Back to Main Menu', tag: 'B', }, ]).tag; // Back to main menu if (tag === 'B') { return; } // Use most recent build if (tag === 'U') { // Build a new app image var newAppImage_1 = "".concat(appImagePrefix).concat(unprocessedBranchName); // Update the configuration (0, clear_1.default)(); console.log('Working...\n'); (0, exec_1.default)("./node_modules/.bin/caccl-deploy update --profile ".concat(deployment.profile, " --app ").concat(deployment.app, " appImage \"").concat(newAppImage_1, "\""), true); // Confirmation (0, clear_1.default)(); print_1.default.title('Now Using [Most Recent Build]'); console.log(''); print_1.default.enterToContinue(); return; } // Use custom version number // Ask user for a new version number (0, clear_1.default)(); print_1.default.subtitle("Current Version: ".concat(versionNumber)); console.log(''); console.log("Current version: ".concat(versionNumber)); console.log(''); console.log('Enter a new version (leave empty to go back):'); var newVersionNumber = (0, prompt_1.default)('> ').trim(); // Skip if cancelling if (newVersionNumber.length === 0) { // Cancel (0, clear_1.default)(); print_1.default.title('Cancelled!'); console.log(''); print_1.default.enterToContinue(); return; } // Perform update // Build a new app image var newAppImage = "".concat(appImagePrefix).concat(unprocessedBranchName).concat(BRANCH_VERSION_SEPARATOR_1.default).concat(newVersionNumber); // Update the configuration (0, clear_1.default)(); console.log('Working...\n'); (0, exec_1.default)("./node_modules/.bin/caccl-deploy update --profile ".concat(deployment.profile, " --app ").concat(deployment.app, " appImage \"").concat(newAppImage, "\""), true); // Confirmation (0, clear_1.default)(); print_1.default.title('Version Updated Successfully'); console.log(''); print_1.default.enterToContinue(); }; exports.default = changeVersion; //# sourceMappingURL=changeVersion.js.map