Created
April 6, 2025 04:12
-
-
Save iamsonal/f17a74726e7b3a373af8c8ce73c1dc34 to your computer and use it in GitHub Desktop.
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
| #!/bin/bash | |
| # --- Configuration --- | |
| PROCESS_CLASSES=true | |
| PROCESS_OBJECTS=true | |
| PROCESS_LWC=false | |
| EXCLUDE_TEST_CLASSES=true | |
| # --- End Configuration --- | |
| BASE_PATH="force-app/main/default" | |
| OUTPUT_FILE="sfdx_code_dump.txt" | |
| # Clear the output file before starting | |
| > "$OUTPUT_FILE" | |
| # Helper function to filter out hidden files | |
| is_hidden_file() { | |
| [[ "$(basename "$1")" == .* ]] | |
| } | |
| # Function to process Apex classes | |
| dump_apex_classes() { | |
| echo "Dumping Apex Classes (.cls files)..." | tee -a "$OUTPUT_FILE" | |
| if [ "$EXCLUDE_TEST_CLASSES" = true ]; then | |
| echo "(Excluding files ending with Test.cls)" | tee -a "$OUTPUT_FILE" | |
| fi | |
| echo "======================================" >> "$OUTPUT_FILE" | |
| find "$BASE_PATH/classes" -type f -name "*.cls" 2>/dev/null | while read -r cls_file; do | |
| filename=$(basename "$cls_file") | |
| if is_hidden_file "$cls_file"; then | |
| continue | |
| fi | |
| if [ "$EXCLUDE_TEST_CLASSES" = true ] && [[ "$filename" == *Test.cls ]]; then | |
| continue | |
| fi | |
| echo "--- File: ${cls_file#$BASE_PATH/} ---" >> "$OUTPUT_FILE" | |
| cat "$cls_file" >> "$OUTPUT_FILE" | |
| echo -e "\n" >> "$OUTPUT_FILE" | |
| done | |
| } | |
| # Function to process Custom Object fields | |
| dump_custom_objects() { | |
| echo "Dumping Custom Object Field Definitions..." | tee -a "$OUTPUT_FILE" | |
| echo "==========================================" >> "$OUTPUT_FILE" | |
| find "$BASE_PATH/objects" -type d -name "fields" 2>/dev/null | while read -r fields_dir; do | |
| find "$fields_dir" -type f 2>/dev/null | while read -r field_file; do | |
| if is_hidden_file "$field_file"; then | |
| continue | |
| fi | |
| echo "--- File: ${field_file#$BASE_PATH/} ---" >> "$OUTPUT_FILE" | |
| cat "$field_file" >> "$OUTPUT_FILE" | |
| echo -e "\n" >> "$OUTPUT_FILE" | |
| done | |
| done | |
| } | |
| # Function to process LWC components | |
| dump_lwc_components() { | |
| echo "Dumping LWC Components..." | tee -a "$OUTPUT_FILE" | |
| echo "======================================" >> "$OUTPUT_FILE" | |
| find "$BASE_PATH/lwc" -type f 2>/dev/null | while read -r lwc_file; do | |
| if is_hidden_file "$lwc_file"; then | |
| continue | |
| fi | |
| echo "--- File: ${lwc_file#$BASE_PATH/} ---" >> "$OUTPUT_FILE" | |
| cat "$lwc_file" >> "$OUTPUT_FILE" | |
| echo -e "\n" >> "$OUTPUT_FILE" | |
| done | |
| } | |
| # Run based on flags | |
| [ "$PROCESS_CLASSES" = true ] && dump_apex_classes | |
| [ "$PROCESS_OBJECTS" = true ] && dump_custom_objects | |
| [ "$PROCESS_LWC" = true ] && dump_lwc_components | |
| echo "✅ Code dump completed: $OUTPUT_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment