I’m sitting here trying to get the folder structure for my project into a kind of ASCII Tree or something. I wasn’t going to manually do this, it would be insane. Especially on any decent size Enterprise Project with an endless supply of folders and nested content. I went digging to come up with a better solution. On Linux I immediately found the Tree Utility which was perfect.
Except I was on OS-X.
First option I gave a go to was to build the thing. Because I like to do things the hard way sometimes. First I needed to get the source, which is available here.
curl -O ftp://mama.indstate.edu/linux/tree/tree-1.7.0.tgz
Once downloaded, unzip the source into a directory and find the following section for the particular operating system you want to use the utility on. The section for OS settings looked like this when I finished editing it.
# Uncomment options below for your particular OS:
# Uncomment for OS X:
CFLAGS=-O2 -Wall -fomit-frame-pointer -no-cpp-precomp
Now get a good build of the command file.
Now let’s get tree into the executable path.
sudo mkdir -p /usr/local/bin
sudo cp tree /usr/local/bin/tree
Make sure your ~/.bash_profile is setup right, include this.
Reload the shell and tree should be available as a command.
The other option which is really simple, if you don’t want to compile to code, is to just use brew to install it.
brew install tree
So now you can use tree, and do cool stuff like pipe it out to a file. If you’re running this against a Node.js Project you may want to delete the node_modules directory and then just reinstall it after running the tree command.
tree > prof-tree.md
Then in your README.md file you can include the folder structure in the description of the project. Here’s a sample output!
│ └── README.md
│ ├── boot
│ │ ├── authentication.js
│ │ ├── explorer.js
│ │ ├── rest-api.js
│ │ └── root.js
│ ├── config.json
│ ├── datasources.json
│ ├── middleware.json
│ ├── model-config.json
│ └── server.js
4 directories, 14 files
That’s a super easy way to offer better documentation that provides some real insight into what various parts of the project structure are actually for.