make-folder-txt 1.0.3 → 1.0.4

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,14 @@ 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 logs
57
+ make-folder-txt --ignore-file .env
58
+ make-folder-txt --ignore-folder dist --ignore-folder coverage --ignore-file secrets.txt
59
+ ```
60
+
53
61
  ---
54
62
 
55
63
  ## šŸŽÆ 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,64 @@ 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" || arg.startsWith("--ignore-folder=")) {
90
+ const value = arg.startsWith("--ignore-folder=")
91
+ ? arg.slice("--ignore-folder=".length)
92
+ : args[i + 1];
93
+ if (!value || value.startsWith("-")) {
94
+ console.error("Error: --ignore-folder requires a folder name.");
95
+ process.exit(1);
96
+ }
97
+ if (!arg.includes("=")) i += 1;
98
+ ignoreDirs.add(value);
99
+ continue;
100
+ }
101
+
102
+ if (arg === "--ignore-file" || arg.startsWith("--ignore-file=")) {
103
+ const value = arg.startsWith("--ignore-file=")
104
+ ? arg.slice("--ignore-file=".length)
105
+ : args[i + 1];
106
+ if (!value || value.startsWith("-")) {
107
+ console.error("Error: --ignore-file requires a file name.");
108
+ process.exit(1);
109
+ }
110
+ if (!arg.includes("=")) i += 1;
111
+ ignoreFiles.add(value);
112
+ continue;
113
+ }
114
+
115
+ if (arg.startsWith("-")) {
116
+ console.error(`Error: Unknown option "${arg}".`);
117
+ process.exit(1);
118
+ }
119
+
120
+ if (!outputArg) {
121
+ outputArg = arg;
122
+ continue;
123
+ }
124
+
125
+ console.error(`Error: Unexpected argument "${arg}".`);
126
+ process.exit(1);
127
+ }
128
+
82
129
  const folderPath = process.cwd();
83
130
 
84
131
  const rootName = path.basename(folderPath);
85
132
 
86
- const outputArg = args.find(arg => !arg.startsWith("-"));
87
133
  const outputFile = outputArg
88
134
  ? path.resolve(outputArg)
89
135
  : path.join(process.cwd(), `${rootName}.txt`);
90
136
 
91
137
  console.log(`\nšŸ“‚ Scanning: ${folderPath}`);
92
138
 
93
- const { lines: treeLines, filePaths } = collectFiles(folderPath, folderPath);
139
+ const { lines: treeLines, filePaths } = collectFiles(folderPath, folderPath, ignoreDirs, ignoreFiles);
94
140
 
95
141
  // ── build output ──────────────────────────────────────────────────────────────
96
142
  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.4",
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": {