本文整理匯總了TypeScript中@elastic/nodegit.Tree.entries方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Tree.entries方法的具體用法?TypeScript Tree.entries怎麽用?TypeScript Tree.entries使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@elastic/nodegit.Tree
的用法示例。
在下文中一共展示了Tree.entries方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: walk
async function* walk(t: Tree): AsyncIterableIterator<FileTree> {
for (const e of t.entries()) {
if (e.isFile() && e.filemode() !== TreeEntry.FILEMODE.LINK) {
yield entry2Tree(e);
} else if (e.isDirectory()) {
const subFolder = await e.getTree();
await (yield* walk(subFolder));
} else {
// ignore other files
}
}
}
示例2: walkTree
private async walkTree(
fileTree: FileTree,
tree: Tree,
paths: string[],
skip: number,
limit: number,
childrenDepth: number = 1,
flatten: boolean = false
): Promise<FileTree> {
const [path, ...rest] = paths;
fileTree.childrenCount = tree.entryCount();
if (!fileTree.children) {
fileTree.children = [];
for (const e of tree.entries().slice(skip, limit)) {
const child = entry2Tree(e);
fileTree.children.push(child);
if (e.isDirectory()) {
const childChildrenCount = (await e.getTree()).entryCount();
if ((childChildrenCount === 1 && flatten) || childrenDepth > 1) {
await this.walkTree(
child,
await e.getTree(),
[],
skip,
limit,
childrenDepth - 1,
flatten
);
}
}
}
fileTree.children.sort(sortFileTree);
}
if (path) {
const entry = await checkExists(
() => Promise.resolve(tree.getEntry(path)),
`path ${fileTree.path}/${path} does not exists.`
);
let child = entry2Tree(entry);
if (entry.isDirectory()) {
child = await this.walkTree(
child,
await entry.getTree(),
rest,
skip,
limit,
childrenDepth,
flatten
);
}
const idx = fileTree.children.findIndex(c => c.name === entry.name());
if (idx >= 0) {
// replace the entry in children if found
fileTree.children[idx] = child;
} else {
fileTree.children.push(child);
}
}
return fileTree;
}