MCPcopy Create free account
hub / github.com/decaporg/decap-cms / allEntriesByFolder

Function allEntriesByFolder

packages/decap-cms-lib-util/src/implementation.ts:565–668  ·  view source on GitHub ↗
({
  listAllFiles,
  readFile,
  readFileMetadata,
  apiName,
  branch,
  localForage,
  folder,
  extension,
  depth,
  getDefaultBranch,
  isShaExistsInBranch,
  getDifferences,
  getFileId,
  filterFile,
  customFetch,
}: AllEntriesByFolderArgs)

Source from the content-addressed store, hash-verified

563 };
564
565export 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;

Callers 2

allEntriesByFolderMethod · 0.90
allEntriesByFolderMethod · 0.90

Calls 2

fetchFilesFunction · 0.85
listFilesFunction · 0.70

Tested by

no test coverage detected