diff --git a/lib/ServerlessProject.js b/lib/ServerlessProject.js index 990a7f464..5baf64264 100644 --- a/lib/ServerlessProject.js +++ b/lib/ServerlessProject.js @@ -403,24 +403,6 @@ class ServerlessProject { }) } - _filterSPaths( collection, options ) { - // TODO: remove this, caller should be filtering such stuff later - let paths = _.get( options, 'paths' ); - if( paths && (paths.length > 0) ) { - collection = _.filter( collection, f => - _.any( paths, p => - p.indexOf( f.getSPath() ) !== -1; - ) - ) - } - - if( _.get( options, 'returnPaths' ) == true ){ - collection = _.map( collection, func => func.getSPath(); ); - } - - return collection; - } - /** * Get Functions * - Returns an array of this project's function instances @@ -430,7 +412,7 @@ class ServerlessProject { */ getAllFunctions(options) { - return this._filterSPaths( _.flatten( _.map( _.values( this.components ), component => + return SUtils.filterSPaths( _.flatten( _.map( _.values( this.components ), component => component.getAllFunctions(); )), options ); } @@ -449,7 +431,7 @@ class ServerlessProject { */ getAllComponents(options){ - return this._filterSPaths( this.components, options ); + return SUtils.filterSPaths( this.components, options ); } getComponent( path ){ @@ -466,7 +448,7 @@ class ServerlessProject { */ getEvents(options) { - return this._filterSPaths( _.flatten( _.map( this.getAllFunctions(), f => f.getAllEvents() ) ), options ); + return SUtils.filterSPaths( _.flatten( _.map( this.getAllFunctions(), f => f.getAllEvents() ) ), options ); } getEvent( path ){ diff --git a/lib/actions/FunctionDeploy.js b/lib/actions/FunctionDeploy.js index 4f94dfe5f..ed42f4b4a 100644 --- a/lib/actions/FunctionDeploy.js +++ b/lib/actions/FunctionDeploy.js @@ -204,7 +204,7 @@ module.exports = function(SPlugin, serverlessPath) { // If --all is selected, load all paths if (_this.evt.options.all) { - _this.evt.options.paths = _this.S.state.getFunctions({ returnPaths: true }); + _this.evt.options.paths = _this.S.getProject().getAllFunctions({ returnPaths: true }); } // Ensure tmp folder exists in _meta @@ -269,7 +269,7 @@ module.exports = function(SPlugin, serverlessPath) { return BbPromise.try(function() { - func = _this.S.state.getFunctions({ paths: [path] })[0]; + func = _this.S.getProject().getFunction( path ); if (!func) throw new SError(`Function could not be found: ${path}`); let newEvt = { diff --git a/lib/actions/PluginCreate.js b/lib/actions/PluginCreate.js index c2b0c4690..bba3129aa 100644 --- a/lib/actions/PluginCreate.js +++ b/lib/actions/PluginCreate.js @@ -155,7 +155,7 @@ usage: serverless plugin create `, // TODO: Remove in V1 because will result in breaking change // Add the newly create plugin to the plugins array of the projects s-project.json file - // TODO: this belongs to Project class + // TODO: this belongs to Project class XXX let sProjectJson = SUtils.readAndParseJsonSync(this.S.getProject().getFilePath('s-project.json')); sProjectJson.plugins.push(pluginName); fs.writeFileSync(this.S.getProject().getFilePath('s-project.json'), JSON.stringify(sProjectJson, null, 2)); diff --git a/lib/utils/index.js b/lib/utils/index.js index 79f761222..4325d658c 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -16,6 +16,7 @@ let BbPromise = require('bluebird'), SCli = require('./cli'), fs = require('fs'), mkdirpAsync = require('mkdirp-then'), + _ = require('lodash'), shortid = require('shortid'); BbPromise.promisifyAll(fs); @@ -557,6 +558,22 @@ exports.populate = function(meta, templates, data, stage, region) { return data; }; +exports.filterSPaths = function( collection, options ) { + let paths = _.get( options, 'paths' ); + if( paths && (paths.length > 0) ) { + collection = _.filter( collection, f => + _.any( paths, p => + p.indexOf( f.getSPath() ) !== -1; + ) + ) + } + + if( _.get( options, 'returnPaths' ) == true ){ + collection = _.map( collection, func => func.getSPath(); ); + } + + return collection; +}; function pathToContext(path) { // Match files under lib, tests, or bin so we only report the