Fixed a bug where you would receive relative paths by default while asking for contents of a dir
This commit is contained in:
parent
67c8e9c31d
commit
7f5d5ba1b1
@ -158,17 +158,28 @@ export function hashUtil(data: BinaryLike) {
|
|||||||
return hash
|
return hash
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listFiles(path: string, recursive?: boolean): Promise<string[]> {
|
export async function listFiles(path: string, recursive?: boolean, relative?: boolean,): Promise<string[]> {
|
||||||
|
|
||||||
if (!recursive) {
|
if (!recursive) {
|
||||||
recursive = false
|
recursive = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!relative) {
|
||||||
|
relative = false
|
||||||
|
}
|
||||||
|
|
||||||
if (!await isDir(path)) {
|
if (!await isDir(path)) {
|
||||||
// UGLY: be specific
|
// UGLY: be specific
|
||||||
throw new Error("This is not a directory")
|
throw new Error("This is not a directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
return await Node.readdir(path, {recursive: recursive})
|
const relativePaths = await Node.readdir(path, {recursive: recursive})
|
||||||
|
|
||||||
|
if (relative) {
|
||||||
|
return relativePaths
|
||||||
|
}
|
||||||
|
|
||||||
|
return relativePaths.map( (_path) => {
|
||||||
|
return `${path}/${_path}`
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user