-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
15 changed files
with
115 additions
and
118 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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
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,84 @@ | ||
import { unlink, access, stat, Stats, lstat, readdir } from "fs-extra-p" | ||
import { Filter } from "./filter" | ||
import BluebirdPromise from "bluebird-lst-c" | ||
import * as path from "path" | ||
|
||
export const MAX_FILE_REQUESTS = 8 | ||
export const CONCURRENCY = {concurrency: MAX_FILE_REQUESTS} | ||
|
||
export function unlinkIfExists(file: string) { | ||
return unlink(file) | ||
.catch(() => { | ||
// ignore | ||
}) | ||
} | ||
|
||
export async function statOrNull(file: string): Promise<Stats | null> { | ||
try { | ||
return await stat(file) | ||
} | ||
catch (e) { | ||
if (e.code === "ENOENT") { | ||
return null | ||
} | ||
else { | ||
throw e | ||
} | ||
} | ||
} | ||
|
||
export async function exists(file: string): Promise<boolean> { | ||
try { | ||
await access(file) | ||
return true | ||
} | ||
catch (e) { | ||
return false | ||
} | ||
} | ||
|
||
export async function walk(initialDirPath: string, consumer?: (file: string, stat: Stats) => void, filter?: Filter): Promise<Array<string>> { | ||
const result: Array<string> = [] | ||
const queue: Array<string> = [initialDirPath] | ||
let addDirToResult = false | ||
while (queue.length > 0) { | ||
const dirPath = queue.pop()! | ||
if (addDirToResult) { | ||
result.push(dirPath) | ||
} | ||
else { | ||
addDirToResult = true | ||
} | ||
|
||
const childNames = await readdir(dirPath) | ||
childNames.sort() | ||
|
||
const dirs: Array<string> = [] | ||
await BluebirdPromise.map(childNames, name => { | ||
const filePath = dirPath + path.sep + name | ||
return lstat(filePath) | ||
.then(stat => { | ||
if (filter != null && !filter(filePath, stat)) { | ||
return | ||
} | ||
|
||
if (consumer != null) { | ||
consumer(filePath, stat) | ||
} | ||
|
||
if (stat.isDirectory()) { | ||
dirs.push(filePath) | ||
} | ||
else { | ||
result.push(filePath) | ||
} | ||
}) | ||
}, CONCURRENCY) | ||
|
||
for (let i = dirs.length - 1; i > -1; i--) { | ||
queue.push(dirs[i]) | ||
} | ||
} | ||
|
||
return result | ||
} |
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
Oops, something went wrong.