cloudflare/cloudflare-typescript

Public

mirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0da2321de9ef80aebb7242994de8e8b475a9a404

Branches

Tags

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

Clone

HTTPS

Download ZIP

scripts/mock

52lines · modeblame

2157ac0dstainless-app[bot]2 years ago1#!/usr/bin/env bash
2
dbae3674stainless-app[bot]2 years ago3set -e
4
5cd "$(dirname "$0")/.."
6
ce41a479stainless-app[bot]2 years ago7if [[ -n "$1" && "$1" != '--'* ]]; then
2157ac0dstainless-app[bot]2 years ago8URL="$1"
9shift
10else
11URL="$(grep 'openapi_spec_url' .stats.yml | cut -d' ' -f2)"
12fi
13
14# Check if the URL is empty
15if [ -z "$URL" ]; then
16echo "Error: No OpenAPI spec path/url provided or found in .stats.yml"
17exit 1
18fi
19
ce41a479stainless-app[bot]2 years ago20echo "==> Starting mock server with URL ${URL}"
21
b2da5c33stainless-app[bot]4 months ago22# Run prism mock on the given spec
2157ac0dstainless-app[bot]2 years ago23if [ "$1" == "--daemon" ]; then
a6729d07stainless-app[bot]4 months ago24# Pre-install the package so the download doesn't eat into the startup timeout
b2da5c33stainless-app[bot]4 months ago25npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism --version
a6729d07stainless-app[bot]4 months ago26
b2da5c33stainless-app[bot]4 months ago27npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock "$URL" &> .prism.log &
2157ac0dstainless-app[bot]2 years ago28
b2da5c33stainless-app[bot]4 months ago29# Wait for server to come online (max 30s)
ce41a479stainless-app[bot]2 years ago30echo -n "Waiting for server"
a6729d07stainless-app[bot]4 months ago31attempts=0
b2da5c33stainless-app[bot]4 months ago32while ! grep -q "✖ fatal\|Prism is listening" ".prism.log" ; do
a6729d07stainless-app[bot]4 months ago33attempts=$((attempts + 1))
34if [ "$attempts" -ge 300 ]; then
35echo
b2da5c33stainless-app[bot]4 months ago36echo "Timed out waiting for Prism server to start"
37cat .prism.log
a6729d07stainless-app[bot]4 months ago38exit 1
39fi
2157ac0dstainless-app[bot]2 years ago40echo -n "."
41sleep 0.1
42done
43
b2da5c33stainless-app[bot]4 months ago44if grep -q "✖ fatal" ".prism.log"; then
45cat .prism.log
46exit 1
47fi
48
2157ac0dstainless-app[bot]2 years ago49echo
50else
b2da5c33stainless-app[bot]4 months ago51npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock "$URL"
2157ac0dstainless-app[bot]2 years ago52fi