2022-08-16 19:23:13 +00:00
|
|
|
import * as walkdir from 'walkdir';
|
2023-02-17 18:32:39 +00:00
|
|
|
import { emittedOnce } from './lib/events-helpers';
|
2022-08-16 19:23:13 +00:00
|
|
|
|
|
|
|
export async function getFiles (directoryPath: string, { filter = null }: {filter?: ((file: string) => boolean) | null} = {}) {
|
|
|
|
const files: string[] = [];
|
|
|
|
const walker = walkdir(directoryPath, {
|
|
|
|
no_recurse: true
|
|
|
|
});
|
|
|
|
walker.on('file', (file) => {
|
|
|
|
if (!filter || filter(file)) { files.push(file); }
|
|
|
|
});
|
2023-02-17 18:32:39 +00:00
|
|
|
await emittedOnce(walker, 'end');
|
2022-08-16 19:23:13 +00:00
|
|
|
return files;
|
|
|
|
}
|