deploy endpoints: fix bugs and add manual deploy select region ability

This commit is contained in:
Austen Collins 2015-09-18 13:16:59 -07:00
parent 3a815d7f8b
commit c869a57000

View File

@ -28,6 +28,7 @@ Promise.promisifyAll(fs);
* @param allTagged
* @returns {*}
*/
module.exports.run = function(JAWS, stage, region, allTagged) {
var command = new CMD(JAWS, stage, region, allTagged);
return command.run();
@ -41,6 +42,7 @@ module.exports.run = function(JAWS, stage, region, allTagged) {
* @param allTagged
* @constructor
*/
function CMD(JAWS, stage, region, allTagged) {
var _this = this;
_this._stage = stage;
@ -50,11 +52,11 @@ function CMD(JAWS, stage, region, allTagged) {
_this._prjRootPath = JAWS._meta.projectRootPath;
_this._prjCreds = JAWS._meta.credentials;
if (region) {
if (region && stage) {
_this._regions = _this._JAWS._meta.projectJson.stages[_this._stage].filter(function(r) {
return (r.region == region);
});
} else {
} else if (stage) {
_this._regions = _this._JAWS._meta.projectJson.stages[_this._stage];
}
}
@ -62,6 +64,7 @@ function CMD(JAWS, stage, region, allTagged) {
/**
* CMD: Run
*/
CMD.prototype.run = Promise.method(function() {
var _this = this;
@ -72,11 +75,11 @@ CMD.prototype.run = Promise.method(function() {
.then(function() {
// If !allTagged, tag current directory
if (!_this._allTagged) {
return CMDtag.tag('api', null, false);
return CMDtag.tag('endpoint', null, false);
}
})
.then(_this._promptStage)
.then(_this._promptRegion)
.then(_this._promptRegions)
.then(function() {
return _this._regions;
})
@ -112,7 +115,10 @@ CMD.prototype.run = Promise.method(function() {
/**
* CMD: Prompt Stage
*/
CMD.prototype._promptStage = Promise.resolve(function() {
CMD.prototype._promptStage = Promise.method(function() {
var _this = this;
// If stage, skip
if (_this._stage) return;
@ -122,15 +128,53 @@ CMD.prototype._promptStage = Promise.resolve(function() {
throw new JawsError('You have no stages in this project');
}
// If project has only one stage, skip select
if (stages.length === 1) {
_this._stage = stages[0];
return;
}
var choices = [];
for (var i = 0; i < stages.length; i++) {
choices.push({
key: (i + 1) + ': ',
value: stages[i]
key: '',
value: stages[i],
label: stages[i]
});
}
return JawsCLI.checklist('Select a stage to deploy to: ', choices);
return JawsCli.select('Select a stage to deploy to: ', choices, false);
});
/**
* CMD: Prompt Regions
*/
CMD.prototype._promptRegions = Promise.method(function() {
var _this = this;
// If regions, skip
if (_this._regions && _this._regions.length) return;
var regions = _this._JAWS._meta.projectJson.stages[_this._stage];
// If stage has only one region, skip select
if (regions.length === 1) {
_this._regions = regions;
return;
}
var choices = [];
for (var i = 0; i < regions.length; i++) {
choices.push({
key: '',
value: regions[i].region,
label: regions[i].region,
});
}
return JawsCli.select('Select a region inthis stage to deploy to: ', choices, false);
});
/**
@ -167,8 +211,9 @@ function ApiDeployer(JAWS, stage, region, prjRootPath, prjJson, prjCreds) {
}
/**
* Deploy
* API Deployer: Deploy
*/
ApiDeployer.prototype.deploy = Promise.method(function() {
var _this = this;
@ -277,7 +322,7 @@ ApiDeployer.prototype._fetchDeployedLambdas = Promise.method(function() {
});
/**
* Validate & Sanitize Tagged Endpoints
* API Deployer: Validate & Sanitize Tagged Endpoints
*/
ApiDeployer.prototype._validateAndSantizeTaggedEndpoints = Promise.method(function() {
@ -309,7 +354,7 @@ ApiDeployer.prototype._validateAndSantizeTaggedEndpoints = Promise.method(functi
});
/**
* Save API ID
* API Deployer: Save API ID
*/
ApiDeployer.prototype._saveApiId = Promise.method(function() {
@ -327,7 +372,7 @@ ApiDeployer.prototype._saveApiId = Promise.method(function() {
});
/**
* Find Or Create API
* API Deployer: Find Or Create API
*/
ApiDeployer.prototype._findOrCreateApi = Promise.method(function() {
@ -369,7 +414,7 @@ ApiDeployer.prototype._findOrCreateApi = Promise.method(function() {
});
/**
* List API Resources
* API Deployer: List API Resources
*/
ApiDeployer.prototype._listApiResources = Promise.method(function() {
@ -402,8 +447,9 @@ ApiDeployer.prototype._listApiResources = Promise.method(function() {
});
/**
* Build Endpoints
* API Deployer: Build Endpoints
*/
ApiDeployer.prototype._buildEndpoints = Promise.method(function() {
var _this = this;
@ -422,8 +468,9 @@ ApiDeployer.prototype._buildEndpoints = Promise.method(function() {
});
/**
* Create Endpoint Resources
* API Deployer: Create Endpoint Resources
*/
ApiDeployer.prototype._createEndpointResources = Promise.method(function(endpoint) {
var _this = this;
@ -493,8 +540,9 @@ ApiDeployer.prototype._createEndpointResources = Promise.method(function(endpoin
});
/**
* Create Endpoint Method
* API Deployer: Create Endpoint Method
*/
ApiDeployer.prototype._createEndpointMethod = Promise.method(function(endpoint) {
var _this = this;
@ -556,7 +604,7 @@ ApiDeployer.prototype._createEndpointMethod = Promise.method(function(endpoint)
});
/**
* Create Endpoint Integration
* API Deployer: Create Endpoint Integration
*/
ApiDeployer.prototype._createEndpointIntegration = Promise.method(function(endpoint) {
@ -634,8 +682,9 @@ ApiDeployer.prototype._createEndpointIntegration = Promise.method(function(endpo
});
/**
* Create Endpoint Method Responses
* API Deployer: Create Endpoint Method Responses
*/
ApiDeployer.prototype._createEndpointMethodResponses = Promise.method(function(endpoint) {
var _this = this;
@ -687,8 +736,9 @@ ApiDeployer.prototype._createEndpointMethodResponses = Promise.method(function(e
});
/**
* Create Endpoint Method Integration Responses
* API Deployer: Create Endpoint Method Integration Responses
*/
ApiDeployer.prototype._createEndpointMethodIntegResponses = Promise.method(function(endpoint) {
var _this = this;
@ -739,8 +789,9 @@ ApiDeployer.prototype._createEndpointMethodIntegResponses = Promise.method(funct
});
/**
* Create Endpoint Method Responses
* API Deployer: Create Endpoint Method Responses
*/
ApiDeployer.prototype._createEndpointMethodResponses = Promise.method(function(endpoint) {
var _this = this;
@ -792,8 +843,9 @@ ApiDeployer.prototype._createEndpointMethodResponses = Promise.method(function(e
});
/**
* Create Endpoint Method Integration Responses
* API Deployer: Create Endpoint Method Integration Responses
*/
ApiDeployer.prototype._createEndpointMethodIntegResponses = Promise.method(function(endpoint) {
var _this = this;
@ -847,8 +899,9 @@ ApiDeployer.prototype._createEndpointMethodIntegResponses = Promise.method(funct
});
/**
* Create Deployment
* API Deployer: Create Deployment
*/
ApiDeployer.prototype._createDeployment = Promise.method(function() {
var _this = this;