Skip to content

Instantly share code, notes, and snippets.

@Dave-lab12
Created November 27, 2025 08:36
Show Gist options
  • Select an option

  • Save Dave-lab12/aa01e0da840d7ad1d9795befe4eb7126 to your computer and use it in GitHub Desktop.

Select an option

Save Dave-lab12/aa01e0da840d7ad1d9795befe4eb7126 to your computer and use it in GitHub Desktop.
// node collect-code.js [paths-to-ignore...]
import { readFileSync, writeFileSync, readdirSync, statSync } from 'fs';
import { join, relative, extname } from 'path';
const rootDir = process.cwd();
const output = [];
const ignore = [
'node_modules',
'dist',
'build',
'.git',
'.svelte-kit',
'src/generated',
...process.argv.slice(2)
];
const codeExts = [
'.js', '.ts', '.jsx', '.tsx', '.svelte',
'.html', '.css', '.scss', '.json',
'.yml', '.yaml', '.md', '.sh'
];
function shouldIgnore(path) {
const rel = relative(rootDir, path);
return ignore.some(p => rel === p || rel.startsWith(p + '/'));
}
function walk(dir) {
if (shouldIgnore(dir)) return;
for (const entry of readdirSync(dir)) {
if (entry.startsWith('.')) continue;
const path = join(dir, entry);
const stats = statSync(path);
if (stats.isDirectory()) {
walk(path);
} else if (codeExts.includes(extname(path)) && !shouldIgnore(path)) {
const rel = relative(rootDir, path);
const content = readFileSync(path, 'utf8');
output.push(`\n${'='.repeat(60)}\nFILE: ${rel}\n${'='.repeat(60)}\n\n${content}`);
console.log(`Added: ${rel}`);
}
}
}
walk(rootDir);
writeFileSync('project-code-collection.txt', output.join('\n'));
console.log(`\nDone! ${output.length} files collected.`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment