UNPKG

folder-structures

Version:

Automatically generate and monitor your project folder structure. The output is a .txt file that shows the folder and file hierarchy in a tree view.

49 lines (40 loc) 1.2 kB
const fs = require('fs').promises; const path = require('path'); async function scanFolderStructure( dirPath, maxDepth = 10, currentDepth = 0, ignoredFolders = [], ignoredFiles = [] ) { if (currentDepth > maxDepth) return null; try { const stats = await fs.stat(dirPath); if (!stats.isDirectory()) throw new Error(`Path "${dirPath}" bukan folder.`); const entries = await fs.readdir(dirPath); const structure = {}; for (const entry of entries) { if (ignoredFolders.includes(entry)) continue; if (ignoredFiles.includes(entry)) continue; const fullPath = path.join(dirPath, entry); const entryStats = await fs.stat(fullPath); if (entryStats.isDirectory()) { structure[entry] = await scanFolderStructure( fullPath, maxDepth, currentDepth + 1, ignoredFolders, ignoredFiles ); } else if (entryStats.isFile()) { structure[entry] = null; } else { structure[entry] = null; } } return structure; } catch (err) { throw err; } } module.exports = { scanFolderStructure };