add untag and tag/untag all

This commit is contained in:
ryanp 2015-08-26 18:43:22 -05:00
parent 2499172937
commit d499696c86
2 changed files with 31 additions and 8 deletions

View File

@ -5,13 +5,13 @@
var JawsError = require('../lib/jaws-error'),
JAWS = require('../lib/index.js'),
program = require('commander'),
handleExit = require('../lib/utils').handleExit;
utils = require('../lib/utils'),
Promise = require('bluebird'),
handleExit = utils.handleExit;
program
.version(JAWS._meta.version);
//TODO: need to provide cli options vars to bypass input
program
.command('new')
.description('Creates a new JAWS project in the current working directory and creates an AWS CloudFormation ' +
@ -69,14 +69,34 @@ program
}
});
//TODO: add untag feature
//TODO: add tag/untag all feature
program
.command('tag')
.option('-u, --untag', 'un-tag lambda')
.option('-a, --all', 'tag all lambda functions in project')
.option('-n, --untag-all', 'un-tag all lambda functions in project')
.description('Tag a lambda function to be deployed the next time you run the deploy command for all' +
' tagged lambdas.')
.action(function() {
handleExit(JAWS.tag());
if (options.all || options.untagAll) {
var shouldTag = (options.all) ? true : false;
handleExit(
utils.findAllLambdas(utils.findProjectRootPath(process.cwd()))
.then(function(lJawsJsonPaths) {
var tagQueue = [];
if (!lJawsJsonPaths) {
throw new JawsError('Could not find any lambdas');
}
lJawsJsonPaths.forEach(function(ljp) {
tagQueue.push(JAWS.tag(ljp, shouldTag));
});
return Promise.all(tagQueue);
})
);
} else {
handleExit(JAWS.tag(null, options.untag));
}
});
program

View File

@ -18,9 +18,12 @@ module.exports = function(JAWS) {
* Tag a lambda for deployment (set deploy = true)
*
* @param fullPathToJawsJson optional. Uses cwd by default
* @param {boolean} untag. default false
* @returns {Promise} full path to jaws.json that was updated
*/
JAWS.tag = function(fullPathToJawsJson) {
JAWS.tag = function(fullPathToJawsJson, untag) {
untag = (untag) ? true : false;
var jawsJsonPath = fullPathToJawsJson || path.join(process.cwd(), 'jaws.json');
return new Promise(function(resolve, reject) {
@ -33,7 +36,7 @@ module.exports = function(JAWS) {
var jawsJson = require(jawsJsonPath);
if (typeof jawsJson.lambda !== 'undefined') {
jawsJson.lambda.deploy = true;
jawsJson.lambda.deploy = !untag;
fs.writeFileSync(jawsJsonPath, JSON.stringify(jawsJson, null, 2));
resolve(jawsJsonPath);
} else {