From 3a4d4e4acdfa205ae85f494a1a289f405bebadf3 Mon Sep 17 00:00:00 2001 From: Austen Collins Date: Sat, 26 Sep 2015 12:36:31 -0700 Subject: [PATCH 01/12] resources: add s3 project bucket --- lib/templates/resources-cf.json | 14 ++++++++++++++ lib/utils/aws.js | 4 ++++ lib/utils/index.js | 16 ++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/lib/templates/resources-cf.json b/lib/templates/resources-cf.json index 60cc01a95..2cb3f594a 100644 --- a/lib/templates/resources-cf.json +++ b/lib/templates/resources-cf.json @@ -9,6 +9,10 @@ "Type": "String", "Default": "myapp.com" }, + "aaProjectBucket": { + "Type": "String", + "Default": "myapp.com" + }, "aaStage": { "Type": "String" }, @@ -204,6 +208,16 @@ } ] } + }, + "ProjectS3Bucket" : { + "Type" : "AWS::S3::Bucket", + "Properties" : { + "AccessControl" : "Private", + "BucketName" : { + "Ref": "aaProjectBucket" + } + }, + "DeletionPolicy" : "Retain" } }, "Outputs": { diff --git a/lib/utils/aws.js b/lib/utils/aws.js index c72495514..cebe9fa9c 100644 --- a/lib/utils/aws.js +++ b/lib/utils/aws.js @@ -488,6 +488,10 @@ exports.cfCreateResourcesStack = function(awsProfile, awsRegion, projRootPath, p ParameterKey: 'aaStage', ParameterValue: projStage, UsePreviousValue: false, + }, { + ParameterKey: 'aaProjectBucket', + ParameterValue: projStage, + UsePreviousValue: false, }, { ParameterKey: 'aaDataModelPrefix', ParameterValue: projStage, diff --git a/lib/utils/index.js b/lib/utils/index.js index 0a90fea8a..84878acba 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -214,6 +214,22 @@ exports.generateLambdaName = function(awsmJson) { }); }; +/** + * Generate ProjectBucket Name + * @param stage + * @param region + * @param projectDomain + * @returns {string} + */ + +exports.generateProjectBucketName = function(stage, region, projectDomain) { + + // Sanitize + stage = stage.trim().toLowerCase; + + +}; + /** * Gets all lambda functionName's * From bf465991609f30c193b426a475e30d7ba0649e57 Mon Sep 17 00:00:00 2001 From: Austen Collins Date: Sat, 26 Sep 2015 15:27:14 -0700 Subject: [PATCH 02/12] new project: refactor for new bucket organization. Change CFcreateresources to use TemplateBody, not S3 --- lib/commands/new_project.js | 62 +++++++++------------------------ lib/templates/resources-cf.json | 6 ++-- lib/utils/aws.js | 27 +++++++------- lib/utils/index.js | 13 ++++--- tests/all.js | 12 +++---- 5 files changed, 48 insertions(+), 72 deletions(-) diff --git a/lib/commands/new_project.js b/lib/commands/new_project.js index ad2e786a7..155e40bcc 100644 --- a/lib/commands/new_project.js +++ b/lib/commands/new_project.js @@ -25,7 +25,7 @@ Promise.promisifyAll(fs); * Run * @param name * @param stage - * @param s3Bucket + * @param domain * @param region * @param notificationEmail * @param profile @@ -33,12 +33,11 @@ Promise.promisifyAll(fs); * @returns {*} */ -module.exports.run = function(name, stage, s3Bucket, domain, region, notificationEmail, profile, noCf) { +module.exports.run = function(name, stage, domain, region, notificationEmail, profile, noCf) { utils.jawsDebug('Running new project:', name); var command = new CMD( name, stage, - s3Bucket, domain, notificationEmail, region, @@ -51,22 +50,20 @@ module.exports.run = function(name, stage, s3Bucket, domain, region, notificatio * CMD Class * @param name * @param stage - * @param s3Bucket * @param domain * @param notificationEmail * @param region * @param profile - * @param noExeCf + * @param noCf * @constructor */ -function CMD(name, stage, s3Bucket, domain, notificationEmail, region, profile, noCf) { +function CMD(name, stage,domain, notificationEmail, region, profile, noCf) { // Defaults this._name = name ? name : null; this._domain = domain ? domain : null; this._stage = stage ? stage.toLowerCase().replace(/\W+/g, '').substring(0, 15) : null; - this._s3Bucket = s3Bucket; this._notificationEmail = notificationEmail; this._region = region; this._profile = profile; @@ -96,7 +93,7 @@ CMD.prototype.run = Promise.method(function() { .bind(_this) .then(_this._prompt) .then(_this._prepareProjectData) - .then(_this._createS3JawsStructure) //see if bucket is avail first before doing work + //.then(_this._createS3JawsStructure) //see if bucket is avail first before doing work .then(_this._createProjectDirectory) .then(function() { if (_this._noCf) { @@ -147,7 +144,7 @@ CMD.prototype._prompt = Promise.method(function() { + os.EOL + ' - You don’t need to currently own this domain. ' + os.EOL - + ' - JAWS mostly uses it to namespace some project AWS resources (S3 Buckets). ' + + ' - JAWS will use it to uniquely namespace S3 buckets that store this project\'s data.' + os.EOL + ' - However, if you do set up this domain as a Hosted Zone on Route 53 you will benefit from extra features' + os.EOL @@ -177,30 +174,6 @@ CMD.prototype._prompt = Promise.method(function() { }, }; - // Prompt: s3 bucket - holds env vars for this project - _this.Prompter.override.s3Bucket = _this._s3Bucket; - - var s3BucketDescription = 'Enter a project S3 Bucket name: ' - + os.EOL - + ' - JAWS uses an extra S3 bucket to store project ENV variables, lambda zips, and cloudformation templates.' - + os.EOL - + ' - This can be an existing bucket you reuse for all of your JAWS projects (must be in same region as your project).' - + os.EOL - + ' - If this doesn\'t exist, JAWS will create it automatically after these prompts in your project region.' - + os.EOL - + ' - You can enter a placeholder for now and change this at any time.' - + os.EOL; - - _this._prompts.properties.s3Bucket = { - description: s3BucketDescription.yellow, - default: 'jaws.myapp.com', - message: 'Bucket name must only contain lowercase letters, numbers, periods and dashes', - conform: function(bucket) { - var re = /^[a-z0-9-.]+$/; - return re.test(bucket); - }, - }; - // Prompt: stage _this.Prompter.override.stage = _this._stage; @@ -269,7 +242,6 @@ CMD.prototype._prompt = Promise.method(function() { _this._name = answers.name; _this._domain = answers.domain; _this._stage = answers.stage.toLowerCase(); - _this._s3Bucket = answers.s3Bucket; _this._notificationEmail = answers.notificationEmail; _this._awsAdminKeyId = answers.awsAdminKeyId; _this._awsAdminSecretKey = answers.awsAdminSecretKey; @@ -382,16 +354,6 @@ CMD.prototype._createProjectDirectory = Promise.method(function() { // Prepare admin.env var adminEnv = 'ADMIN_AWS_PROFILE=' + _this._profile + os.EOL; - // Prepare CloudFormation template - var cfTemplate = utils.readAndParseJsonSync(__dirname + '/../templates/resources-cf.json'); - cfTemplate.Parameters.aaProjectName.Default = _this._name; - cfTemplate.Parameters.aaProjectDomain.Default = _this._domain; - cfTemplate.Parameters.aaProjectName.AllowedValues = [_this._name]; - cfTemplate.Parameters.aaStage.Default = _this._stage; - cfTemplate.Parameters.aaDataModelPrefix.Default = _this._stage; //to simplify bootstrap use same stage - cfTemplate.Parameters.aaNotficationEmail.Default = _this._notificationEmail; - cfTemplate.Description = _this._name + " resources"; - // Create Project Scaffolding return utils.writeFile( path.join(_this._projectRootPath, 'back', '.env'), @@ -404,7 +366,14 @@ CMD.prototype._createProjectDirectory = Promise.method(function() { fs.mkdirAsync(path.join(_this._projectRootPath, 'tests')), fs.mkdirAsync(path.join(_this._projectRootPath, 'back', 'aws_modules')), utils.writeFile(path.join(_this._projectRootPath, 'admin.env'), adminEnv), - utils.generateResourcesCf(_this._projectRootPath, _this._name, _this._stage, _this._region, _this._notificationEmail), + utils.generateResourcesCf( + _this._projectRootPath, + _this._name, + _this._domain, + _this._stage, + _this._region, + _this._notificationEmail + ), fs.writeFileAsync(path.join(_this._projectRootPath, '.gitignore'), fs.readFileSync(__dirname + '/../templates/gitignore')), ]); }); @@ -458,7 +427,7 @@ CMD.prototype._createCfStack = Promise.method(function() { _this._projectRootPath, _this._name, _this._stage, - _this._s3Bucket, + _this._domain, _this._notificationEmail) .then(function(cfData) { return AWSUtils.monitorCf(cfData, _this._profile, _this._region, 'create'); @@ -497,6 +466,7 @@ CMD.prototype._createProjectJson = Promise.method(function(cfData) { region: _this._region, iamRoleArnLambda: iamRoleArnLambda || '', iamRoleArnApiGateway: iamRoleArnApiGateway || '', + jawsBucket: utils.generateJawsBucketName(_this._stage, _this._region, _this._domain) }]; jawsJson.jawsBuckets[_this._region] = _this._s3Bucket; diff --git a/lib/templates/resources-cf.json b/lib/templates/resources-cf.json index 2cb3f594a..6fd5079e7 100644 --- a/lib/templates/resources-cf.json +++ b/lib/templates/resources-cf.json @@ -9,7 +9,7 @@ "Type": "String", "Default": "myapp.com" }, - "aaProjectBucket": { + "aaJawsBucket": { "Type": "String", "Default": "myapp.com" }, @@ -209,12 +209,12 @@ ] } }, - "ProjectS3Bucket" : { + "JawsBucket" : { "Type" : "AWS::S3::Bucket", "Properties" : { "AccessControl" : "Private", "BucketName" : { - "Ref": "aaProjectBucket" + "Ref": "aaJawsBucket" } }, "DeletionPolicy" : "Retain" diff --git a/lib/utils/aws.js b/lib/utils/aws.js index cebe9fa9c..ab6f1601c 100644 --- a/lib/utils/aws.js +++ b/lib/utils/aws.js @@ -464,21 +464,26 @@ exports.cfUpdateLambdasStack = function(JAWS, stage, region, lambdaRoleArn) { * @returns {Promise} */ -exports.cfCreateResourcesStack = function(awsProfile, awsRegion, projRootPath, projName, projStage, bucketName, projNotificationEmail) { +exports.cfCreateResourcesStack = function(awsProfile, awsRegion, projRootPath, projName, projStage, projDomain, projNotificationEmail) { + var _this = this; _this.configAWS(awsProfile, awsRegion); var CF = Promise.promisifyAll(new AWS.CloudFormation({ apiVersion: '2010-05-15', - })), - stackName = _this.cfGetResourcesStackName(projStage, projName); + })); + + var stackName = _this.cfGetResourcesStackName(projStage, projName); + var jawsBucket = utils.generateJawsBucketName(projStage, awsRegion, projDomain); + var resourcesTemplate = require('../templates/resources-cf.json'); var params = { StackName: stackName, Capabilities: [ 'CAPABILITY_IAM', ], + TemplateBody: JSON.stringify(resourcesTemplate), OnFailure: 'ROLLBACK', Parameters: [{ ParameterKey: 'aaProjectName', @@ -489,8 +494,8 @@ exports.cfCreateResourcesStack = function(awsProfile, awsRegion, projRootPath, p ParameterValue: projStage, UsePreviousValue: false, }, { - ParameterKey: 'aaProjectBucket', - ParameterValue: projStage, + ParameterKey: 'aaJawsBucket', + ParameterValue: jawsBucket, UsePreviousValue: false, }, { ParameterKey: 'aaDataModelPrefix', @@ -515,11 +520,9 @@ exports.cfCreateResourcesStack = function(awsProfile, awsRegion, projRootPath, p },], }; - return _this.putCfFile(awsProfile, projRootPath, awsRegion, bucketName, projName, projStage, 'resources') - .then(function(templateUrl) { - params.TemplateURL = templateUrl; - return CF.createStackAsync(params); - }); + // Create CloudFormation Stack + return CF.createStackAsync(params); + }; /** @@ -606,9 +609,9 @@ exports.monitorCf = function(cfData, awsProfile, region, createOrUpdate, checkFr stackStatus = stackData.Stacks[0].StackStatus; if (!stackStatus || validStatuses.indexOf(stackStatus) === -1) { + console.log((data.Stacks && data.Stacks.length ? data.Stacks[0] : data)); return reject(new JawsError( - 'Something went wrong while ' + createOrUpdate + 'ing your cloudformation', - JawsError.errorCodes.UNKNOWN)); + 'Something went wrong while ' + createOrUpdate + 'ing your cloudformation')); } else { return callback(); } diff --git a/lib/utils/index.js b/lib/utils/index.js index 84878acba..ea8ab1eca 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -215,19 +215,21 @@ exports.generateLambdaName = function(awsmJson) { }; /** - * Generate ProjectBucket Name + * Generate JawsBucket Name * @param stage * @param region * @param projectDomain * @returns {string} */ -exports.generateProjectBucketName = function(stage, region, projectDomain) { +exports.generateJawsBucketName = function(stage, region, projectDomain) { // Sanitize - stage = stage.trim().toLowerCase; - + stage = stage.trim().toLowerCase(); + region = region.trim().toLowerCase(); + projectDomain = projectDomain.trim().toLowerCase(); + return stage + '.' + region + '.' + projectDomain; }; /** @@ -318,10 +320,11 @@ exports.npmInstall = function(dir) { process.chdir(cwd); }; -exports.generateResourcesCf = function(projRootPath, projName, stage, region, notificationEmail) { +exports.generateResourcesCf = function(projRootPath, projName, projDomain, stage, region, notificationEmail) { var cfTemplate = require('../templates/resources-cf'); cfTemplate.Parameters.aaProjectName.Default = projName; cfTemplate.Parameters.aaProjectName.AllowedValues = [projName]; + cfTemplate.Parameters.aaProjectDomain.Default = projDomain; cfTemplate.Parameters.aaStage.Default = stage; cfTemplate.Parameters.aaDataModelPrefix.Default = stage; //to simplify bootstrap use same stage cfTemplate.Parameters.aaNotficationEmail.Default = notificationEmail; diff --git a/tests/all.js b/tests/all.js index fe550eba8..6d423adf0 100644 --- a/tests/all.js +++ b/tests/all.js @@ -15,11 +15,11 @@ describe('AllTests', function() { }); //require tests vs inline so we can run sequentially - require('./cli/tag'); - require('./cli/module_install'); - require('./cli/env'); - require('./cli/module_create'); - require('./cli/run'); + //require('./cli/tag'); + //require('./cli/module_install'); + //require('./cli/env'); + //require('./cli/module_create'); + //require('./cli/run'); /** * Tests below create AWS Resources @@ -29,5 +29,5 @@ describe('AllTests', function() { //require('./cli/deploy_resources'); //require('./cli/deploy_endpoint'); //require('./cli/new_stage_region'); - //require('./cli/new_project'); + require('./cli/new_project'); }); \ No newline at end of file From f5741141e9855278582544e2379f8f4f3c62d536 Mon Sep 17 00:00:00 2001 From: Austen Collins Date: Sat, 26 Sep 2015 19:59:15 -0700 Subject: [PATCH 03/12] new command: finish refactor --- lib/commands/new_project.js | 80 +++++++++++++++++--------------- lib/commands/new_stage_region.js | 18 +++---- lib/templates/jaws.json | 4 +- lib/utils/aws.js | 3 +- lib/utils/index.js | 2 +- 5 files changed, 56 insertions(+), 51 deletions(-) diff --git a/lib/commands/new_project.js b/lib/commands/new_project.js index 155e40bcc..02bca77ca 100644 --- a/lib/commands/new_project.js +++ b/lib/commands/new_project.js @@ -86,14 +86,13 @@ CMD.prototype.run = Promise.method(function() { return Promise.try(function() { - // ASCII Greeting - JawsCLI.ascii(); + // ASCII Greeting + JawsCLI.ascii(); - }) + }) .bind(_this) .then(_this._prompt) .then(_this._prepareProjectData) - //.then(_this._createS3JawsStructure) //see if bucket is avail first before doing work .then(_this._createProjectDirectory) .then(function() { if (_this._noCf) { @@ -107,8 +106,10 @@ CMD.prototype.run = Promise.method(function() { if (_this._spinner) { _this._spinner.stop(true); } - return cfData; - }); + _this._cfData = cfData; + }) + .bind(_this) + .then(_this._putEnvFile); } }) .then(_this._createProjectJson); @@ -318,6 +319,9 @@ CMD.prototype._prepareProjectData = Promise.method(function() { _this._name = _this._name + '-' + shortid.generate().replace(/\W+/g, '').substring(0, 19); } + // Set JAWS Bucket + _this._jawsBucket = utils.generateJawsBucketName(_this._stage, _this._region, _this._domain); + // Validate: If no profile, ensure access keys, create profile if (!_this._profile) { @@ -356,10 +360,10 @@ CMD.prototype._createProjectDirectory = Promise.method(function() { // Create Project Scaffolding return utils.writeFile( - path.join(_this._projectRootPath, 'back', '.env'), - 'JAWS_STAGE=' + _this._stage - + '\nJAWS_DATA_MODEL_STAGE=' + _this._stage - ) + path.join(_this._projectRootPath, 'back', '.env'), + 'JAWS_STAGE=' + _this._stage + + '\nJAWS_DATA_MODEL_STAGE=' + _this._stage + ) .then(function() { return Promise.all([ fs.mkdirAsync(path.join(_this._projectRootPath, 'front')), @@ -388,24 +392,21 @@ CMD.prototype._createProjectDirectory = Promise.method(function() { * @private */ -CMD.prototype._createS3JawsStructure = Promise.method(function() { +CMD.prototype._putEnvFile = Promise.method(function() { var _this = this; - return AWSUtils.createBucket(_this._profile, _this._region, _this._s3Bucket) - .then(function() { + var envFileContents = 'JAWS_STAGE=' + _this._stage + + '\nJAWS_DATA_MODEL_STAGE=' + _this._stage; - var envFileContents = 'JAWS_STAGE=' + _this._stage - + '\nJAWS_DATA_MODEL_STAGE=' + _this._stage; + return AWSUtils.putEnvFile( + _this._profile, + _this._region, + _this._jawsBucket, + _this._name, + _this._stage, + envFileContents); - return AWSUtils.putEnvFile( - _this._profile, - _this._region, - _this._s3Bucket, - _this._name, - _this._stage, - envFileContents); - }); }); /** @@ -422,13 +423,15 @@ CMD.prototype._createCfStack = Promise.method(function() { // Create CF stack return AWSUtils.cfCreateResourcesStack( - _this._profile, - _this._region, - _this._projectRootPath, - _this._name, - _this._stage, - _this._domain, - _this._notificationEmail) + _this._profile, + _this._region, + _this._projectRootPath, + _this._name, + _this._stage, + _this._domain, + _this._notificationEmail, + _this._jawsBucket + ) .then(function(cfData) { return AWSUtils.monitorCf(cfData, _this._profile, _this._region, 'create'); }); @@ -443,18 +446,19 @@ CMD.prototype._createCfStack = Promise.method(function() { */ CMD.prototype._createProjectJson = Promise.method(function(cfData) { + var _this = this, iamRoleArnLambda, iamRoleArnApiGateway; - if (cfData) { - for (var i = 0; i < cfData.Outputs.length; i++) { - if (cfData.Outputs[i].OutputKey === 'IamRoleArnLambda') { - iamRoleArnLambda = cfData.Outputs[i].OutputValue; + if (_this._cfData) { + for (var i = 0; i < _this._cfData.Outputs.length; i++) { + if (_this._cfData.Outputs[i].OutputKey === 'IamRoleArnLambda') { + iamRoleArnLambda = _this._cfData.Outputs[i].OutputValue; } - if (cfData.Outputs[i].OutputKey === 'IamRoleArnApiGateway') { - iamRoleArnApiGateway = cfData.Outputs[i].OutputValue; + if (_this._cfData.Outputs[i].OutputKey === 'IamRoleArnApiGateway') { + iamRoleArnApiGateway = _this._cfData.Outputs[i].OutputValue; } } } @@ -466,11 +470,11 @@ CMD.prototype._createProjectJson = Promise.method(function(cfData) { region: _this._region, iamRoleArnLambda: iamRoleArnLambda || '', iamRoleArnApiGateway: iamRoleArnApiGateway || '', - jawsBucket: utils.generateJawsBucketName(_this._stage, _this._region, _this._domain) + jawsBucket: _this._jawsBucket, }]; - jawsJson.jawsBuckets[_this._region] = _this._s3Bucket; jawsJson.name = _this._name; + jawsJson.domain = _this._domain; fs.writeFileSync(path.join(_this._projectRootPath, 'jaws.json'), JSON.stringify(jawsJson, null, 2)); diff --git a/lib/commands/new_stage_region.js b/lib/commands/new_stage_region.js index 9923c7d3c..9e9395c88 100644 --- a/lib/commands/new_stage_region.js +++ b/lib/commands/new_stage_region.js @@ -260,18 +260,20 @@ CMD.prototype._createCfStack = Promise.method(function() { _this._spinner = JawsCLI.spinner(); _this._spinner.start(); + // Create CF stack return AWSUtils.cfCreateResourcesStack( - _this._JAWS._meta.profile, - _this._region, - _this._JAWS._meta.projectRootPath, - _this._JAWS._meta.projectJson.name, - _this._stage, - _this._s3Bucket, - '' // TODO: read email out of existing jaws-cf.json? - ) + _this._JAWS._meta.profile, + _this._region, + _this._JAWS._meta.projectRootPath, + _this._JAWS._meta.projectJson.name, + _this._stage, + _this._domain, + '' // TODO: read email out of existing jaws-cf.json? + ) .then(function(cfData) { return AWSUtils.monitorCf(cfData, _this._JAWS._meta.profile, _this._region, 'create'); }); + }); /** diff --git a/lib/templates/jaws.json b/lib/templates/jaws.json index 7a67a01fd..d9fcfce9b 100644 --- a/lib/templates/jaws.json +++ b/lib/templates/jaws.json @@ -4,6 +4,6 @@ "location": "https://github.com/...", "author": "", "description": "", - "stages": {}, - "jawsBuckets": {} + "domain": "", + "stages": {} } \ No newline at end of file diff --git a/lib/utils/aws.js b/lib/utils/aws.js index ab6f1601c..4385ce4c1 100644 --- a/lib/utils/aws.js +++ b/lib/utils/aws.js @@ -464,7 +464,7 @@ exports.cfUpdateLambdasStack = function(JAWS, stage, region, lambdaRoleArn) { * @returns {Promise} */ -exports.cfCreateResourcesStack = function(awsProfile, awsRegion, projRootPath, projName, projStage, projDomain, projNotificationEmail) { +exports.cfCreateResourcesStack = function(awsProfile, awsRegion, projRootPath, projName, projStage, projDomain, projNotificationEmail, jawsBucket) { var _this = this; @@ -475,7 +475,6 @@ exports.cfCreateResourcesStack = function(awsProfile, awsRegion, projRootPath, p })); var stackName = _this.cfGetResourcesStackName(projStage, projName); - var jawsBucket = utils.generateJawsBucketName(projStage, awsRegion, projDomain); var resourcesTemplate = require('../templates/resources-cf.json'); var params = { diff --git a/lib/utils/index.js b/lib/utils/index.js index ea8ab1eca..6b7e78730 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -229,7 +229,7 @@ exports.generateJawsBucketName = function(stage, region, projectDomain) { region = region.trim().toLowerCase(); projectDomain = projectDomain.trim().toLowerCase(); - return stage + '.' + region + '.' + projectDomain; + return 'jaws.' + stage + '.' + region + '.' + projectDomain; }; /** From 0ac1ae3ddc299b442417d8546a20bdd02ff53e04 Mon Sep 17 00:00:00 2001 From: Austen Collins Date: Sun, 27 Sep 2015 12:20:18 -0700 Subject: [PATCH 04/12] new stage region: start refactor, add interactive prompts for usability --- bin/jaws | 19 +-- lib/commands/new_project.js | 33 +++-- lib/commands/new_stage_region.js | 220 +++++++++++++++++++------------ lib/utils/aws.js | 8 +- 4 files changed, 174 insertions(+), 106 deletions(-) diff --git a/bin/jaws b/bin/jaws index 9b9e0aafc..56377c019 100755 --- a/bin/jaws +++ b/bin/jaws @@ -58,26 +58,19 @@ program } else if (cmd == 'region' || cmd == 'stage') { var theParams = process.argv.slice(3); - if (!theParams) { - throw new JawsError('Missing params', JawsError.errorCodes.UNKNOWN); - } - - if (theParams[0][0] == '-') { //TODO: how do we get around this commander shortcoming? + if (theParams[0] + && theParams[0][0] + && theParams[0][0] == '-') { //TODO: how do we get around this commander shortcoming? throw new JawsError('Specify options after cmd', JawsError.errorCodes.UNKNOWN); } - //TODO: iterate thru cmds to see how many are before - - if (theParams.length < 2) { - throw new JawsError('must specify stage name', JawsError.errorCodes.UNKNOWN); - } - - var CmdNewStageRegion = require('../lib/commands/new_stage_region'), - stageName = theParams[1]; + var CmdNewStageRegion = require('../lib/commands/new_stage_region'); + var stage = theParams[1] ? theParams[1] : null; execute(CmdNewStageRegion.run( JAWS, cmd, - stageName, + stage, options.region, options.s3Bucket, options.dontExeCf diff --git a/lib/commands/new_project.js b/lib/commands/new_project.js index 02bca77ca..e2cd40c94 100644 --- a/lib/commands/new_project.js +++ b/lib/commands/new_project.js @@ -102,14 +102,15 @@ CMD.prototype.run = Promise.method(function() { return false; } else { return _this._createCfStack() + .bind(_this) .then(function(cfData) { if (_this._spinner) { _this._spinner.stop(true); } _this._cfData = cfData; }) - .bind(_this) - .then(_this._putEnvFile); + .then(_this._putEnvFile) + .then(_this._putCfFile); } }) .then(_this._createProjectJson); @@ -384,12 +385,8 @@ CMD.prototype._createProjectDirectory = Promise.method(function() { }); /** - * CMD Create S3 Bucket - * (if DNE) and upload the 1st stage env var - * Format: /JAWS/envVars// - * - * @returns {Promise} - * @private + * CMD Put ENV File + * - Uploads .env file to jawsbucket */ CMD.prototype._putEnvFile = Promise.method(function() { @@ -409,6 +406,26 @@ CMD.prototype._putEnvFile = Promise.method(function() { }); +/** + * CMD: Put CF File + * - Uploads timestamped CF file to jawsbucket + */ + +CMD.prototype._putCfFile = Promise.method(function() { + + var _this = this; + + return AWSUtils.putCfFile( + _this._profile, + _this._projectRootPath, + _this._region, + _this._jawsBucket, + _this._name, + _this._stage, + 'resources'); + +}); + /** * CMD: Create CloudFormation Stack */ diff --git a/lib/commands/new_stage_region.js b/lib/commands/new_stage_region.js index 9e9395c88..cc7575e0c 100644 --- a/lib/commands/new_stage_region.js +++ b/lib/commands/new_stage_region.js @@ -10,6 +10,7 @@ var JawsError = require('../jaws-error'), JawsCLI = require('../utils/cli'), Promise = require('bluebird'), fs = require('fs'), + os = require('os'), path = require('path'), AWSUtils = require('../utils/aws'), utils = require('../utils'); @@ -22,13 +23,12 @@ Promise.promisifyAll(fs); * @param type 'stage'|'region' * @param stage * @param region Optional. Will be prompted for if omitted - * @param s3Bucket Optional. only valid for type of region * @param noCf Optional * @returns {*} */ -module.exports.run = function(JAWS, type, stage, region, s3Bucket, noCf) { - var command = new CMD(JAWS, type, stage, region, s3Bucket, noCf); +module.exports.run = function(JAWS, type, stage, region, noCf) { + var command = new CMD(JAWS, type, stage, region, noCf); return command.run(); }; @@ -37,14 +37,16 @@ module.exports.run = function(JAWS, type, stage, region, s3Bucket, noCf) { * @constructor */ -function CMD(JAWS, type, stage, region, s3Bucket, noCf) { +function CMD(JAWS, type, stage, region, noCf) { this._JAWS = JAWS; this._type = type; this._stage = stage; this._region = region; - this._s3Bucket = s3Bucket; this._noCf = noCf; this._spinner = null; + this._prompts = { + properties: {}, + }; } /** @@ -55,26 +57,22 @@ CMD.prototype.run = Promise.method(function() { var _this = this; - // Status - if (_this._type === 'stage') JawsCLI.log('Creating new stage "' + _this._stage + '"...'); - if (_this._type === 'region') JawsCLI.log('Creating new region within stage "' + _this._stage + '"...'); - return _this._JAWS.validateProject() .bind(_this) - .then(_this._promptRegion) .then(function() { - if (_this._type == 'stage') { //if stage we now have region, so we know bucket - _this._s3Bucket = _this._JAWS._meta.projectJson.jawsBuckets[_this._region]; - } else { - return _this._promptJawsS3Bucket(); - } + // Report Status + if (_this._type === 'stage') JawsCLI.log('Creating new stage...'); + if (_this._type === 'region') JawsCLI.log('Creating new region...'); }) + .then(_this._promptStage) + .then(_this._promptRegion) .then(_this._validate) .then(_this._createEnvFile) .then(function() { return utils.generateResourcesCf( _this._JAWS._meta.projectRootPath, _this._JAWS._meta.projectJson.name, + _this._JAWS._meta.projectJson.domain, _this._stage, _this._region, '' @@ -91,34 +89,94 @@ CMD.prototype.run = Promise.method(function() { return false; } else { return _this._createCfStack() + .bind(_this) .then(function(cfData) { if (_this._spinner) { _this._spinner.stop(true); } - return cfData; - }); + + _this._cfData = cfData; + }) + .then(_this._putEnvFile) + .then(_this._putCfFile); } }) .then(_this._updateProjectJson); }); +/** + * CMD: Prompt: Stage + */ + +CMD.prototype._promptStage = Promise.method(function() { + + var _this = this; + + if (_this._stage) return; + + if (_this._type === 'stage') { + + // User is creating a stage + _this.Prompter = JawsCLI.prompt(); + var stageDescription = 'Enter the name of the stage to be created: ' + os.EOL; + + _this._prompts.properties.stage = { + description: stageDescription.yellow, + default: 'dev', + message: 'Stage must be letters only', + conform: function(stage) { + var re = /^[a-zA-Z]+$/; + return re.test(stage); + }, + }; + + // Show Prompt + return _this.Prompter.getAsync(_this._prompts) + .then(function(answers) { + _this._stage = answers.stage; + }); + + } else { + + // User is creating a region + var stages = Object.keys(_this._JAWS._meta.projectJson.stages); + + // Check if project has stages + if (!stages.length) { + throw new JawsError('This project has no stages'); + } + + // If project only has 1 stage, skip prompt + if (stages.length === 1) { + _this._stage = stages[0]; + return; + } + + // Create Choices + var choices = []; + for (var i = 0; i < stages.length; i++) { + choices.push({ + key: (i + 1) + ') ', + value: stages[i], + label: stages[i], + }); + } + + return JawsCli.select('Which stage are you creating a region for: ', choices, false) + .then(function(results) { + _this._stage = results[0].value; + }); + } +}); + /** * CMD: Prompt: Region */ CMD.prototype._promptRegion = Promise.method(function() { - var _this = this, - msg = 'Choose a region lambda supports: ', - validRegions = AWSUtils.validLambdaRegions; - if (_this._type == 'stage') { //must use existing region - validRegions = Object.keys(_this._JAWS._meta.projectJson.jawsBuckets); - if (validRegions.length == 1) { - _this._region = validRegions[0]; - return Promise.resolve(); - } - msg = 'Choose an existing project region: '; - } + var _this = this, + validRegions = AWSUtils.validLambdaRegions; if (validRegions.indexOf(_this._region) != -1) { //they specified region and its valid return Promise.resolve(); @@ -133,44 +191,18 @@ CMD.prototype._promptRegion = Promise.method(function() { }); }); + if (_this._type === 'stage') { + var msg = 'Choose a region for your new stage:' + } else { + var msg = 'Choose a region lambda supports: ' + } + return JawsCLI.select(msg, choices, false) .then(function(results) { - console.log('results', results[0].value); _this._region = results[0].value; }); }); -CMD.prototype._promptJawsS3Bucket = function() { - var _this = this; - - //Don't ever auto-create s3 bucket as its against best practice, and this is not the quick start path - var Prompter = JawsCLI.prompt(), - prompts = { - properties: { - s3Bucket: { - description: 'Enter EXISTING s3 bucket for this region. Must be in THIS region: '.yellow, - required: true, - default: 'jaws-' + _this._region + '.yourapp.com', - message: 'Bucket name must only contain lowercase letters, numbers, periods and dashes', - conform: function(bucket) { - var re = /^[a-z0-9-.]+$/; - return re.test(bucket); - } - } - } - }; - - Prompter.override = { - s3Bucket: _this._s3Bucket, - }; - - return Prompter.getAsync(prompts) - .then(function(answers) { - _this._s3Bucket = answers.s3Bucket; - return _this._s3Bucket; - }); -}; - /** * CMD: Validate */ @@ -189,6 +221,9 @@ CMD.prototype._validate = Promise.method(function() { throw new JawsError('Stage and region are required'); } + // Set JAWS Bucket + _this._jawsBucket = utils.generateJawsBucketName(_this._stage, _this._region, _this._JAWS._meta.projectJson.domain); + // Stage Validations if (_this._type === 'stage') { @@ -224,26 +259,6 @@ CMD.prototype._validate = Promise.method(function() { return Promise.resolve(); }); -/** - * CMD: Create ENV File - */ - -CMD.prototype._createEnvFile = Promise.method(function() { - - var _this = this; - - var envFileContents = 'JAWS_STAGE=' + _this._stage - + '\nJAWS_DATA_MODEL_STAGE=' + _this._stage; - - return AWSUtils.putEnvFile( - _this._JAWS._meta.profile, - _this._region, - _this._s3Bucket, - _this._JAWS._meta.projectJson.name, - _this._stage, - envFileContents); -}); - /** * CMD: Create CF Stack */ @@ -268,7 +283,8 @@ CMD.prototype._createCfStack = Promise.method(function() { _this._JAWS._meta.projectJson.name, _this._stage, _this._domain, - '' // TODO: read email out of existing jaws-cf.json? + '', // TODO: read email out of existing jaws-cf.json? + _this._jawsBucket ) .then(function(cfData) { return AWSUtils.monitorCf(cfData, _this._JAWS._meta.profile, _this._region, 'create'); @@ -276,6 +292,48 @@ CMD.prototype._createCfStack = Promise.method(function() { }); +/** + * CMD Put ENV File + * - Uploads .env file to jawsbucket + */ + +CMD.prototype._putEnvFile = Promise.method(function() { + + var _this = this; + + var envFileContents = 'JAWS_STAGE=' + _this._stage + + '\nJAWS_DATA_MODEL_STAGE=' + _this._stage; + + return AWSUtils.putEnvFile( + _this._profile, + _this._region, + _this._jawsBucket, + _this._name, + _this._stage, + envFileContents); + +}); + +/** + * CMD: Put CF File + * - Uploads timestamped CF file to jawsbucket + */ + +CMD.prototype._putCfFile = Promise.method(function() { + + var _this = this; + + return AWSUtils.putCfFile( + _this._profile, + _this._projectRootPath, + _this._region, + _this._jawsBucket, + _this._name, + _this._stage, + 'resources'); + +}); + /** * CMD: Update Project JSON */ diff --git a/lib/utils/aws.js b/lib/utils/aws.js index 4385ce4c1..fd8a9aeb1 100644 --- a/lib/utils/aws.js +++ b/lib/utils/aws.js @@ -348,7 +348,7 @@ exports.putCfFile = function(awsProfile, projRootPath, awsRegion, bucketName, pr var d = new Date(), cfPath = path.join(projRootPath, 'cloudformation', projStage, awsRegion, type + '-cf.json'), - key = ['JAWS', projName, projStage, 'cloudformation/' + type].join('/') + '@' + d.getTime() + '.json', + key = ['JAWS', projName, projStage, awsRegion, 'cloudformation/' + type].join('/') + '@' + d.getTime() + '.json', params = { Bucket: bucketName, Key: key, @@ -695,7 +695,7 @@ exports.getS3Object = function(awsProfile, awsRegion, params) { */ exports.getEnvFile = function(awsProfile, awsRegion, bucketName, projectName, stage) { - var key = ['JAWS', projectName, stage, 'envVars', '.env'].join('/'), + var key = ['JAWS', projectName, stage, awsRegion, 'envVars', '.env'].join('/'), params = { Bucket: bucketName, Key: key, @@ -717,7 +717,7 @@ exports.getEnvFile = function(awsProfile, awsRegion, bucketName, projectName, st exports.putEnvFile = function(awsProfile, awsRegion, bucketName, projectName, stage, contents) { var params = { Bucket: bucketName, - Key: ['JAWS', projectName, stage, 'envVars', '.env'].join('/'), + Key: ['JAWS', projectName, stage, awsRegion, 'envVars', '.env'].join('/'), ACL: 'private', ContentType: 'text/plain', Body: contents, @@ -738,7 +738,7 @@ exports.putEnvFile = function(awsProfile, awsRegion, bucketName, projectName, st exports.putLambdaZip = function(awsProfile, awsRegion, bucketName, projectName, stage, lambdaName, zipBuffer) { var d = new Date(), - key = ['JAWS', projectName, stage, 'lambdas', lambdaName + '@' + d.getTime() + '.zip'].join('/'), + key = ['JAWS', projectName, stage, awsRegion, 'lambdas', lambdaName + '@' + d.getTime() + '.zip'].join('/'), params = { Bucket: bucketName, Key: key, From 4edd6511378bec4ec862f29094bb17f942b43c2d Mon Sep 17 00:00:00 2001 From: Austen Collins Date: Sun, 27 Sep 2015 16:50:20 -0700 Subject: [PATCH 05/12] bucket reorganization: more refactoring of new command and new stage/region command --- bin/jaws | 21 +++++------------- lib/commands/new_project.js | 16 +++++++++----- lib/commands/new_stage_region.js | 38 ++++++++++++++++++-------------- lib/index.js | 14 ++++++++---- 4 files changed, 47 insertions(+), 42 deletions(-) diff --git a/bin/jaws b/bin/jaws index 56377c019..ae5d764b4 100755 --- a/bin/jaws +++ b/bin/jaws @@ -24,8 +24,9 @@ program * New * - Create a new project|stage|region */ + program - .command('new [params]') + .command('new ') .description('new project, stage and region commands\n\nValid \'s:' + '\n\nproject: create new JAWS project in CWD.' + '\n\t Ex: jaws new project' + @@ -36,43 +37,33 @@ program ) .option('-d, --dont-exe-cf', 'Don\'t execute CloudFormation, just generate it.') .option('-r, --region ', 'name of aws region to use') - .option('-b, --s3-bucket ', '[project,region] only: JAWS S3 bucket name. Will be created if DNE in "project" cmd. Must exist for "region" cmd.') + .option('-u, --domain ', '[project] only: domain') .option('-n, --proj-name ', '[project] only: name for new project') .option('-s, --stage ', '[project] only: same of stage for new project') .option('-e, --email ', '[project] only: notification email to use in CloudFormation') .option('-p, --aws-profile ', '[project] only: Admin AWS profile as defined in ~/.aws/credentials to use') - .action(function(cmd, params, options) { + .action(function(cmd, options) { if (cmd == 'project') { var CmdNewProject = require('../lib/commands/new_project'); execute(CmdNewProject.run( options.projName, options.stage ? options.stage.toLowerCase() : null, - options.s3Bucket, options.region, + options.domain, options.email, options.awsProfile, options.dontExeCf )); } else if (cmd == 'region' || cmd == 'stage') { - var theParams = process.argv.slice(3); - - if (theParams[0] - && theParams[0][0] - && theParams[0][0] == '-') { //TODO: how do we get around this commander shortcoming? - throw new JawsError('Specify options after cmd', JawsError.errorCodes.UNKNOWN); - } var CmdNewStageRegion = require('../lib/commands/new_stage_region'); - var stage = theParams[1] ? theParams[1] : null; - execute(CmdNewStageRegion.run( JAWS, cmd, - stage, + options.stage, options.region, - options.s3Bucket, options.dontExeCf )); } else { diff --git a/lib/commands/new_project.js b/lib/commands/new_project.js index e2cd40c94..19f8b9049 100644 --- a/lib/commands/new_project.js +++ b/lib/commands/new_project.js @@ -33,14 +33,14 @@ Promise.promisifyAll(fs); * @returns {*} */ -module.exports.run = function(name, stage, domain, region, notificationEmail, profile, noCf) { +module.exports.run = function(name, stage, region, domain, notificationEmail, profile, noCf) { utils.jawsDebug('Running new project:', name); var command = new CMD( name, stage, + region, domain, notificationEmail, - region, profile, noCf); return command.run(); @@ -58,7 +58,7 @@ module.exports.run = function(name, stage, domain, region, notificationEmail, pr * @constructor */ -function CMD(name, stage,domain, notificationEmail, region, profile, noCf) { +function CMD(name, stage, region, domain, notificationEmail, profile, noCf) { // Defaults this._name = name ? name : null; @@ -96,9 +96,13 @@ CMD.prototype.run = Promise.method(function() { .then(_this._createProjectDirectory) .then(function() { if (_this._noCf) { - JawsCLI.log('Project and env var file in s3 successfully created. CloudFormation file can be run manually'); - JawsCLI.log('!!MAKE SURE!! to create stack with name: ' + AWSUtils.cfGetResourcesStackName(_this._stage, _this._name)); - JawsCLI.log('After creating CF stack, remember to put the IAM role outputs in your project jaws.json'); + JawsCLI.log('Remember to run CloudFormation manually'); + JawsCLI.log('!!MAKE SURE!! to create stack with name: ' + AWSUtils.cfGetResourcesStackName( + _this._stage, + _this._name + )); + JawsCLI.log('After creating CF stack, remember to put the IAM role outputs and jawsBucket in your ' + + 'project jaws.json in the right stage/region.'); return false; } else { return _this._createCfStack() diff --git a/lib/commands/new_stage_region.js b/lib/commands/new_stage_region.js index cc7575e0c..b4c5f3e39 100644 --- a/lib/commands/new_stage_region.js +++ b/lib/commands/new_stage_region.js @@ -47,6 +47,8 @@ function CMD(JAWS, type, stage, region, noCf) { this._prompts = { properties: {}, }; + + console.log(type, stage, region, noCf) } /** @@ -79,13 +81,15 @@ CMD.prototype.run = Promise.method(function() { ); }) .then(function() { + if (_this._noCf) { - JawsCLI.log('ENV var file created in s3. CloudFormation file can be run manually'); + JawsCLI.log('Remember to run CloudFormation manually'); JawsCLI.log('!!MAKE SURE!! to create stack with name: ' + AWSUtils.cfGetResourcesStackName( _this._stage, _this._JAWS._meta.projectJson.name )); - JawsCLI.log('After creating CF stack, remember to put the IAM role outputs in your project jaws.json'); + JawsCLI.log('After creating CF stack, remember to put the IAM role outputs and jawsBucket in your ' + + 'project jaws.json in the right stage/region.'); return false; } else { return _this._createCfStack() @@ -94,7 +98,6 @@ CMD.prototype.run = Promise.method(function() { if (_this._spinner) { _this._spinner.stop(true); } - _this._cfData = cfData; }) .then(_this._putEnvFile) @@ -192,9 +195,9 @@ CMD.prototype._promptRegion = Promise.method(function() { }); if (_this._type === 'stage') { - var msg = 'Choose a region for your new stage:' + var msg = 'Choose a region for your new stage:'; } else { - var msg = 'Choose a region lambda supports: ' + var msg = 'Choose a region lambda supports: '; } return JawsCLI.select(msg, choices, false) @@ -305,10 +308,10 @@ CMD.prototype._putEnvFile = Promise.method(function() { + '\nJAWS_DATA_MODEL_STAGE=' + _this._stage; return AWSUtils.putEnvFile( - _this._profile, + _this._JAWS._meta.profile, _this._region, _this._jawsBucket, - _this._name, + _this._JAWS._meta.projectJson.name, _this._stage, envFileContents); @@ -324,11 +327,11 @@ CMD.prototype._putCfFile = Promise.method(function() { var _this = this; return AWSUtils.putCfFile( - _this._profile, - _this._projectRootPath, + _this._JAWS._meta.profile, + _this._JAWS._meta.projectRootPath, _this._region, _this._jawsBucket, - _this._name, + _this._JAWS._meta.projectJson.name, _this._stage, 'resources'); @@ -338,7 +341,7 @@ CMD.prototype._putCfFile = Promise.method(function() { * CMD: Update Project JSON */ -CMD.prototype._updateProjectJson = Promise.method(function(cfData) { +CMD.prototype._updateProjectJson = Promise.method(function() { var _this = this; @@ -346,16 +349,17 @@ CMD.prototype._updateProjectJson = Promise.method(function(cfData) { region: _this._region, iamRoleArnLambda: '', iamRoleArnApiGateway: '', + jawsBucket: _this._jawsBucket, }; - if (cfData) { - for (var i = 0; i < cfData.Outputs.length; i++) { - if (cfData.Outputs[i].OutputKey === 'IamRoleArnLambda') { - regionObj.iamRoleArnLambda = cfData.Outputs[i].OutputValue; + if (_this._cfData) { + for (var i = 0; i < _this._cfData.Outputs.length; i++) { + if (_this._cfData.Outputs[i].OutputKey === 'IamRoleArnLambda') { + regionObj.iamRoleArnLambda = _this._cfData.Outputs[i].OutputValue; } - if (cfData.Outputs[i].OutputKey === 'IamRoleArnApiGateway') { - regionObj.iamRoleArnApiGateway = cfData.Outputs[i].OutputValue; + if (_this._cfData.Outputs[i].OutputKey === 'IamRoleArnApiGateway') { + regionObj.iamRoleArnApiGateway = _this._cfData.Outputs[i].OutputValue; } } } diff --git a/lib/index.js b/lib/index.js index 03c99a8be..561c2741d 100755 --- a/lib/index.js +++ b/lib/index.js @@ -85,8 +85,11 @@ Jaws.prototype.validateProject = Promise.method(function() { */ Jaws.prototype.getEnvFile = Promise.method(function(region, stage) { - var _this = this, - bucket = _this._meta.projectJson.jawsBuckets[region]; + + var _this = this; + + var bucket = utils.getProjRegionConfigForStage(_this._meta.projectJson, stage, region); + bucket = bucket.jawsBucket; JawsCLI.log('Getting ENV file from S3 bucket: ' + bucket + ' in ' + region); @@ -103,8 +106,11 @@ Jaws.prototype.getEnvFile = Promise.method(function(region, stage) { */ Jaws.prototype.putEnvFile = Promise.method(function(region, stage, contents) { - var _this = this, - bucket = _this._meta.projectJson.jawsBuckets[region]; + + var _this = this; + + var bucket = utils.getProjRegionConfigForStage(_this._meta.projectJson, stage, region); + bucket = bucket.jawsBucket; JawsCLI.log('Uploading ENV file from S3 bucket: ' + bucket + ' in ' + region); From a7fb6c4f7293bdb0debd199f4c5c74b123282583 Mon Sep 17 00:00:00 2001 From: Austen Collins Date: Sun, 27 Sep 2015 17:09:00 -0700 Subject: [PATCH 06/12] minor fixes --- lib/commands/env.js | 1 - lib/commands/new_stage_region.js | 2 -- lib/index.js | 1 - 3 files changed, 4 deletions(-) diff --git a/lib/commands/env.js b/lib/commands/env.js index c92baff48..c8f2a79de 100644 --- a/lib/commands/env.js +++ b/lib/commands/env.js @@ -97,7 +97,6 @@ module.exports.listEnv = function(JAWS, stage, region, showWhereUsed) { JawsCLI.log('------------------------------'); JawsCLI.log(mapForRegion.regionName); JawsCLI.log('------------------------------'); - console.log(chalk.bold(mapForRegion.raw + '')); console.log(''); }); diff --git a/lib/commands/new_stage_region.js b/lib/commands/new_stage_region.js index b4c5f3e39..fa20e8539 100644 --- a/lib/commands/new_stage_region.js +++ b/lib/commands/new_stage_region.js @@ -47,8 +47,6 @@ function CMD(JAWS, type, stage, region, noCf) { this._prompts = { properties: {}, }; - - console.log(type, stage, region, noCf) } /** diff --git a/lib/index.js b/lib/index.js index 561c2741d..685ccbe97 100755 --- a/lib/index.js +++ b/lib/index.js @@ -92,7 +92,6 @@ Jaws.prototype.getEnvFile = Promise.method(function(region, stage) { bucket = bucket.jawsBucket; JawsCLI.log('Getting ENV file from S3 bucket: ' + bucket + ' in ' + region); - return AWSUtils.getEnvFile( _this._meta.profile, region, From a5e6ba2269cb6b00ef67ffd527cfafca79a625bf Mon Sep 17 00:00:00 2001 From: Austen Collins Date: Sun, 27 Sep 2015 18:14:15 -0700 Subject: [PATCH 07/12] bucket reorganization: fix path --- lib/utils/aws.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/utils/aws.js b/lib/utils/aws.js index fd8a9aeb1..4385ce4c1 100644 --- a/lib/utils/aws.js +++ b/lib/utils/aws.js @@ -348,7 +348,7 @@ exports.putCfFile = function(awsProfile, projRootPath, awsRegion, bucketName, pr var d = new Date(), cfPath = path.join(projRootPath, 'cloudformation', projStage, awsRegion, type + '-cf.json'), - key = ['JAWS', projName, projStage, awsRegion, 'cloudformation/' + type].join('/') + '@' + d.getTime() + '.json', + key = ['JAWS', projName, projStage, 'cloudformation/' + type].join('/') + '@' + d.getTime() + '.json', params = { Bucket: bucketName, Key: key, @@ -695,7 +695,7 @@ exports.getS3Object = function(awsProfile, awsRegion, params) { */ exports.getEnvFile = function(awsProfile, awsRegion, bucketName, projectName, stage) { - var key = ['JAWS', projectName, stage, awsRegion, 'envVars', '.env'].join('/'), + var key = ['JAWS', projectName, stage, 'envVars', '.env'].join('/'), params = { Bucket: bucketName, Key: key, @@ -717,7 +717,7 @@ exports.getEnvFile = function(awsProfile, awsRegion, bucketName, projectName, st exports.putEnvFile = function(awsProfile, awsRegion, bucketName, projectName, stage, contents) { var params = { Bucket: bucketName, - Key: ['JAWS', projectName, stage, awsRegion, 'envVars', '.env'].join('/'), + Key: ['JAWS', projectName, stage, 'envVars', '.env'].join('/'), ACL: 'private', ContentType: 'text/plain', Body: contents, @@ -738,7 +738,7 @@ exports.putEnvFile = function(awsProfile, awsRegion, bucketName, projectName, st exports.putLambdaZip = function(awsProfile, awsRegion, bucketName, projectName, stage, lambdaName, zipBuffer) { var d = new Date(), - key = ['JAWS', projectName, stage, awsRegion, 'lambdas', lambdaName + '@' + d.getTime() + '.zip'].join('/'), + key = ['JAWS', projectName, stage, 'lambdas', lambdaName + '@' + d.getTime() + '.zip'].join('/'), params = { Bucket: bucketName, Key: key, From 8a3d982abdfe5a8a8b30bd81cc6f12865fd9ae77 Mon Sep 17 00:00:00 2001 From: doapp-ryanp Date: Mon, 28 Sep 2015 14:30:39 -0500 Subject: [PATCH 08/12] remove back dir --- lib/commands/deploy_lambda.js | 16 ++++----- lib/commands/env.js | 10 +++--- lib/commands/module_create.js | 3 +- lib/commands/module_install.js | 2 +- lib/commands/new_project.js | 34 +++++++++---------- lib/utils/index.js | 6 ++-- tests/cli/dash.js | 2 +- tests/cli/deploy_endpoint.js | 6 ++-- tests/cli/env.js | 2 +- tests/cli/module_create.js | 2 +- tests/cli/module_install.js | 4 +-- tests/cli/new_stage_region.js | 2 +- tests/cli/run.js | 2 +- tests/cli/tag.js | 6 ++-- .../aws_modules/bundle/browserify/awsm.json | 0 .../aws_modules/bundle/browserify/event.json | 0 .../aws_modules/bundle/browserify/handler.js | 2 +- .../aws_modules/bundle/browserify/index.js | 0 .../aws_modules/bundle/nonoptimized/awsm.json | 0 .../bundle/nonoptimized/event.json | 0 .../bundle/nonoptimized/handler.js | 2 +- .../aws_modules/bundle/nonoptimized/index.js | 0 .../aws_modules/bundle/package.json | 0 .../aws_modules/jaws-core-js/.gitignore | 0 .../aws_modules/jaws-core-js/README.md | 0 .../aws_modules/jaws-core-js/awsm.json | 0 .../aws_modules/jaws-core-js/env/index.js | 0 .../aws_modules/jaws-core-js/package.json | 0 .../aws_modules/sessions/create/awsm.json | 0 .../aws_modules/sessions/create/event.json | 0 .../aws_modules/sessions/create/index.js | 0 .../aws_modules/sessions/show/awsm.json | 0 .../aws_modules/sessions/show/event.json | 0 .../aws_modules/sessions/show/index.js | 0 .../aws_modules/users/create/awsm.json | 0 .../aws_modules/users/create/event.json | 0 .../aws_modules/users/create/index.js | 0 37 files changed, 49 insertions(+), 52 deletions(-) rename tests/test-prj/{back => }/aws_modules/bundle/browserify/awsm.json (100%) rename tests/test-prj/{back => }/aws_modules/bundle/browserify/event.json (100%) rename tests/test-prj/{back => }/aws_modules/bundle/browserify/handler.js (88%) rename tests/test-prj/{back => }/aws_modules/bundle/browserify/index.js (100%) rename tests/test-prj/{back => }/aws_modules/bundle/nonoptimized/awsm.json (100%) rename tests/test-prj/{back => }/aws_modules/bundle/nonoptimized/event.json (100%) rename tests/test-prj/{back => }/aws_modules/bundle/nonoptimized/handler.js (88%) rename tests/test-prj/{back => }/aws_modules/bundle/nonoptimized/index.js (100%) rename tests/test-prj/{back => }/aws_modules/bundle/package.json (100%) rename tests/test-prj/{back => }/aws_modules/jaws-core-js/.gitignore (100%) rename tests/test-prj/{back => }/aws_modules/jaws-core-js/README.md (100%) rename tests/test-prj/{back => }/aws_modules/jaws-core-js/awsm.json (100%) rename tests/test-prj/{back => }/aws_modules/jaws-core-js/env/index.js (100%) rename tests/test-prj/{back => }/aws_modules/jaws-core-js/package.json (100%) rename tests/test-prj/{back => }/aws_modules/sessions/create/awsm.json (100%) rename tests/test-prj/{back => }/aws_modules/sessions/create/event.json (100%) rename tests/test-prj/{back => }/aws_modules/sessions/create/index.js (100%) rename tests/test-prj/{back => }/aws_modules/sessions/show/awsm.json (100%) rename tests/test-prj/{back => }/aws_modules/sessions/show/event.json (100%) rename tests/test-prj/{back => }/aws_modules/sessions/show/index.js (100%) rename tests/test-prj/{back => }/aws_modules/users/create/awsm.json (100%) rename tests/test-prj/{back => }/aws_modules/users/create/event.json (100%) rename tests/test-prj/{back => }/aws_modules/users/create/index.js (100%) diff --git a/lib/commands/deploy_lambda.js b/lib/commands/deploy_lambda.js index 4c9683b00..439ed28a7 100644 --- a/lib/commands/deploy_lambda.js +++ b/lib/commands/deploy_lambda.js @@ -478,8 +478,8 @@ Packager.prototype._createDistFolder = Promise.method(function() { // Copy entire test project to temp folder _this._excludePatterns = _this._awsmJson.lambda.package.excludePatterns || []; wrench.copyDirSyncRecursive( - path.join(_this._JAWS._meta.projectRootPath, 'back'), - path.join(_this._distDir, 'back'), + _this._JAWS._meta.projectRootPath, + _this._distDir, { exclude: function(name, prefix) { if (!_this._excludePatterns.length) { @@ -487,8 +487,7 @@ Packager.prototype._createDistFolder = Promise.method(function() { } var relPath = path.join( - prefix.replace(path.join(_this._distDir, 'back'), ''), - name); + prefix.replace(_this._distDir, ''), name); return _this._excludePatterns.some(function(sRegex) { relPath = (relPath.charAt(0) == path.sep) ? relPath.substr(1) : relPath; @@ -515,8 +514,7 @@ Packager.prototype._createDistFolder = Promise.method(function() { // Get ENV file from S3 return _this._JAWS.getEnvFile(_this._region, _this._stage) .then(function(s3ObjData) { - var targetBackDir = path.join(_this._distDir, 'back'); - fs.writeFileSync(path.join(targetBackDir, '.env'), s3ObjData.Body); + fs.writeFileSync(path.join(_this._distDir, '.env'), s3ObjData.Body); }); }); @@ -540,7 +538,7 @@ Packager.prototype._packageNodeJs = Promise.method(function() { // Lambda freaks out if code doesnt end in newline var ocbWithNewline = optimizedCodeBuffer.concat(new Buffer('\n')); - var envData = fs.readFileSync(path.join(_this._distDir, 'back', '.env')); + var envData = fs.readFileSync(path.join(_this._distDir, '.env')); var handlerFileName = _this._awsmJson.lambda.cloudFormation.Handler.split('.')[0], compressPaths = [ @@ -607,7 +605,7 @@ Packager.prototype._browserifyBundle = Promise.method(function() { compress: {}, }; var b = browserify({ - basedir: path.join(_this._distDir, 'back'), + basedir: _this._distDir, entries: [_this._awsmJson.lambda.cloudFormation.Handler.split('.')[0] + '.js'], standalone: 'lambda', browserField: false, // Setup for node app (copy logic of --node in bin/args.js) @@ -680,7 +678,7 @@ Packager.prototype._generateIncludePaths = function() { _this._awsmJson.lambda.package.optimize.includePaths.forEach(function(p) { try { - var fullPath = path.resolve(path.join(_this._distDir, 'back', p)); + var fullPath = path.resolve(path.join(_this._distDir, p)); var stats = fs.lstatSync(fullPath); } catch (e) { console.error('Cant find includePath ', p, e); diff --git a/lib/commands/env.js b/lib/commands/env.js index c8f2a79de..545b58fd6 100644 --- a/lib/commands/env.js +++ b/lib/commands/env.js @@ -27,7 +27,7 @@ module.exports.getEnvFileAsMap = function(JAWS, stage, region) { var deferred; if (stage == 'local') { - deferred = Promise.resolve(fs.readFileSync(path.join(JAWS._meta.projectRootPath, 'back', '.env'))); + deferred = Promise.resolve(fs.readFileSync(path.join(JAWS._meta.projectRootPath, '.env'))); } else { deferred = JAWS.getEnvFile(region, stage) .then(function(s3ObjData) { @@ -83,9 +83,9 @@ module.exports._getEnvFiles = function(JAWS, stage, region) { */ module.exports.listEnv = function(JAWS, stage, region, showWhereUsed) { var _this = this, - backDir = path.join(JAWS._meta.projectRootPath, 'back'); + projRootDir = JAWS._meta.projectRootPath; - return utils.findAllAwsmJsons(backDir) + return utils.findAllAwsmJsons(projRootDir) .then(function(awsmJsonPaths) { return [awsmJsonPaths, _this._getEnvFiles(JAWS, stage, region)]; }) @@ -107,7 +107,7 @@ module.exports.listEnv = function(JAWS, stage, region, showWhereUsed) { var awsmJson = require(ajp); if (awsmJson.lambda && awsmJson.lambda.envVars) { awsmJson.lambda.envVars.forEach(function(key) { - var rel = path.relative(path.join(backDir, 'aws_modules'), ajp); + var rel = path.relative(path.join(projRootDir, 'aws_modules'), ajp); if (envInBackMap[key]) { envInBackMap[key].push(rel); } else { @@ -201,7 +201,7 @@ module.exports.setEnvKey = function(JAWS, stage, region, key, val) { }); if (stage == 'local') { - putEnvQ.push(utils.writeFile(path.join(JAWS._meta.projectRootPath, 'back', '.env'), contents)); + putEnvQ.push(utils.writeFile(path.join(JAWS._meta.projectRootPath, '.env'), contents)); } else { putEnvQ.push(JAWS.putEnvFile(mapForRegion.regionName, stage, contents)); } diff --git a/lib/commands/module_create.js b/lib/commands/module_create.js index b04c2deac..0613dc224 100644 --- a/lib/commands/module_create.js +++ b/lib/commands/module_create.js @@ -78,7 +78,7 @@ CMD.prototype._installCore = Promise.method(function() { } if (!!jawsCoreName) { - var existingJawsCorePath = path.join(_this._JAWS._meta.projectRootPath, 'back', 'aws_modules', jawsCoreName); + var existingJawsCorePath = path.join(_this._JAWS._meta.projectRootPath, 'aws_modules', jawsCoreName); utils.jawsDebug('Looking for existing jaws core in ' + existingJawsCorePath); @@ -123,7 +123,6 @@ CMD.prototype._createSkeleton = Promise.method(function() { var actionTemplateJson = utils.readAndParseJsonSync(path.join(templatesPath, 'action.awsm.json')); var modulePath = path.join( _this._JAWS._meta.projectRootPath, - 'back', 'aws_modules', _this._module.name); var actionPath = path.join(modulePath, _this._module.action); diff --git a/lib/commands/module_install.js b/lib/commands/module_install.js index 192ff27fb..8f8d3c736 100644 --- a/lib/commands/module_install.js +++ b/lib/commands/module_install.js @@ -147,7 +147,7 @@ CMD.prototype._downloadMod = Promise.method(function() { CMD.prototype._installFiles = Promise.method(function(tempDirPath) { var _this = this, srcAwsmJsonPath = path.join(tempDirPath, 'awsm.json'), - awsModsPath = path.join(_this._JAWS._meta.projectRootPath, 'back', 'aws_modules'); + awsModsPath = path.join(_this._JAWS._meta.projectRootPath, 'aws_modules'); if (!utils.fileExistsSync(srcAwsmJsonPath)) { throw new JawsError('Module missing awsm.json file in root of project', JawsError.errorCodes.UNKNOWN); diff --git a/lib/commands/new_project.js b/lib/commands/new_project.js index 19f8b9049..c0e885f0d 100644 --- a/lib/commands/new_project.js +++ b/lib/commands/new_project.js @@ -86,10 +86,10 @@ CMD.prototype.run = Promise.method(function() { return Promise.try(function() { - // ASCII Greeting - JawsCLI.ascii(); + // ASCII Greeting + JawsCLI.ascii(); - }) + }) .bind(_this) .then(_this._prompt) .then(_this._prepareProjectData) @@ -365,15 +365,15 @@ CMD.prototype._createProjectDirectory = Promise.method(function() { // Create Project Scaffolding return utils.writeFile( - path.join(_this._projectRootPath, 'back', '.env'), - 'JAWS_STAGE=' + _this._stage - + '\nJAWS_DATA_MODEL_STAGE=' + _this._stage - ) + path.join(_this._projectRootPath, '.env'), + 'JAWS_STAGE=' + _this._stage + + '\nJAWS_DATA_MODEL_STAGE=' + _this._stage + ) .then(function() { return Promise.all([ fs.mkdirAsync(path.join(_this._projectRootPath, 'front')), fs.mkdirAsync(path.join(_this._projectRootPath, 'tests')), - fs.mkdirAsync(path.join(_this._projectRootPath, 'back', 'aws_modules')), + fs.mkdirAsync(path.join(_this._projectRootPath, 'aws_modules')), utils.writeFile(path.join(_this._projectRootPath, 'admin.env'), adminEnv), utils.generateResourcesCf( _this._projectRootPath, @@ -444,15 +444,15 @@ CMD.prototype._createCfStack = Promise.method(function() { // Create CF stack return AWSUtils.cfCreateResourcesStack( - _this._profile, - _this._region, - _this._projectRootPath, - _this._name, - _this._stage, - _this._domain, - _this._notificationEmail, - _this._jawsBucket - ) + _this._profile, + _this._region, + _this._projectRootPath, + _this._name, + _this._stage, + _this._domain, + _this._notificationEmail, + _this._jawsBucket + ) .then(function(cfData) { return AWSUtils.monitorCf(cfData, _this._profile, _this._region, 'create'); }); diff --git a/lib/utils/index.js b/lib/utils/index.js index 6b7e78730..ef5bb28bf 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -36,7 +36,7 @@ exports.findAllAwsmPathsOfType = function(projectRootPath, type) { break; } - return _this.readRecursively(path.join(projectRootPath, 'back'), '*awsm.json') + return _this.readRecursively(projectRootPath, '*awsm.json') .then(function(jsonPaths) { return new Promise(function(resolve, reject) { @@ -44,7 +44,7 @@ exports.findAllAwsmPathsOfType = function(projectRootPath, type) { // Check each file to ensure it is a lambda async.eachLimit(jsonPaths, 10, function(jsonPath, cb) { - var lambdaJawsPath = path.join(projectRootPath, 'back', jsonPath), + var lambdaJawsPath = path.join(projectRootPath, jsonPath), json = require(lambdaJawsPath); if (typeof json[jawsJsonAttr] !== 'undefined') jawsPathsOfType.push(lambdaJawsPath); @@ -397,7 +397,7 @@ function getStack() { var origPrepareStackTrace = Error.prepareStackTrace; // Override with function that just returns `stack` - Error.prepareStackTrace = function (_, stack) { + Error.prepareStackTrace = function(_, stack) { return stack; }; diff --git a/tests/cli/dash.js b/tests/cli/dash.js index 19532a1f3..15a56a886 100644 --- a/tests/cli/dash.js +++ b/tests/cli/dash.js @@ -35,7 +35,7 @@ describe('Test "dash" command', function() { 'back/aws_modules/bundle/nonoptimized']) .then(function(pp) { projPath = pp; - process.chdir(path.join(projPath, 'back')); + process.chdir(projPath); JAWS = new Jaws(); }) .then(function() { diff --git a/tests/cli/deploy_endpoint.js b/tests/cli/deploy_endpoint.js index 03a6eeee8..e6c8aec48 100644 --- a/tests/cli/deploy_endpoint.js +++ b/tests/cli/deploy_endpoint.js @@ -33,9 +33,9 @@ describe('Test deploy endpoint command', function() { JAWS = new Jaws(); // Get Lambda Paths - lambdaPaths.lambda1 = path.join(projPath, 'back', 'aws_modules', 'sessions', 'show', 'awsm.json'); - lambdaPaths.lambda2 = path.join(projPath, 'back', 'aws_modules', 'sessions', 'create', 'awsm.json'); - lambdaPaths.lambda3 = path.join(projPath, 'back', 'aws_modules', 'users', 'create', 'awsm.json'); + lambdaPaths.lambda1 = path.join(projPath, 'aws_modules', 'sessions', 'show', 'awsm.json'); + lambdaPaths.lambda2 = path.join(projPath, 'aws_modules', 'sessions', 'create', 'awsm.json'); + lambdaPaths.lambda3 = path.join(projPath, 'aws_modules', 'users', 'create', 'awsm.json'); }) .then(function() { CmdTag.tagAll(JAWS, 'endpoint', false); diff --git a/tests/cli/env.js b/tests/cli/env.js index 6a486712d..d656f3e22 100644 --- a/tests/cli/env.js +++ b/tests/cli/env.js @@ -26,7 +26,7 @@ describe('Test "env" command', function() { config.usEast1Bucket) .then(function(pp) { projPath = pp; - process.chdir(path.join(projPath, 'back', 'aws_modules', 'sessions', 'show')); + process.chdir(path.join(projPath, 'aws_modules', 'sessions', 'show')); JAWS = new Jaws(); done(); }); diff --git a/tests/cli/module_create.js b/tests/cli/module_create.js index 9e265a52b..558d7c6bd 100644 --- a/tests/cli/module_create.js +++ b/tests/cli/module_create.js @@ -29,7 +29,7 @@ describe('Test "new module" command', function() { config.usEast1Bucket) .then(function(pp) { projPath = pp; - process.chdir(path.join(projPath, 'back')); + process.chdir(projPath); JAWS = new Jaws(); done(); }); diff --git a/tests/cli/module_install.js b/tests/cli/module_install.js index 0075cf792..80bb408e4 100644 --- a/tests/cli/module_install.js +++ b/tests/cli/module_install.js @@ -29,10 +29,10 @@ describe('Test "install" command', function() { config.usEast1Bucket) .then(function(pp) { projPath = pp; - process.chdir(path.join(projPath, 'back', 'aws_modules', 'sessions', 'show')); + process.chdir(path.join(projPath, 'aws_modules', 'sessions', 'show')); // Delete jaws-core-js temporarily - rimraf.sync(path.join(projPath, 'back', 'aws_modules', 'jaws-core-js')); + rimraf.sync(path.join(projPath, 'aws_modules', 'jaws-core-js')); JAWS = new Jaws(); done(); diff --git a/tests/cli/new_stage_region.js b/tests/cli/new_stage_region.js index 6a4e71e04..3c11bb086 100644 --- a/tests/cli/new_stage_region.js +++ b/tests/cli/new_stage_region.js @@ -36,7 +36,7 @@ describe('Test "new stage/region" command', function() { config.usEast1Bucket) .then(function(pp) { projPath = pp; - process.chdir(path.join(projPath, 'back')); + process.chdir(projPath); JAWS = new Jaws(); done(); }); diff --git a/tests/cli/run.js b/tests/cli/run.js index 8a7890717..2ea124123 100644 --- a/tests/cli/run.js +++ b/tests/cli/run.js @@ -26,7 +26,7 @@ describe('Test "run" command', function() { config.usEast1Bucket) .then(function(pp) { projPath = pp; - process.chdir(path.join(projPath, 'back', 'aws_modules', 'sessions', 'show')); + process.chdir(path.join(projPath, 'aws_modules', 'sessions', 'show')); JAWS = new Jaws(); done(); }); diff --git a/tests/cli/tag.js b/tests/cli/tag.js index d5b1abc08..54ca4f86f 100644 --- a/tests/cli/tag.js +++ b/tests/cli/tag.js @@ -33,9 +33,9 @@ describe('Test "tag" command', function() { JAWS = new Jaws(); // Get Lambda Paths - modulePaths.lambda1 = path.join(projPath, 'back', 'aws_modules', 'sessions', 'show', 'awsm.json'); - modulePaths.lambda2 = path.join(projPath, 'back', 'aws_modules', 'sessions', 'create', 'awsm.json'); - modulePaths.lambda3 = path.join(projPath, 'back', 'aws_modules', 'users', 'create', 'awsm.json'); + modulePaths.lambda1 = path.join(projPath, 'aws_modules', 'sessions', 'show', 'awsm.json'); + modulePaths.lambda2 = path.join(projPath, 'aws_modules', 'sessions', 'create', 'awsm.json'); + modulePaths.lambda3 = path.join(projPath, 'aws_modules', 'users', 'create', 'awsm.json'); done(); }); }); diff --git a/tests/test-prj/back/aws_modules/bundle/browserify/awsm.json b/tests/test-prj/aws_modules/bundle/browserify/awsm.json similarity index 100% rename from tests/test-prj/back/aws_modules/bundle/browserify/awsm.json rename to tests/test-prj/aws_modules/bundle/browserify/awsm.json diff --git a/tests/test-prj/back/aws_modules/bundle/browserify/event.json b/tests/test-prj/aws_modules/bundle/browserify/event.json similarity index 100% rename from tests/test-prj/back/aws_modules/bundle/browserify/event.json rename to tests/test-prj/aws_modules/bundle/browserify/event.json diff --git a/tests/test-prj/back/aws_modules/bundle/browserify/handler.js b/tests/test-prj/aws_modules/bundle/browserify/handler.js similarity index 88% rename from tests/test-prj/back/aws_modules/bundle/browserify/handler.js rename to tests/test-prj/aws_modules/bundle/browserify/handler.js index 2f57b65a0..6a7eddc1c 100644 --- a/tests/test-prj/back/aws_modules/bundle/browserify/handler.js +++ b/tests/test-prj/aws_modules/bundle/browserify/handler.js @@ -3,7 +3,7 @@ //Testing how the top npm modules work with browserify //https://www.npmjs.com/browse/depended -require('../../jaws-core-js/env'); +require('../../jaws-core-js/env/index'); var action = require('./index.js'); diff --git a/tests/test-prj/back/aws_modules/bundle/browserify/index.js b/tests/test-prj/aws_modules/bundle/browserify/index.js similarity index 100% rename from tests/test-prj/back/aws_modules/bundle/browserify/index.js rename to tests/test-prj/aws_modules/bundle/browserify/index.js diff --git a/tests/test-prj/back/aws_modules/bundle/nonoptimized/awsm.json b/tests/test-prj/aws_modules/bundle/nonoptimized/awsm.json similarity index 100% rename from tests/test-prj/back/aws_modules/bundle/nonoptimized/awsm.json rename to tests/test-prj/aws_modules/bundle/nonoptimized/awsm.json diff --git a/tests/test-prj/back/aws_modules/bundle/nonoptimized/event.json b/tests/test-prj/aws_modules/bundle/nonoptimized/event.json similarity index 100% rename from tests/test-prj/back/aws_modules/bundle/nonoptimized/event.json rename to tests/test-prj/aws_modules/bundle/nonoptimized/event.json diff --git a/tests/test-prj/back/aws_modules/bundle/nonoptimized/handler.js b/tests/test-prj/aws_modules/bundle/nonoptimized/handler.js similarity index 88% rename from tests/test-prj/back/aws_modules/bundle/nonoptimized/handler.js rename to tests/test-prj/aws_modules/bundle/nonoptimized/handler.js index 2f57b65a0..6a7eddc1c 100644 --- a/tests/test-prj/back/aws_modules/bundle/nonoptimized/handler.js +++ b/tests/test-prj/aws_modules/bundle/nonoptimized/handler.js @@ -3,7 +3,7 @@ //Testing how the top npm modules work with browserify //https://www.npmjs.com/browse/depended -require('../../jaws-core-js/env'); +require('../../jaws-core-js/env/index'); var action = require('./index.js'); diff --git a/tests/test-prj/back/aws_modules/bundle/nonoptimized/index.js b/tests/test-prj/aws_modules/bundle/nonoptimized/index.js similarity index 100% rename from tests/test-prj/back/aws_modules/bundle/nonoptimized/index.js rename to tests/test-prj/aws_modules/bundle/nonoptimized/index.js diff --git a/tests/test-prj/back/aws_modules/bundle/package.json b/tests/test-prj/aws_modules/bundle/package.json similarity index 100% rename from tests/test-prj/back/aws_modules/bundle/package.json rename to tests/test-prj/aws_modules/bundle/package.json diff --git a/tests/test-prj/back/aws_modules/jaws-core-js/.gitignore b/tests/test-prj/aws_modules/jaws-core-js/.gitignore similarity index 100% rename from tests/test-prj/back/aws_modules/jaws-core-js/.gitignore rename to tests/test-prj/aws_modules/jaws-core-js/.gitignore diff --git a/tests/test-prj/back/aws_modules/jaws-core-js/README.md b/tests/test-prj/aws_modules/jaws-core-js/README.md similarity index 100% rename from tests/test-prj/back/aws_modules/jaws-core-js/README.md rename to tests/test-prj/aws_modules/jaws-core-js/README.md diff --git a/tests/test-prj/back/aws_modules/jaws-core-js/awsm.json b/tests/test-prj/aws_modules/jaws-core-js/awsm.json similarity index 100% rename from tests/test-prj/back/aws_modules/jaws-core-js/awsm.json rename to tests/test-prj/aws_modules/jaws-core-js/awsm.json diff --git a/tests/test-prj/back/aws_modules/jaws-core-js/env/index.js b/tests/test-prj/aws_modules/jaws-core-js/env/index.js similarity index 100% rename from tests/test-prj/back/aws_modules/jaws-core-js/env/index.js rename to tests/test-prj/aws_modules/jaws-core-js/env/index.js diff --git a/tests/test-prj/back/aws_modules/jaws-core-js/package.json b/tests/test-prj/aws_modules/jaws-core-js/package.json similarity index 100% rename from tests/test-prj/back/aws_modules/jaws-core-js/package.json rename to tests/test-prj/aws_modules/jaws-core-js/package.json diff --git a/tests/test-prj/back/aws_modules/sessions/create/awsm.json b/tests/test-prj/aws_modules/sessions/create/awsm.json similarity index 100% rename from tests/test-prj/back/aws_modules/sessions/create/awsm.json rename to tests/test-prj/aws_modules/sessions/create/awsm.json diff --git a/tests/test-prj/back/aws_modules/sessions/create/event.json b/tests/test-prj/aws_modules/sessions/create/event.json similarity index 100% rename from tests/test-prj/back/aws_modules/sessions/create/event.json rename to tests/test-prj/aws_modules/sessions/create/event.json diff --git a/tests/test-prj/back/aws_modules/sessions/create/index.js b/tests/test-prj/aws_modules/sessions/create/index.js similarity index 100% rename from tests/test-prj/back/aws_modules/sessions/create/index.js rename to tests/test-prj/aws_modules/sessions/create/index.js diff --git a/tests/test-prj/back/aws_modules/sessions/show/awsm.json b/tests/test-prj/aws_modules/sessions/show/awsm.json similarity index 100% rename from tests/test-prj/back/aws_modules/sessions/show/awsm.json rename to tests/test-prj/aws_modules/sessions/show/awsm.json diff --git a/tests/test-prj/back/aws_modules/sessions/show/event.json b/tests/test-prj/aws_modules/sessions/show/event.json similarity index 100% rename from tests/test-prj/back/aws_modules/sessions/show/event.json rename to tests/test-prj/aws_modules/sessions/show/event.json diff --git a/tests/test-prj/back/aws_modules/sessions/show/index.js b/tests/test-prj/aws_modules/sessions/show/index.js similarity index 100% rename from tests/test-prj/back/aws_modules/sessions/show/index.js rename to tests/test-prj/aws_modules/sessions/show/index.js diff --git a/tests/test-prj/back/aws_modules/users/create/awsm.json b/tests/test-prj/aws_modules/users/create/awsm.json similarity index 100% rename from tests/test-prj/back/aws_modules/users/create/awsm.json rename to tests/test-prj/aws_modules/users/create/awsm.json diff --git a/tests/test-prj/back/aws_modules/users/create/event.json b/tests/test-prj/aws_modules/users/create/event.json similarity index 100% rename from tests/test-prj/back/aws_modules/users/create/event.json rename to tests/test-prj/aws_modules/users/create/event.json diff --git a/tests/test-prj/back/aws_modules/users/create/index.js b/tests/test-prj/aws_modules/users/create/index.js similarity index 100% rename from tests/test-prj/back/aws_modules/users/create/index.js rename to tests/test-prj/aws_modules/users/create/index.js From 7b0848035fbba38d75de6c6c76f41acc22044166 Mon Sep 17 00:00:00 2001 From: doapp-ryanp Date: Mon, 28 Sep 2015 14:31:48 -0500 Subject: [PATCH 09/12] remove front dir --- docs/project_structure.md | 2 -- lib/commands/new_project.js | 1 - 2 files changed, 3 deletions(-) diff --git a/docs/project_structure.md b/docs/project_structure.md index 808835536..30ce398a8 100644 --- a/docs/project_structure.md +++ b/docs/project_structure.md @@ -2,8 +2,6 @@ All JAWS apps use the directory structure described in the diagram below. This scaffolding can be generated by running the `jaws new project` command. -Web, mobile and IoT applications can be built on JAWS, since JAWS is mostly a back-end focused framework. JAWS comes with a `front` folder, but doesn't do much with it (yet). - ![jaws framework structural diagram](../img/jaws_files_diagram.png) ## jaws.json diff --git a/lib/commands/new_project.js b/lib/commands/new_project.js index c0e885f0d..ac87f6f8d 100644 --- a/lib/commands/new_project.js +++ b/lib/commands/new_project.js @@ -371,7 +371,6 @@ CMD.prototype._createProjectDirectory = Promise.method(function() { ) .then(function() { return Promise.all([ - fs.mkdirAsync(path.join(_this._projectRootPath, 'front')), fs.mkdirAsync(path.join(_this._projectRootPath, 'tests')), fs.mkdirAsync(path.join(_this._projectRootPath, 'aws_modules')), utils.writeFile(path.join(_this._projectRootPath, 'admin.env'), adminEnv), From abe490b4c65714a44d507d6b78d3271548523f34 Mon Sep 17 00:00:00 2001 From: doapp-ryanp Date: Mon, 28 Sep 2015 14:40:33 -0500 Subject: [PATCH 10/12] remove back dir --- docs/commands.md | 10 +++++----- tests/cli/dash.js | 6 +++--- tests/cli/deploy_endpoint.js | 2 +- tests/cli/deploy_lambda.js | 12 ++++++------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index 0db6635f5..930dafe01 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -24,17 +24,17 @@ Create a project, a project region or a project stage using the `new` commands. * ##### `$ jaws module create` - * Creates one or both of the following in the `back/aws_modules` folder. Default is to create both: - * A lambda function in the `back/aws_modules` folder with basic scaffolding. + * Creates one or both of the following in the `aws_modules` folder. Default is to create both: + * A lambda function in the `aws_modules` folder with basic scaffolding. * An API gateway configuration * ##### `$ jaws module install` - * Download and installs an awsm from github to the `back/aws_modules` dir. By default installs module dependencies (if any) + * Download and installs an awsm from github to the `aws_modules` dir. By default installs module dependencies (if any) * ##### `$ jaws module update` - * Updates an existing awsm in the `back/aws_modules` dir. By default installs module dependencies (if any) + * Updates an existing awsm in the `aws_modules` dir. By default installs module dependencies (if any) ### Dash Commands @@ -46,7 +46,7 @@ Deploy your lambdas and endpoints using the JAWS dashboard. ### ENV Commands -Modeled after Heroku's environment variable commands, these commands manage environment variable files for all stages. There is a reserved stage `local` which stores the env var file in `back/.env`. Otherwise they are stored is s3 at `s3:///JAWS/envVars//` +Modeled after Heroku's environment variable commands, these commands manage environment variable files for all stages. There is a reserved stage `local` which stores the env var file in `.env`. Otherwise they are stored is s3 at `s3:///JAWS/envVars//` * ##### `$ jaws env list` diff --git a/tests/cli/dash.js b/tests/cli/dash.js index 15a56a886..76f33515d 100644 --- a/tests/cli/dash.js +++ b/tests/cli/dash.js @@ -30,9 +30,9 @@ describe('Test "dash" command', function() { config.iamRoleArnLambda, config.iamRoleArnApiGateway, config.usEast1Bucket, - ['back/aws_modules/jaws-core-js', - 'back/aws_modules/bundle/browserify', - 'back/aws_modules/bundle/nonoptimized']) + ['aws_modules/jaws-core-js', + 'aws_modules/bundle/browserify', + 'aws_modules/bundle/nonoptimized']) .then(function(pp) { projPath = pp; process.chdir(projPath); diff --git a/tests/cli/deploy_endpoint.js b/tests/cli/deploy_endpoint.js index e6c8aec48..34cb8ad3f 100644 --- a/tests/cli/deploy_endpoint.js +++ b/tests/cli/deploy_endpoint.js @@ -29,7 +29,7 @@ describe('Test deploy endpoint command', function() { config.usEast1Bucket) .then(function(pp) { projPath = pp; - process.chdir(path.join(projPath, 'back/aws_modules/sessions/show')); + process.chdir(path.join(projPath, 'aws_modules/sessions/show')); JAWS = new Jaws(); // Get Lambda Paths diff --git a/tests/cli/deploy_lambda.js b/tests/cli/deploy_lambda.js index 43850e892..21f3a8a54 100644 --- a/tests/cli/deploy_lambda.js +++ b/tests/cli/deploy_lambda.js @@ -28,8 +28,8 @@ describe('Test "deploy lambda" command', function() { config.iamRoleArnLambda, config.iamRoleArnApiGateway, config.usEast1Bucket, - ['back/aws_modules/jaws-core-js', - 'back/aws_modules/bundle', + ['aws_modules/jaws-core-js', + 'aws_modules/bundle', ]) .then(function(pp) { projPath = pp; @@ -44,7 +44,7 @@ describe('Test "deploy lambda" command', function() { it('Multi level module deploy', function(done) { this.timeout(0); - process.chdir(path.join(projPath, 'back/aws_modules/sessions/show')); + process.chdir(path.join(projPath, 'aws_modules/sessions/show')); CmdDeployLambda.run(JAWS, config.stage, [config.region], false, config.noExecuteCf) .then(function(d) { @@ -57,7 +57,7 @@ describe('Test "deploy lambda" command', function() { it('browserify deploy', function(done) { this.timeout(0); - process.chdir(path.join(projPath, 'back/aws_modules/bundle/browserify')); + process.chdir(path.join(projPath, 'aws_modules/bundle/browserify')); CmdDeployLambda.run(JAWS, config.stage, [config.region], false, config.noExecuteCf) .then(function(d) { @@ -70,7 +70,7 @@ describe('Test "deploy lambda" command', function() { it('non optimized deploy', function(done) { this.timeout(0); - process.chdir(path.join(projPath, 'back/aws_modules/bundle/nonoptimized')); + process.chdir(path.join(projPath, 'aws_modules/bundle/nonoptimized')); CmdDeployLambda.run(JAWS, config.stage, [config.region], false, config.noExecuteCf) .then(function(d) { @@ -83,7 +83,7 @@ describe('Test "deploy lambda" command', function() { it('deploy multiple', function(done) { this.timeout(0); - var bundleDirPath = path.join(projPath, 'back/aws_modules/bundle'); + var bundleDirPath = path.join(projPath, 'aws_modules/bundle'); process.chdir(bundleDirPath); From 10dc271c9baf0a4f0aef45e18d16863450bd5ea6 Mon Sep 17 00:00:00 2001 From: doapp-ryanp Date: Mon, 28 Sep 2015 15:51:33 -0500 Subject: [PATCH 11/12] bugfig --- lib/commands/deploy_lambda.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/commands/deploy_lambda.js b/lib/commands/deploy_lambda.js index 439ed28a7..12e5f7276 100644 --- a/lib/commands/deploy_lambda.js +++ b/lib/commands/deploy_lambda.js @@ -469,12 +469,13 @@ Packager.prototype._createDistFolder = Promise.method(function() { // Create dist folder var d = new Date(); _this._distDir = path.join(os.tmpdir(), _this._lambdaName + '@' + d.getTime()); - fs.mkdirSync(_this._distDir); // Status JawsCLI.log('Lambda Deployer: Packaging "' + _this._lambdaName + '"...'); JawsCLI.log('Lambda Deployer: Saving in dist dir ' + _this._distDir); + utils.jawsDebug('copying', _this._JAWS._meta.projectRootPath, 'to', _this._distDir); + // Copy entire test project to temp folder _this._excludePatterns = _this._awsmJson.lambda.package.excludePatterns || []; wrench.copyDirSyncRecursive( @@ -483,6 +484,7 @@ Packager.prototype._createDistFolder = Promise.method(function() { { exclude: function(name, prefix) { if (!_this._excludePatterns.length) { + utils.jawsDebug('no exclude patterns'); return false; } @@ -507,9 +509,7 @@ Packager.prototype._createDistFolder = Promise.method(function() { } ); - utils.jawsDebug('Packaging stage & region:'); - utils.jawsDebug(_this._stage); - utils.jawsDebug(_this._region); + utils.jawsDebug('Packaging stage & region:', _this._stage, _this._region); // Get ENV file from S3 return _this._JAWS.getEnvFile(_this._region, _this._stage) From d333d867e0bab057047c6172bd6aaf92b899e57a Mon Sep 17 00:00:00 2001 From: doapp-ryanp Date: Mon, 28 Sep 2015 15:54:49 -0500 Subject: [PATCH 12/12] docs --- docs/project_structure.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/project_structure.md b/docs/project_structure.md index 30ce398a8..1e36786dd 100644 --- a/docs/project_structure.md +++ b/docs/project_structure.md @@ -20,7 +20,6 @@ The following attributes should exist in either a project or lambda `jaws.json` * **author**: `John Serverless http://www.john.com` * **description**: project/module or lambda desc. * **stages**: map of all your stages, and regions those stages are in as well as IAM roles -* **jawsBuckets**: map of region to bucket name for JAWS S3 bucket in the region ## admin.env