@jigneshdpanchal/project-tree 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,208 @@
1
+ # project-tree 🌳
2
+
3
+ [![npm version](https://img.shields.io/npm/v/project-tree.svg?style=flat)](https://www.npmjs.com/package/project-tree)
4
+ [![Downloads](https://img.shields.io/npm/dt/project-tree.svg)](https://www.npmjs.com/package/project-tree)
5
+ [![License](https://img.shields.io/npm/l/project-tree.svg)](https://opensource.org/licenses/ISC)
6
+
7
+ A simple and fast CLI tool to generate a clean directory tree for **any Node.js project**.
8
+ It automatically ignores common folders like `node_modules`, `.git`, build outputs, and more.
9
+
10
+ Perfect for:
11
+ - Project documentation
12
+ - README files
13
+ - Code reviews
14
+ - Understanding unfamiliar codebases
15
+
16
+ ---
17
+
18
+ ## ✨ Features
19
+
20
+ - 📂 Works with **any project structure** (frontend, backend, monorepo)
21
+ - 🚫 Ignores common clutter (`node_modules`, `.git`, `dist`, etc.)
22
+ - ⚡ Fast and dependency-free
23
+ - 🖥 Cross-platform (Windows, macOS, Linux)
24
+ - 📄 Clean, readable tree output
25
+
26
+ ---
27
+
28
+ ## 📦 Installation
29
+
30
+ ### Option 1: Use without installing (recommended)
31
+
32
+ ```bash
33
+ npx project-tree
34
+
35
+ ```
36
+
37
+ ### Option 2: Install globally
38
+
39
+ ```bash
40
+ npm install -g project-tree
41
+
42
+ ```
43
+
44
+ ### 🚀 Usage
45
+
46
+ 1. Generate tree for current directory
47
+
48
+ ```bash
49
+ project-tree
50
+
51
+ ```
52
+
53
+ 2. Generate tree for a specific folder
54
+
55
+ ```bash
56
+ project-tree src
57
+ project-tree backend
58
+
59
+ ```
60
+
61
+ ### Example output
62
+
63
+ project-tree
64
+ ├── bin
65
+ │ └── project-tree.js
66
+ ├── package.json
67
+ └── README.md
68
+
69
+ ### 🚫 Ignored by Default
70
+
71
+ The following files and folders are ignored automatically:
72
+
73
+ * node_modules
74
+ * .git
75
+ * .next
76
+ * dist
77
+ * build
78
+ * coverage
79
+ * .env
80
+ * .DS_Store
81
+ * Lock files (package-lock.json, yarn.lock, pnpm-lock.yaml)
82
+
83
+ This keeps the output clean and readable.
84
+
85
+ ## ⚙ CLI Options
86
+
87
+ | Option | Description |
88
+ | ------------------------ | ------------------------------------------ |
89
+ | `--help`, `-h` | Show this help message |
90
+ | `--depth <number>` | Limit tree output to a specific depth |
91
+ | `--ignore <file/folder> | Ignore additional files or folders |
92
+ | `--json` | Output tree as JSON (useful for scripting) |
93
+
94
+ ## Examples:
95
+
96
+ ```bash
97
+
98
+ # Show help
99
+ project-tree --help
100
+
101
+ # Limit depth to 2 levels
102
+ project-tree src --depth 2
103
+
104
+ # Ignore additional folder
105
+ project-tree --ignore logs
106
+
107
+ # Output JSON
108
+ project-tree backend --json
109
+
110
+ ```
111
+
112
+ ### 🧰 Requirements
113
+
114
+ Node.js v14 or higher
115
+
116
+ ### 🛠 Development (Local Testing)
117
+
118
+ 1. Clone the repo and link it locally:
119
+
120
+ ```bash
121
+
122
+ git clone https://github.com/yourusername/project-tree.git
123
+ cd project-tree
124
+ npm install
125
+ npm link
126
+
127
+ ```
128
+
129
+ 2. Run anywhere:
130
+
131
+ ```bash
132
+ project-tree
133
+
134
+ ```
135
+
136
+ ### 📌 Use cases
137
+
138
+ * Add project structure to README
139
+ * Quickly inspect backend projects
140
+ * Share folder layout in documentation
141
+ * Understand large repositories faster
142
+
143
+ ### 🤝 Contributing
144
+
145
+ Contributions are welcome!
146
+
147
+ 1. Fork the repository
148
+
149
+ 2. Clone your fork:
150
+
151
+ ```bash
152
+
153
+ git clone https://github.com/yourusername/project-tree.git
154
+ cd project-tree
155
+
156
+ ```
157
+ 3. Install dependencies:
158
+
159
+ ```bash
160
+
161
+ npm install
162
+
163
+ ```
164
+
165
+ 4. Link locally for testing:
166
+
167
+ ```bash
168
+
169
+ npm link
170
+
171
+ ```
172
+
173
+ 5. Make your changes and test:
174
+
175
+ ```bash
176
+ project-tree
177
+
178
+ ```
179
+
180
+ 6. Commit, push, and create a pull request
181
+
182
+ ### Coding Guidelines:
183
+
184
+ * Use CommonJS modules (require)
185
+ * Keep no unnecessary dependencies
186
+ * Maintain cross-platform compatibility
187
+ * Write clear and descriptive commit messages
188
+
189
+ ### 📄 License
190
+
191
+ ISC License
192
+
193
+ ### ⭐ Support
194
+
195
+ If you find this useful, consider starring the project ⭐
196
+ Happy coding! 🚀
197
+
198
+
199
+ ---
200
+
201
+ This version:
202
+
203
+ - Adds **badges** for npm version, downloads, and license
204
+ - Adds **CLI options** section with examples
205
+ - Fixes spacing and markdown formatting
206
+ - Keeps **installation, usage, ignored files, and requirements** clear
207
+ - Adds **structured contributing guide**
208
+
@@ -0,0 +1,165 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+
6
+ // --------------------
7
+ // CLI Argument Parsing
8
+ // --------------------
9
+ const args = process.argv.slice(2);
10
+
11
+ // Default root directory
12
+ let ROOT_DIR = ".";
13
+ let MAX_DEPTH = Infinity;
14
+ let JSON_OUTPUT = false;
15
+
16
+ // Default ignore list
17
+ const DEFAULT_IGNORE = new Set([
18
+ "node_modules",
19
+ ".git",
20
+ ".next",
21
+ "dist",
22
+ "build",
23
+ "coverage",
24
+ ".env",
25
+ ".DS_Store",
26
+ "package-lock.json",
27
+ "yarn.lock",
28
+ "pnpm-lock.yaml"
29
+ ]);
30
+
31
+ // User-specified additional ignores
32
+ const USER_IGNORE = new Set();
33
+
34
+ // --------------------
35
+ // Parse Arguments
36
+ // --------------------
37
+ for (let i = 0; i < args.length; i++) {
38
+ const arg = args[i];
39
+
40
+ switch (arg) {
41
+ case "--help":
42
+ case "-h":
43
+ console.log(`
44
+ project-tree 🌳 - Generate a directory tree
45
+
46
+ Usage:
47
+ project-tree [directory] [options]
48
+
49
+ Options:
50
+ --help, -h Show this help message
51
+ --depth <number> Limit tree to a specific depth
52
+ --ignore <name> Ignore additional files or folders
53
+ --json Output tree as JSON
54
+
55
+ Examples:
56
+ project-tree
57
+ project-tree src --depth 2 --ignore logs
58
+ project-tree backend --json
59
+ `);
60
+ process.exit(0);
61
+
62
+ case "--depth":
63
+ const depth = args[i + 1];
64
+ if (!depth || isNaN(depth)) {
65
+ console.error("Error: --depth requires a number");
66
+ process.exit(1);
67
+ }
68
+ MAX_DEPTH = parseInt(depth, 10);
69
+ i++;
70
+ break;
71
+
72
+ case "--ignore":
73
+ const ignoreName = args[i + 1];
74
+ if (!ignoreName) {
75
+ console.error("Error: --ignore requires a file or folder name");
76
+ process.exit(1);
77
+ }
78
+ USER_IGNORE.add(ignoreName);
79
+ i++;
80
+ break;
81
+
82
+ case "--json":
83
+ JSON_OUTPUT = true;
84
+ break;
85
+
86
+ default:
87
+ if (!arg.startsWith("-")) {
88
+ ROOT_DIR = arg;
89
+ }
90
+ break;
91
+ }
92
+ }
93
+
94
+ // --------------------
95
+ // Tree Generation
96
+ // --------------------
97
+ function generateTree(dir, prefix = "", depth = 0) {
98
+ let items;
99
+ try {
100
+ items = fs.readdirSync(dir, { withFileTypes: true });
101
+ } catch {
102
+ return null;
103
+ }
104
+
105
+ // Filter ignored items
106
+ items = items.filter(
107
+ item => !DEFAULT_IGNORE.has(item.name) && !USER_IGNORE.has(item.name)
108
+ );
109
+
110
+ // Sort directories first, optional
111
+ items.sort((a, b) => (a.isDirectory() && !b.isDirectory() ? -1 : 0));
112
+
113
+ // Build tree structure
114
+ const tree = [];
115
+
116
+ items.forEach((item, index) => {
117
+ const isLast = index === items.length - 1;
118
+ const connector = isLast ? "└── " : "├── ";
119
+ const name = item.name;
120
+
121
+ const node = { name };
122
+
123
+ if (item.isDirectory() && depth + 1 < MAX_DEPTH) {
124
+ const children = generateTree(path.join(dir, name), prefix + (isLast ? " " : "│ "), depth + 1);
125
+ if (children) node.children = children;
126
+ }
127
+
128
+ tree.push(node);
129
+
130
+ // Print text if not JSON
131
+ if (!JSON_OUTPUT) {
132
+ console.log(prefix + connector + name);
133
+ if (node.children && node.children.length > 0) {
134
+ printTree(node.children, prefix + (isLast ? " " : "│ "));
135
+ }
136
+ }
137
+ });
138
+
139
+ return tree;
140
+ }
141
+
142
+ // Helper to print JSON-like tree in text mode
143
+ function printTree(tree, prefix = "") {
144
+ tree.forEach((node, index) => {
145
+ const isLast = index === tree.length - 1;
146
+ const connector = isLast ? "└── " : "├── ";
147
+ console.log(prefix + connector + node.name);
148
+ if (node.children) {
149
+ printTree(node.children, prefix + (isLast ? " " : "│ "));
150
+ }
151
+ });
152
+ }
153
+
154
+ // --------------------
155
+ // Run CLI
156
+ // --------------------
157
+ const rootName = path.basename(path.resolve(ROOT_DIR)) || ".";
158
+
159
+ if (JSON_OUTPUT) {
160
+ const jsonTree = { name: rootName, children: generateTree(ROOT_DIR) };
161
+ console.log(JSON.stringify(jsonTree, null, 2));
162
+ } else {
163
+ console.log(rootName);
164
+ generateTree(ROOT_DIR);
165
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@jigneshdpanchal/project-tree",
3
+ "version": "1.0.1",
4
+ "description": "Generate a clean directory tree for any Node.js project",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "project-tree": "bin/project-tree.js"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "keywords": [
13
+ "tree",
14
+ "directory",
15
+ "cli",
16
+ "nodejs",
17
+ "project-tree"
18
+ ],
19
+ "author": "Jignesh Panchal",
20
+ "license": "ISC",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/jigneshdpanchal/project-tree.git"
24
+ },
25
+ "type": "commonjs"
26
+ }