mock 871 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env bash
  2. set -e
  3. cd "$(dirname "$0")/.."
  4. if [[ -n "$1" && "$1" != '--'* ]]; then
  5. URL="$1"
  6. shift
  7. else
  8. URL="$(grep 'openapi_spec_url' .stats.yml | cut -d' ' -f2)"
  9. fi
  10. # Check if the URL is empty
  11. if [ -z "$URL" ]; then
  12. echo "Error: No OpenAPI spec path/url provided or found in .stats.yml"
  13. exit 1
  14. fi
  15. echo "==> Starting mock server with URL ${URL}"
  16. # Run prism mock on the given spec
  17. if [ "$1" == "--daemon" ]; then
  18. npm exec --package=@stainless-api/[email protected] -- prism mock "$URL" &> .prism.log &
  19. # Wait for server to come online
  20. echo -n "Waiting for server"
  21. while ! grep -q "✖ fatal\|Prism is listening" ".prism.log" ; do
  22. echo -n "."
  23. sleep 0.1
  24. done
  25. if grep -q "✖ fatal" ".prism.log"; then
  26. cat .prism.log
  27. exit 1
  28. fi
  29. echo
  30. else
  31. npm exec --package=@stainless-api/[email protected] -- prism mock "$URL"
  32. fi