An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# tree-console

δΈ­ζ–‡



NPM Version


Downloads


License

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)