Skip to content

Instantly share code, notes, and snippets.

@SanariSan
Created May 14, 2025 11:21
Show Gist options
  • Save SanariSan/e760f868586ee59cf4e4eff51d4d0daa to your computer and use it in GitHub Desktop.
Save SanariSan/e760f868586ee59cf4e4eff51d4d0daa to your computer and use it in GitHub Desktop.
Recursively clip code files with path prepend (for ai to get proj summary)
import { appendFileSync, readFileSync } from 'fs';
import { readdir } from 'fs/promises';
import { join } from 'path';
const ROOT = './src';
const OUT = 'samples_clipped.txt';
const init = async () => {
const entries = await readdir(ROOT, {
recursive: true,
withFileTypes: true,
});
const files = entries.filter((e) => e.isFile());
for (const entry of files) {
const fullPath = join(entry.parentPath, entry.name);
const content = readFileSync(fullPath, 'utf-8');
const out = `/*start of file [${fullPath}]*/\n` + content;
appendFileSync(OUT, out + `/*end of file [${fullPath}]*/\n\n`);
}
};
init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment