template.sh 1.2 KB

123456789101112131415161718192021222324252627282930
  1. #!/bin/bash
  2. find ./engine/assets/template/ ! -name 'template.go' -type f -exec rm -f {} +
  3. echo "package template" > ./engine/assets/template/template.go
  4. echo "" >> ./engine/assets/template/template.go
  5. echo "var AllData = map[string][]byte{" >> ./engine/assets/template/template.go
  6. for FILE_FULL in $(find ./hosts/localhost/template/ | grep -v 'hosts/localhost/template/$' | grep -v '.keep'); do
  7. FILE_BASE="$(basename -- $FILE_FULL)"
  8. FILE_GO_BASE="${FILE_BASE//[\-\.]/_}_file.go"
  9. FILE_GO_FULL="./engine/assets/template/${FILE_GO_BASE}"
  10. GO_VAR_NAME="${FILE_GO_BASE}"
  11. GO_VAR_NAME=$(echo "$GO_VAR_NAME" | sed -E 's/^([a-zA-Z]{1})/\U\1/g')
  12. GO_VAR_NAME=$(echo "$GO_VAR_NAME" | sed -E 's/(_)([a-zA-Z]{1})/\U\2/g')
  13. GO_VAR_NAME=$(echo "$GO_VAR_NAME" | sed -e 's/\.go$//g')
  14. GO_VAR_NAME="Var${GO_VAR_NAME}"
  15. FILE_CONTENT=$(cat ${FILE_FULL})
  16. FILE_CONTENT=$(echo "$FILE_CONTENT" | sed -E 's/([`]+)/` + "\1" + `/g')
  17. # Write target file
  18. echo "package template" > ${FILE_GO_FULL}
  19. echo "" >> ${FILE_GO_FULL}
  20. echo "var ${GO_VAR_NAME} = []byte(\`${FILE_CONTENT}\`)" >> ${FILE_GO_FULL}
  21. # Add files to hash
  22. echo " \"${FILE_BASE}\": ${GO_VAR_NAME}," >> ./engine/assets/template/template.go
  23. done
  24. echo "}" >> ./engine/assets/template/template.go