#!/bin/sh
# CMD for the css-watcher dev container. Bind-mounts from compose.dev:
#   /build/assets, /build/views, /build/src, /build/public, tailwind.config.js
# Output goes to /build/public/assets/css/app.css, which is the host's
# public/assets/css/app.css (gitignored).
set -eu

# Vendor JS bundles never change between iterations — copy once on start
# so a host bind-mount over public/assets/js/vendor stays populated.
# `cp -u` skips when the destination is already up-to-date, so subsequent
# container restarts are no-ops.
mkdir -p public/assets/js/vendor
cp -u node_modules/@alpinejs/csp/dist/cdn.min.js public/assets/js/vendor/alpine-csp.min.js
cp -u node_modules/htmx.org/dist/htmx.min.js     public/assets/js/vendor/htmx.min.js
cp -u node_modules/sortablejs/Sortable.min.js    public/assets/js/vendor/sortable.min.js

# Direct binary path instead of `npx` — when the container runs as a
# non-root host user (see compose.dev.yml `user:` directive), npx may try
# to write to a $HOME it can't access. The locally-installed binary just
# works.
exec ./node_modules/.bin/tailwindcss \
    -i assets/css/input.css \
    -o public/assets/css/app.css \
    --watch
