# folder-tree-generator

> Generate a folder tree structure using command line or code.

Latest version **1.1.7** (published 2022-12-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install folder-tree-generator
pnpm add folder-tree-generator
yarn add folder-tree-generator
bun add folder-tree-generator
```

Provides the command `ftg`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.7 |
| Published | 2022-12-04 |
| First published | 2022-11-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 79.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Ezequiel Garay |
| Maintainers | ezemgaray |
| Keywords | folder, structure, tree, directory, dir, docs, documentation, text |

## Links

- npm: https://www.npmjs.com/package/folder-tree-generator
- Repository: https://github.com/ezemgaray/folder-tree-generator
- Homepage: https://github.com/ezemgaray/folder-tree-generator#readme
- Issues: https://github.com/ezemgaray/folder-tree-generator/issues
- npm.io page: https://npm.io/package/folder-tree-generator

## Dependencies (3)

- [chalk](https://npm.io/package/chalk.md) ^4.1.2
- [commander](https://npm.io/package/commander.md) ^9.4.1
- [update-notifier](https://npm.io/package/update-notifier.md) ^5.1.0

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 1.1.7 (latest) — 2022-12-04
- 1.1.6 — 2022-12-04
- 1.1.5 — 2022-12-04
- 1.1.4 — 2022-12-04
- 1.1.3 — 2022-12-04
- 1.1.2 — 2022-12-04
- 1.1.1 — 2022-11-29
- 1.1.0 — 2022-11-29
- 1.0.13 — 2022-11-27
- 1.0.12 — 2022-11-27
- 1.0.11 — 2022-11-27
- 1.0.10 — 2022-11-27
- 1.0.9 — 2022-11-27
- 1.0.8 — 2022-11-27
- 1.0.7 — 2022-11-27
- … 7 more at https://npm.io/package/folder-tree-generator/versions

## README

<div align="center">

# Folder Tree Generator - FTG

Generate a folder tree structure using command line or code.

[![NPM version](https://badgen.net/npm/v/folder-tree-generator)](https://npmjs.com/package/folder-tree-generator)
[![NPM downloads](https://badgen.net/npm/dw/folder-tree-generator)](https://npmjs.com/package/folder-tree-generator)
[![Open issues](https://badgen.net/github/open-issues/ezemgaray/folder-tree-generator)](https://github.com/ezemgaray/folder-tree-generator/issues)
[![Open prs](https://badgen.net/github/open-prs/ezemgaray/folder-tree-generator)](https://github.com/ezemgaray/folder-tree-generator/pulls)

</div>

<div align="center">

<a href="https://www.buymeacoffee.com/ezemgaray">
<img src="https://cdn.buymeacoffee.com/buttons/default-black.png" width="170" />
</a>

</div>

```text
├── folder-tree-generator
│   ├── .editorconfig
│   ├── .gitignore
│   ├── .prettierrc.json
│   ├── README.md
│   ├── package-lock.json
│   ├── package.json
│   ├── src
│   │   ├── example
│   │   │   └── index.ts
│   │   ├── folder1
│   │   │   ├── folder2
│   │   │   ├── folder3
│   │   │   │   └── folder4
│   │   ├── index.ts
│   │   ├── bin
│   │   │   └── index.ts
│   │   ├── utils
│   │   │   ├── drawTreeFromJsonDir.ts
│   │   │   ├── ftg.ts
│   │   │   ├── index.ts
│   │   │   ├── parseDirToJson.ts
│   │   │   └── sortFolder.ts
│   └── tsconfig.json
```

## CLI Usage

### Install globally

```sh
npm i folder-tree-generator -g
```

### Run FTG

```sh
$ ftg [options]
```

Help options

```sh
$ ftg --help

Usage: dist [options]

Options:
  -V, --version          output the version number
  -d, --directory [dir]  Directory path. (default: "[current path]")
  -f, --folder-only      Draw folders only.
  -s, --sort             Sort alphabetically and put folders first and then files.
  -c, --comments         Show "Empty folder" comment (--folder-only must be false)
  -e, --export [path]    Set the folder path to export "ftg_tree_[date].txt" or just -e or --export for the default export to the current path
  -i, --ignore [regex]   Regex list to ignore folders and/or files (separated by commas) - eg: "example($|/.*),index.ts"
  --emojis               Show emojis - folder: 📁 - File: 📄
  -h, --help             display help for command
```

### NPX

```sh
npx folder-tree-generator [options]
```

## Code Usage

```sh
npm i folder-tree-generator
```

```typescript
import { ftg, FtgOptions } from 'folder-tree-generator'

// get current path
const path = process.cwd()

// ftg options
const options: FtgOptions = { sort: true, emojis: true }

console.log('👇👇 Tree with options:', options)


const tree = ftg(path, options)
console.log(tree)

// OUTPUT

👇👇 Tree with options: { sort: true, emojis: true }
├── 📁 folder-tree-generator
│   ├── 📁 src
│   │   ├── 📁 example
│   │   │   └── 📄 index.ts
│   │   ├── 📁 bin
│   │   │   └── 📄 index.ts
│   │   ├── 📁 utils
│   │   │   ├── 📄 drawTreeFromJsonDir.ts
│   │   │   ├── 📄 ftg.ts
│   │   │   ├── 📄 index.ts
│   │   │   ├── 📄 parseDirToJson.ts
│   │   │   └── 📄 sortFolder.ts
│   │   └── 📄 index.ts
│   ├── 📄 .editorconfig
│   ├── 📄 .gitignore
│   ├── 📄 .prettierrc.json
│   ├── 📄 README.md
│   ├── 📄 package-lock.json
│   ├── 📄 package.json
│   └── 📄 tsconfig.json

```

### Options

| Terminal             | Code                | Type    | Default                                                        | Description                                                                                                             |
| -------------------- | ------------------- | ------- | -------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| -d -directory [dir]  | Path is a parameter | string  | **Terminal**: currentFolder - **Code**: path is required param | Folder Path                                                                                                             |
| -f, --folders-only   | folderOnly          | boolean | false                                                          | generate tree only with folders (ignore files)                                                                          |
| -s, --sort           | sort                | boolean | false                                                          | Sort alphabetically and put folders first and then files.                                                               |
| -c, --comments       | comments            | boolean | false                                                          | Show "Empty folder" comment (--folder-only must be false)                                                               |
| -e, --export [path]  | [Not Available]     | string  | false                                                          | Set the folder path to export `"ftg_tree_[date].txt"` or just -e or --export for the default export to the current path |
| -i, --ignore [regex] | ignore              | string  | false                                                          | Regex list to ignore folders and/or files (separated by commas) - eg: "example($&#124;/.\*),index.ts"                   |
| --emojis             | emojis              | boolean | false                                                          | Show emojis - folder: 📁 - File: 📄                                                                                     |

## Ignore files/folders

By default ftg ignore the following files and folders

- .vscode
- .DS_Store
- .git
- node_modules
- dist
- coverage
- .husky

### Regex to ignore (-i, --ignore)

**Example**

Ignore all index.ts files and folders named "/example"

```sh
ftg -i 'example($|/.*),index.ts'
```

**Output**

```sh
├── folder-tree-generator
│   ├── .editorconfig
│   ├── .prettierrc.json
│   ├── .versionrc
│   ├── CHANGELOG.md
│   ├── LICENSE
│   ├── README.md
│   ├── package-lock.json
│   ├── package.json
│   ├── src
│   │   ├── bin
│   │   ├── utils
│   │   │   ├── drawTreeFromJsonDir.ts
│   │   │   ├── ftg.ts
│   │   │   ├── parseDirToJson.ts
│   │   │   └── sortFolder.ts
│   └── tsconfig.json
```

## Comments

If files and folders are included and the `comments` option is also added, empty folders will show the comment "# Empty folder"

```sh
├── folder-tree-generator
│   ├── .editorconfig
│   ├── .gitignore
│   ├── .prettierrc.json
│   ├── README.md
│   ├── package-lock.json
│   ├── package.json
│   ├── src
│   │   ├── example
│   │   │   └── index.ts
│   │   ├── folder1
│   │   │   ├── folder2 # Empty folder
│   │   │   ├── folder3
│   │   │   │   └── folder4 # Empty folder
│   │   ├── index.ts
│   │   ├── bin
│   │   │   └── index.ts
│   │   ├── utils
│   │   │   ├── drawTreeFromJsonDir.ts
│   │   │   ├── ftg.ts
│   │   │   ├── index.ts
│   │   │   ├── parseDirToJson.ts
│   │   │   └── sortFolder.ts
│   └── tsconfig.json
```

## TODO

- Unit testing jest
- Add command flags
  - --sort ✅
  - --folder-only ✅
  - --ignore (regex[]) ✅
  - --export ✅
  - --size (include file/folder size)
- add ftg() options
  - sort ✅
  - folderOnly ✅
  - ignore (regex[]) ✅
  - size (include file/folder size)
- Add comment "# Empty folder" (if you are including files but the folder is empty literally) ✅
- Interactive terminal
- Show available version in terminal ✅
- Show emojis ✅
- CHANGELOG.md ✅

---
_Source: https://npm.io/package/folder-tree-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
