-
Notifications
You must be signed in to change notification settings - Fork 0
/
map-project-structure.js
39 lines (31 loc) · 1.16 KB
/
map-project-structure.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import fs from 'fs';
import path from 'path';
function mapFiles(dir, excludedPaths = [], prefix = '', isLast = true) {
const items = fs.readdirSync(dir);
items.forEach((item, index) => {
const fullPath = path.join(dir, item);
const isExcludedPath = excludedPaths.includes(fullPath);
const isDirectory = fs.statSync(fullPath).isDirectory();
const isLastItem = index === items.length - 1;
if (isExcludedPath) {
return;
}
// Print the current item with tree structure
console.log(`${prefix}${isLast ? '└─' : '├─'} ${item}`);
if (isDirectory) {
// Recurse into directories
mapFiles(fullPath, excludedPaths, `${prefix}${isLast ? ' ' : '│ '}`, isLastItem);
}
});
}
// Define the directory to start mapping from
const projectDir = path.resolve(); // Start from the current directory
// Define the paths to exclude
const excludedPaths = [
path.join(projectDir, 'node_modules'),
path.join(projectDir, '.git'),
path.join(projectDir, '.env')
];
// Start mapping the files
console.log(projectDir);
mapFiles(projectDir, excludedPaths);