1 | "use strict"
|
2 |
|
3 | const Promise = require("bluebird")
|
4 | const co = Promise.coroutine
|
5 |
|
6 | module.exports = function (opts, func) {
|
7 |
|
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 |
|
16 | const arr = this._[opts.files ? "files" : "globs"]
|
17 |
|
18 | const run = s => co(func).apply(this, [s, o].concat(args))
|
19 |
|
20 | yield (opts.every ? Promise.all(arr.map(run)) : run(arr))
|
21 |
|
22 | return this
|
23 | })
|
24 | }
|