dce-dev-wizard
Version:
Wizard for managing development apps at Harvard DCE.
192 lines • 9.86 kB
JavaScript
;
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());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var path_1 = __importDefault(require("path"));
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 exec_1 = __importDefault(require("../helpers/exec"));
var getPackageJSON_1 = __importDefault(require("../helpers/getPackageJSON"));
var validateNodeVersion_1 = __importDefault(require("../helpers/validateNodeVersion"));
// Get current working directory
var currDir = (process.env.PWD || process.env.CWD);
/**
* Perform a deploy now
* @author Gabe Abrams
* @param deployment the currently selected deployment
*/
var deployNow = function (deployment) { return __awaiter(void 0, void 0, void 0, function () {
var tag, deployConfig, parts, branchOrVersion, isVersion, processedBranchName, confirmOption, packageJSON, actionsPanelURL, diff, secondaryConfirmOption;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
tag = (0, showChooser_1.default)({
question: 'Have you changed the deploy config?',
options: [
{
description: 'Yes, I changed env vars, branch, and/or version',
tag: 'Y',
},
{
description: 'No, I just want to deploy with same config',
tag: 'N',
},
],
title: 'Ready to Deploy',
}).tag;
// Show loading indicator
(0, clear_1.default)();
console.log('Loading current info...\n');
deployConfig = (0, getDeploymentConfig_1.default)(deployment);
parts = deployConfig.appImage.split(':');
branchOrVersion = parts[parts.length - 1];
isVersion = branchOrVersion.includes('.');
processedBranchName = branchOrVersion.replace('-', '/');
// Information
(0, clear_1.default)();
print_1.default.title('About to Deploy');
console.log('');
console.log('Information:');
console.log("Deploying to: ".concat(deployment.name));
console.log("Branch: ".concat(isVersion ? 'main branch' : processedBranchName));
console.log("Version: ".concat(isVersion ? branchOrVersion : '[Most Recent Build]'));
if (tag === 'Y') {
console.log('Operation: update deploy config then restart');
}
else {
console.log('Operation: restart with unmodified config');
}
console.log('');
confirmOption = (0, showChooser_1.default)({
question: 'Ready to continue?',
options: [
{
description: 'Yes',
tag: 'Y',
},
{
description: 'No',
tag: 'N',
},
],
dontClear: true,
});
if (confirmOption.tag === 'N') {
// Cancel
(0, clear_1.default)();
print_1.default.title('Cancelled!');
console.log('');
print_1.default.enterToContinue();
return [2 /*return*/];
}
// Validate Node version
return [4 /*yield*/, (0, validateNodeVersion_1.default)()];
case 1:
// Validate Node version
_a.sent();
packageJSON = (0, getPackageJSON_1.default)(path_1.default.join(currDir, 'package.json'));
if (packageJSON.repository && packageJSON.repository.url) {
actionsPanelURL = (packageJSON.repository.url
.replace('git+http', 'http')
.replace('.git', '/actions'));
// Print warning
(0, clear_1.default)();
print_1.default.title('Did you wait for the action to finish?');
console.log('');
console.log('Actions panel:');
console.log(actionsPanelURL);
console.log('');
print_1.default.enterToContinue();
}
// Redeploy
if (tag === 'Y') {
(0, clear_1.default)();
console.log('Loading diff...\n');
diff = (0, exec_1.default)("./node_modules/.bin/caccl-deploy stack --profile ".concat(deployment.profile, " --app ").concat(deployment.app, " diff"));
console.log('');
print_1.default.title('Confirm Deploy Config Diff:');
console.log('');
console.log(diff);
secondaryConfirmOption = (0, showChooser_1.default)({
question: 'Ready to continue?',
options: [
{
description: 'Yes',
tag: 'Y',
},
{
description: 'No',
tag: 'N',
},
],
dontClear: true,
});
if (secondaryConfirmOption.tag === 'N') {
// Cancel
(0, clear_1.default)();
print_1.default.title('Cancelled!');
console.log('');
print_1.default.enterToContinue();
return [2 /*return*/];
}
// Deploy (update config)
(0, exec_1.default)("./node_modules/.bin/caccl-deploy stack --profile ".concat(deployment.profile, " --app ").concat(deployment.app, " deploy -y"), true);
}
else {
// Restart
(0, clear_1.default)();
console.log('Restarting service...');
console.log('');
(0, exec_1.default)("./node_modules/.bin/caccl-deploy restart --profile ".concat(deployment.profile, " --app ").concat(deployment.app, " -y"), true);
}
// Confirmation
(0, clear_1.default)();
print_1.default.title('Deploy Successful');
console.log('');
print_1.default.enterToContinue();
return [2 /*return*/];
}
});
}); };
exports.default = deployNow;
//# sourceMappingURL=deployNow.js.map