assets.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. # Try to generate from source file name
  12. TARGET_FILE=$(echo "${SOURCE_FILE}" | sed 's/\.dev\.\(css\|js\)$/.\1/')
  13. if [[ "${TARGET_FILE}" = "" ]]; then
  14. echo "Target file is not set"
  15. exit 1
  16. fi
  17. fi
  18. # Check if source file exists
  19. if [[ ! -f "${SOURCE_FILE}" ]]; then
  20. echo "Source file does not exists: ${SOURCE_FILE}"
  21. exit 1
  22. fi
  23. # Re-create empty target file
  24. if [[ -f "${TARGET_FILE}" ]]; then
  25. rm ${TARGET_FILE}
  26. fi
  27. touch ${TARGET_FILE}
  28. IFS=""
  29. while read line; do
  30. if [[ ${line} == "/*"* ]]; then
  31. if [[ ${line} == *"*/" ]]; then
  32. if [[ ${line} == *"import("* ]]; then
  33. FILE_TO_IMPORT=$(echo "${line}" | grep -oP "/*\s?import\(\K[^)]+")
  34. DATA_TO_IMPORT=$(curl -s "${FILE_TO_IMPORT}")
  35. echo "${DATA_TO_IMPORT}" >> ${TARGET_FILE}
  36. else
  37. echo "${line}" >> ${TARGET_FILE}
  38. fi
  39. else
  40. echo "${line}" >> ${TARGET_FILE}
  41. fi
  42. else
  43. echo "${line}" >> ${TARGET_FILE}
  44. fi
  45. done < ${SOURCE_FILE}