main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
517 bytes
|
Rev | Line | |
---|
[d565449] | 1 | import { dirname, resolve } from 'path';
|
---|
| 2 | import { readdir, stat } from 'fs';
|
---|
| 3 | import { promisify } from 'util';
|
---|
| 4 |
|
---|
| 5 | const toStats = promisify(stat);
|
---|
| 6 | const toRead = promisify(readdir);
|
---|
| 7 |
|
---|
| 8 | export default async function (start, callback) {
|
---|
| 9 | let dir = resolve('.', start);
|
---|
| 10 | let tmp, stats = await toStats(dir);
|
---|
| 11 |
|
---|
| 12 | if (!stats.isDirectory()) {
|
---|
| 13 | dir = dirname(dir);
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | while (true) {
|
---|
| 17 | tmp = await callback(dir, await toRead(dir));
|
---|
| 18 | if (tmp) return resolve(dir, tmp);
|
---|
| 19 | dir = dirname(tmp = dir);
|
---|
| 20 | if (tmp === dir) break;
|
---|
| 21 | }
|
---|
| 22 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.