-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(internal): add scripts/mock (#206)
- Loading branch information
1 parent
8f6d698
commit d181de7
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,3 @@ jobs: | |
./gradlew --build-cache --parallel --no-daemon \ | ||
build testClasses -x test | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
cd "$(dirname "$0")/.." | ||
|
||
if [[ -n "$1" && "$1" != '--'* ]]; then | ||
URL="$1" | ||
shift | ||
else | ||
URL="$(grep 'openapi_spec_url' .stats.yml | cut -d' ' -f2)" | ||
fi | ||
|
||
# Check if the URL is empty | ||
if [ -z "$URL" ]; then | ||
echo "Error: No OpenAPI spec path/url provided or found in .stats.yml" | ||
exit 1 | ||
fi | ||
|
||
echo "==> Starting mock server with URL ${URL}" | ||
|
||
# Run prism mock on the given spec | ||
if [ "$1" == "--daemon" ]; then | ||
npm exec --package=@stoplight/prism-cli@~5.3.2 -- prism mock "$URL" &> .prism.log & | ||
|
||
# Wait for server to come online | ||
echo -n "Waiting for server" | ||
while ! grep -q "✖ fatal\|Prism is listening" ".prism.log" ; do | ||
echo -n "." | ||
sleep 0.1 | ||
done | ||
|
||
if grep -q "✖ fatal" ".prism.log"; then | ||
cat .prism.log | ||
exit 1 | ||
fi | ||
|
||
echo | ||
else | ||
npm exec --package=@stoplight/prism-cli@~5.3.2 -- prism mock "$URL" | ||
fi |