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