diff --git a/lib/Function.js b/lib/Function.js index 44c0ae390..5beffdbc8 100644 --- a/lib/Function.js +++ b/lib/Function.js @@ -171,7 +171,8 @@ class ServerlessFunction { while( !_this._S.classes.Component.isComponentDir( p ) ) { if( SUtils.fileExistsSync(path.join(p, 's-templates.json'))) { - templates.unshift( require(path.join(p, 's-templates.json')) ); + let template = JSON.parse(fs.readFileSync(path.join(p, 's-templates.json'), 'utf8')); + templates.unshift(template); } p = path.join( p, '..' ); } @@ -266,10 +267,7 @@ class ServerlessFunction { // Populate let clone = _this.get(); clone = SUtils.populate(_this._S.state.getMeta(), _this.getTemplates(), clone, options.stage, options.region); - clone.endpoints = []; - for (let i = 0; i < _this.endpoints.length; i++) { - clone.endpoints[i] = _this.endpoints[i].getPopulated(options); - } + clone.endpoints = _this.endpoints.map( endpoint => endpoint.getPopulated(options) ); return clone; } diff --git a/lib/Project.js b/lib/Project.js index 0055682bd..ec3d57a13 100644 --- a/lib/Project.js +++ b/lib/Project.js @@ -299,7 +299,7 @@ class ServerlessProject extends VarContainer { resources = SUtils.readAndParseJsonSync(_this._S.getProject().getFilePath('s-resources-cf.json')); } - return _.flatten( _.map( _.values( _this.components ), c => c.getCFSnippets() ) ); + return _.flattenDeep( _.map( _.values( _this.components ), c => c.getCFSnippets() ) ); }) .then(function (cfSnippets) { @@ -477,7 +477,7 @@ class ServerlessProject extends VarContainer { getAllComponents(options){ if( _.get( options, 'paths' ) ){ - options.paths = _.map( options.paths, p => p.split(path.sep)[0] ); + options.paths = _.map( options.paths, p => p && p.split(path.sep)[0] ); } return SUtils.filterSPaths( _.values( this.components ), options ); } @@ -535,7 +535,7 @@ class ServerlessProject extends VarContainer { } getRegion( stageName, regionName ){ - if( this.hasStage( stageName ) ){ + if( this.validateStageExists( stageName ) ){ let stage = this.getStage( stageName ); if( stage.hasRegion( regionName ) ){