當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Tree.entries方法代碼示例

本文整理匯總了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
     }
   }
 }
開發者ID:elastic,項目名稱:kibana,代碼行數:12,代碼來源:git_operations.ts

示例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;
  }
開發者ID:elastic,項目名稱:kibana,代碼行數:61,代碼來源:git_operations.ts


注:本文中的@elastic/nodegit.Tree.entries方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。