Tree-console is a small, extremely simple CLI tool with Node.js. You can use tree-cli command to print out the directory tree structure in terminal.
Make sure you have Node.js (version 12 or above) installed and install globally:
npm install tree-console -gYou can run the tree-cli command in the shell like this:
$ tree-cli -d ./tree-console --ignore node_modules,.git,.DS_Store
Β·
βββ tree-console
    βββ .gitignore
    βββ .npmignore
    βββ LICENSE
    βββ README.md
    βββ README_zh.md
    βββ bin
    β   βββ tree-cli.js
    βββ package-lock.json
    βββ package.json
    βββ read-dir-to-tree.js
    βββ tree.js
Usage: tree-cli [options]
Options:
  -V, --version               output the version number
  -d, --dir <directoryPath>   the directory path you want to render by tree
  -o, --out <filename>        write the tree to a new file
  -i, --ignore <ignoreFiles>  ignore the specified directory or file, they will not be listed
  -l, --level <level>         the depth of the directory tree
  -c, --color [color]         treeβs color which output to the terminal (default: "white")
  -h, --help                  display help for command
First install using npm:
npm install tree-console --saveUse it in your project:
var tree = require('tree-console');
console.log(
    tree.getStringTree([
        {
            name: "done",
            children: [
                { name: "hiking" }, 
                { name: "camping"}
            ]
        }, {
            name: "todos",
            children: [
                { name: "scuba diving" },
                { name: "surfing" }
            ]
        }
    ]
));Will then printing the results:
Β·
βββ done
β   βββ hiking
β   βββ camping
βββ todos
    βββ scuba diving
    βββ surfing
See from the example above, getStringTree() accepts an array of objects as a parameter, it also accepts the second parameter which is optional, you can use as follows:
tree.getStringTree([
    {
        title: "done",
        items: [
            { title: "hiking" }, 
            { title: "camping"}
        ]
    }
], {
    label: "title",
    children: "items"
})getStringTree(array, [option])
the option's default value is {label: "name", children: "children"}
- π² Lists directory content in a tree structure
- π Write tree structure to a new file
- π Supports colourized outputs
- π¬ Convert an array to a tree structure
git clone --depth=1 https://github.com/egsee/tree-console.git