1.2.1 • Published 2 years ago

tree-console v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

tree-console

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

1.2.1

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.5

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago