This commit is contained in:
Austen Collins 2015-09-28 14:27:42 -07:00
commit 8dc0012fa0
40 changed files with 65 additions and 71 deletions

View File

@ -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://<projjaws.json:envVarBucket.name>/JAWS/envVars/<projectName>/<stage>`
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://<projjaws.json:envVarBucket.name>/JAWS/envVars/<projectName>/<stage>`
* ##### `$ jaws env list`

View File

@ -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
@ -22,7 +20,6 @@ The following attributes should exist in either a project or lambda `jaws.json`
* **author**: `John Serverless <john@gmail.com> 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

View File

@ -473,26 +473,27 @@ 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(
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) {
utils.jawsDebug('no exclude patterns');
return false;
}
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;
@ -512,15 +513,12 @@ 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)
.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);
});
});
@ -544,7 +542,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 = [
@ -611,7 +609,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)
@ -684,7 +682,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);

View File

@ -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));
}

View File

@ -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);

View File

@ -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);

View File

@ -366,15 +366,14 @@ 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,
@ -445,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');
});

View File

@ -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);
@ -230,6 +230,7 @@ exports.generateJawsBucketName = function(stage, region, projectDomain) {
projectDomain = projectDomain.trim().toLowerCase();
return 'jaws-' + stage + '-' + region + '-' + projectDomain;
};
/**

View File

@ -30,12 +30,12 @@ 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(path.join(projPath, 'back'));
process.chdir(projPath);
JAWS = new Jaws();
})
.then(function() {

View File

@ -29,13 +29,13 @@ 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
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);

View File

@ -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);

View File

@ -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();
});

View File

@ -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();
});

View File

@ -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();

View File

@ -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();
});

View File

@ -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();
});

View File

@ -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();
});
});

View File

@ -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');

View File

@ -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');