#!/bin/sh
#
# Create individual and combined schema diagrams
#

set -e

for format in svg pdf ; do
  # Create individual schema diagrams
  for schema in crossref orcid ror uspto ; do
    (
      cat docs/schema/schema-head.dot docs/schema/$schema.dot
      bin/a3k list-source-schema $schema | bin/schema2dot.sed
    ) | dot -T$format  -o docs/schema/$schema.$format
  done

  # Create the "other" schema diagram
    (
      cat docs/schema/schema-head.dot docs/schema/other.dot
      (
        for schema in asjcs doaj funder-names journal-names ; do
          bin/a3k list-source-schema $schema
        done
        bin/a3k list-process-schema
      ) | bin/schema2dot.sed
    ) | dot -T$format  -o docs/schema/other.$format

  # Create combined schema diagram
  (
    ( cd docs/schema ; cat schema-head.dot crossref.dot orcid.dot ror.dot uspto.dot other.dot )
    ( bin/a3k list-source-schema ; bin/a3k list-process-schema ) |
      bin/schema2dot.sed
  ) | dot -T$format  -o docs/schema/all.$format
done
