DEV Community

Cover image for Automate project tree with protree
Ahmed Abdalla Elbilal
Ahmed Abdalla Elbilal

Posted on • Edited on

Automate project tree with protree

Intro
Some projects use a tree structure in their README file as some form of good documentation, which may look something like this

.
├── file1
├── file2
└── dir1
│   └── file3
└── dir2
    └── file4
Enter fullscreen mode Exit fullscreen mode

The Issue
The documentation may be forgotten by some developers, and if they remember, it may be a noisy process to move through the new files and then to align those tree characters └── ├── correctly.

Protree Automation
protree is a CLI tool build with JS to help in building the project tree structure. Protree can create a tree for your project and add it to your markdown with the code block format. Once you add new files to your project, all you have to do is run protree, and all changes will be handled automatically.

Usage

I will assume that you have a project with come folders in it.

1- First install protree

npm i protree
Enter fullscreen mode Exit fullscreen mode

2- Command form

protree path out
Enter fullscreen mode Exit fullscreen mode

3- Add script to your package.json file

{
...
"protree" : "protree . README.md"
...
}
Enter fullscreen mode Exit fullscreen mode

4- Add a protree comment in your README.md file in the place you want the tree to be in

<!-- protree -->
Enter fullscreen mode Exit fullscreen mode

5- Run command

npm run protree
Enter fullscreen mode Exit fullscreen mode

Ingoring files
By default, protree ignores the .git and node_modules directories.
It is possible to exclude more files from being included in the tree structure by creating a .ptignore file and adding all the ignored files to it.
The .ptignore file works similarly to the .gitignore file. You can ignore files or patterns of files, for example, *.json files.

Feel free to read more about protree.

Top comments (0)