Skip to content

Instantly share code, notes, and snippets.

@SanariSan
Last active November 20, 2025 11:01
Show Gist options
  • Select an option

  • Save SanariSan/e760f868586ee59cf4e4eff51d4d0daa to your computer and use it in GitHub Desktop.

Select an option

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 = './';
const IGNORE: (string | RegExp)[] = [
'img',
'.github',
'.git',
'.gitignore',
'.npmignore',
'ai.ignore.ts',
'CHANGELOG.md',
'README.md',
'pnpm-lock.yaml',
'yarn.lock',
'tsconfig.json',
'eslint.config.js',
'node_modules',
'vite.config.ts',
'LICENSE',
'build.sh',
'lefthook.yml',
'.editorconfig',
new RegExp('.*.txt'),
'test',
];
const OUT = 'out.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);
if (IGNORE.some((el) => (el instanceof RegExp ? el.test(fullPath) : fullPath.includes(el)))) {
continue;
}
console.log({ fullPath });
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