generate.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env bash
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # generate.sh — generates railroad diagrams for the SQL grammar.
  12. set -euo pipefail
  13. cd "$(dirname "$0")"
  14. dest=../layouts/partials/sql-grammar
  15. # Clean up files from last run.
  16. rm -rf scratch
  17. # Run the railroad diagram generator, using a pinned version from our custom
  18. # fork.
  19. docker run --rm -i materialize/rr:v0.0.5 -nostyles -svg -noinline -width:600 - < sql-grammar.bnf > diagrams.zip
  20. # Extract the SVGs we care about and move them into place.
  21. mkdir scratch
  22. (
  23. cd scratch
  24. unzip -j ../diagrams.zip
  25. rm -f ../diagrams.zip Railroad-Diagram-Generator.svg index.html
  26. for f in *; do
  27. # Rewrite any underscores in filenames to hyphens, for consistency with
  28. # other Hugo partials.
  29. if [[ $f = *_* ]]; then
  30. mv -f "$f" "${f//_/-}"
  31. fi
  32. done
  33. )
  34. rm -rf $dest
  35. mv scratch $dest
  36. # ping hugo again
  37. sleep 3
  38. touch "$dest"/*