make-folder-txt 1.0.3 → 1.0.5

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 CHANGED
@@ -50,6 +50,15 @@ make-folder-txt
50
50
 
51
51
  That's it. A `my-project.txt` file will be created in the same directory.
52
52
 
53
+ Ignore specific folders/files by name:
54
+
55
+ ```bash
56
+ make-folder-txt --ignore-folder examples extensions docs
57
+ make-folder-txt --ignore-folder examples extensions "docs and explaination"
58
+ make-folder-txt --ignore-folder examples extensions docs --ignore-file LICENSE
59
+ make-folder-txt --ignore-file .env .env.local secrets.txt
60
+ ```
61
+
53
62
  ---
54
63
 
55
64
  ## šŸŽÆ Real World Examples
@@ -19,7 +19,7 @@ const BINARY_EXTS = new Set([
19
19
 
20
20
  // ── helpers ───────────────────────────────────────────────────────────────────
21
21
 
22
- function collectFiles(dir, rootDir, indent = "", lines = [], filePaths = []) {
22
+ function collectFiles(dir, rootDir, ignoreDirs, ignoreFiles, indent = "", lines = [], filePaths = []) {
23
23
  let entries;
24
24
  try {
25
25
  entries = fs.readdirSync(dir, { withFileTypes: true });
@@ -38,14 +38,14 @@ function collectFiles(dir, rootDir, indent = "", lines = [], filePaths = []) {
38
38
  const childIndent = indent + (isLast ? " " : "│ ");
39
39
 
40
40
  if (entry.isDirectory()) {
41
- if (IGNORE_DIRS.has(entry.name)) {
41
+ if (ignoreDirs.has(entry.name)) {
42
42
  lines.push(`${indent}${connector}${entry.name}/ [skipped]`);
43
43
  return;
44
44
  }
45
45
  lines.push(`${indent}${connector}${entry.name}/`);
46
- collectFiles(path.join(dir, entry.name), rootDir, childIndent, lines, filePaths);
46
+ collectFiles(path.join(dir, entry.name), rootDir, ignoreDirs, ignoreFiles, childIndent, lines, filePaths);
47
47
  } else {
48
- if (IGNORE_FILES.has(entry.name)) return;
48
+ if (ignoreFiles.has(entry.name)) return;
49
49
  lines.push(`${indent}${connector}${entry.name}`);
50
50
  const relPath = "/" + path.relative(rootDir, path.join(dir, entry.name)).split(path.sep).join("/");
51
51
  filePaths.push({ abs: path.join(dir, entry.name), rel: relPath });
@@ -79,18 +79,86 @@ if (args.includes("-v") || args.includes("--version")) {
79
79
  process.exit(0);
80
80
  }
81
81
 
82
+ const ignoreDirs = new Set(IGNORE_DIRS);
83
+ const ignoreFiles = new Set(IGNORE_FILES);
84
+ let outputArg = null;
85
+
86
+ for (let i = 0; i < args.length; i += 1) {
87
+ const arg = args[i];
88
+
89
+ if (arg === "--ignore-folder") {
90
+ let consumed = 0;
91
+ while (i + 1 < args.length && !args[i + 1].startsWith("-")) {
92
+ ignoreDirs.add(args[i + 1]);
93
+ i += 1;
94
+ consumed += 1;
95
+ }
96
+ if (consumed === 0) {
97
+ console.error("Error: --ignore-folder requires at least one folder name.");
98
+ process.exit(1);
99
+ }
100
+ continue;
101
+ }
102
+
103
+ if (arg.startsWith("--ignore-folder=")) {
104
+ const value = arg.slice("--ignore-folder=".length);
105
+ if (!value) {
106
+ console.error("Error: --ignore-folder requires a folder name.");
107
+ process.exit(1);
108
+ }
109
+ ignoreDirs.add(value);
110
+ continue;
111
+ }
112
+
113
+ if (arg === "--ignore-file") {
114
+ let consumed = 0;
115
+ while (i + 1 < args.length && !args[i + 1].startsWith("-")) {
116
+ ignoreFiles.add(args[i + 1]);
117
+ i += 1;
118
+ consumed += 1;
119
+ }
120
+ if (consumed === 0) {
121
+ console.error("Error: --ignore-file requires at least one file name.");
122
+ process.exit(1);
123
+ }
124
+ continue;
125
+ }
126
+
127
+ if (arg.startsWith("--ignore-file=")) {
128
+ const value = arg.slice("--ignore-file=".length);
129
+ if (!value) {
130
+ console.error("Error: --ignore-file requires a file name.");
131
+ process.exit(1);
132
+ }
133
+ ignoreFiles.add(value);
134
+ continue;
135
+ }
136
+
137
+ if (arg.startsWith("-")) {
138
+ console.error(`Error: Unknown option "${arg}".`);
139
+ process.exit(1);
140
+ }
141
+
142
+ if (!outputArg) {
143
+ outputArg = arg;
144
+ continue;
145
+ }
146
+
147
+ console.error(`Error: Unexpected argument "${arg}".`);
148
+ process.exit(1);
149
+ }
150
+
82
151
  const folderPath = process.cwd();
83
152
 
84
153
  const rootName = path.basename(folderPath);
85
154
 
86
- const outputArg = args.find(arg => !arg.startsWith("-"));
87
155
  const outputFile = outputArg
88
156
  ? path.resolve(outputArg)
89
157
  : path.join(process.cwd(), `${rootName}.txt`);
90
158
 
91
159
  console.log(`\nšŸ“‚ Scanning: ${folderPath}`);
92
160
 
93
- const { lines: treeLines, filePaths } = collectFiles(folderPath, folderPath);
161
+ const { lines: treeLines, filePaths } = collectFiles(folderPath, folderPath, ignoreDirs, ignoreFiles);
94
162
 
95
163
  // ── build output ──────────────────────────────────────────────────────────────
96
164
  const out = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "make-folder-txt",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Generate a single .txt file containing the full folder structure and file contents of any project, ignoring node_modules and other junk.",
5
5
  "main": "bin/make-folder-txt.js",
6
6
  "bin": {