#!/usr/bin/env python3 """Watch src/ for changes and rebuild dist/asw.css.""" import os import subprocess import pyinotify WATCH_DIR = os.path.expanduser("~/projects/asw/src") BUILD_CMD = ["npm", "run", "build"] class RebuildHandler(pyinotify.ProcessEvent): def process_default(self, event): if event.name and event.name.endswith(".css"): print(f"[watch] {event.name} changed → rebuilding...") result = subprocess.run(BUILD_CMD, cwd=os.path.dirname(WATCH_DIR), capture_output=True, text=True) if result.returncode == 0: print("[watch] Build OK") else: print(f"[watch] Build FAILED:\n{result.stderr}") def main(): wm = pyinotify.WatchManager() mask = pyinotify.IN_MODIFY | pyinotify.IN_CREATE | pyinotify.IN_DELETE handler = RebuildHandler() notifier = pyinotify.Notifier(wm, handler) wm.add_watch(WATCH_DIR, mask, rec=True) print(f"[watch] Watching {WATCH_DIR} for changes. Ctrl+C to stop.") notifier.loop() if __name__ == "__main__": main()