Skip to content

Instantly share code, notes, and snippets.

@derektamsen
Last active December 25, 2023 07:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save derektamsen/c0cd95efc2132b93b4af348c8cbd04e3 to your computer and use it in GitHub Desktop.
Save derektamsen/c0cd95efc2132b93b4af348c8cbd04e3 to your computer and use it in GitHub Desktop.
Makefile to render all mermaid diagrams in the directory it is placed in.
src_files := $(wildcard *.mmd)
out_files := $(patsubst %.mmd,output/%.png,$(src_files))
.PHONY: all clean
all: $(out_files)
output/%.png: %.mmd
mkdir -p $(dir $@)
mmdc -c ./mermaidconfig.json \
-i $< \
-o $@
clean:
rm output/*.png
{
"theme": "default"
}
@Enough7
Copy link

Enough7 commented Dec 22, 2023

Hey,
thanks for sharing your work.
I modified it a little bit, so that the build is only run when the origin-diagram changed and clean only deletes the images in output not the whole folder.

src_files := $(wildcard *.mmd)
out_files := $(patsubst %.mmd,output/%.png,$(src_files))

.PHONY: all clean

all: $(out_files)

output/%.png: %.mmd
	mkdir -p $(dir $@)
	mmdc -c ./mermaidconfig.json \
		-i $< \
		-o $@

clean:
	rm output/*.png

mermaidconfig.json:

{
    "theme": "default"
}

@derektamsen
Copy link
Author

@Enough7 You are welcome! Thanks of the modification. I have also updated the gist with your suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment