https://github.com/yswrepos/tree-console
π A small, extremely simple CLI tool with Node.js. Lists directory content in a tree structure.
https://github.com/yswrepos/tree-console
cli command-line console console-tree directory-tree terminal tree tree-cli tree-console
Last synced: 4 months ago
JSON representation
π A small, extremely simple CLI tool with Node.js. Lists directory content in a tree structure.
- Host: GitHub
- URL: https://github.com/yswrepos/tree-console
- Owner: yswrepos
- License: mit
- Created: 2021-12-06T13:00:39.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-12-15T14:23:44.000Z (over 4 years ago)
- Last Synced: 2025-08-24T12:26:04.389Z (9 months ago)
- Topics: cli, command-line, console, console-tree, directory-tree, terminal, tree, tree-cli, tree-console
- Language: JavaScript
- Homepage:
- Size: 24.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tree-console
Tree-console is a small, extremely simple CLI tool with [Node.js](https://nodejs.org). 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:
```sh
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 the directory path you want to render by tree
-o, --out write the tree to a new file
-i, --ignore ignore the specified directory or file, they will not be listed
-l, --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:
```sh
npm install tree-console --save
```
Use it in your project:
```js
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:
```js
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
```sh
git clone --depth=1 https://github.com/egsee/tree-console.git
```
### License
[MIT](./LICENSE)