Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { error } from '~/utils/errors'; | ||
import asTag from '~/utils/as-tag'; | ||
import _glob from 'glob'; | ||
|
||
export default glob; | ||
|
||
function glob(pattern: string): Promise<string[]>; | ||
function glob( | ||
literals: TemplateStringsArray, | ||
...placeholders: any[] | ||
): Promise<string[]>; | ||
/** | ||
* String tag; returns a promise resolving with all paths matching a glob | ||
* @returns Promise<string[]> | ||
*/ | ||
async function glob(...args: any[]): Promise<string[]> { | ||
try { | ||
const pattern = asTag(args.shift(), ...args); | ||
return await new Promise((resolve: (arg: string[]) => void, reject) => | ||
_glob(pattern, { cwd: process.cwd() }, (err, matches) => | ||
err ? reject(err) : resolve(matches) | ||
) | ||
); | ||
} catch (err) { | ||
throw error(err); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters