cutbox_theme_validator 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env bash
  2. error="no"
  3. if [[ "$(which jv)" == "jv not found" ]]; then
  4. echo "jv is required for json schema validation"
  5. echo "go install github.com/santhosh-tekuri/jsonschema/v5/cmd/jv@v5"
  6. exit 2
  7. fi
  8. if (( $# != 1 )); then
  9. echo "
  10. Validate a .cutboxTheme file
  11. usage: $(basename $0) <cutbox_theme_filename>
  12. "
  13. exit 1
  14. fi
  15. json=$1
  16. jv https://cutbox.github.io/schema/cutbox.theme.schema.json "$json" 2>&1 \
  17. | perl -pe 's|/|.|g' \
  18. | perl -pe 's|\$defs|defs|g' \
  19. | perl -pe 's|\[[SI]#(.*?)\]|\1|g' \
  20. | perl -pe 's|[.]properties[.].*[.]\$ref\E||' \
  21. | perl -pe "s| doesn't validate with '.defs.hex-color'|doesn't validate|" \
  22. | perl -pe "s|\Q'^ *#?[0-9a-fA-F]{6,8} *$'\E||" \
  23. | sed 's|http:..||' \
  24. | tr -d "'#]$" \
  25. | perl -pe "s|\Q.defs.hex-color.pattern does not match pattern\E|: invalid hex color:|"a \
  26. | sed 's|cutbox.github.io.schemas.cutbox.theme.schema.json||' \
  27. | sed "s| doesnt validate with|[Error] Invalid CutBox Theme :: $json\n|" \
  28. | perl -pe "s|\..* doesnt validate\n||" \
  29. | perl -pe "s|^ *||" \
  30. | while read line; do
  31. if [[ "${line}" =~ ": invalid hex color" ]]; then
  32. property=$(perl -pe "s|(.*) : invalid hex color:|\1|" <<< $line)
  33. echo "${line} ⟶ $(jq "$property" "$json")"
  34. else
  35. echo ${line}
  36. fi
  37. done \
  38. | while read line; do
  39. if [[ "$line" == "[Error] Invalid CutBox Theme :: $json" ]]; then
  40. error="yes"
  41. printf "\x1B[1;31m[Error]\x1B[0m Invalid CutBox Theme :: $json"
  42. else
  43. echo "$line"
  44. fi
  45. done
  46. if [[ "$error" == "no" ]]; then
  47. exit 0
  48. else
  49. exit 1
  50. fi