forked from Bluma-Protocol-Org/Bluma-Protocol-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_code_context.sh
executable file
·62 lines (50 loc) · 1.74 KB
/
get_code_context.sh
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
#!/bin/bash
# This works for next.js projects currently
# Put this in your root folder of your project
# run the command chmod +x get_code_context.sh
# then run ./get_code_context.sh
# Use the current directory as the project directory
project_dir=$(pwd)
# Use a fixed name for the output file in the current directory
output_file="${project_dir}/code_context.txt"
# Check if the output file exists and remove it if it does
if [ -f "$output_file" ]; then
rm "$output_file"
fi
# List of directories to look for
directories=("app" "components" "config" "constants" "context" "lib" "providers" "services")
# directories=("src")
# List of file types to ignore
ignore_files=("*.ico" "*.png" "*.jpg" "*.jpeg" "*.gif" "*.svg")
# Recursive function to read files and append their content
read_files() {
for entry in "$1"/*
do
if [ -d "$entry" ]; then
# If entry is a directory, call this function recursively
read_files "$entry"
elif [ -f "$entry" ]; then
# Check if the file type should be ignored
should_ignore=false
for ignore_pattern in "${ignore_files[@]}"; do
if [[ "$entry" == $ignore_pattern ]]; then
should_ignore=true
break
fi
done
# If the file type should not be ignored, append its relative path and content to the output file
if ! $should_ignore; then
relative_path=${entry#"$project_dir/"}
echo "// File: $relative_path" >> "$output_file"
cat "$entry" >> "$output_file"
echo "" >> "$output_file"
fi
fi
done
}
# Call the recursive function for each specified directory in the project directory
for dir in "${directories[@]}"; do
if [ -d "${project_dir}/${dir}" ]; then
read_files "${project_dir}/${dir}"
fi
done