forked from cms/tibi-svelte-starter
28 lines
636 B
JavaScript
28 lines
636 B
JavaScript
const fs = require("fs")
|
|
const path = require("path")
|
|
|
|
const dir = "."
|
|
|
|
function getTree(dir) {
|
|
const files = fs.readdirSync(dir)
|
|
|
|
return files
|
|
.filter(function (file) {
|
|
if (file.match(/^\./)) {
|
|
return false
|
|
}
|
|
return true
|
|
})
|
|
.map(function (file) {
|
|
const f = { name: file }
|
|
if (fs.statSync(dir + "/" + file).isDirectory()) {
|
|
f.isDir = true
|
|
f.elements = getTree(dir + "/" + file)
|
|
}
|
|
return f
|
|
})
|
|
}
|
|
|
|
const tree = getTree(dir)
|
|
console.log(JSON.stringify(tree, null, 4))
|