my-notes-viewer/scripts/build-index.js
2022-06-22 16:02:46 +02:00

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))