changed project structure with a new back folder

This commit is contained in:
Eslam A. Hefnawy 2015-11-23 03:06:08 +02:00
parent afd710c68f
commit 70fca1ed05
8 changed files with 36 additions and 22 deletions

View File

@ -5,7 +5,7 @@ const path = require('path'),
JawsUtils = require('./utils/index'),
JawsCLI = require('./utils/cli'),
JawsError = require('./jaws-error'),
awsMisc = require('./utils/aws/Misc'),
awsMisc = require('./utils/aws/Misc'),
BbPromise = require('bluebird'),
dotenv = require('dotenv');
@ -47,7 +47,7 @@ class Jaws {
path: path.join(this._projectRootPath, 'admin.env'),
});
this._awsProfile = process.env.JAWS_ADMIN_AWS_PROFILE;
this._awsProfile = process.env.JAWS_ADMIN_AWS_PROFILE;
if (!this._awsAdminKeyId) this._awsAdminKeyId = awsMisc.profilesGet(this._awsProfile)[this._awsProfile].aws_access_key_id;
if (!this._awsAdminSecretKey) this._awsAdminSecretKey = awsMisc.profilesGet(this._awsProfile)[this._awsProfile].aws_secret_access_key;
}

View File

@ -60,21 +60,33 @@ usage: jaws env list <stage> <region>`,
* @returns {Promise}
*/
envList(evt) {
let _this = this;
if (this.Jaws.cli) {
// Add options to evt
this.evt = this.Jaws.cli.options;
// Add region & stage from params.
this.evt.stage = this.Jaws.cli.params[0];
this.evt.region = this.Jaws.cli.params[1];
if (!evt.stage || !evt.region) {
return BbPromise.reject(new JawsError('Must specify a stage and region'), JawsError.errorCodes.UNKNOWN);
}
let awsModsDir = path.join(this.Jaws._projectRootPath, 'slss_modules');
if (!this.evt.stage || !this.evt.region) {
return BbPromise.reject(new JawsError('Must specify a stage and region'), JawsError.errorCodes.UNKNOWN);
}
let _this = this;
let awsModsDir = path.join(this.Jaws._projectRootPath, 'back', 'slss_modules');
return JawsUtils.findAllAwsmJsons(awsModsDir)
.then(awsmJsonPaths => {
return [awsmJsonPaths, awsMisc.getEnvFiles(_this.Jaws, evt.region, evt.stage)];
return [awsmJsonPaths, awsMisc.getEnvFiles(_this.Jaws, _this.evt.region, _this.evt.stage)];
})
.spread((awsmJsonPaths, envMapsByRegion) => {
let envInBackMap = {};
JawsCLI.log(`ENV vars for stage ${evt.stage}:`);
JawsCLI.log(`ENV vars for stage ${_this.evt.stage}:`);
envMapsByRegion.forEach(mapForRegion => {
JawsCLI.log('------------------------------');
JawsCLI.log(mapForRegion.regionName);

View File

@ -220,7 +220,7 @@ usage: jaws module create <module resource> <action>`,
_createSkeleton() {
let _this = this,
writeFilesDeferred = [],
modulePath = path.join(this.Jaws._projectRootPath, 'slss_modules', _this.evt.resource),
modulePath = path.join(this.Jaws._projectRootPath, 'back', 'slss_modules', _this.evt.resource),
actionPath = path.join(modulePath, _this.evt.action);
// If module/action already exists, throw error
@ -276,14 +276,14 @@ usage: jaws module create <module resource> <action>`,
switch (_this.evt.runtime) {
case 'nodejs':
if (_this.evt.pkgMgr == 'npm') {
let node_modules_path = path.join(_this.Jaws._projectRootPath, 'node_modules');
let node_modules_path = path.join(_this.Jaws._projectRootPath, 'back', 'node_modules');
// Create node_modules if DNE in project
if (!JawsUtils.dirExistsSync(node_modules_path)) {
deferredWrites.push(fs.mkdirAsync(node_modules_path));
}
let modulePath = path.join(_this.Jaws._projectRootPath, 'node_modules', _this.evt.resource);
let modulePath = path.join(_this.Jaws._projectRootPath, 'back', 'node_modules', _this.evt.resource);
// create module dir if DNE in node_modules
if (!JawsUtils.dirExistsSync(modulePath)) {

View File

@ -141,9 +141,9 @@ usage: jaws module postinstall <pkgMgr> <moduleName>`,
pkgMgrDir = 'node_modules';
}
let srcAwsmPath = path.join(_this.Jaws._projectRootPath, pkgMgrDir, _this.evt.moduleName, 'awsm'),
srcAwsmJsonPath = path.join(_this.Jaws._projectRootPath, pkgMgrDir, _this.evt.moduleName, 'awsm.json'),
awsModsPath = path.join(_this.Jaws._projectRootPath, 'slss_modules');
let srcAwsmPath = path.join(_this.Jaws._projectRootPath, 'back', pkgMgrDir, _this.evt.moduleName, 'awsm'),
srcAwsmJsonPath = path.join(_this.Jaws._projectRootPath, 'back', pkgMgrDir, _this.evt.moduleName, 'awsm.json'),
awsModsPath = path.join(_this.Jaws._projectRootPath, 'back', 'slss_modules');
if (!JawsUtils.fileExistsSync(srcAwsmJsonPath)) {
return BbPromise.reject(new JawsError('Module missing awsm.json file in root of project', JawsError.errorCodes.UNKNOWN));
@ -193,6 +193,7 @@ usage: jaws module postinstall <pkgMgr> <moduleName>`,
* @private
*/
_saveCfTemplate() {
let _this = this,
awsmJson = _this._rootAwsmJson,
projectCfPath = path.join(_this.Jaws._projectRootPath, 'cloudformation');
@ -209,6 +210,7 @@ usage: jaws module postinstall <pkgMgr> <moduleName>`,
})
.then(function(files) {
files.forEach(function(file) {
file = path.join(projectCfPath, file);
if (JawsUtils.endsWith(file, 'resources-cf.json')) {
@ -243,7 +245,7 @@ usage: jaws module postinstall <pkgMgr> <moduleName>`,
regionStageResourcesCfJson.Resources[resourceKey] = cfExtensionPoints.resources[resourceKey];
});
JawsUtils.writeFile(file, JSON.stringify(regionStageResourcesCfJson, null, 2));
}
});

View File

@ -388,9 +388,10 @@ class ProjectCreate extends JawsPlugin {
)
.then(function() {
return BbPromise.all([
fs.mkdirAsync(path.join(_this._projectRootPath, 'tests')),
fs.mkdirAsync(path.join(_this._projectRootPath, 'lib')),
fs.mkdirAsync(path.join(_this._projectRootPath, 'slss_modules')),
fs.mkdirAsync(path.join(_this._projectRootPath, 'back')),
fs.mkdirAsync(path.join(_this._projectRootPath, 'back', 'tests')),
fs.mkdirAsync(path.join(_this._projectRootPath, 'back', 'lib')),
fs.mkdirAsync(path.join(_this._projectRootPath, 'back', 'slss_modules')),
JawsUtils.writeFile(path.join(_this._projectRootPath, 'admin.env'), adminEnv),
JawsUtils.writeFile(path.join(_this._projectRootPath, 'README.md'), readme),
JawsUtils.generateResourcesCf(

View File

@ -301,7 +301,6 @@ module.exports = function(config) {
Value: projStage,
},],
};
console.log(params)
// Create CloudFormation Stack
return CloudFormation.createStackPromised(params);

View File

@ -179,7 +179,7 @@ exports.getFunctions = function(baseDir, functionPaths) {
exports.findAllEnvletsForAwsm = function(projectRootPath, modName) {
let _this = this;
return this.getFunctions(path.join(projectRootPath, 'slss_modules', modName), null)
return this.getFunctions(path.join(projectRootPath, 'back', 'slss_modules', modName), null)
.then(function(allAwsmJson) {
let envletKeys = [];
allAwsmJson.forEach(function(awsmJson) {

View File

@ -30,9 +30,9 @@ describe('All Tests', function() {
//require('./tests/actions/ProjectCreate');
//require('./tests/actions/VersionLambda');
//require('./tests/actions/ModuleCreate');
require('./tests/actions/FunctionDeploy');
//require('./tests/actions/FunctionDeploy');
//require('./tests/actions/StageCreate');
//require('./tests/actions/ProjectCreate');
require('./tests/actions/ProjectCreate');
//require('./tests/actions/EnvList');
//require('./tests/actions/EnvGet');
//require('./tests/actions/EnvUnset');