serve.sh 841 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env bash
  2. # p5.js Skill — Local Development Server
  3. # Serves the current directory over HTTP for loading local assets (fonts, images)
  4. #
  5. # Usage:
  6. # bash scripts/serve.sh [port] [directory]
  7. #
  8. # Examples:
  9. # bash scripts/serve.sh # serve CWD on port 8080
  10. # bash scripts/serve.sh 3000 # serve CWD on port 3000
  11. # bash scripts/serve.sh 8080 ./my-project # serve specific directory
  12. PORT="${1:-8080}"
  13. DIR="${2:-.}"
  14. echo "=== p5.js Dev Server ==="
  15. echo "Serving: $(cd "$DIR" && pwd)"
  16. echo "URL: http://localhost:$PORT"
  17. echo "Press Ctrl+C to stop"
  18. echo ""
  19. cd "$DIR" && python3 -m http.server "$PORT" 2>/dev/null || {
  20. echo "Python3 not found. Trying Node.js..."
  21. npx serve -l "$PORT" "$DIR" 2>/dev/null || {
  22. echo "Error: Need python3 or npx (Node.js) for local server"
  23. exit 1
  24. }
  25. }