Skip to content

Commit

Permalink
feat(public/tags): adds glob tag
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed May 18, 2019
1 parent 4419db2 commit 69e3d9a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/public/tags/glob.ts
@@ -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);
}
}
1 change: 1 addition & 0 deletions src/public/tags/index.ts
@@ -1,5 +1,6 @@
export { default as ensure } from './ensure';
export { default as exists } from './exists';
export { default as glob } from './glob';
export { default as kpo } from './kpo';
export { default as line } from './line';
export { default as log } from './log';
Expand Down

0 comments on commit 69e3d9a

Please sign in to comment.