@jigneshdpanchal/project-tree 1.0.1 → 1.0.3
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 +7 -4
- package/bin/project-tree.js +46 -52
- package/package.json +26 -26
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# project-tree 🌳
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/project-tree)
|
|
4
|
-
[](https://www.npmjs.com/package/project-tree)
|
|
3
|
+
[](https://www.npmjs.com/package/@jigneshdpanchal/project-tree)
|
|
4
|
+
[](https://www.npmjs.com/package/@jigneshdpanchal/project-tree)
|
|
5
5
|
[](https://opensource.org/licenses/ISC)
|
|
6
6
|
|
|
7
7
|
A simple and fast CLI tool to generate a clean directory tree for **any Node.js project**.
|
|
@@ -60,12 +60,15 @@ project-tree backend
|
|
|
60
60
|
|
|
61
61
|
### Example output
|
|
62
62
|
|
|
63
|
+
```bash
|
|
63
64
|
project-tree
|
|
64
65
|
├── bin
|
|
65
66
|
│ └── project-tree.js
|
|
66
67
|
├── package.json
|
|
67
68
|
└── README.md
|
|
68
69
|
|
|
70
|
+
```
|
|
71
|
+
|
|
69
72
|
### 🚫 Ignored by Default
|
|
70
73
|
|
|
71
74
|
The following files and folders are ignored automatically:
|
|
@@ -119,7 +122,7 @@ Node.js v14 or higher
|
|
|
119
122
|
|
|
120
123
|
```bash
|
|
121
124
|
|
|
122
|
-
git clone https://github.com/
|
|
125
|
+
git clone https://github.com/jigneshdpanchal/project-tree.git
|
|
123
126
|
cd project-tree
|
|
124
127
|
npm install
|
|
125
128
|
npm link
|
|
@@ -150,7 +153,7 @@ Contributions are welcome!
|
|
|
150
153
|
|
|
151
154
|
```bash
|
|
152
155
|
|
|
153
|
-
git clone https://github.com/
|
|
156
|
+
git clone https://github.com/jigneshdpanchal/project-tree.git
|
|
154
157
|
cd project-tree
|
|
155
158
|
|
|
156
159
|
```
|
package/bin/project-tree.js
CHANGED
|
@@ -3,17 +3,12 @@
|
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const path = require("path");
|
|
5
5
|
|
|
6
|
-
// --------------------
|
|
7
|
-
// CLI Argument Parsing
|
|
8
|
-
// --------------------
|
|
9
6
|
const args = process.argv.slice(2);
|
|
10
7
|
|
|
11
|
-
// Default root directory
|
|
12
8
|
let ROOT_DIR = ".";
|
|
13
9
|
let MAX_DEPTH = Infinity;
|
|
14
10
|
let JSON_OUTPUT = false;
|
|
15
11
|
|
|
16
|
-
// Default ignore list
|
|
17
12
|
const DEFAULT_IGNORE = new Set([
|
|
18
13
|
"node_modules",
|
|
19
14
|
".git",
|
|
@@ -28,12 +23,10 @@ const DEFAULT_IGNORE = new Set([
|
|
|
28
23
|
"pnpm-lock.yaml"
|
|
29
24
|
]);
|
|
30
25
|
|
|
31
|
-
// User-specified additional ignores
|
|
32
26
|
const USER_IGNORE = new Set();
|
|
33
27
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// --------------------
|
|
28
|
+
/* ---------------- CLI ARG PARSING ---------------- */
|
|
29
|
+
|
|
37
30
|
for (let i = 0; i < args.length; i++) {
|
|
38
31
|
const arg = args[i];
|
|
39
32
|
|
|
@@ -56,10 +49,10 @@ Examples:
|
|
|
56
49
|
project-tree
|
|
57
50
|
project-tree src --depth 2 --ignore logs
|
|
58
51
|
project-tree backend --json
|
|
59
|
-
|
|
52
|
+
`);
|
|
60
53
|
process.exit(0);
|
|
61
54
|
|
|
62
|
-
case "--depth":
|
|
55
|
+
case "--depth": {
|
|
63
56
|
const depth = args[i + 1];
|
|
64
57
|
if (!depth || isNaN(depth)) {
|
|
65
58
|
console.error("Error: --depth requires a number");
|
|
@@ -68,8 +61,9 @@ Examples:
|
|
|
68
61
|
MAX_DEPTH = parseInt(depth, 10);
|
|
69
62
|
i++;
|
|
70
63
|
break;
|
|
64
|
+
}
|
|
71
65
|
|
|
72
|
-
case "--ignore":
|
|
66
|
+
case "--ignore": {
|
|
73
67
|
const ignoreName = args[i + 1];
|
|
74
68
|
if (!ignoreName) {
|
|
75
69
|
console.error("Error: --ignore requires a file or folder name");
|
|
@@ -78,6 +72,7 @@ Examples:
|
|
|
78
72
|
USER_IGNORE.add(ignoreName);
|
|
79
73
|
i++;
|
|
80
74
|
break;
|
|
75
|
+
}
|
|
81
76
|
|
|
82
77
|
case "--json":
|
|
83
78
|
JSON_OUTPUT = true;
|
|
@@ -91,75 +86,74 @@ Examples:
|
|
|
91
86
|
}
|
|
92
87
|
}
|
|
93
88
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
function generateTree(dir, prefix = "", depth = 0) {
|
|
89
|
+
/* ---------------- TREE GENERATION ---------------- */
|
|
90
|
+
|
|
91
|
+
function generateTree(dir, depth = 0) {
|
|
98
92
|
let items;
|
|
93
|
+
|
|
99
94
|
try {
|
|
100
95
|
items = fs.readdirSync(dir, { withFileTypes: true });
|
|
101
96
|
} catch {
|
|
102
|
-
return
|
|
97
|
+
return [];
|
|
103
98
|
}
|
|
104
99
|
|
|
105
|
-
// Filter ignored items
|
|
106
100
|
items = items.filter(
|
|
107
|
-
item =>
|
|
101
|
+
item =>
|
|
102
|
+
!DEFAULT_IGNORE.has(item.name) &&
|
|
103
|
+
!USER_IGNORE.has(item.name)
|
|
108
104
|
);
|
|
109
105
|
|
|
110
|
-
//
|
|
111
|
-
items.sort((a, b) =>
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
items.forEach((item, index) => {
|
|
117
|
-
const isLast = index === items.length - 1;
|
|
118
|
-
const connector = isLast ? "└── " : "├── ";
|
|
119
|
-
const name = item.name;
|
|
106
|
+
// directories first, then files, alphabetical
|
|
107
|
+
items.sort((a, b) => {
|
|
108
|
+
if (a.isDirectory() && !b.isDirectory()) return -1;
|
|
109
|
+
if (!a.isDirectory() && b.isDirectory()) return 1;
|
|
110
|
+
return a.name.localeCompare(b.name);
|
|
111
|
+
});
|
|
120
112
|
|
|
121
|
-
|
|
113
|
+
return items.map(item => {
|
|
114
|
+
const node = { name: item.name };
|
|
122
115
|
|
|
123
116
|
if (item.isDirectory() && depth + 1 < MAX_DEPTH) {
|
|
124
|
-
|
|
125
|
-
|
|
117
|
+
node.children = generateTree(
|
|
118
|
+
path.join(dir, item.name),
|
|
119
|
+
depth + 1
|
|
120
|
+
);
|
|
126
121
|
}
|
|
127
122
|
|
|
128
|
-
|
|
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
|
-
}
|
|
123
|
+
return node;
|
|
137
124
|
});
|
|
138
|
-
|
|
139
|
-
return tree;
|
|
140
125
|
}
|
|
141
126
|
|
|
142
|
-
|
|
127
|
+
/* ---------------- TREE PRINTING ---------------- */
|
|
128
|
+
|
|
143
129
|
function printTree(tree, prefix = "") {
|
|
144
130
|
tree.forEach((node, index) => {
|
|
145
131
|
const isLast = index === tree.length - 1;
|
|
146
132
|
const connector = isLast ? "└── " : "├── ";
|
|
133
|
+
|
|
147
134
|
console.log(prefix + connector + node.name);
|
|
148
|
-
|
|
149
|
-
|
|
135
|
+
|
|
136
|
+
if (node.children && node.children.length > 0) {
|
|
137
|
+
printTree(
|
|
138
|
+
node.children,
|
|
139
|
+
prefix + (isLast ? " " : "│ ")
|
|
140
|
+
);
|
|
150
141
|
}
|
|
151
142
|
});
|
|
152
143
|
}
|
|
153
144
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
// --------------------
|
|
145
|
+
/* ---------------- ENTRY POINT ---------------- */
|
|
146
|
+
|
|
157
147
|
const rootName = path.basename(path.resolve(ROOT_DIR)) || ".";
|
|
158
148
|
|
|
159
149
|
if (JSON_OUTPUT) {
|
|
160
|
-
const
|
|
161
|
-
|
|
150
|
+
const tree = {
|
|
151
|
+
name: rootName,
|
|
152
|
+
children: generateTree(ROOT_DIR)
|
|
153
|
+
};
|
|
154
|
+
console.log(JSON.stringify(tree, null, 2));
|
|
162
155
|
} else {
|
|
163
156
|
console.log(rootName);
|
|
164
|
-
generateTree(ROOT_DIR);
|
|
157
|
+
const tree = generateTree(ROOT_DIR);
|
|
158
|
+
printTree(tree);
|
|
165
159
|
}
|
package/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@jigneshdpanchal/project-tree",
|
|
3
|
-
"version": "1.0.
|
|
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
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@jigneshdpanchal/project-tree",
|
|
3
|
+
"version": "1.0.3",
|
|
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
|
+
}
|