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

Function getFolderFiles

packages/decap-cms-backend-test/src/implementation.ts:125–150  ·  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

123}
124
125export function getFolderFiles(
126 tree: RepoTree,
127 folder: string,
128 extension: string,
129 depth: number,
130 files = [] as RepoFile[],
131 path = folder,
132) {
133 if (depth <= 0) {
134 return files;
135 }
136
137 Object.keys(tree[folder] || {}).forEach(key => {
138 if (extname(key)) {
139 const file = (tree[folder] as RepoTree)[key] as RepoFile;
140 if (!extension || key.endsWith(`.${extension}`)) {
141 files.unshift({ content: file.content, path: `${path}/${key}` });
142 }
143 } else {
144 const subTree = tree[folder] as RepoTree;
145 return getFolderFiles(subTree, key, extension, depth - 1, files, `${path}/${key}`);
146 }
147 });
148
149 return files;
150}
151
152export default class TestBackend implements Implementation {
153 mediaFolder: string;

Callers 5

moveFileFunction · 0.85
traverseCursorMethod · 0.85
entriesByFolderMethod · 0.85
getMediaMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected