Skip to content

🌟 A small, extremely simple CLI tool with Node.js. Lists directory content in a tree structure.

License

Notifications You must be signed in to change notification settings

yswrepos/tree-console

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

tree-console

NPM Version Downloads License

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.

Install

Make sure you have Node.js (version 12 or above) installed and install globally:

npm install tree-console -g

Use in terminal

You 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

Options

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

Use in browser

First install using npm:

npm install tree-console --save

Use 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"}

Why tree-console?

  • 🌲 Lists directory content in a tree structure
  • πŸ“ Write tree structure to a new file
  • 🌈 Supports colourized outputs
  • 🐬 Convert an array to a tree structure

Cloning this repository

git clone --depth=1 https://github.com/egsee/tree-console.git

License

MIT

About

🌟 A small, extremely simple CLI tool with Node.js. Lists directory content in a tree structure.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published