Skip to content

Instantly share code, notes, and snippets.

@wwahammy
Last active August 29, 2015 14:06
Show Gist options
  • Save wwahammy/2134bf2ed496dc40b651 to your computer and use it in GitHub Desktop.
Save wwahammy/2134bf2ed496dc40b651 to your computer and use it in GitHub Desktop.
How do I get buildFilters always return the function from createMatchFunction
/**
* I want this to always return the promise that resoslves to the result of createMatchFunction(ignore)
*
* this is in a larger file but it's not relevant
*/
function buildFilters(dir, options) {
var jpmignorePath = path.join(dir, ".jpmignore");
//fs is from require('fs-promises')
return fs.exists(jpmignorePath).then(function (exists){
//add defaults
//this list is easy to fill so far
var ignore = [ new MiniMatch('.zip', mmopt), new MiniMatch('.xpi', mmopt)];
if (options.command != "test")
{
ignore.push(new MiniMatch('/tests', mmopt));
}
//.jpmignore exists, add filters for every lin in the file
if (exists)
{
//buildJpmFilters returns a promise that resolves with an array of MiniMatch objects
buildJpmFilters(jpmignorePath).then( function(filters) {
//combine the list of MiniMatch objects we already have with the new ones
ignore = ignore.concat(filters)
//return the function created by createMatchFunction(ignore)
return createMatchFunction(ignore);
});
// PROBLEM uh oh, I can't return the then above because I want to just have the function from createMatchFunction
// like below but here all I have is the promise... how do I return the RESULT of the promise?
}
else
{
//easy, just return this and I retun a function
return createMatchFunction(ignore);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment