Skip to content

Commit

Permalink
feat(@tinacms/api-git): GET /:relPath returns content list for direct…
Browse files Browse the repository at this point in the history
…ories
  • Loading branch information
ncphillips committed Sep 24, 2020
1 parent 90f7e15 commit c613b20
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion packages/@tinacms/api-git/src/repo.ts
Expand Up @@ -81,7 +81,16 @@ export class Repo {

if (stats.isDirectory()) {
// TODO: Get list of files in the directory
return {}
const dir = fs.readdirSync(absolutePath, { withFileTypes: true })
return {
path: relPath,
contents: dir.map(file => ({
id: path.join(relPath, file.name),
filename: file.name,
directory: relPath,
type: file.isFile() ? 'file' : 'dir',
})),
}
}

// TODO: Return file contents like in getFileAtHead
Expand Down
2 changes: 1 addition & 1 deletion packages/@tinacms/api-git/src/router.ts
Expand Up @@ -79,7 +79,7 @@ export function router(repo: Repo, config: Partial<GitRouterConfig> = {}) {
* if file return file contents
* if directory
*/
res.json({ status: 'success', path, file })
res.json({ status: 'success', file })
} catch {
res.status(500).json({ status: 'error' })
}
Expand Down

0 comments on commit c613b20

Please sign in to comment.