UNPKG

budgie-cli

Version:
26 lines (19 loc) 956 B
import * as glob from "glob"; export { IOptions as IGlobOptions } from "glob"; export const globAsync = async (pattern: string, options: glob.IOptions = {}): Promise<ReadonlyArray<string>> => new Promise<ReadonlyArray<string>>((resolve, reject) => { glob(pattern, options, (error: Error | null, matches: ReadonlyArray<string>) => { if (error !== null) { reject(error); return; } resolve(matches); }); }); export const globAllAsync = async (patterns: ReadonlyArray<string>, options: glob.IOptions = {}) => (await Promise.all(patterns.map(async (pattern: string) => globAsync(pattern, options)))).reduce( (allResults: ReadonlyArray<string>, nextResults: ReadonlyArray<string>) => allResults.concat(nextResults), [], ); export type IGlobAsync = typeof globAsync; export type IGlobAllAsync = typeof globAllAsync;