({
listAllFiles,
readFile,
readFileMetadata,
apiName,
branch,
localForage,
folder,
extension,
depth,
getDefaultBranch,
isShaExistsInBranch,
getDifferences,
getFileId,
filterFile,
customFetch,
}: AllEntriesByFolderArgs)
| 563 | }; |
| 564 | |
| 565 | export async function allEntriesByFolder({ |
| 566 | listAllFiles, |
| 567 | readFile, |
| 568 | readFileMetadata, |
| 569 | apiName, |
| 570 | branch, |
| 571 | localForage, |
| 572 | folder, |
| 573 | extension, |
| 574 | depth, |
| 575 | getDefaultBranch, |
| 576 | isShaExistsInBranch, |
| 577 | getDifferences, |
| 578 | getFileId, |
| 579 | filterFile, |
| 580 | customFetch, |
| 581 | }: AllEntriesByFolderArgs) { |
| 582 | async function listAllFilesAndPersist() { |
| 583 | const files = await listAllFiles(folder, extension, depth); |
| 584 | const branch = await getDefaultBranch(); |
| 585 | await persistLocalTree({ |
| 586 | localForage, |
| 587 | localTree: { |
| 588 | head: branch.sha, |
| 589 | files: files.map(f => ({ id: f.id!, path: f.path, name: basename(f.path) })), |
| 590 | }, |
| 591 | branch: branch.name, |
| 592 | depth, |
| 593 | extension, |
| 594 | folder, |
| 595 | }); |
| 596 | return files; |
| 597 | } |
| 598 | |
| 599 | async function listFiles() { |
| 600 | const localTree = await getLocalTree({ localForage, branch, folder, extension, depth }); |
| 601 | if (localTree) { |
| 602 | const branch = await getDefaultBranch(); |
| 603 | // if the branch was forced pushed the local tree sha can be removed from the remote tree |
| 604 | const localTreeInBranch = await isShaExistsInBranch(branch.name, localTree.head); |
| 605 | if (!localTreeInBranch) { |
| 606 | console.log( |
| 607 | `Can't find local tree head '${localTree.head}' in branch '${branch.name}', rebuilding local tree`, |
| 608 | ); |
| 609 | return listAllFilesAndPersist(); |
| 610 | } |
| 611 | const diff = await getDiffFromLocalTree({ |
| 612 | branch, |
| 613 | localTree, |
| 614 | folder, |
| 615 | extension, |
| 616 | depth, |
| 617 | getDifferences, |
| 618 | getFileId, |
| 619 | filterFile, |
| 620 | }).catch(e => { |
| 621 | console.log('Failed getting diff from local tree:', e); |
| 622 | return null; |
no test coverage detected