Giter VIP home page Giter VIP 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 command that produces a nicely-formatted indented output of directories and files. When a directory argument is given, tree lists all the files and/or directories found in the given directory.

Note: Symlinks are not followed.

Quickstart

Instantly execute the command in your current directory via npx:

npx tree-node-cli -I "node_modules" # ignore node_modules

Or via Yarn 2+:

yarn dlx -p tree-node-cli tree -I "node_modules" # ignore node_modules

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.
    -s, --sizes               Show filesizes.
    -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.
    -S, --line-ascii          Turn on ASCII line graphics.
    -h, --help                output usage information

Node.js 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.
sizes false Boolean Show filesizes as well.
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.
lineAscii false Boolean Turn on ASCII line graphics.
const string = tree('path/to/dir', {
  allFiles: true,
  exclude: [/node_modules/, /lcov/],
  maxDepth: 4,
});

console.log(string);

License

MIT

tree-node-cli's People

Contributors

dependabot[bot] avatar ksr-yasuda avatar marcofugaro avatar olistic avatar slorber avatar tomotoes avatar vruzhentsov avatar yangshun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

tree-node-cli's Issues

version number release update

Hi Team!

Just ran a global installation

npm install -g tree-node-cli

then my routine version check after installs,

tree --version

and noticed the release version and installed version were not ==

1.6.0 vs 1.3.0

is 1.6 dev ? or do we just need to create a new github release?

[Feature request] File sizes

It would be really useful if this library would support outputting the file sizes, like this

Screenshot 2020-05-13 at 04 57 11

To replicate what's in the screenshot:

  • brew install tree
  • tree --du -h build/

--du stands for disk usage

-h stands for human readable.

However I think this can be simplified with just a -s, --sizes option.

For the filesize formatting, pretty-bites can be used.

Tree branch characters sometimes can't be displayed

Thanks for this, it's a life changer on my system which does not have the base tree in its repository.

I sometimes get something like this within tmux:

ss-2020-06-05_015826

Yet I don't think it's an utf-8 issue because I can see characters with diacritics with no issue. Also, this does not happen all the time, but I am not sure exactly how to reproduce it yet. It could be related to re-attaching a tmux session after SSH, but this needs some more digging, I'm not sure yet.

Is this something you already observed, and do those characters replacing the tree ring a bell?

incompatible with node <8.6.0

tree.js uses object spread, which is apparently not supported without a flag in node <8.6.0. Could either replace with an object.assign() or transpile for publishing.

License issue

Hi @yangshun

We use this package on Docusaurus (dev only) but its dependency "fast-folder-size" moved from license ISC to Anti-War ISC:

Being related to "anti war" is a concern for some users as reported here: facebook/docusaurus#8247

We only use it in dev/tests, but just having to download such package may be frightening for users.
We run it in CIs for tests, and I don't even know if all GitHub Actions CI servers run in countries that respect that license...

Note, the dependency was just "ISC" at 1.6.1, maybe we could freeze deps to that specific version instead?
https://github.com/simoneb/fast-folder-size/tree/v1.6.1


On Docusaurus (and many other projects?) we don't even use the sizes option.

My suggestion would be to have no dependency and allow providing a callback for computing the folderSize. Docs can recommend "fast-folder-size" as a possible implementation.

tree('path/to/dir',{
  sizes: true,
  getFolderSize: require("fast-folder-size/sync"),
});

(maybe the API could be adjusted as well)

Does it make sense?

Some question about ignore directory

Hello, is there have any parameter for distinction keep node_modules or hide it.

When i run tree -I "node_modules" i got a result as below:

my-directory
β”œβ”€β”€ assets
β”‚   └── a.png
β”œβ”€β”€ index.js
β”œβ”€β”€ package-lock.json
β”œβ”€β”€ package.json
β”œβ”€β”€ readme.md
└── test.js

The result i want(i want to keep itself when i add a ignore directory):

my-directory
β”œβ”€β”€ node_modules
β”œβ”€β”€ assets
β”‚   └── a.png
β”œβ”€β”€ index.js
β”œβ”€β”€ package-lock.json
β”œβ”€β”€ package.json
β”œβ”€β”€ readme.md
└── test.js

Add sort option

Unfortunately the fs.readdirSync(path); ordering is not guaranteed across OS

I'm using Tree (node API) to create Jest snapshots of FS paths on Docusaurus, it works great

But unfortunately, the tree order is non-deterministic and this leads to the CI failing but just on Windows: https://github.com/facebook/docusaurus/runs/5071012843?check_suite_focus=true

image

Let me know if you can give me access on Git/npm @yangshun, I'd be happy to refresh a bit this package as there"s not a lot of good alternatives

Node 10

Hello @yangshun, is Node 10 not supported? I just updated Docusaurus to v1.1.0, which uses this module, and my tests are failing because of Node 10 not being in the engines field of this package.

feature_request(option): Markdown output

1. Summary

It would be nice, if would be possible print output to Markdown format.

2. Example data

Simple tree structure:

KiraTreeNodeCLI/
β”œβ”€β”€ KiraDirectory/
β”‚   └── KiraSecondFile.txt
└── KiraFirstFile.txt

3. Expected result

# KiraTreeNodeCLI

1. KiraFirstFile.txt

## KiraDirectory

1. KiraSecondFile.txt

4. Argumentation

I want to publish my big list of books, so that it can be conveniently referenced. For example, that would be possible show my Astronomy books to other users, I could share link https://KiraExample.com/KiraBooksList#Astronomy; Physics books β€” https://KiraExample.com/KiraBooksList#Physics and so on.

Yes, I know regular expressions. But currently, I have tree β†’ Markdown conversion difficulties, because I can't do, that files would be higher than directories in output (KiraFirstFile.txt than KiraDirectory/).

5. Examples of expected behavior

5.1. Markdown format

It would be very nice, if tree-node-cli can print output in Markdown format directly. For example, if I will run command:

tree --markdown

I will get the expected result from section Β«Expected resultΒ»:

# KiraTreeNodeCLI

1. KiraFirstFile.txt

## KiraDirectory

1. KiraSecondFile.txt

5.2. dirs-end

If you are for any reason will not do conversion to Markdown, it would be nice to have at least --dirs-end option. Files in this case will always be located above the directories.

  • Command:
tree -F --dirs-end
  • Result:
KiraTreeNodeCLI/
β”œβ”€β”€ KiraFirstFile.txt
└── KiraDirectory/
    └── KiraSecondFile.txt

6. Not helped

I can't find in Internet third-party tools for conversion filesystem tree structure to Markdown format.

7. Do not offer

I don't need to convert filesystem tree structure to Markdown list; please, do not offer it. I need, that directories and subdirectories would be converted to Markdown headers; please, read section Β«ArgumentationΒ».

Thanks.

fast-folder-size install behind proxy error

I wanted to follow up regarding #34 as I am trying to install tree-node-cli behind a proxy.

fast-folder-size uses an HTTP call to retrieve a utility for Windows hosts and didn't support proxies when installing it until 2.2.0.

Would it be possible to look into refactoring tree-node-cli to not use fast-folder-size?

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.