add initRuntime util function

This commit is contained in:
Austen Collins 2015-09-29 08:32:54 -07:00
parent 657af1aa46
commit 8efa408b33
4 changed files with 40 additions and 7 deletions

View File

@ -110,6 +110,7 @@ program
name: theParams[1],
action: theParams[2],
runtime: options.runtime || 'nodejs',
npm: options.npm || false,
};
if (options.lambda) {

View File

@ -124,8 +124,10 @@ CMD.prototype._promptStage = Promise.method(function() {
});
/**
* CMD: Set Regions
* this._stage must be set before calling this method
*/
CMD.prototype._setRegions = Promise.method(function() {
var stage = this._stage,
region = this._region,//may not be set, default is to deploy to all regions in stage
@ -311,6 +313,7 @@ Deployer.prototype.deploy = Promise.method(function() {
* @returns {Promise} true if there was an existing stack, false if not
* @private
*/
Deployer.prototype._generateLambdaCf = function(taggedLambdaPkgs, lambdaRoleArn) {
//TODO: docs: if someone manually changes resource or action dir names and does NOT mark the changed awsm.jsons
//for deploy they will lose a lambda

View File

@ -25,7 +25,7 @@ module.exports.run = function(JAWS, module) {
};
/**
* CMD Classlam
* CMD Class
*/
function CMD(JAWS, module) {
@ -65,11 +65,13 @@ CMD.prototype.run = Promise.method(function() {
});
/**
* Install jaws core if it DNE
* CMD: Install jaws core if it DNE
*
* @returns {Promise}
*/
CMD.prototype._installCore = Promise.method(function() {
var _this = this,
jawsCoreName = '';

View File

@ -44,12 +44,12 @@ 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, jsonPath),
json = require(lambdaJawsPath);
var lambdaJawsPath = path.join(projectRootPath, jsonPath),
json = require(lambdaJawsPath);
if (typeof json[jawsJsonAttr] !== 'undefined') jawsPathsOfType.push(lambdaJawsPath);
return cb();
},
if (typeof json[jawsJsonAttr] !== 'undefined') jawsPathsOfType.push(lambdaJawsPath);
return cb();
},
function(error) {
if (error) reject(error);
@ -263,7 +263,9 @@ exports.getAllLambdaNames = function(projectRootPath) {
* @param regionName
* @returns {*} region object for stage
*/
exports.getProjRegionConfigForStage = function(projectJawsJson, stage, regionName) {
var projectStageObj = projectJawsJson.stages[stage];
var region = projectStageObj.filter(function(regionObj) {
@ -343,6 +345,7 @@ exports.generateResourcesCf = function(projRootPath, projName, projDomain, stage
*
* @param str
*/
var debuggerCache = {};
exports.jawsDebugWithContext = function(context) {
if (process.env.DEBUG) {
@ -414,3 +417,27 @@ function getStack() {
return stack;
}
/**
* Init Runtime
* - Checks for/creates a package manager file for the runtime param
* - Installs jaws-core
*/
exports.initRuntime = function(JAWS, runtime) {
var _this = this;
if (runtime === 'nodejs') {
// Check if package.json exists at project root
if (!utils.fileExistsSync(path.join(JAWS._meta.projectRootPath, 'package.json'))) {
// Create package.json
var packageJsonTemplate = require('../templates/nodejs/package.json');
packageJsonTemplate.name = JAWS._meta.projectJson.name;
return fs.writeFileAsync(JAWS._meta.projectRootPath, packageJsonTemplate);
}
}
};