make-folder-txt 2.2.1 ā 2.2.2
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/bin/make-folder-txt.js +27 -22
- package/make-folder-txt.txt +4 -1151
- package/package.json +1 -1
package/bin/make-folder-txt.js
CHANGED
|
@@ -470,9 +470,7 @@ function createInteractiveConfig() {
|
|
|
470
470
|
maxFileSize: '500KB',
|
|
471
471
|
splitMethod: 'none',
|
|
472
472
|
splitSize: '5MB',
|
|
473
|
-
copyToClipboard: false
|
|
474
|
-
ignoreFolders: [],
|
|
475
|
-
ignoreFiles: []
|
|
473
|
+
copyToClipboard: false
|
|
476
474
|
};
|
|
477
475
|
|
|
478
476
|
let currentStep = 0;
|
|
@@ -525,17 +523,36 @@ function createInteractiveConfig() {
|
|
|
525
523
|
},
|
|
526
524
|
transform: (value) => ['y', 'yes'].includes(value.toLowerCase())
|
|
527
525
|
},
|
|
526
|
+
{
|
|
527
|
+
key: 'addToTxtIgnore',
|
|
528
|
+
question: 'Add ignore patterns to .txtignore file? (y/n): ',
|
|
529
|
+
default: 'n',
|
|
530
|
+
validate: (value) => {
|
|
531
|
+
const answer = value.toLowerCase();
|
|
532
|
+
if (!['y', 'n', 'yes', 'no'].includes(answer)) return 'Please enter y/n or yes/no';
|
|
533
|
+
return true;
|
|
534
|
+
},
|
|
535
|
+
transform: (value) => ['y', 'yes'].includes(value.toLowerCase())
|
|
536
|
+
},
|
|
528
537
|
{
|
|
529
538
|
key: 'ignoreFolders',
|
|
530
539
|
question: 'Ignore folders (comma-separated, or press Enter to skip): ',
|
|
531
540
|
default: '',
|
|
532
|
-
|
|
541
|
+
ask: () => config.addToTxtIgnore,
|
|
542
|
+
transform: (value) => {
|
|
543
|
+
if (!value || value.trim() === '') return [];
|
|
544
|
+
return value.split(',').map(f => f.trim()).filter(f => f);
|
|
545
|
+
}
|
|
533
546
|
},
|
|
534
547
|
{
|
|
535
548
|
key: 'ignoreFiles',
|
|
536
549
|
question: 'Ignore files (comma-separated, or press Enter to skip): ',
|
|
537
550
|
default: '',
|
|
538
|
-
|
|
551
|
+
ask: () => config.addToTxtIgnore,
|
|
552
|
+
transform: (value) => {
|
|
553
|
+
if (!value || value.trim() === '') return [];
|
|
554
|
+
return value.split(',').map(f => f.trim()).filter(f => f);
|
|
555
|
+
}
|
|
539
556
|
}
|
|
540
557
|
];
|
|
541
558
|
|
|
@@ -583,21 +600,19 @@ function createInteractiveConfig() {
|
|
|
583
600
|
|
|
584
601
|
function saveConfig() {
|
|
585
602
|
try {
|
|
586
|
-
// Create .txtconfig file
|
|
603
|
+
// Create .txtconfig file with proper formatting
|
|
587
604
|
const configPath = path.join(process.cwd(), '.txtconfig');
|
|
588
605
|
const configContent = `{
|
|
589
606
|
"maxFileSize": "${config.maxFileSize}",
|
|
590
607
|
"splitMethod": "${config.splitMethod}",
|
|
591
608
|
"splitSize": "${config.splitSize}",
|
|
592
|
-
"copyToClipboard": ${config.copyToClipboard}
|
|
593
|
-
"ignoreFolders": ${JSON.stringify(config.ignoreFolders)},
|
|
594
|
-
"ignoreFiles": ${JSON.stringify(config.ignoreFiles)}
|
|
609
|
+
"copyToClipboard": ${config.copyToClipboard}
|
|
595
610
|
}`;
|
|
596
611
|
|
|
597
612
|
fs.writeFileSync(configPath, configContent);
|
|
598
613
|
|
|
599
|
-
// Update .txtignore if
|
|
600
|
-
if (config.ignoreFolders.length > 0 || config.ignoreFiles.length > 0) {
|
|
614
|
+
// Update .txtignore if user wants to add ignore patterns
|
|
615
|
+
if (config.addToTxtIgnore && (config.ignoreFolders.length > 0 || config.ignoreFiles.length > 0)) {
|
|
601
616
|
const ignorePath = path.join(process.cwd(), '.txtignore');
|
|
602
617
|
let ignoreContent = '';
|
|
603
618
|
|
|
@@ -622,7 +637,7 @@ function createInteractiveConfig() {
|
|
|
622
637
|
|
|
623
638
|
console.log('\nā
Configuration saved successfully!');
|
|
624
639
|
console.log(`š Config file: ${configPath}`);
|
|
625
|
-
if (config.ignoreFolders.length > 0 || config.ignoreFiles.length > 0) {
|
|
640
|
+
if (config.addToTxtIgnore && (config.ignoreFolders.length > 0 || config.ignoreFiles.length > 0)) {
|
|
626
641
|
console.log(`š Ignore patterns added to .txtignore`);
|
|
627
642
|
}
|
|
628
643
|
console.log('\nš” You can now run: make-folder-txt --use-config');
|
|
@@ -698,16 +713,6 @@ async function main() {
|
|
|
698
713
|
newArgs.push('--copy');
|
|
699
714
|
}
|
|
700
715
|
|
|
701
|
-
// Add ignore folders
|
|
702
|
-
if (config.ignoreFolders.length > 0) {
|
|
703
|
-
newArgs.push('--ignore-folder', ...config.ignoreFolders);
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
// Add ignore files
|
|
707
|
-
if (config.ignoreFiles.length > 0) {
|
|
708
|
-
newArgs.push('--ignore-file', ...config.ignoreFiles);
|
|
709
|
-
}
|
|
710
|
-
|
|
711
716
|
// Replace args with config-based args
|
|
712
717
|
args.splice(0, args.length, ...newArgs);
|
|
713
718
|
}
|
package/make-folder-txt.txt
CHANGED
|
@@ -9,1163 +9,18 @@ Root: C:\Programming\make-folder-txt
|
|
|
9
9
|
|
|
10
10
|
make-folder-txt/
|
|
11
11
|
āāā .git/ [skipped]
|
|
12
|
-
āāā bin/
|
|
13
|
-
ā āāā make-folder-txt.js
|
|
12
|
+
āāā bin/ [skipped]
|
|
14
13
|
āāā .txtconfig
|
|
15
14
|
āāā LICENSE
|
|
16
15
|
āāā package.json
|
|
17
16
|
āāā README.md
|
|
18
17
|
|
|
19
|
-
Total files:
|
|
18
|
+
Total files: 4
|
|
20
19
|
|
|
21
20
|
================================================================================
|
|
22
21
|
FILE CONTENTS
|
|
23
22
|
================================================================================
|
|
24
23
|
|
|
25
|
-
--------------------------------------------------------------------------------
|
|
26
|
-
FILE: /bin/make-folder-txt.js
|
|
27
|
-
--------------------------------------------------------------------------------
|
|
28
|
-
#!/usr/bin/env node
|
|
29
|
-
|
|
30
|
-
const fs = require("fs");
|
|
31
|
-
const path = require("path");
|
|
32
|
-
const { version } = require("../package.json");
|
|
33
|
-
const { execSync } = require("child_process");
|
|
34
|
-
|
|
35
|
-
// āā config āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
36
|
-
const IGNORE_DIRS = new Set(["node_modules", ".git", ".next", "dist", "build", ".cache"]);
|
|
37
|
-
const IGNORE_FILES = new Set([".DS_Store", "Thumbs.db", "desktop.ini", ".txtignore"]);
|
|
38
|
-
|
|
39
|
-
const BINARY_EXTS = new Set([
|
|
40
|
-
".png", ".jpg", ".jpeg", ".gif", ".bmp", ".ico", ".svg", ".webp",
|
|
41
|
-
".pdf", ".zip", ".tar", ".gz", ".rar", ".7z",
|
|
42
|
-
".exe", ".dll", ".so", ".dylib", ".bin",
|
|
43
|
-
".mp3", ".mp4", ".wav", ".avi", ".mov",
|
|
44
|
-
".woff", ".woff2", ".ttf", ".eot", ".otf",
|
|
45
|
-
".lock",
|
|
46
|
-
]);
|
|
47
|
-
|
|
48
|
-
// āā helpers āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
49
|
-
|
|
50
|
-
function readTxtIgnore(rootDir) {
|
|
51
|
-
const txtIgnorePath = path.join(rootDir, '.txtignore');
|
|
52
|
-
const ignorePatterns = new Set();
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
const content = fs.readFileSync(txtIgnorePath, 'utf8');
|
|
56
|
-
const lines = content.split('\n')
|
|
57
|
-
.map(line => line.trim())
|
|
58
|
-
.filter(line => line && !line.startsWith('#'));
|
|
59
|
-
|
|
60
|
-
lines.forEach(line => ignorePatterns.add(line));
|
|
61
|
-
} catch (err) {
|
|
62
|
-
// .txtignore doesn't exist or can't be read - that's fine
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return ignorePatterns;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function copyToClipboard(text) {
|
|
69
|
-
try {
|
|
70
|
-
if (process.platform === 'win32') {
|
|
71
|
-
// Windows
|
|
72
|
-
execSync(`echo ${JSON.stringify(text).replace(/"/g, '""')} | clip`, { stdio: 'ignore' });
|
|
73
|
-
} else if (process.platform === 'darwin') {
|
|
74
|
-
// macOS
|
|
75
|
-
execSync(`echo ${JSON.stringify(text)} | pbcopy`, { stdio: 'ignore' });
|
|
76
|
-
} else {
|
|
77
|
-
// Linux (requires xclip or xsel)
|
|
78
|
-
try {
|
|
79
|
-
execSync(`echo ${JSON.stringify(text)} | xclip -selection clipboard`, { stdio: 'ignore' });
|
|
80
|
-
} catch {
|
|
81
|
-
try {
|
|
82
|
-
execSync(`echo ${JSON.stringify(text)} | xsel --clipboard --input`, { stdio: 'ignore' });
|
|
83
|
-
} catch {
|
|
84
|
-
console.warn('ā ļø Could not copy to clipboard. Install xclip or xsel on Linux.');
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return true;
|
|
90
|
-
} catch (err) {
|
|
91
|
-
console.warn('ā ļø Could not copy to clipboard:', err.message);
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function collectFiles(
|
|
97
|
-
dir,
|
|
98
|
-
rootDir,
|
|
99
|
-
ignoreDirs,
|
|
100
|
-
ignoreFiles,
|
|
101
|
-
onlyFolders,
|
|
102
|
-
onlyFiles,
|
|
103
|
-
options = {},
|
|
104
|
-
) {
|
|
105
|
-
const {
|
|
106
|
-
indent = "",
|
|
107
|
-
lines = [],
|
|
108
|
-
filePaths = [],
|
|
109
|
-
inSelectedFolder = false,
|
|
110
|
-
hasOnlyFilters = false,
|
|
111
|
-
rootName = "",
|
|
112
|
-
txtIgnore = new Set(),
|
|
113
|
-
force = false,
|
|
114
|
-
} = options;
|
|
115
|
-
|
|
116
|
-
let entries;
|
|
117
|
-
try {
|
|
118
|
-
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
119
|
-
} catch {
|
|
120
|
-
return { lines, filePaths, hasIncluded: false };
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
entries.sort((a, b) => {
|
|
124
|
-
if (a.isDirectory() === b.isDirectory()) return a.name.localeCompare(b.name);
|
|
125
|
-
return a.isDirectory() ? -1 : 1;
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
entries.forEach((entry, idx) => {
|
|
129
|
-
const isLast = idx === entries.length - 1;
|
|
130
|
-
const connector = isLast ? "āāā " : "āāā ";
|
|
131
|
-
const childIndent = indent + (isLast ? " " : "ā ");
|
|
132
|
-
|
|
133
|
-
if (entry.isDirectory()) {
|
|
134
|
-
if (!force && ignoreDirs.has(entry.name)) {
|
|
135
|
-
if (!hasOnlyFilters) {
|
|
136
|
-
lines.push(`${indent}${connector}${entry.name}/ [skipped]`);
|
|
137
|
-
}
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Get relative path for .txtignore pattern matching
|
|
142
|
-
const relPathForIgnore = path.relative(rootDir, path.join(dir, entry.name)).split(path.sep).join("/");
|
|
143
|
-
|
|
144
|
-
// Check against .txtignore patterns (both dirname and relative path) unless force is enabled
|
|
145
|
-
if (!force && (txtIgnore.has(entry.name) || txtIgnore.has(`${entry.name}/`) || txtIgnore.has(relPathForIgnore) || txtIgnore.has(`${relPathForIgnore}/`) || txtIgnore.has(`/${relPathForIgnore}/`))) {
|
|
146
|
-
if (!hasOnlyFilters) {
|
|
147
|
-
lines.push(`${indent}${connector}${entry.name}/ [skipped]`);
|
|
148
|
-
}
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const childPath = path.join(dir, entry.name);
|
|
153
|
-
const childInSelectedFolder = inSelectedFolder || onlyFolders.has(entry.name);
|
|
154
|
-
const childLines = [];
|
|
155
|
-
const childFiles = [];
|
|
156
|
-
const child = collectFiles(
|
|
157
|
-
childPath,
|
|
158
|
-
rootDir,
|
|
159
|
-
ignoreDirs,
|
|
160
|
-
ignoreFiles,
|
|
161
|
-
onlyFolders,
|
|
162
|
-
onlyFiles,
|
|
163
|
-
{
|
|
164
|
-
indent: childIndent,
|
|
165
|
-
lines: childLines,
|
|
166
|
-
filePaths: childFiles,
|
|
167
|
-
inSelectedFolder: childInSelectedFolder,
|
|
168
|
-
hasOnlyFilters,
|
|
169
|
-
rootName,
|
|
170
|
-
txtIgnore,
|
|
171
|
-
force,
|
|
172
|
-
},
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
const explicitlySelectedFolder = hasOnlyFilters && onlyFolders.has(entry.name);
|
|
176
|
-
const shouldIncludeDir = !hasOnlyFilters || child.hasIncluded || explicitlySelectedFolder;
|
|
177
|
-
|
|
178
|
-
if (shouldIncludeDir) {
|
|
179
|
-
lines.push(`${indent}${connector}${entry.name}/`);
|
|
180
|
-
lines.push(...child.lines);
|
|
181
|
-
filePaths.push(...child.filePaths);
|
|
182
|
-
}
|
|
183
|
-
} else {
|
|
184
|
-
if (!force && ignoreFiles.has(entry.name)) return;
|
|
185
|
-
|
|
186
|
-
// Get relative path for .txtignore pattern matching
|
|
187
|
-
const relPathForIgnore = path.relative(rootDir, path.join(dir, entry.name)).split(path.sep).join("/");
|
|
188
|
-
|
|
189
|
-
// Check against .txtignore patterns (both filename and relative path) unless force is enabled
|
|
190
|
-
if (!force && (txtIgnore.has(entry.name) || txtIgnore.has(relPathForIgnore) || txtIgnore.has(`/${relPathForIgnore}`))) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// Ignore .txt files that match the folder name (e.g., foldername.txt) unless force is enabled
|
|
195
|
-
if (!force && entry.name.endsWith('.txt') && entry.name === `${rootName}.txt`) return;
|
|
196
|
-
|
|
197
|
-
const shouldIncludeFile = !hasOnlyFilters || inSelectedFolder || onlyFiles.has(entry.name);
|
|
198
|
-
if (!shouldIncludeFile) return;
|
|
199
|
-
|
|
200
|
-
lines.push(`${indent}${connector}${entry.name}`);
|
|
201
|
-
const relPath = "/" + path.relative(rootDir, path.join(dir, entry.name)).split(path.sep).join("/");
|
|
202
|
-
filePaths.push({ abs: path.join(dir, entry.name), rel: relPath });
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
return { lines, filePaths, hasIncluded: filePaths.length > 0 || lines.length > 0 };
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
function parseFileSize(sizeStr) {
|
|
210
|
-
const units = {
|
|
211
|
-
'B': 1,
|
|
212
|
-
'KB': 1024,
|
|
213
|
-
'MB': 1024 * 1024,
|
|
214
|
-
'GB': 1024 * 1024 * 1024,
|
|
215
|
-
'TB': 1024 * 1024 * 1024 * 1024
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
const match = sizeStr.match(/^(\d+(?:\.\d+)?)\s*(B|KB|MB|GB|TB)$/i);
|
|
219
|
-
if (!match) {
|
|
220
|
-
console.error(`Error: Invalid size format "${sizeStr}". Use format like "500KB", "2MB", "1GB".`);
|
|
221
|
-
process.exit(1);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const value = parseFloat(match[1]);
|
|
225
|
-
const unit = match[2].toUpperCase();
|
|
226
|
-
return Math.floor(value * units[unit]);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function readContent(absPath, force = false, maxFileSize = 500 * 1024) {
|
|
230
|
-
const ext = path.extname(absPath).toLowerCase();
|
|
231
|
-
if (!force && BINARY_EXTS.has(ext)) return "[binary / skipped]";
|
|
232
|
-
try {
|
|
233
|
-
const stat = fs.statSync(absPath);
|
|
234
|
-
if (!force && stat.size > maxFileSize) {
|
|
235
|
-
const sizeStr = stat.size < 1024 ? `${stat.size} B` :
|
|
236
|
-
stat.size < 1024 * 1024 ? `${(stat.size / 1024).toFixed(1)} KB` :
|
|
237
|
-
stat.size < 1024 * 1024 * 1024 ? `${(stat.size / (1024 * 1024)).toFixed(1)} MB` :
|
|
238
|
-
`${(stat.size / (1024 * 1024 * 1024)).toFixed(1)} GB`;
|
|
239
|
-
return `[file too large: ${sizeStr} ā skipped]`;
|
|
240
|
-
}
|
|
241
|
-
return fs.readFileSync(absPath, "utf8");
|
|
242
|
-
} catch (err) {
|
|
243
|
-
return `[could not read file: ${err.message}]`;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
function splitByFolders(treeLines, filePaths, rootName, effectiveMaxSize, forceFlag) {
|
|
248
|
-
const folders = new Map();
|
|
249
|
-
|
|
250
|
-
// Group files by folder
|
|
251
|
-
filePaths.forEach(({ abs, rel }) => {
|
|
252
|
-
const folderPath = path.dirname(rel);
|
|
253
|
-
const folderKey = folderPath === '/' ? rootName : folderPath.slice(1);
|
|
254
|
-
|
|
255
|
-
if (!folders.has(folderKey)) {
|
|
256
|
-
folders.set(folderKey, []);
|
|
257
|
-
}
|
|
258
|
-
folders.get(folderKey).push({ abs, rel });
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
const results = [];
|
|
262
|
-
|
|
263
|
-
folders.forEach((files, folderName) => {
|
|
264
|
-
const out = [];
|
|
265
|
-
const divider = "=".repeat(80);
|
|
266
|
-
const subDivider = "-".repeat(80);
|
|
267
|
-
|
|
268
|
-
out.push(divider);
|
|
269
|
-
out.push(`START OF FOLDER: ${folderName}`);
|
|
270
|
-
out.push(divider);
|
|
271
|
-
out.push("");
|
|
272
|
-
|
|
273
|
-
// Add folder structure (only this folder's structure)
|
|
274
|
-
const folderTreeLines = treeLines.filter(line =>
|
|
275
|
-
line.includes(folderName + '/') || line === `${rootName}/`
|
|
276
|
-
);
|
|
277
|
-
|
|
278
|
-
out.push(divider);
|
|
279
|
-
out.push("PROJECT STRUCTURE");
|
|
280
|
-
out.push(divider);
|
|
281
|
-
out.push(`Root: ${folderPath}\n`);
|
|
282
|
-
out.push(`${rootName}/`);
|
|
283
|
-
folderTreeLines.forEach(l => out.push(l));
|
|
284
|
-
out.push("");
|
|
285
|
-
out.push(`Total files in this folder: ${files.length}`);
|
|
286
|
-
out.push("");
|
|
287
|
-
|
|
288
|
-
out.push(divider);
|
|
289
|
-
out.push("FILE CONTENTS");
|
|
290
|
-
out.push(divider);
|
|
291
|
-
|
|
292
|
-
files.forEach(({ abs, rel }) => {
|
|
293
|
-
out.push("");
|
|
294
|
-
out.push(subDivider);
|
|
295
|
-
out.push(`FILE: ${rel}`);
|
|
296
|
-
out.push(subDivider);
|
|
297
|
-
out.push(readContent(abs, forceFlag, effectiveMaxSize));
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
out.push("");
|
|
301
|
-
out.push(divider);
|
|
302
|
-
out.push(`END OF FOLDER: ${folderName}`);
|
|
303
|
-
out.push(divider);
|
|
304
|
-
|
|
305
|
-
const fileName = `${rootName}-${folderName.replace(/[\/\\]/g, '-')}.txt`;
|
|
306
|
-
const filePath = path.join(process.cwd(), fileName);
|
|
307
|
-
|
|
308
|
-
fs.writeFileSync(filePath, out.join("\n"), "utf8");
|
|
309
|
-
const sizeKB = (fs.statSync(filePath).size / 1024).toFixed(1);
|
|
310
|
-
|
|
311
|
-
results.push({
|
|
312
|
-
file: filePath,
|
|
313
|
-
size: sizeKB,
|
|
314
|
-
files: files.length,
|
|
315
|
-
folder: folderName
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
return results;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
function splitByFiles(filePaths, rootName, effectiveMaxSize, forceFlag) {
|
|
323
|
-
const results = [];
|
|
324
|
-
|
|
325
|
-
filePaths.forEach(({ abs, rel }) => {
|
|
326
|
-
const out = [];
|
|
327
|
-
const divider = "=".repeat(80);
|
|
328
|
-
const subDivider = "-".repeat(80);
|
|
329
|
-
const fileName = path.basename(rel, path.extname(rel));
|
|
330
|
-
|
|
331
|
-
out.push(divider);
|
|
332
|
-
out.push(`FILE: ${rel}`);
|
|
333
|
-
out.push(divider);
|
|
334
|
-
out.push("");
|
|
335
|
-
|
|
336
|
-
out.push(divider);
|
|
337
|
-
out.push("FILE CONTENTS");
|
|
338
|
-
out.push(divider);
|
|
339
|
-
out.push(readContent(abs, forceFlag, effectiveMaxSize));
|
|
340
|
-
|
|
341
|
-
out.push("");
|
|
342
|
-
out.push(divider);
|
|
343
|
-
out.push(`END OF FILE: ${rel}`);
|
|
344
|
-
out.push(divider);
|
|
345
|
-
|
|
346
|
-
const outputFileName = `${rootName}-${fileName}.txt`;
|
|
347
|
-
const filePath = path.join(process.cwd(), outputFileName);
|
|
348
|
-
|
|
349
|
-
fs.writeFileSync(filePath, out.join("\n"), "utf8");
|
|
350
|
-
const sizeKB = (fs.statSync(filePath).size / 1024).toFixed(1);
|
|
351
|
-
|
|
352
|
-
results.push({
|
|
353
|
-
file: filePath,
|
|
354
|
-
size: sizeKB,
|
|
355
|
-
files: 1,
|
|
356
|
-
fileName: fileName
|
|
357
|
-
});
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
return results;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
function splitBySize(treeLines, filePaths, rootName, splitSize, effectiveMaxSize, forceFlag) {
|
|
364
|
-
const results = [];
|
|
365
|
-
let currentPart = 1;
|
|
366
|
-
let currentSize = 0;
|
|
367
|
-
let currentFiles = [];
|
|
368
|
-
|
|
369
|
-
const divider = "=".repeat(80);
|
|
370
|
-
const subDivider = "-".repeat(80);
|
|
371
|
-
|
|
372
|
-
// Start with header
|
|
373
|
-
let out = [];
|
|
374
|
-
out.push(divider);
|
|
375
|
-
out.push(`START OF FOLDER: ${rootName} (Part ${currentPart})`);
|
|
376
|
-
out.push(divider);
|
|
377
|
-
out.push("");
|
|
378
|
-
|
|
379
|
-
out.push(divider);
|
|
380
|
-
out.push("PROJECT STRUCTURE");
|
|
381
|
-
out.push(divider);
|
|
382
|
-
out.push(`Root: ${folderPath}\n`);
|
|
383
|
-
out.push(`${rootName}/`);
|
|
384
|
-
treeLines.forEach(l => out.push(l));
|
|
385
|
-
out.push("");
|
|
386
|
-
out.push(`Total files: ${filePaths.length}`);
|
|
387
|
-
out.push("");
|
|
388
|
-
|
|
389
|
-
out.push(divider);
|
|
390
|
-
out.push("FILE CONTENTS");
|
|
391
|
-
out.push(divider);
|
|
392
|
-
|
|
393
|
-
filePaths.forEach(({ abs, rel }) => {
|
|
394
|
-
const content = readContent(abs, forceFlag, effectiveMaxSize);
|
|
395
|
-
const fileContent = [
|
|
396
|
-
"",
|
|
397
|
-
subDivider,
|
|
398
|
-
`FILE: ${rel}`,
|
|
399
|
-
subDivider,
|
|
400
|
-
content
|
|
401
|
-
];
|
|
402
|
-
|
|
403
|
-
const contentSize = fileContent.join("\n").length;
|
|
404
|
-
|
|
405
|
-
// Check if adding this file would exceed the split size
|
|
406
|
-
if (currentSize + contentSize > splitSize && currentFiles.length > 0) {
|
|
407
|
-
// Finish current part
|
|
408
|
-
out.push("");
|
|
409
|
-
out.push(divider);
|
|
410
|
-
out.push(`END OF FOLDER: ${rootName} (Part ${currentPart})`);
|
|
411
|
-
out.push(divider);
|
|
412
|
-
|
|
413
|
-
// Write current part
|
|
414
|
-
const fileName = `${rootName}-part-${currentPart}.txt`;
|
|
415
|
-
const filePath = path.join(process.cwd(), fileName);
|
|
416
|
-
fs.writeFileSync(filePath, out.join("\n"), "utf8");
|
|
417
|
-
const sizeKB = (fs.statSync(filePath).size / 1024).toFixed(1);
|
|
418
|
-
|
|
419
|
-
results.push({
|
|
420
|
-
file: filePath,
|
|
421
|
-
size: sizeKB,
|
|
422
|
-
files: currentFiles.length,
|
|
423
|
-
part: currentPart
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
// Start new part
|
|
427
|
-
currentPart++;
|
|
428
|
-
currentSize = 0;
|
|
429
|
-
currentFiles = [];
|
|
430
|
-
|
|
431
|
-
out = [];
|
|
432
|
-
out.push(divider);
|
|
433
|
-
out.push(`START OF FOLDER: ${rootName} (Part ${currentPart})`);
|
|
434
|
-
out.push(divider);
|
|
435
|
-
out.push("");
|
|
436
|
-
|
|
437
|
-
out.push(divider);
|
|
438
|
-
out.push("PROJECT STRUCTURE");
|
|
439
|
-
out.push(divider);
|
|
440
|
-
out.push(`Root: ${folderPath}\n`);
|
|
441
|
-
out.push(`${rootName}/`);
|
|
442
|
-
treeLines.forEach(l => out.push(l));
|
|
443
|
-
out.push("");
|
|
444
|
-
out.push(`Total files: ${filePaths.length}`);
|
|
445
|
-
out.push("");
|
|
446
|
-
|
|
447
|
-
out.push(divider);
|
|
448
|
-
out.push("FILE CONTENTS");
|
|
449
|
-
out.push(divider);
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
// Add file to current part
|
|
453
|
-
out.push(...fileContent);
|
|
454
|
-
currentSize += contentSize;
|
|
455
|
-
currentFiles.push(rel);
|
|
456
|
-
});
|
|
457
|
-
|
|
458
|
-
// Write final part
|
|
459
|
-
out.push("");
|
|
460
|
-
out.push(divider);
|
|
461
|
-
out.push(`END OF FOLDER: ${rootName} (Part ${currentPart})`);
|
|
462
|
-
out.push(divider);
|
|
463
|
-
|
|
464
|
-
const fileName = `${rootName}-part-${currentPart}.txt`;
|
|
465
|
-
const filePath = path.join(process.cwd(), fileName);
|
|
466
|
-
fs.writeFileSync(filePath, out.join("\n"), "utf8");
|
|
467
|
-
const sizeKB = (fs.statSync(filePath).size / 1024).toFixed(1);
|
|
468
|
-
|
|
469
|
-
results.push({
|
|
470
|
-
file: filePath,
|
|
471
|
-
size: sizeKB,
|
|
472
|
-
files: currentFiles.length,
|
|
473
|
-
part: currentPart
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
return results;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
// āā configuration āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
480
|
-
|
|
481
|
-
function createInteractiveConfig() {
|
|
482
|
-
const readline = require('readline');
|
|
483
|
-
const fs = require('fs');
|
|
484
|
-
const path = require('path');
|
|
485
|
-
const os = require('os');
|
|
486
|
-
|
|
487
|
-
const rl = readline.createInterface({
|
|
488
|
-
input: process.stdin,
|
|
489
|
-
output: process.stdout
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
console.log('\nš§ make-folder-txt Configuration Setup');
|
|
493
|
-
console.log('=====================================\n');
|
|
494
|
-
|
|
495
|
-
return new Promise((resolve) => {
|
|
496
|
-
const config = {
|
|
497
|
-
maxFileSize: '500KB',
|
|
498
|
-
splitMethod: 'none',
|
|
499
|
-
splitSize: '5MB',
|
|
500
|
-
copyToClipboard: false,
|
|
501
|
-
ignoreFolders: [],
|
|
502
|
-
ignoreFiles: []
|
|
503
|
-
};
|
|
504
|
-
|
|
505
|
-
let currentStep = 0;
|
|
506
|
-
const questions = [
|
|
507
|
-
{
|
|
508
|
-
key: 'maxFileSize',
|
|
509
|
-
question: 'Maximum file size to include (e.g., 500KB, 2MB, 1GB): ',
|
|
510
|
-
default: '500KB',
|
|
511
|
-
validate: (value) => {
|
|
512
|
-
if (!value.trim()) return true;
|
|
513
|
-
const validUnits = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
514
|
-
const match = value.match(/^(\d+(?:\.\d+)?)\s*([A-Z]+)$/i);
|
|
515
|
-
if (!match) return 'Please enter a valid size (e.g., 500KB, 2MB, 1GB)';
|
|
516
|
-
if (!validUnits.includes(match[2].toUpperCase())) return `Invalid unit. Use: ${validUnits.join(', ')}`;
|
|
517
|
-
return true;
|
|
518
|
-
}
|
|
519
|
-
},
|
|
520
|
-
{
|
|
521
|
-
key: 'splitMethod',
|
|
522
|
-
question: 'Split output method (none, folder, file, size): ',
|
|
523
|
-
default: 'none',
|
|
524
|
-
validate: (value) => {
|
|
525
|
-
const validMethods = ['none', 'folder', 'file', 'size'];
|
|
526
|
-
if (!validMethods.includes(value.toLowerCase())) return `Please choose: ${validMethods.join(', ')}`;
|
|
527
|
-
return true;
|
|
528
|
-
}
|
|
529
|
-
},
|
|
530
|
-
{
|
|
531
|
-
key: 'splitSize',
|
|
532
|
-
question: 'Split size when using size method (e.g., 5MB, 10MB): ',
|
|
533
|
-
default: '5MB',
|
|
534
|
-
ask: () => config.splitMethod === 'size',
|
|
535
|
-
validate: (value) => {
|
|
536
|
-
if (!value.trim()) return true;
|
|
537
|
-
const validUnits = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
538
|
-
const match = value.match(/^(\d+(?:\.\d+)?)\s*([A-Z]+)$/i);
|
|
539
|
-
if (!match) return 'Please enter a valid size (e.g., 5MB, 10MB)';
|
|
540
|
-
if (!validUnits.includes(match[2].toUpperCase())) return `Invalid unit. Use: ${validUnits.join(', ')}`;
|
|
541
|
-
return true;
|
|
542
|
-
}
|
|
543
|
-
},
|
|
544
|
-
{
|
|
545
|
-
key: 'copyToClipboard',
|
|
546
|
-
question: 'Copy to clipboard automatically? (y/n): ',
|
|
547
|
-
default: 'n',
|
|
548
|
-
validate: (value) => {
|
|
549
|
-
const answer = value.toLowerCase();
|
|
550
|
-
if (!['y', 'n', 'yes', 'no'].includes(answer)) return 'Please enter y/n or yes/no';
|
|
551
|
-
return true;
|
|
552
|
-
},
|
|
553
|
-
transform: (value) => ['y', 'yes'].includes(value.toLowerCase())
|
|
554
|
-
},
|
|
555
|
-
{
|
|
556
|
-
key: 'ignoreFolders',
|
|
557
|
-
question: 'Ignore folders (comma-separated, or press Enter to skip): ',
|
|
558
|
-
default: '',
|
|
559
|
-
transform: (value) => value ? value.split(',').map(f => f.trim()).filter(f => f) : []
|
|
560
|
-
},
|
|
561
|
-
{
|
|
562
|
-
key: 'ignoreFiles',
|
|
563
|
-
question: 'Ignore files (comma-separated, or press Enter to skip): ',
|
|
564
|
-
default: '',
|
|
565
|
-
transform: (value) => value ? value.split(',').map(f => f.trim()).filter(f => f) : []
|
|
566
|
-
}
|
|
567
|
-
];
|
|
568
|
-
|
|
569
|
-
function askQuestion() {
|
|
570
|
-
if (currentStep >= questions.length) {
|
|
571
|
-
// Save configuration
|
|
572
|
-
saveConfig();
|
|
573
|
-
return;
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
const q = questions[currentStep];
|
|
577
|
-
|
|
578
|
-
// Skip if conditional ask returns false
|
|
579
|
-
if (q.ask && !q.ask()) {
|
|
580
|
-
currentStep++;
|
|
581
|
-
askQuestion();
|
|
582
|
-
return;
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
const defaultValue = typeof q.default === 'function' ? q.default() : q.default;
|
|
586
|
-
rl.question(q.question + (defaultValue ? `(${defaultValue}) ` : ''), (answer) => {
|
|
587
|
-
const value = answer.trim() || defaultValue;
|
|
588
|
-
|
|
589
|
-
// Validate input
|
|
590
|
-
if (q.validate) {
|
|
591
|
-
const validation = q.validate(value);
|
|
592
|
-
if (validation !== true) {
|
|
593
|
-
console.log(`ā ${validation}`);
|
|
594
|
-
askQuestion();
|
|
595
|
-
return;
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
// Transform value if needed
|
|
600
|
-
if (q.transform) {
|
|
601
|
-
config[q.key] = q.transform(value);
|
|
602
|
-
} else {
|
|
603
|
-
config[q.key] = value;
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
currentStep++;
|
|
607
|
-
askQuestion();
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
function saveConfig() {
|
|
612
|
-
try {
|
|
613
|
-
// Create .txtconfig file
|
|
614
|
-
const configPath = path.join(process.cwd(), '.txtconfig');
|
|
615
|
-
const configContent = `{
|
|
616
|
-
"maxFileSize": "${config.maxFileSize}",
|
|
617
|
-
"splitMethod": "${config.splitMethod}",
|
|
618
|
-
"splitSize": "${config.splitSize}",
|
|
619
|
-
"copyToClipboard": ${config.copyToClipboard},
|
|
620
|
-
"ignoreFolders": ${JSON.stringify(config.ignoreFolders)},
|
|
621
|
-
"ignoreFiles": ${JSON.stringify(config.ignoreFiles)}
|
|
622
|
-
}`;
|
|
623
|
-
|
|
624
|
-
fs.writeFileSync(configPath, configContent);
|
|
625
|
-
|
|
626
|
-
// Update .txtignore if there are ignore patterns
|
|
627
|
-
if (config.ignoreFolders.length > 0 || config.ignoreFiles.length > 0) {
|
|
628
|
-
const ignorePath = path.join(process.cwd(), '.txtignore');
|
|
629
|
-
let ignoreContent = '';
|
|
630
|
-
|
|
631
|
-
// Read existing content if file exists
|
|
632
|
-
if (fs.existsSync(ignorePath)) {
|
|
633
|
-
ignoreContent = fs.readFileSync(ignorePath, 'utf8');
|
|
634
|
-
if (!ignoreContent.endsWith('\n')) ignoreContent += '\n';
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
// Add new ignore patterns
|
|
638
|
-
const newPatterns = [
|
|
639
|
-
...config.ignoreFolders.map(f => f.endsWith('/') ? f : `${f}/`),
|
|
640
|
-
...config.ignoreFiles
|
|
641
|
-
];
|
|
642
|
-
|
|
643
|
-
if (newPatterns.length > 0) {
|
|
644
|
-
ignoreContent += '\n# Added by make-folder-txt config\n';
|
|
645
|
-
ignoreContent += newPatterns.join('\n') + '\n';
|
|
646
|
-
fs.writeFileSync(ignorePath, ignoreContent);
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
console.log('\nā
Configuration saved successfully!');
|
|
651
|
-
console.log(`š Config file: ${configPath}`);
|
|
652
|
-
if (config.ignoreFolders.length > 0 || config.ignoreFiles.length > 0) {
|
|
653
|
-
console.log(`š Ignore patterns added to .txtignore`);
|
|
654
|
-
}
|
|
655
|
-
console.log('\nš” You can now run: make-folder-txt --use-config');
|
|
656
|
-
|
|
657
|
-
} catch (err) {
|
|
658
|
-
console.error('ā Error saving configuration:', err.message);
|
|
659
|
-
} finally {
|
|
660
|
-
rl.close();
|
|
661
|
-
resolve();
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
askQuestion();
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
function loadConfig() {
|
|
670
|
-
const fs = require('fs');
|
|
671
|
-
const path = require('path');
|
|
672
|
-
|
|
673
|
-
try {
|
|
674
|
-
const configPath = path.join(process.cwd(), '.txtconfig');
|
|
675
|
-
if (!fs.existsSync(configPath)) {
|
|
676
|
-
console.error('ā .txtconfig file not found. Run --make-config first.');
|
|
677
|
-
process.exit(1);
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
const configContent = fs.readFileSync(configPath, 'utf8');
|
|
681
|
-
return JSON.parse(configContent);
|
|
682
|
-
} catch (err) {
|
|
683
|
-
console.error('ā Error loading configuration:', err.message);
|
|
684
|
-
process.exit(1);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
// āā main āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
689
|
-
|
|
690
|
-
async function main() {
|
|
691
|
-
const args = process.argv.slice(2);
|
|
692
|
-
|
|
693
|
-
if (args.includes("-v") || args.includes("--version")) {
|
|
694
|
-
console.log(`v${version}`);
|
|
695
|
-
console.log("Built by Muhammad Saad Amin");
|
|
696
|
-
process.exit(0);
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
if (args.includes("--make-config")) {
|
|
700
|
-
await createInteractiveConfig();
|
|
701
|
-
process.exit(0);
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
if (args.includes("--use-config")) {
|
|
705
|
-
const config = loadConfig();
|
|
706
|
-
|
|
707
|
-
// Apply config to command line arguments
|
|
708
|
-
const newArgs = [];
|
|
709
|
-
|
|
710
|
-
// Add max file size if not default
|
|
711
|
-
if (config.maxFileSize !== '500KB') {
|
|
712
|
-
newArgs.push('--skip-large', config.maxFileSize);
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
// Add split method if not none
|
|
716
|
-
if (config.splitMethod !== 'none') {
|
|
717
|
-
newArgs.push('--split-method', config.splitMethod);
|
|
718
|
-
if (config.splitMethod === 'size') {
|
|
719
|
-
newArgs.push('--split-size', config.splitSize);
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
// Add copy to clipboard if true
|
|
724
|
-
if (config.copyToClipboard) {
|
|
725
|
-
newArgs.push('--copy');
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
// Add ignore folders
|
|
729
|
-
if (config.ignoreFolders.length > 0) {
|
|
730
|
-
newArgs.push('--ignore-folder', ...config.ignoreFolders);
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
// Add ignore files
|
|
734
|
-
if (config.ignoreFiles.length > 0) {
|
|
735
|
-
newArgs.push('--ignore-file', ...config.ignoreFiles);
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
// Replace args with config-based args
|
|
739
|
-
args.splice(0, args.length, ...newArgs);
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
if (args.includes("--help") || args.includes("-h")) {
|
|
743
|
-
console.log(`
|
|
744
|
-
\x1b[33mmake-folder-txt\x1b[0m
|
|
745
|
-
Dump an entire project folder into a single readable .txt file.
|
|
746
|
-
|
|
747
|
-
\x1b[33mUSAGE\x1b[0m
|
|
748
|
-
make-folder-txt [options]
|
|
749
|
-
|
|
750
|
-
\x1b[33mOPTIONS\x1b[0m
|
|
751
|
-
--ignore-folder, -ifo <names...> Ignore specific folders by name
|
|
752
|
-
--ignore-file, -ifi <names...> Ignore specific files by name
|
|
753
|
-
--only-folder, -ofo <names...> Include only specific folders
|
|
754
|
-
--only-file, -ofi <names...> Include only specific files
|
|
755
|
-
--skip-large <size> Skip files larger than specified size (default: 500KB)
|
|
756
|
-
--no-skip Include all files regardless of size
|
|
757
|
-
--split-method <method> Split output: folder, file, or size
|
|
758
|
-
--split-size <size> Split output when size exceeds limit (requires --split-method size)
|
|
759
|
-
--copy Copy output to clipboard
|
|
760
|
-
--force Include everything (overrides all ignore patterns)
|
|
761
|
-
--make-config Create interactive configuration
|
|
762
|
-
--use-config Use configuration from .txtconfig file
|
|
763
|
-
--help, -h Show this help message
|
|
764
|
-
--version, -v Show version information
|
|
765
|
-
|
|
766
|
-
\x1b[33mEXAMPLES\x1b[0m
|
|
767
|
-
make-folder-txt
|
|
768
|
-
make-folder-txt --copy
|
|
769
|
-
make-folder-txt --force
|
|
770
|
-
make-folder-txt --skip-large 400KB
|
|
771
|
-
make-folder-txt --skip-large 5GB
|
|
772
|
-
make-folder-txt --no-skip
|
|
773
|
-
make-folder-txt --split-method folder
|
|
774
|
-
make-folder-txt --split-method file
|
|
775
|
-
make-folder-txt --split-method size --split-size 5MB
|
|
776
|
-
make-folder-txt --ignore-folder node_modules dist
|
|
777
|
-
make-folder-txt -ifo node_modules dist
|
|
778
|
-
make-folder-txt --ignore-file .env .env.local
|
|
779
|
-
make-folder-txt -ifi .env .env.local
|
|
780
|
-
make-folder-txt --only-folder src docs
|
|
781
|
-
make-folder-txt -ofo src docs
|
|
782
|
-
make-folder-txt --only-file package.json README.md
|
|
783
|
-
make-folder-txt -ofi package.json README.md
|
|
784
|
-
make-folder-txt --make-config
|
|
785
|
-
make-folder-txt --use-config
|
|
786
|
-
|
|
787
|
-
\x1b[33m.TXTIGNORE FILE\x1b[0m
|
|
788
|
-
Create a .txtignore file in your project root to specify files/folders to ignore.
|
|
789
|
-
Works like .gitignore - supports file names, path patterns, and comments.
|
|
790
|
-
|
|
791
|
-
Example .txtignore:
|
|
792
|
-
node_modules/
|
|
793
|
-
*.log
|
|
794
|
-
.env
|
|
795
|
-
coverage/
|
|
796
|
-
LICENSE
|
|
797
|
-
`);
|
|
798
|
-
process.exit(0);
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
const ignoreDirs = new Set(IGNORE_DIRS);
|
|
802
|
-
const ignoreFiles = new Set(IGNORE_FILES);
|
|
803
|
-
const onlyFolders = new Set();
|
|
804
|
-
const onlyFiles = new Set();
|
|
805
|
-
let outputArg = null;
|
|
806
|
-
let copyToClipboardFlag = false;
|
|
807
|
-
let forceFlag = false;
|
|
808
|
-
let maxFileSize = 500 * 1024; // Default 500KB
|
|
809
|
-
let noSkipFlag = false;
|
|
810
|
-
let splitMethod = null; // 'folder', 'file', 'size'
|
|
811
|
-
let splitSize = null; // size in bytes
|
|
812
|
-
|
|
813
|
-
for (let i = 0; i < args.length; i += 1) {
|
|
814
|
-
const arg = args[i];
|
|
815
|
-
|
|
816
|
-
if (arg === "--copy") {
|
|
817
|
-
copyToClipboardFlag = true;
|
|
818
|
-
continue;
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
if (arg === "--force") {
|
|
822
|
-
forceFlag = true;
|
|
823
|
-
continue;
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
if (arg === "--no-skip") {
|
|
827
|
-
noSkipFlag = true;
|
|
828
|
-
continue;
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
if (arg === "--skip-large") {
|
|
832
|
-
if (i + 1 >= args.length || args[i + 1].startsWith("-")) {
|
|
833
|
-
console.error("Error: --skip-large requires a size value (e.g., 400KB, 5GB).");
|
|
834
|
-
process.exit(1);
|
|
835
|
-
}
|
|
836
|
-
maxFileSize = parseFileSize(args[i + 1]);
|
|
837
|
-
i += 1;
|
|
838
|
-
continue;
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
if (arg.startsWith("--skip-large=")) {
|
|
842
|
-
const value = arg.slice("--skip-large=".length);
|
|
843
|
-
if (!value) {
|
|
844
|
-
console.error("Error: --skip-large requires a size value (e.g., 400KB, 5GB).");
|
|
845
|
-
process.exit(1);
|
|
846
|
-
}
|
|
847
|
-
maxFileSize = parseFileSize(value);
|
|
848
|
-
continue;
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
if (arg === "--split-method") {
|
|
852
|
-
if (i + 1 >= args.length || args[i + 1].startsWith("-")) {
|
|
853
|
-
console.error("Error: --split-method requires a method (folder, file, or size).");
|
|
854
|
-
process.exit(1);
|
|
855
|
-
}
|
|
856
|
-
const method = args[i + 1].toLowerCase();
|
|
857
|
-
if (!['folder', 'file', 'size'].includes(method)) {
|
|
858
|
-
console.error("Error: --split-method must be one of: folder, file, size");
|
|
859
|
-
process.exit(1);
|
|
860
|
-
}
|
|
861
|
-
splitMethod = method;
|
|
862
|
-
i += 1;
|
|
863
|
-
continue;
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
if (arg.startsWith("--split-method=")) {
|
|
867
|
-
const value = arg.slice("--split-method=".length);
|
|
868
|
-
if (!value) {
|
|
869
|
-
console.error("Error: --split-method requires a method (folder, file, or size).");
|
|
870
|
-
process.exit(1);
|
|
871
|
-
}
|
|
872
|
-
const method = value.toLowerCase();
|
|
873
|
-
if (!['folder', 'file', 'size'].includes(method)) {
|
|
874
|
-
console.error("Error: --split-method must be one of: folder, file, size");
|
|
875
|
-
process.exit(1);
|
|
876
|
-
}
|
|
877
|
-
splitMethod = method;
|
|
878
|
-
continue;
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
if (arg === "--split-size") {
|
|
882
|
-
if (i + 1 >= args.length || args[i + 1].startsWith("-")) {
|
|
883
|
-
console.error("Error: --split-size requires a size value (e.g., 5MB, 10MB).");
|
|
884
|
-
process.exit(1);
|
|
885
|
-
}
|
|
886
|
-
splitSize = parseFileSize(args[i + 1]);
|
|
887
|
-
i += 1;
|
|
888
|
-
continue;
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
if (arg.startsWith("--split-size=")) {
|
|
892
|
-
const value = arg.slice("--split-size=".length);
|
|
893
|
-
if (!value) {
|
|
894
|
-
console.error("Error: --split-size requires a size value (e.g., 5MB, 10MB).");
|
|
895
|
-
process.exit(1);
|
|
896
|
-
}
|
|
897
|
-
splitSize = parseFileSize(value);
|
|
898
|
-
continue;
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
if (arg === "--ignore-folder" || arg === "-ifo") {
|
|
902
|
-
let consumed = 0;
|
|
903
|
-
while (i + 1 < args.length && !args[i + 1].startsWith("-")) {
|
|
904
|
-
// Normalize the folder name: remove backslashes, trailing slashes, and leading ./
|
|
905
|
-
let folderName = args[i + 1];
|
|
906
|
-
folderName = folderName.replace(/\\/g, '/'); // Convert backslashes to forward slashes
|
|
907
|
-
folderName = folderName.replace(/^\.?\//, ''); // Remove leading ./ or /
|
|
908
|
-
folderName = folderName.replace(/\/+$/, ''); // Remove trailing slashes
|
|
909
|
-
ignoreDirs.add(folderName);
|
|
910
|
-
i += 1;
|
|
911
|
-
consumed += 1;
|
|
912
|
-
}
|
|
913
|
-
if (consumed === 0) {
|
|
914
|
-
console.error("Error: --ignore-folder requires at least one folder name.");
|
|
915
|
-
process.exit(1);
|
|
916
|
-
}
|
|
917
|
-
continue;
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
if (arg.startsWith("--ignore-folder=") || arg.startsWith("-ifo=")) {
|
|
921
|
-
const value = arg.startsWith("--ignore-folder=")
|
|
922
|
-
? arg.slice("--ignore-folder=".length)
|
|
923
|
-
: arg.slice("-ifo=".length);
|
|
924
|
-
if (!value) {
|
|
925
|
-
console.error("Error: --ignore-folder requires a folder name.");
|
|
926
|
-
process.exit(1);
|
|
927
|
-
}
|
|
928
|
-
// Normalize the folder name
|
|
929
|
-
let folderName = value;
|
|
930
|
-
folderName = folderName.replace(/\\/g, '/'); // Convert backslashes to forward slashes
|
|
931
|
-
folderName = folderName.replace(/^\.?\//, ''); // Remove leading ./ or /
|
|
932
|
-
folderName = folderName.replace(/\/+$/, ''); // Remove trailing slashes
|
|
933
|
-
ignoreDirs.add(folderName);
|
|
934
|
-
continue;
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
if (arg === "--ignore-file" || arg === "-ifi") {
|
|
938
|
-
let consumed = 0;
|
|
939
|
-
while (i + 1 < args.length && !args[i + 1].startsWith("-")) {
|
|
940
|
-
ignoreFiles.add(args[i + 1]);
|
|
941
|
-
i += 1;
|
|
942
|
-
consumed += 1;
|
|
943
|
-
}
|
|
944
|
-
if (consumed === 0) {
|
|
945
|
-
console.error("Error: --ignore-file requires at least one file name.");
|
|
946
|
-
process.exit(1);
|
|
947
|
-
}
|
|
948
|
-
continue;
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
if (arg.startsWith("--ignore-file=") || arg.startsWith("-ifi=")) {
|
|
952
|
-
const value = arg.startsWith("--ignore-file=")
|
|
953
|
-
? arg.slice("--ignore-file=".length)
|
|
954
|
-
: arg.slice("-ifi=".length);
|
|
955
|
-
if (!value) {
|
|
956
|
-
console.error("Error: --ignore-file requires a file name.");
|
|
957
|
-
process.exit(1);
|
|
958
|
-
}
|
|
959
|
-
ignoreFiles.add(value);
|
|
960
|
-
continue;
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
if (arg === "--only-folder" || arg === "-ofo") {
|
|
964
|
-
let consumed = 0;
|
|
965
|
-
while (i + 1 < args.length && !args[i + 1].startsWith("-")) {
|
|
966
|
-
// Normalize the folder name
|
|
967
|
-
let folderName = args[i + 1];
|
|
968
|
-
folderName = folderName.replace(/\\/g, '/'); // Convert backslashes to forward slashes
|
|
969
|
-
folderName = folderName.replace(/^\.?\//, ''); // Remove leading ./ or /
|
|
970
|
-
folderName = folderName.replace(/\/+$/, ''); // Remove trailing slashes
|
|
971
|
-
onlyFolders.add(folderName);
|
|
972
|
-
i += 1;
|
|
973
|
-
consumed += 1;
|
|
974
|
-
}
|
|
975
|
-
if (consumed === 0) {
|
|
976
|
-
console.error("Error: --only-folder requires at least one folder name.");
|
|
977
|
-
process.exit(1);
|
|
978
|
-
}
|
|
979
|
-
continue;
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
if (arg.startsWith("--only-folder=") || arg.startsWith("-ofo=")) {
|
|
983
|
-
const value = arg.startsWith("--only-folder=")
|
|
984
|
-
? arg.slice("--only-folder=".length)
|
|
985
|
-
: arg.slice("-ofo=".length);
|
|
986
|
-
if (!value) {
|
|
987
|
-
console.error("Error: --only-folder requires a folder name.");
|
|
988
|
-
process.exit(1);
|
|
989
|
-
}
|
|
990
|
-
// Normalize the folder name
|
|
991
|
-
let folderName = value;
|
|
992
|
-
folderName = folderName.replace(/\\/g, '/'); // Convert backslashes to forward slashes
|
|
993
|
-
folderName = folderName.replace(/^\.?\//, ''); // Remove leading ./ or /
|
|
994
|
-
folderName = folderName.replace(/\/+$/, ''); // Remove trailing slashes
|
|
995
|
-
onlyFolders.add(folderName);
|
|
996
|
-
continue;
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
if (arg === "--only-file" || arg === "-ofi") {
|
|
1000
|
-
let consumed = 0;
|
|
1001
|
-
while (i + 1 < args.length && !args[i + 1].startsWith("-")) {
|
|
1002
|
-
onlyFiles.add(args[i + 1]);
|
|
1003
|
-
i += 1;
|
|
1004
|
-
consumed += 1;
|
|
1005
|
-
}
|
|
1006
|
-
if (consumed === 0) {
|
|
1007
|
-
console.error("Error: --only-file requires at least one file name.");
|
|
1008
|
-
process.exit(1);
|
|
1009
|
-
}
|
|
1010
|
-
continue;
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
if (arg.startsWith("--only-file=") || arg.startsWith("-ofi=")) {
|
|
1014
|
-
const value = arg.startsWith("--only-file=")
|
|
1015
|
-
? arg.slice("--only-file=".length)
|
|
1016
|
-
: arg.slice("-ofi=".length);
|
|
1017
|
-
if (!value) {
|
|
1018
|
-
console.error("Error: --only-file requires a file name.");
|
|
1019
|
-
process.exit(1);
|
|
1020
|
-
}
|
|
1021
|
-
onlyFiles.add(value);
|
|
1022
|
-
continue;
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
// Unknown argument
|
|
1026
|
-
console.error(`Error: Unknown option "${arg}"`);
|
|
1027
|
-
console.error("Use --help for available options.");
|
|
1028
|
-
process.exit(1);
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
// Validate split options
|
|
1032
|
-
if (splitMethod === 'size' && !splitSize) {
|
|
1033
|
-
console.error("Error: --split-method size requires --split-size to be specified");
|
|
1034
|
-
process.exit(1);
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
if (splitSize && splitMethod !== 'size') {
|
|
1038
|
-
console.error("Error: --split-size can only be used with --split-method size");
|
|
1039
|
-
process.exit(1);
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
// āā config āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
1043
|
-
|
|
1044
|
-
const folderPath = process.cwd();
|
|
1045
|
-
const rootName = path.basename(folderPath);
|
|
1046
|
-
const txtIgnore = readTxtIgnore(folderPath);
|
|
1047
|
-
|
|
1048
|
-
// āā build tree & collect file paths āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
1049
|
-
|
|
1050
|
-
const { lines: treeLines, filePaths } = collectFiles(
|
|
1051
|
-
folderPath,
|
|
1052
|
-
folderPath,
|
|
1053
|
-
ignoreDirs,
|
|
1054
|
-
ignoreFiles,
|
|
1055
|
-
onlyFolders,
|
|
1056
|
-
onlyFiles,
|
|
1057
|
-
{ rootName, txtIgnore, force: forceFlag }
|
|
1058
|
-
);
|
|
1059
|
-
|
|
1060
|
-
// āā build output filename āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
1061
|
-
|
|
1062
|
-
let outputFile = outputArg || path.join(folderPath, `${rootName}.txt`);
|
|
1063
|
-
|
|
1064
|
-
// āā handle output splitting āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
1065
|
-
|
|
1066
|
-
const effectiveMaxSize = noSkipFlag ? Infinity : maxFileSize;
|
|
1067
|
-
|
|
1068
|
-
if (splitMethod) {
|
|
1069
|
-
console.log(`š§ Splitting output by: ${splitMethod}`);
|
|
1070
|
-
|
|
1071
|
-
let results;
|
|
1072
|
-
|
|
1073
|
-
if (splitMethod === 'folder') {
|
|
1074
|
-
results = splitByFolders(treeLines, filePaths, rootName, effectiveMaxSize, forceFlag);
|
|
1075
|
-
} else if (splitMethod === 'file') {
|
|
1076
|
-
results = splitByFiles(filePaths, rootName, effectiveMaxSize, forceFlag);
|
|
1077
|
-
} else if (splitMethod === 'size') {
|
|
1078
|
-
results = splitBySize(treeLines, filePaths, rootName, splitSize, effectiveMaxSize, forceFlag);
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
console.log(`ā
Done! Created ${results.length} split files:`);
|
|
1082
|
-
console.log('');
|
|
1083
|
-
|
|
1084
|
-
results.forEach((result, index) => {
|
|
1085
|
-
if (splitMethod === 'folder') {
|
|
1086
|
-
console.log(`š Folder: ${result.folder}`);
|
|
1087
|
-
} else if (splitMethod === 'file') {
|
|
1088
|
-
console.log(`š File: ${result.fileName}`);
|
|
1089
|
-
} else if (splitMethod === 'size') {
|
|
1090
|
-
console.log(`š¦ Part ${result.part}`);
|
|
1091
|
-
}
|
|
1092
|
-
console.log(`š Output : ${result.file}`);
|
|
1093
|
-
console.log(`š Size : ${result.size} KB`);
|
|
1094
|
-
console.log(`šļø Files : ${result.files}`);
|
|
1095
|
-
console.log('');
|
|
1096
|
-
});
|
|
1097
|
-
|
|
1098
|
-
if (copyToClipboardFlag) {
|
|
1099
|
-
console.log('ā ļø --copy flag is not compatible with splitting - clipboard copy skipped');
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
process.exit(0);
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
// āā build output (no splitting) āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
1106
|
-
const out = [];
|
|
1107
|
-
const divider = "=".repeat(80);
|
|
1108
|
-
const subDivider = "-".repeat(80);
|
|
1109
|
-
|
|
1110
|
-
out.push(divider);
|
|
1111
|
-
out.push(`START OF FOLDER: ${rootName}`);
|
|
1112
|
-
out.push(divider);
|
|
1113
|
-
out.push("");
|
|
1114
|
-
|
|
1115
|
-
out.push(divider);
|
|
1116
|
-
out.push("PROJECT STRUCTURE");
|
|
1117
|
-
out.push(divider);
|
|
1118
|
-
out.push(`Root: ${folderPath}\n`);
|
|
1119
|
-
|
|
1120
|
-
out.push(`${rootName}/`);
|
|
1121
|
-
treeLines.forEach(l => out.push(l));
|
|
1122
|
-
out.push("");
|
|
1123
|
-
out.push(`Total files: ${filePaths.length}`);
|
|
1124
|
-
out.push("");
|
|
1125
|
-
|
|
1126
|
-
out.push(divider);
|
|
1127
|
-
out.push("FILE CONTENTS");
|
|
1128
|
-
out.push(divider);
|
|
1129
|
-
|
|
1130
|
-
filePaths.forEach(({ abs, rel }) => {
|
|
1131
|
-
out.push("");
|
|
1132
|
-
out.push(subDivider);
|
|
1133
|
-
out.push(`FILE: ${rel}`);
|
|
1134
|
-
out.push(subDivider);
|
|
1135
|
-
out.push(readContent(abs, forceFlag, effectiveMaxSize));
|
|
1136
|
-
});
|
|
1137
|
-
|
|
1138
|
-
out.push("");
|
|
1139
|
-
out.push(divider);
|
|
1140
|
-
out.push(`END OF FOLDER: ${rootName}`);
|
|
1141
|
-
out.push(divider);
|
|
1142
|
-
|
|
1143
|
-
fs.writeFileSync(outputFile, out.join("\n"), "utf8");
|
|
1144
|
-
|
|
1145
|
-
const sizeKB = (fs.statSync(outputFile).size / 1024).toFixed(1);
|
|
1146
|
-
console.log(`ā
Done!`);
|
|
1147
|
-
console.log(`š Output : ${outputFile}`);
|
|
1148
|
-
console.log(`š Size : ${sizeKB} KB`);
|
|
1149
|
-
console.log(`šļø Files : ${filePaths.length}`);
|
|
1150
|
-
|
|
1151
|
-
if (copyToClipboardFlag) {
|
|
1152
|
-
const content = fs.readFileSync(outputFile, 'utf8');
|
|
1153
|
-
const success = copyToClipboard(content);
|
|
1154
|
-
if (success) {
|
|
1155
|
-
console.log(`š Copied to clipboard!`);
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
|
|
1159
|
-
console.log('');
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
|
-
// Run the main function
|
|
1163
|
-
main().catch(err => {
|
|
1164
|
-
console.error('ā Error:', err.message);
|
|
1165
|
-
process.exit(1);
|
|
1166
|
-
});
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
24
|
--------------------------------------------------------------------------------
|
|
1170
25
|
FILE: /.txtconfig
|
|
1171
26
|
--------------------------------------------------------------------------------
|
|
@@ -1173,9 +28,7 @@ FILE: /.txtconfig
|
|
|
1173
28
|
"maxFileSize": "400KB",
|
|
1174
29
|
"splitMethod": "none",
|
|
1175
30
|
"splitSize": "5MB",
|
|
1176
|
-
"copyToClipboard":
|
|
1177
|
-
"ignoreFolders": ["skip"],
|
|
1178
|
-
"ignoreFiles": ["skip"]
|
|
31
|
+
"copyToClipboard": true
|
|
1179
32
|
}
|
|
1180
33
|
|
|
1181
34
|
--------------------------------------------------------------------------------
|
|
@@ -1209,7 +62,7 @@ FILE: /package.json
|
|
|
1209
62
|
--------------------------------------------------------------------------------
|
|
1210
63
|
{
|
|
1211
64
|
"name": "make-folder-txt",
|
|
1212
|
-
"version": "2.2.
|
|
65
|
+
"version": "2.2.1",
|
|
1213
66
|
"description": "Generate a single .txt file containing the full folder structure and file contents of any project, ignoring node_modules and other junk.",
|
|
1214
67
|
"main": "bin/make-folder-txt.js",
|
|
1215
68
|
"bin": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "make-folder-txt",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
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": {
|