From eeebc91723d27060738b9da222024ce4bb39f8cd Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Sun, 4 Aug 2019 22:53:58 -0500 Subject: [PATCH] Little niceties around development process. --- .gitignore | 1 + Makefile | 18 +++++++++++++----- makewatch | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 makewatch diff --git a/.gitignore b/.gitignore index 45d62d8..ab5f965 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.sw? +dist/ diff --git a/Makefile b/Makefile index 8d345d1..f893229 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,15 @@ -deploy: - -rm -r dist - mkdir dist - cp flashcards.* dist - git describe --always --tags | xargs --replace=INSERTED -- sed -i -e 's/%VERSION%/INSERTED/' dist/* +deploy: clean build aws s3 sync dist s3://flashcards.jdbernard.com rm -r dist + +serve-local: + (cd dist && python -m SimpleHTTPServer &) + ./makewatch build + +build: flashcards.* + -mkdir dist + cp flashcards.* dist + git describe --always --dirty --tags | xargs --replace=INSERTED -- sed -i -e 's/%VERSION%/INSERTED/' dist/* + +clean: + -rm -r dist diff --git a/makewatch b/makewatch new file mode 100644 index 0000000..a40b3ff --- /dev/null +++ b/makewatch @@ -0,0 +1,48 @@ +#!/bin/bash -e + +# Don Marti +# (If you need a license on this in order to use it, +# mail me and I'll put a license on it. Otherwise, +# de minimis non curat lex.) + +# re-run make, with the supplied arguments, when a +# Makefile prerequisite changes. Example: +# makewatch test +# Fun to use with Auto Reload (Firefox) or Tincr (Chrome) and Pandoc +# https://addons.mozilla.org/en-US/firefox/addon/auto-reload/ +# http://tin.cr/ +# http://johnmacfarlane.net/pandoc/ +# Requires inotifywait. Probably requires GNU Make to +# get the right "-dnr" output. Not tested with other +# "make" implementations + +# If $MAKEWATCH is set to an existing file or +# space-separated list of files, also checks those. + +make_prereqs() { + # Make "make" figure out what files it's interested in. + echo "Makefile" + find $MAKEWATCH + gmake -dnr $* | tr ' ' '\n' | \ + grep ".*'.$" | grep -o '\w.*\b' +} + +prereq_files() { + # prerequisites mentioned in a Makefile + # that are extant files + echo ' ' + for f in `make_prereqs $* | sort -u`; do + [ -e $f ] && echo -n "$f "; + done + echo +} + +make $* +while true; do + fl=$(prereq_files $*) + ev=$(inotifywait --quiet --format %e $fl) + if [ "xOPEN" != "x$ev" ]; then + sleep 1 + make $* + fi +done