concatenate_swift_files.sh 1018 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. #
  3. # Combines *.swift files into a single file.
  4. #
  5. # Usage
  6. # ------
  7. #
  8. # ./combine_swift_files.sh source_dir destination_file [optional_header_text]
  9. #
  10. destination=$2
  11. headermessage=$3
  12. if [ "$#" -lt 2 ]
  13. then
  14. echo "\nUsage:\n"
  15. echo " ./combine_swift_files.sh source_dir destination_file [optional_header_text]\n"
  16. exit 1
  17. fi
  18. # Create empty destination file
  19. echo > "$destination";
  20. text=""
  21. destination_filename=$(basename "$destination")
  22. for swift in `find $1 ! -name "$destination_filename" -name "*.swift"`;
  23. do
  24. filename=$(basename "$swift")
  25. text="$text\n// ----------------------------";
  26. text="$text\n//";
  27. text="$text\n// ${filename}";
  28. text="$text\n//";
  29. text="$text\n// ----------------------------\n\n";
  30. text="$text$(cat "${swift}";)\n\n";
  31. echo "Combining $swift";
  32. done;
  33. # Add header message
  34. if [ -n "$headermessage" ]
  35. then
  36. text="$headermessage\n\n$text"
  37. fi
  38. # Write to destination file
  39. echo -e "$text" > "$destination"
  40. echo -e "\nSwift files combined into $destination"