-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexport-code.js
More file actions
102 lines (80 loc) · 2.08 KB
/
Copy pathexport-code.js
File metadata and controls
102 lines (80 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
const OUTPUT_FILE = 'all-project-code.txt';
const ALLOWED_EXTENSIONS = new Set([
'.ts',
'.js',
'.tsx',
'.jsx',
'.sql',
'.md',
]);
const EXCLUDED_FILENAMES = new Set([
'package-lock.json',
'pnpm-lock.yaml',
'yarn.lock',
]);
// Optional folder filter
let targetPath = process.argv[2];
if (targetPath) {
targetPath = targetPath
.replace(/\\/g, '/')
.replace(/^\.\//, '')
.replace(/\/+$/, '');
}
try {
let files = execSync('git ls-files --cached --others --exclude-standard', {
encoding: 'utf8',
})
.split('\n')
.filter(Boolean)
.sort();
// Filter by folder if provided
if (targetPath) {
files = files.filter((file) => {
const normalized = file.replace(/\\/g, '/');
return (
normalized === targetPath || normalized.startsWith(targetPath + '/')
);
});
}
// Filter by extension
files = files.filter((file) => {
const filename = path.basename(file);
if (EXCLUDED_FILENAMES.has(filename)) {
return false;
}
const ext = path.extname(file).toLowerCase();
return ALLOWED_EXTENSIONS.has(ext);
});
let output = `
============================================================
PROJECT EXPORT
Generated: ${new Date().toISOString()}
============================================================
Path Filter: ${targetPath || 'ALL'}
Files Exported: ${files.length}
`;
for (const file of files) {
output += `
============================================================
FILE: ${file}
============================================================
`;
try {
output += fs.readFileSync(file, 'utf8');
output += '\n';
} catch (err) {
output += `[ERROR READING FILE]\n${err.message}\n`;
}
}
fs.writeFileSync(OUTPUT_FILE, output);
console.log(`✅ Exported ${files.length} files`);
console.log(`📄 Output: ${OUTPUT_FILE}`);
if (targetPath) {
console.log(`📂 Filtered Path: ${targetPath}`);
}
} catch (err) {
console.error('❌ Error:', err.message);
}