Skip to content

Commit

Permalink
feat(utils/paths): adds getPaths
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed May 6, 2019
1 parent 9439e55 commit eda621b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/utils/paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import path from 'path';
import up from 'find-up';

export default async function getPaths(
...directories: string[]
): Promise<string[]> {
const all = await Promise.all(directories.map(each));

const a: string[] = [];
let b: string[] = [];
for (let bins of all) {
if (bins.length) {
a.push(bins.shift() as string);
b = b.concat(bins);
}
}

return a.concat(b).filter((x, i, arr) => x && arr.indexOf(x) === i);
}

export async function each(directory: string): Promise<string[]> {
const bin = await up('node_modules/.bin', { cwd: directory });
return bin ? [bin].concat(await each(path.join(directory, '../'))) : [];
}

0 comments on commit eda621b

Please sign in to comment.