Code Monkey home page Code Monkey logo

tree-node-cli's Introduction

tree-node-cli

Lists the contents of directories in a tree-like format, similar to the Linux tree command. Both CLI and Node APIs are provided.

Tree is a recursive directory listing program that produces a depth indented listing of files. When a directory argument is given, tree lists all the files and/or directories found in the given directory.

Installation

$ npm install tree-node-cli
# or globally
$ npm install -g tree-node-cli

Example

$ tree -L 2 -I "node_modules"
tree-node-cli
β”œβ”€β”€ LICENSE
β”œβ”€β”€ README.md
β”œβ”€β”€ __tests__
β”‚   β”œβ”€β”€ __fixtures__
β”‚   β”œβ”€β”€ __snapshots__
β”‚   β”œβ”€β”€ fixtures
β”‚   └── tree.test.js
β”œβ”€β”€ bin
β”‚   └── tree
β”œβ”€β”€ jest.config.js
β”œβ”€β”€ package.json
β”œβ”€β”€ tree.js
└── yarn.lock

CLI

$ tree [options] [path/to/dir]

Note: Use the command treee on Windows and Linux to avoid conflicts with built-in tree command.

The following options are available:

$ tree -h

  Usage: tree [options]

  Options:

    -V, --version             output the version number
    -a, --all-files           All files, include hidden files, are printed.
    --dirs-first              List directories before files.
    -d, --dirs-only           List directories only.
    -I, --exclude [patterns]  Exclude files that match the pattern. | separates alternate patterns. Wrap your entire pattern in double quotes. E.g. `"node_modules|coverage".
    -L, --max-depth <n>       Max display depth of the directory tree.
    -r, --reverse             Sort the output in reverse alphabetic order.
    -F, --trailing-slash      Append a '/' for directories.
    -h, --help                output usage information

API

const tree = require('tree-node-cli');
const string = tree('path/to/dir', options);

options is a configuration object with the following fields:

Field Default Type Description
allFiles false Boolean All files are printed. By default, tree does not print hidden files (those beginning with a dot).
dirsFirst false Boolean List directories before files.
dirsOnly false Boolean List directories only.
exclude [] Array An array of regex to test each filename against. Matching files will be excluded and matching directories will not be traversed into.
maxDepth Number.POSITIVE_INFINITY Number Max display depth of the directory tree.
reverse false Boolean Sort the output in reverse alphabetic order.
trailingSlash false Boolean Appends a trailing slash behind directories.
const string = tree('path/to/dir'), {
  allFiles: true,
  exclude: [/node_modules/, /lcov/],
  maxDepth: 4,
});

console.log(string);

License

MIT

tree-node-cli's People

Stargazers

 avatar

Watchers

 avatar

Forkers

the-cc-dev

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.