This Node.js script recursively generates a file tree for a given repository, ignoring specified directories (e.g., node_modules, .git). The output is formatted as a tree-like structure, which can be saved to a text file.
- Recursively traverses a directory structure.
- Ignores specified directories (e.g.,
node_modules,.git). - Produces a tree-like formatted string of the directory structure.
- Optionally saves the output to a text file.
- Node.js (version 12 or higher)
-
Clone the Repository (or copy the script into your project):
git clone https://github.com/yourusername/repo-name.git cd repo-name -
Set the Repository Path:
Modify the
repoPathvariable ingenerateFileMap.jsto point to the absolute path of your repository:const repoPath = 'c:/path/to/your/repo'; // Use forward slashes -
Run the Script:
Execute the script using Node.js:
node generateFileMap.jsornode generateFileTree.js -
Output:
The script will print the tree-like structure to the console and save it to
fileTree.txtin the repository root.
├── lib/
│ ├── models/
│ ├── pages/
│ ├── images/
│ ├── components/
│ ├── services/
│ ├── main.dart
│ └── firebase_options.dart
├── assets/
├── test/
├── ios/
├── android/
├── pubspec.yaml
└── README.md
To ignore additional directories, add them to the ignoreDirs set. For example, to also ignore dist and coverage directories:
const ignoreDirs = new Set(['node_modules', '.git', 'dist', 'coverage']);
By default, the script writes the tree structure to fileTree.txt in the repository root. To change the output file name or path, modify the outputFilePath variable:
const outputFilePath = path.join(repoPath, 'customFileName.txt');
This project is licensed under the MIT License.
Feel free to modify and enhance the script to fit your specific requirements. Contributions are welcome!
If you have suggestions for improving this script or find any issues, please open an issue or submit a pull request on GitHub.
Charlie Palmer