-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport-debug-bundle.sh
More file actions
executable file
·111 lines (95 loc) · 2.18 KB
/
Copy pathexport-debug-bundle.sh
File metadata and controls
executable file
·111 lines (95 loc) · 2.18 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
108
109
110
111
#!/usr/bin/env bash
set -Eeuo pipefail
PROJECT_ROOT="${1:-$(pwd)}"
OUTPUT_FILE="${2:-$PROJECT_ROOT/codedock-debug-bundle.txt}"
if [[ ! -d "$PROJECT_ROOT" ]]; then
echo "ERROR: Project root does not exist: $PROJECT_ROOT" >&2
exit 1
fi
cd "$PROJECT_ROOT"
INCLUDE_EXTENSIONS=(
"*.go"
"*.ts"
"*.tsx"
"*.js"
"*.jsx"
"*.json"
"*.md"
"*.txt"
"*.yaml"
"*.yml"
"*.sql"
"*.sh"
"*.bash"
"*.zsh"
"*.html"
"*.css"
"*.scss"
"*.xml"
"*.toml"
"*.ini"
"*.cfg"
"*.conf"
"Dockerfile"
".env.example"
)
EXCLUDE_DIRS=(
".git"
"node_modules"
"dist"
"build"
".next"
"coverage"
".turbo"
".cache"
"tmp"
"vendor"
".idea"
".vscode-test"
)
build_find_expr() {
local first=1
for dir in "${EXCLUDE_DIRS[@]}"; do
if [[ $first -eq 1 ]]; then
printf '( -path "./%s" -o -path "./%s/*"' "$dir" "$dir"
first=0
else
printf ' -o -path "./%s" -o -path "./%s/*"' "$dir" "$dir"
fi
done
printf ' )'
}
EXCLUDE_EXPR="$(build_find_expr)"
{
echo "============================================================"
echo "CodeDock Debug Bundle"
echo "Generated at: $(date -Iseconds)"
echo "Project root: $PROJECT_ROOT"
echo "============================================================"
echo
echo "==================== FILE TREE =============================="
echo
find . $(printf '! %s ' "$EXCLUDE_EXPR") -prune -o -type f -print 2>/dev/null | sort
echo
echo "==================== FILE CONTENTS =========================="
echo
while IFS= read -r file; do
rel="${file#./}"
echo "------------------------------------------------------------"
echo "FILE: $rel"
echo "------------------------------------------------------------"
if file "$file" | grep -qiE 'text|json|xml|javascript|typescript|html|css|shell|unicode'; then
sed -n '1,400p' "$file"
else
echo "[skipped non-text or unsupported file]"
fi
echo
done < <(
find . $(printf '! %s ' "$EXCLUDE_EXPR") -prune -o -type f \( \
$(printf -- '-name "%s" -o ' "${INCLUDE_EXTENSIONS[@]}" | sed 's/ -o $//') \
\) -print | sort
)
} > "$OUTPUT_FILE"
echo "Done."
echo "Bundle written to: $OUTPUT_FILE"
wc -l "$OUTPUT_FILE"