2020-01-28 13:07:56 +08:00
|
|
|
'use strict';
|
|
|
|
const path = require('path');
|
2020-03-22 05:13:25 +08:00
|
|
|
const pathExists = require('path-exists');
|
2020-01-28 13:07:56 +08:00
|
|
|
const pLocate = require('p-locate');
|
|
|
|
|
2020-03-22 05:13:25 +08:00
|
|
|
module.exports = (iterable, opts) => {
|
|
|
|
opts = Object.assign({
|
|
|
|
cwd: process.cwd()
|
|
|
|
}, opts);
|
2020-01-28 13:07:56 +08:00
|
|
|
|
2020-03-22 05:13:25 +08:00
|
|
|
return pLocate(iterable, el => pathExists(path.resolve(opts.cwd, el)), opts);
|
2020-01-28 13:07:56 +08:00
|
|
|
};
|
|
|
|
|
2020-03-22 05:13:25 +08:00
|
|
|
module.exports.sync = (iterable, opts) => {
|
|
|
|
opts = Object.assign({
|
|
|
|
cwd: process.cwd()
|
|
|
|
}, opts);
|
2020-01-28 13:07:56 +08:00
|
|
|
|
2020-03-22 05:13:25 +08:00
|
|
|
for (const el of iterable) {
|
|
|
|
if (pathExists.sync(path.resolve(opts.cwd, el))) {
|
|
|
|
return el;
|
2020-01-28 13:07:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|