@jpwilliams/gitree
Version:
Print a directory tree that shows Git status and ignores files dictated by .gitignore.
23 lines (17 loc) • 421 B
JavaScript
function getFileTarget (list, dirs) {
const dir = dirs.shift()
if (!dir) return list
const foundDir = list.find((file) => {
return (file.type === 'directory' && file.name === dir)
})
if (foundDir) {
return getFileTarget(foundDir.contents, dirs)
}
list.push({
type: 'directory',
name: dir,
contents: []
})
return getFileTarget(list[list.length - 1].contents, dirs)
}
module.exports = getFileTarget