Skip to content

Instantly share code, notes, and snippets.

@macghriogair
Created April 25, 2019 09:35
Show Gist options
  • Save macghriogair/5a0a36fad534fa5c23592b4ab2793082 to your computer and use it in GitHub Desktop.
Save macghriogair/5a0a36fad534fa5c23592b4ab2793082 to your computer and use it in GitHub Desktop.
[ERD diagram generation via Makefile] #erd #make
#!/usr/bin/make -f
.DEFAULT_GOAL := help
.ONESHELL:
cwd := $(shell pwd)
comma := ,
.PHONY: build-erd
ERD_BIN := $(shell command -v erd 2> /dev/null)
ERD_INPUT_DIR := './docs/erm'
ERD_OUTPUT_DIR := '$(ERD_INPUT_DIR)/output'
ERD_FILES := $(notdir $(shell find $(ERD_INPUT_DIR)/*.er -type f))
# currently OSX only
PDF_MERGER := '/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py'
build-erd: $(ERD_OUTPUT_DIR)/svg $(ERD_OUTPUT_DIR)/pdf ## Build ER diagrams from .er files located in docs folder
@echo "Generate SVGs and PDFs.."
ifndef ERD_BIN
$(error "erd is not available. please install")
endif
@for file in $(ERD_FILES); do \
$(ERD_BIN) -i $(ERD_INPUT_DIR)/$$file -o $(ERD_OUTPUT_DIR)/svg/$$file.svg; \
$(ERD_BIN) -i $(ERD_INPUT_DIR)/$$file -o $(ERD_OUTPUT_DIR)/pdf/$$file.pdf; \
done; \
@echo "Merging PDFs.."
@test -f $(PDF_MERGER) || (echo "No merge tool available, exiting without merging."; exit 1)
@$(PDF_MERGER) -o $(ERD_OUTPUT_DIR)/pdf/merged.pdf $(ERD_OUTPUT_DIR)/pdf/*.pdf
@open $(ERD_OUTPUT_DIR)/pdf/merged.pdf
@echo "Done."
$(ERD_OUTPUT_DIR)/svg:
@rm -rf mkdir -p $(ERD_OUTPUT_DIR)/svg
@mkdir -p $(ERD_OUTPUT_DIR)/svg
$(ERD_OUTPUT_DIR)/pdf:
@rm -rf $(ERD_OUTPUT_DIR)/pdf
@mkdir -p $(ERD_OUTPUT_DIR)/pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment