/ faang-playbook / scripts / dump_repo.py
swadhinbiswas feat: add Netflix L5 interview playbook · 2/2/2026
41c1cbb
107 lines · 2.9 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
103
104
105
106
107
#!/usr/bin/env python3
"""Generate a single-file dump of the repository.

Outputs:
- TREE.txt: a simple directory tree
- REPO_DUMP.md: tree + full contents of every .md file

This is useful when you need to share the repo as a single artifact.
"""

from __future__ import annotations

import os
from pathlib import Path


REPO_ROOT = Path(__file__).resolve().parents[1]
OUTPUT_TREE = REPO_ROOT / "TREE.txt"
OUTPUT_DUMP = REPO_ROOT / "REPO_DUMP.md"


def is_hidden(path: Path) -> bool:
    return any(part.startswith(".") for part in path.parts)


def iter_paths(root: Path) -> list[Path]:
    paths: list[Path] = []
    for p in sorted(root.rglob("*")):
        rel = p.relative_to(root)
        if is_hidden(rel):
            continue
        if rel.parts and rel.parts[0] in {".git"}:
            continue
        paths.append(p)
    return paths


def render_tree(root: Path) -> str:
    lines: list[str] = []
    for p in iter_paths(root):
        rel = p.relative_to(root)
        depth = len(rel.parts) - 1
        indent = "  " * depth
        name = rel.name + ("/" if p.is_dir() else "")
        lines.append(f"{indent}{name}")
    return "\n".join(lines) + "\n"


def iter_markdown_files(root: Path) -> list[Path]:
    md_files: list[Path] = []
    for p in root.rglob("*.md"):
        rel = p.relative_to(root)
        if is_hidden(rel):
            continue
        if rel.parts and rel.parts[0] in {".git"}:
            continue
        if rel.name in {OUTPUT_DUMP.name, OUTPUT_TREE.name}:
            continue
        md_files.append(p)

    # Sort with stable, human-friendly ordering.
    return sorted(md_files, key=lambda x: str(x.relative_to(root)).lower())


def main() -> int:
    tree_text = render_tree(REPO_ROOT)
    OUTPUT_TREE.write_text(tree_text, encoding="utf-8")

    md_files = iter_markdown_files(REPO_ROOT)

    # Use 4-backtick fences so embedded ``` blocks don't break the dump.
    fence = "````"

    out_lines: list[str] = []
    out_lines.append("# BigTech-FAANG-Job-Roadmap — Repo Dump")
    out_lines.append("")
    out_lines.append("This file is auto-generated by `scripts/dump_repo.py`.")
    out_lines.append("")
    out_lines.append("## Tree")
    out_lines.append(f"{fence}text")
    out_lines.append(tree_text.rstrip("\n"))
    out_lines.append(fence)
    out_lines.append("")
    out_lines.append("## Files")
    out_lines.append("")

    for p in md_files:
        rel = p.relative_to(REPO_ROOT).as_posix()
        content = p.read_text(encoding="utf-8")
        out_lines.append(f"### {rel}")
        out_lines.append("")
        out_lines.append(f"{fence}markdown")
        out_lines.append(content.rstrip("\n"))
        out_lines.append(fence)
        out_lines.append("")

    OUTPUT_DUMP.write_text("\n".join(out_lines).rstrip("\n") + "\n", encoding="utf-8")

    print(f"Wrote: {OUTPUT_TREE}")
    print(f"Wrote: {OUTPUT_DUMP}")
    print(f"Markdown files included: {len(md_files)}")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())