All files parseFiles.ts

0% Statements 0/10
0% Branches 0/1
0% Functions 0/4
0% Lines 0/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23                                             
import { promisify } from "util";
import glob from "glob";
import flatten from "lodash/flatten";
import { AnnotatedComment } from "./AnnotatedComment";
import { Plugin } from "./Plugin";
import { parseFile } from "./parseFile";
 
const globAsync = promisify(glob);
 
export async function parseFiles<T>(
  pattern: string,
  bodyParser: Plugin<any, any>["parse"],
  { filter }: { filter: (path: string) => boolean } = { filter: () => true }
): Promise<AnnotatedComment<T>[]> {
  return globAsync(pattern, { nodir: true })
    .then(paths =>
      Promise.all(
        paths.filter(filter).map(path => parseFile<T>(path, bodyParser))
      )
    )
    .then(flatten);
}