diff --git a/Build/lib/tree-dir.ts b/Build/lib/tree-dir.ts index 7dec4cfe..6a17b7d0 100644 --- a/Build/lib/tree-dir.ts +++ b/Build/lib/tree-dir.ts @@ -1,5 +1,5 @@ import fsp from 'fs/promises'; -import { sep } from 'path'; +import { sep, relative } from 'path'; interface TreeFileType { type: 'file', @@ -19,19 +19,20 @@ export type TreeTypeArray = TreeType[]; type VoidOrVoidArray = void | VoidOrVoidArray[]; -export const treeDir = async (path: string): Promise => { +export const treeDir = async (rootPath: string): Promise => { const tree: TreeTypeArray = []; const walk = async (dir: string, node: TreeTypeArray): Promise => { const promises: Array> = []; for await (const child of await fsp.opendir(dir)) { const childFullPath = child.parentPath + sep + child.name; + const childRelativeToRoot = relative(rootPath, childFullPath); if (child.isDirectory()) { const newNode: TreeDirectoryType = { type: 'directory', name: child.name, - path: childFullPath, + path: childRelativeToRoot, children: [] }; node.push(newNode); @@ -42,7 +43,7 @@ export const treeDir = async (path: string): Promise => { const newNode: TreeFileType = { type: 'file', name: child.name, - path: childFullPath + path: childRelativeToRoot }; node.push(newNode); continue; @@ -51,7 +52,7 @@ export const treeDir = async (path: string): Promise => { return Promise.all(promises); }; - await walk(path, tree); + await walk(rootPath, tree); return tree; };