1 |
3a515b92
|
cagy
|
'use strict';
|
2 |
|
|
const path = require('path');
|
3 |
|
|
const pathExists = require('path-exists');
|
4 |
|
|
const pLocate = require('p-locate');
|
5 |
|
|
|
6 |
|
|
module.exports = (iterable, options) => {
|
7 |
|
|
options = Object.assign({
|
8 |
|
|
cwd: process.cwd()
|
9 |
|
|
}, options);
|
10 |
|
|
|
11 |
|
|
return pLocate(iterable, el => pathExists(path.resolve(options.cwd, el)), options);
|
12 |
|
|
};
|
13 |
|
|
|
14 |
|
|
module.exports.sync = (iterable, options) => {
|
15 |
|
|
options = Object.assign({
|
16 |
|
|
cwd: process.cwd()
|
17 |
|
|
}, options);
|
18 |
|
|
|
19 |
|
|
for (const el of iterable) {
|
20 |
|
|
if (pathExists.sync(path.resolve(options.cwd, el))) {
|
21 |
|
|
return el;
|
22 |
|
|
}
|
23 |
|
|
}
|
24 |
|
|
};
|