16 lines
381 B
JavaScript
16 lines
381 B
JavaScript
|
async function getFiles (directoryPath, { filter = null } = {}) {
|
||
|
const files = [];
|
||
|
const walker = require('walkdir').walk(directoryPath, {
|
||
|
no_recurse: true
|
||
|
});
|
||
|
walker.on('file', (file) => {
|
||
|
if (!filter || filter(file)) {
|
||
|
files.push(file);
|
||
|
}
|
||
|
});
|
||
|
await new Promise((resolve) => walker.on('end', resolve));
|
||
|
return files;
|
||
|
}
|
||
|
|
||
|
module.exports = getFiles;
|