Convert logIfVerbose to jawsDebug.

This commit is contained in:
Aaron Boushley 2015-09-24 19:21:34 -07:00
parent 32e515184e
commit c0b8076563
8 changed files with 38 additions and 33 deletions

View File

@ -74,7 +74,7 @@ CMD.prototype.run = Promise.method(function() {
.then(_this._validate)
.then(_this._getTaggedLambdaPaths)
.then(function() {
utils.logIfVerbose('Deploying to stage: ' + _this._stage);
utils.jawsDebug('deploy_lambda', 'Deploying to stage:', _this._stage);
return _this._regions;
})
.each(function(region) {
@ -137,8 +137,8 @@ CMD.prototype._setRegions = Promise.method(function() {
this._regions = projJson.stages[stage];
}
utils.logIfVerbose('Deploying to regions:');
utils.logIfVerbose(this._regions);
utils.jawsDebug('deploy_lambda', 'Deploying to regions:');
utils.jawsDebug('deploy_lambda', this._regions);
});
/**
@ -268,7 +268,7 @@ Deployer.prototype.deploy = Promise.method(function() {
var createOrUpdate,
cfDeferred;
utils.logIfVerbose('Deploying with lambda role arn ' + lambdaRoleArn);
utils.jawsDebug('deploy_lambda', 'Deploying with lambda role arn ' + lambdaRoleArn);
if (existingStack) {
cfDeferred = AWSUtils.cfUpdateLambdasStack(_this._JAWS, _this._stage, _this._region, lambdaRoleArn);
@ -327,7 +327,7 @@ Deployer.prototype._generateLambdaCf = function(taggedLambdaPkgs, lambdaRoleArn)
throw new JawsError(e.message, JawsError.errorCodes.UNKNOWN);
}
utils.logIfVerbose('no exsting lambda stack');
utils.jawsDebug('deploy_lambda', 'no exsting lambda stack');
existingStack = false;
return false;
})
@ -353,15 +353,15 @@ Deployer.prototype._generateLambdaCf = function(taggedLambdaPkgs, lambdaRoleArn)
Ref: "aaLambdaRoleArn"
};
utils.logIfVerbose('adding Resource ' + pkg.lambdaName + ': ');
utils.logIfVerbose(lResource);
utils.jawsDebug('deploy_lambda', 'adding Resource ' + pkg.lambdaName + ': ');
utils.jawsDebug('deploy_lambda', lResource);
lambdaCf.Resources[pkg.lambdaName] = lResource;
});
// If existing lambdas CF template
if (cfTemplateBody) {
utils.logIfVerbose('existing stack detected');
utils.jawsDebug('deploy_lambda', 'existing stack detected');
// Find all lambdas in project, and copy ones that are in existing lambda-cf
var existingTemplate = JSON.parse(cfTemplateBody);
@ -371,7 +371,7 @@ Deployer.prototype._generateLambdaCf = function(taggedLambdaPkgs, lambdaRoleArn)
Object.keys(existingTemplate.Resources).forEach(function(resource) {
if (!lambdaCf.Resources[resource] && allLambdaNames.indexOf(resource) != -1) {
utils.logIfVerbose('Adding exsiting lambda ' + resource);
utils.jawsDebug('deploy_lambda', 'Adding exsiting lambda ' + resource);
lambdaCf.Resources[resource] = existingTemplate.Resources[resource];
}
});
@ -391,7 +391,7 @@ Deployer.prototype._generateLambdaCf = function(taggedLambdaPkgs, lambdaRoleArn)
'lambdas-cf.json'
);
utils.logIfVerbose('Wrting to ' + lambdasCfPath);
utils.jawsDebug('deploy_lambda', 'Wrting to ' + lambdasCfPath);
return utils.writeFile(lambdasCfPath, JSON.stringify(lambdaCfTemplate, null, 2))
.then(function() {
@ -423,7 +423,7 @@ Packager.prototype.createLambdaName = function() {
var _this = this,
name = utils.generateLambdaName(_this._awsmJson);
utils.logIfVerbose('computed lambdaName: ' + name);
utils.jawsDebug('deploy_lambda', 'computed lambdaName: ' + name);
return name;
};
@ -508,9 +508,9 @@ Packager.prototype._createDistFolder = Promise.method(function() {
}
);
utils.logIfVerbose('Packaging stage & region:');
utils.logIfVerbose(_this._stage);
utils.logIfVerbose(_this._region);
utils.jawsDebug('deploy_lambda', 'Packaging stage & region:');
utils.jawsDebug('deploy_lambda', _this._stage);
utils.jawsDebug('deploy_lambda', _this._region);
// Get ENV file from S3
return _this._JAWS.getEnvFile(_this._region, _this._stage)

View File

@ -80,10 +80,10 @@ CMD.prototype._installCore = Promise.method(function() {
if (!!jawsCoreName) {
var existingJawsCorePath = path.join(_this._JAWS._meta.projectRootPath, 'back', 'aws_modules', jawsCoreName);
utils.logIfVerbose('Looking for existing jaws core in ' + existingJawsCorePath);
utils.jawsDebug('module_create', 'Looking for existing jaws core in ' + existingJawsCorePath);
if (!utils.dirExistsSync(existingJawsCorePath)) {
utils.logIfVerbose(jawsCoreName + ' DNE, installing');
utils.jawsDebug('module_create', jawsCoreName + ' DNE, installing');
return modInstall.install(_this._JAWS, 'https://github.com/jaws-framework/' + jawsCoreName, true, false);
}
}
@ -211,4 +211,4 @@ CMD.prototype._createSkeleton = Promise.method(function() {
// Write Files
writeFilesDeferred.push(utils.writeFile(path.join(actionPath, 'awsm.json'), JSON.stringify(actionTemplateJson, null, 2)));
return Promise.all(writeFilesDeferred);
});
});

View File

@ -113,7 +113,7 @@ CMD.prototype._downloadMod = Promise.method(function() {
return temp.mkdirAsync('awsm')
.then(function(tempDirPath) {
return new Promise(function(resolve, reject) {
utils.logIfVerbose('Downloading awsm to ' + tempDirPath);
utils.jawsDebug('module_install', 'Downloading awsm to ' + tempDirPath);
JawsCLI.log('Downloading aws-module ...');
spinner.start();

View File

@ -15,7 +15,6 @@ var JawsError = require('../jaws-error'),
path = require('path'),
os = require('os'),
chalk = require('chalk'),
debug = require('debug')('jaws:new_project'),
AWSUtils = require('../utils/aws'),
utils = require('../utils'),
shortid = require('shortid');
@ -35,7 +34,7 @@ Promise.promisifyAll(fs);
*/
module.exports.run = function(name, stage, s3Bucket, domain, region, notificationEmail, profile, noCf) {
debug('Running new project: ' + name);
utils.jawsDebug('new_project', 'Running new project:', name);
var command = new CMD(
name,
stage,
@ -124,7 +123,7 @@ CMD.prototype.run = Promise.method(function() {
CMD.prototype._prompt = Promise.method(function() {
debug('Prompting for new project information');
utils.jawsDebug('new_project', 'Prompting for new project information');
var _this = this;
var nameDescription = 'Enter a project name: ' + os.EOL;

View File

@ -7,7 +7,6 @@
var Promise = require('bluebird'),
AWS = require('aws-sdk'),
path = require('path'),
debug = require('debug')('jaws:utils_aws'),
os = require('os'),
JawsError = require('../jaws-error/index'),
utils = require('../utils'),
@ -85,7 +84,7 @@ module.exports.profilesMap = function() {
* @param secretKey
*/
module.exports.profilesSet = function(awsProfile, awsRegion, accessKeyId, secretKey) {
debug('Setting new AWS profile:' + awsProfile);
utils.jawsDebug('utils_aws', 'Setting new AWS profile:', awsProfile);
var configDir = this.getConfigDir(),
credsPath = path.join(configDir, 'credentials'),
configPath = path.join(configDir, 'config');
@ -696,7 +695,7 @@ exports.getEnvFile = function(awsProfile, awsRegion, bucketName, projectName, st
Key: key,
};
utils.logIfVerbose('env var s3 key: ' + key);
utils.jawsDebug('utils_aws', 'env var s3 key: ' + key);
return this.getS3Object(awsProfile, awsRegion, params);
};
@ -742,7 +741,7 @@ exports.putLambdaZip = function(awsProfile, awsRegion, bucketName, projectName,
Body: zipBuffer,
};
utils.logIfVerbose('lambda zip s3 key: ' + key);
utils.jawsDebug('utils_aws', 'lambda zip s3 key: ' + key);
return this.putS3Object(awsProfile, awsRegion, params)
.then(function() {

View File

@ -139,7 +139,7 @@ Select._clear = function() {
// Private: Close
Select._close = function(cb) {
utils.logIfVerbose('Closing select listener');
utils.jawsDebug('utils_cli', 'Closing select listener');
var _this = this;
process.stdin.pause();

View File

@ -5,7 +5,7 @@
*/
require('shelljs/global');
var Promise = require('bluebird'),
debug = require('debug')('jaws:util'),
rawDebug = require('debug'),
path = require('path'),
async = require('async'),
readdirp = require('readdirp'),
@ -183,9 +183,16 @@ exports.findAllAwsmJsons = function(startPath) {
*
* @param str
*/
exports.logIfVerbose = function(str) {
if (process.env.JAWS_VERBOSE) {
console.log(str);
var debuggerCache = {};
exports.jawsDebug = function(context) {
if (process.env.DEBUG) {
context = 'jaws:' + context;
if (!debuggerCache[context]) {
debuggerCache[context] = rawDebug(context);
}
debuggerCache[context].apply(null, Array.prototype.slice.call(arguments, 1));
}
};
@ -197,7 +204,7 @@ exports.logIfVerbose = function(str) {
* @returns {Promise}
*/
exports.writeFile = function(filePath, contents) {
debug('Writing file: ' + filePath, contents);
this.jawsDebug('util', 'Writing file:', filePath);
if (contents === undefined) {
contents = '';

View File

@ -31,7 +31,7 @@ module.exports.createTestProject = function(projectName,
// Create Test Project
var tmpProjectPath = path.join(os.tmpdir(), projectName + '-' + uuid.v4());
utils.logIfVerbose('Creating test proj in ' + tmpProjectPath + '\n');
utils.jawsDebug('test_utils', 'Creating test proj in ' + tmpProjectPath + '\n');
if (fs.existsSync(tmpProjectPath)) {
return Promise.reject(new JawsError('Temp dir ' + tmpProjectPath + ' already exists'));
@ -72,7 +72,7 @@ module.exports.createTestProject = function(projectName,
if (npmInstallDirs) {
npmInstallDirs.forEach(function(dir) {
var fullPath = path.join(tmpProjectPath, dir);
utils.logIfVerbose('Running NPM install on ' + fullPath);
utils.jawsDebug('test_utils', 'Running NPM install on ' + fullPath);
utils.npmInstall(fullPath);
});
}