mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
Cleanups
This commit is contained in:
parent
8f9ea9773d
commit
4411518e4a
@ -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 ){
|
||||
|
||||
@ -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 = {
|
||||
|
||||
@ -155,7 +155,7 @@ usage: serverless plugin create <plugin>`,
|
||||
|
||||
// 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));
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user