assets.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/bash
  2. SOURCE_FILE=${1}
  3. TARGET_FILE=${2}
  4. # Check if source file is set
  5. if [[ "${SOURCE_FILE}" = "" ]]; then
  6. echo "Source file is not set"
  7. exit 1
  8. fi
  9. # Check if target file is set
  10. if [[ "${TARGET_FILE}" = "" ]]; then
  11. echo "Target file is not set"
  12. exit 1
  13. fi
  14. # Check if source file exists
  15. if [[ ! -f "${SOURCE_FILE}" ]]; then
  16. echo "Source file does not exists: ${SOURCE_FILE}"
  17. exit 1
  18. fi
  19. # Re-create empty target file
  20. if [[ -f "${TARGET_FILE}" ]]; then
  21. rm ${TARGET_FILE}
  22. fi
  23. touch ${TARGET_FILE}
  24. IFS=""
  25. while read line; do
  26. if [[ ${line} == "/*"* ]]; then
  27. if [[ ${line} == *"*/" ]]; then
  28. if [[ ${line} == *"import("* ]]; then
  29. FILE_TO_IMPORT=$(echo "${line}" | grep -oP "/*\s?import\(\K[^)]+")
  30. DATA_TO_IMPORT=$(curl -s "${FILE_TO_IMPORT}")
  31. echo "${DATA_TO_IMPORT}" >> ${TARGET_FILE}
  32. else
  33. echo "${line}" >> ${TARGET_FILE}
  34. fi
  35. else
  36. echo "${line}" >> ${TARGET_FILE}
  37. fi
  38. else
  39. echo "${line}" >> ${TARGET_FILE}
  40. fi
  41. done < ${SOURCE_FILE}