Skip to content

Commit

Permalink
Use a tempfile while recompiling the views
Browse files Browse the repository at this point in the history
so the target file is not truncated before the recompilation is done, which will trigger livereload on an empty file
  • Loading branch information
baelter committed Oct 10, 2024
1 parent 66999bc commit e7a1c7e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ override CRYSTAL_FLAGS += --error-on-warnings --link-flags=-pie
livereload:
@echo "Starting livereload server..."
@which livereload > /dev/null || npm install -g livereload
@(pid=$$!; trap 'kill -TERM $$pid' INT; livereload -w 2000 static &)
@(pid=$$!; trap 'kill -TERM $$pid' INT; livereload static &)

.PHONY: views
views: $(VIEW_TARGETS)
Expand All @@ -25,7 +25,10 @@ dev-ui: livereload watch-views

static/views/%.html: views/%.ecr $(VIEW_PARTIALS)
@mkdir -p static/views
@INPUT=$< crystal run views/_render.cr > $@ && echo "Rendered $< to $@"
@TEMP_FILE=$$(mktemp) && \
INPUT=$< crystal run views/_render.cr > $$TEMP_FILE && \
mv $$TEMP_FILE $@ && \
echo "Rendered $< to $@"

.PHONY: clean-views
clean-views:
Expand Down

0 comments on commit e7a1c7e

Please sign in to comment.