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

Function getFolderFiles

packages/decap-cms-backend-test/src/implementation.ts:106–131  ·  view source on GitHub ↗
(
  tree: RepoTree,
  folder: string,
  extension: string,
  depth: number,
  files = [] as RepoFile[],
  path = folder,
)

Source from the content-addressed store, hash-verified

104}
105
106export function getFolderFiles(
107 tree: RepoTree,
108 folder: string,
109 extension: string,
110 depth: number,
111 files = [] as RepoFile[],
112 path = folder,
113) {
114 if (depth <= 0) {
115 return files;
116 }
117
118 Object.keys(tree[folder] || {}).forEach(key => {
119 if (extname(key)) {
120 const file = (tree[folder] as RepoTree)[key] as RepoFile;
121 if (!extension || key.endsWith(`.${extension}`)) {
122 files.unshift({ content: file.content, path: `${path}/${key}` });
123 }
124 } else {
125 const subTree = tree[folder] as RepoTree;
126 return getFolderFiles(subTree, key, extension, depth - 1, files, `${path}/${key}`);
127 }
128 });
129
130 return files;
131}
132
133export default class TestBackend implements Implementation {
134 mediaFolder: string;

Callers 5

traverseCursorMethod · 0.85
entriesByFolderMethod · 0.85
getMediaMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected