Created
May 12, 2026 13:03
-
-
Save kalwalt/1f44c8916cf51b09f31397c6d470e67c to your computer and use it in GitHub Desktop.
A script to bundle source files into a single Markdown file for analysis (e.g., NotebookLM).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import argparse | |
| # Configurazioni: estensioni supportate | |
| EXTENSIONS = ('.cpp', '.h', '.hpp', '.js', '.ts', '.txt', '.ino') | |
| # Cartelle da ignorare | |
| IGNORE_DIRS = {'node_modules', 'build', 'dist', '.git', 'emsdk', 'venv'} | |
| def bundle_code(output_filename): | |
| # Assicuriamoci che il file abbia l'estensione .md | |
| if not output_filename.endswith('.md'): | |
| output_filename += '.md' | |
| try: | |
| with open(output_filename, 'w', encoding='utf-8') as outfile: | |
| outfile.write(f"# Project Codebase Bundle\n") | |
| outfile.write(f"Generato automaticamente per l'analisi in NotebookLM\n\n") | |
| for root, dirs, files in os.walk('.'): | |
| # Filtra le cartelle ignorate | |
| dirs[:] = [d for d in dirs if d not in IGNORE_DIRS] | |
| for file in files: | |
| if file.endswith(EXTENSIONS): | |
| file_path = os.path.join(root, file) | |
| outfile.write(f"## File: {file_path}\n") | |
| # Mapping linguaggio per il markdown | |
| lang_map = { | |
| '.cpp': 'cpp', '.h': 'cpp', '.hpp': 'cpp', | |
| '.js': 'javascript', '.ts': 'typescript', | |
| '.txt': 'text', '.ino': 'cpp' | |
| } | |
| ext = os.path.splitext(file)[1] | |
| lang = lang_map.get(ext, "") | |
| outfile.write(f"```{lang}\n") | |
| try: | |
| with open(file_path, 'r', encoding='utf-8') as infile: | |
| outfile.write(infile.read()) | |
| except Exception as e: | |
| outfile.write(f"// Errore nella lettura del file: {e}\n") | |
| outfile.write(f"\n```\n\n") | |
| print(f"✅ Successo! Il bundle è stato salvato in: {output_filename}") | |
| except Exception as e: | |
| print(f"❌ Errore durante la creazione del file: {e}") | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser(description="Concatena i file sorgente in un unico file Markdown per NotebookLM.") | |
| # Aggiunta dell'argomento con un valore di default | |
| parser.add_argument( | |
| "filename", | |
| nargs="?", | |
| default="project_bundle.md", | |
| help="Il nome del file di output (default: project_bundle.md)" | |
| ) | |
| args = parser.parse_args() | |
| bundle_code(args.filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment