UNPKG

712 BJavaScriptView Raw
1"use strict"
2
3const Promise = require("bluebird")
4const co = Promise.coroutine
5
6module.exports = function (opts, func) {
7 // assign against defaults
8 opts = Object.assign({every: 1, files: 1}, opts)
9 func = opts.func || func
10
11 return co(function * (o) {
12 o = o || {}
13 const args = []
14 args.push.apply(args, arguments) && args.shift()
15 // grab alias to chosen source type
16 const arr = this._[opts.files ? "files" : "globs"]
17 // wrapper pass all arguments to plugin func
18 const run = s => co(func).apply(this, [s, o].concat(args))
19 // loop thru EACH if `every`, else send full source array
20 yield (opts.every ? Promise.all(arr.map(run)) : run(arr))
21 // send back instance allow chain
22 return this
23 })
24}