本文整理匯總了TypeScript中@elastic/nodegit.Tree類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Tree類的具體用法?TypeScript Tree怎麽用?TypeScript Tree使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Tree類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
}
示例3:
() => Promise.resolve(tree.getEntry(path)),