-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge.sh
57 lines (47 loc) · 1.71 KB
/
merge.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
#!/bin/bash
# Set output file
output_file="merged_modules_and_tests.txt"
# Remove output file if it exists
rm -f "$output_file"
# Function to print folder structure
print_structure() {
echo -e "\nFolder Structure:" > "$output_file"
tree modules tests >> "$output_file"
echo -e "\n\n=== Begin File Contents ===\n\n" >> "$output_file"
}
# Function to append specific files if they exist
append_file_if_exists() {
local file=$1
if [ -f "$file" ]; then
echo -e "\n\n=== File: $file ===\n" >> "$output_file"
cat "$file" >> "$output_file"
echo -e "\n--- End of $file ---\n" >> "$output_file"
fi
}
# Print the folder structure first
print_structure
# Directories to process
directories=("modules" "tests")
# Process files folder by folder
for dir in "${directories[@]}"; do
for folder in $(find "$dir" -type d | sort); do
# Add folder name if it contains files
if [ -n "$(ls -A $folder/*.js 2>/dev/null)" ]; then
echo -e "\n\n=== Folder: $folder ===\n" >> "$output_file"
# Process each .js file in the folder
for file in $folder/*.js; do
if [ -f "$file" ]; then
echo -e "\n--- File: $file ---\n" >> "$output_file"
cat "$file" >> "$output_file"
echo -e "\n--- End of $file ---\n" >> "$output_file"
fi
done
fi
done
done
# Append specific root-level files if they exist
root_files=("package.json" ".babelrc" "jest.config.js" "jest.setup.js")
for file in "${root_files[@]}"; do
append_file_if_exists "$file"
done
echo "Files from 'modules', 'tests', and specific root-level files have been merged into $output_file"