cloudflare/cloudflare-typescript

Public

mirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
77e92d58cf5fdde81c29f7ee93ad243eb3b653a7

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

scripts/mock

52lines · modecode

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 # Pre-install the package so the download doesn't eat into the startup timeout
25 npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism --version
26
27 npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock "$URL" &> .prism.log &
28
29 # Wait for server to come online (max 30s)
30 echo -n "Waiting for server"
31 attempts=0
32 while ! grep -q "✖ fatal\|Prism is listening" ".prism.log" ; do
33 attempts=$((attempts + 1))
34 if [ "$attempts" -ge 300 ]; then
35 echo
36 echo "Timed out waiting for Prism server to start"
37 cat .prism.log
38 exit 1
39 fi
40 echo -n "."
41 sleep 0.1
42 done
43
44 if grep -q "✖ fatal" ".prism.log"; then
45 cat .prism.log
46 exit 1
47 fi
48
49 echo
50else
51 npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock "$URL"
52fi