From 20ae7df57d38c6263edcf8ca05184dabff841600 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Sat, 19 Jul 2025 15:10:56 +0700 Subject: [PATCH] Improve build system and watch script --- Makefile | 18 ++++++++++++++---- dev-browser.sh | 24 ------------------------ watch.sh | 39 ++++++++++++++++++++++++--------------- 3 files changed, 38 insertions(+), 43 deletions(-) delete mode 100755 dev-browser.sh diff --git a/Makefile b/Makefile index 259b938..7285279 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,21 @@ -.PHONY: tailwind build publish +.PHONY: watch clean tailwind static build publish + +clean: + rm -rf build/* tailwind: npx @tailwindcss/cli -i ./resources/input.css -o ./resources/static/output.css -build: tailwind - rsync -av --delete resources/static/ build/static/ +static: + rsync -av resources/static/ build/static/ + +build: clj -M:build -publish: build +org: ./org/* + emacs -Q --script build-org.el + +watch: tailwind static build + +publish: build-org tailwind static build rsync -av --delete build/ joe-vps:/home/josephferano/websites/ferano.io/ diff --git a/dev-browser.sh b/dev-browser.sh deleted file mode 100755 index 5b014e2..0000000 --- a/dev-browser.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -# Wait for DevTools to start listening on websocket -sleep 1 - -BRAVE_PORT=9222 -brave-browser --new-window --user-data-dir=/tmp/brave-dev --remote-debugging-port=${BRAVE_PORT} & -BRAVE_PID=$! -echo "Wait 2 seconds, then go..." -sleep 2 - -TAB_ID=$(curl -s http://localhost:${BRAVE_PORT}/json | jq -r '.[] | .id') -echo "Got Tab ID: $TAB_ID" - -HTTP_PORT=$(grep "python -m http.server 3000" watch.sh | grep -o -e "[[:digit:]]\+") -echo "Found Jetty Port: $HTTP_PORT" -JS_NAV=$(cat < .tab-id -echo "Open http://localhost:${HTTP_PORT}" -echo $JS_NAV | websocat ws://localhost:9222/devtools/page/${TAB_ID} > /dev/null diff --git a/watch.sh b/watch.sh index 2afc557..3a20d58 100755 --- a/watch.sh +++ b/watch.sh @@ -1,34 +1,43 @@ #!/bin/sh -python -m http.server 3000 --directory build & +BRAVE_PORT=9222 +HTTP_PORT=${1:-3000} + +brave-browser --new-window --user-data-dir=/tmp/brave-dev --remote-debugging-port=${BRAVE_PORT} & +BRAVE_PID=$! +echo "Wait 1 seconds, then go..." +sleep 1 + +TAB_ID=$(curl -s http://localhost:${BRAVE_PORT}/json | jq -r '.[] | .id') +echo "Got Tab ID: $TAB_ID" + +JS_NAV=$(cat < .tab-id +echo "Open http://localhost:${HTTP_PORT}" +echo $JS_NAV | websocat ws://localhost:${BRAVE_PORT}/devtools/page/${TAB_ID} > /dev/null + +python -m http.server $HTTP_PORT --directory build & PID_HTTP=$! -sleep 2 +sleep 1 if ! kill -0 $PID_HTTP 2>/dev/null; then echo "Failed to start HTTP server" exit 1 fi -# When using the -d flag, entr will exist, so just keep looping with a function to get it to relaunch -watch_static() { - while true; do - echo resources/static/ | entr -dp rsync -av --delete resources/static/ build/static/ - sleep 0.5 - done -} - -watch_static & -PID_WATCH_STATIC=$! - cleanup() { echo "Shutting down..." kill $PID_HTTP 2>/dev/null - kill $PID_WATCH_STATIC 2>/dev/null + kill $BRAVE_PID 2>/dev/null exit 0 } trap cleanup SIGINT SIGTERM -find src/ resources/ -name "*.clj" -o -name "*.edn" | entr -r clj -M:build +find src/ resources/ -name "*.clj" -o -name "*.edn" | entr -r make -j3 watch cleanup