function deepTraversal(node) {
if (!node) return nodeList
const stack = []
const nodeList = []
stack.push(node)
while(stack.length) {
const currentNode = stack.pop()
if (currentNode != null) {
nodeList.push(currentNode)
const children = currentNode.children = []
for (let i = children.length - 1; i >= 0; i--) {
stack.push(children[i])
}
}
}
return nodeList
}
function fs() {}
function path() {}
function deepReadFile(dirPath) {
const stack = []
const fileList = []
stack.push(dirPath)
while(stack.length) {
const currentDirPath = stack.pop()
const stats = fs.statSync(currentDirPath)
const fileObj = {}
fileObj.name = currentDirPath
if (stats.isDirectory()) {
fileObj.type = 'dir'
fileList.push(fileObj)
const children = fs.readdirSync(currentDirPath)
for (let i = children.length - 1; i >= 0; i--) {
const childPath = path.join(currentDirPath, children[i])
stack.push(childPath)
}
} else {
fileObj.type = path.extname(currentDirPath).substring(1)
fileList.push(fileObj)
}
}
return fileList
}
console