Skip to content

Commit 8136386

Browse files
authored
chore: make pnpm dev start local builder stack (#5853)
1 parent a515a4f commit 8136386

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

apps/builder/dev/backend.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,27 @@ builder_backend_start_postgrest() {
3131
builder_compose up -d postgrest
3232
}
3333

34+
builder_backend_wait_for_postgrest() {
35+
local timeout_seconds="${1:-60}"
36+
local port
37+
port="$(builder_compose port postgrest 3000)"
38+
local url="http://127.0.0.1:${port##*:}/UserProduct?select=userId&limit=0"
39+
local timeout_at
40+
timeout_at="$(($(date +%s) + timeout_seconds))"
41+
42+
until {
43+
local status
44+
status="$(curl -s -o /dev/null -w "%{http_code}" "$url" || true)"
45+
[ "$status" -ge 200 ] && [ "$status" -lt 500 ]
46+
}; do
47+
if [ "$(date +%s)" -ge "$timeout_at" ]; then
48+
echo "Timed out waiting for PostgREST" >&2
49+
return 1
50+
fi
51+
sleep 0.2
52+
done
53+
}
54+
3455
builder_backend_wait_for_db() {
3556
local timeout_seconds="${1:-60}"
3657
local timeout_at

apps/builder/dev/run-local.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ source "$ROOT_DIR/apps/builder/dev/backend.sh"
77
builder_backend_init
88

99
cleanup() {
10-
if [ "${LOCAL_DEV_CLEANUP:-false}" != "true" ]; then
10+
if [ "${LOCAL_DEV_CLEANUP:-${LOCAL_DEV_START_BUILDER:-true}}" != "true" ]; then
1111
return
1212
fi
1313

@@ -29,7 +29,8 @@ builder_backend_wait_for_db
2929
builder_backend_bootstrap_if_empty
3030
builder_generate_prisma_client auto
3131
builder_backend_start_postgrest
32+
builder_backend_wait_for_postgrest
3233

3334
if [ "${LOCAL_DEV_START_BUILDER:-true}" = "true" ]; then
34-
exec pnpm --dir "$ROOT_DIR" dev
35+
pnpm --dir "$ROOT_DIR" --filter=@webstudio-is/builder dev
3536
fi

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
"scripts": {
88
"build": "pnpm -r --filter='!./fixtures/*' build",
99
"dts": "pnpm -r dts",
10-
"dev": "pnpm --filter='@webstudio-is/builder' dev",
11-
"dev:local": "bash ./apps/builder/dev/run-local.sh",
12-
"dev:backend": "LOCAL_DEV_START_BUILDER=false bash ./apps/builder/dev/run-local.sh",
13-
"dev:local:reset": "LOCAL_DEV_RESET_DB=true bash ./apps/builder/dev/run-local.sh",
10+
"dev": "bash ./apps/builder/dev/run-local.sh",
1411
"lint": "oxlint --deny-warnings",
1512
"fixtures": "pnpm -r fixtures:link && pnpm -r fixtures:sync && pnpm -r fixtures:build",
1613
"checks": "pnpm -r test && pnpm -r typecheck && pnpm lint && pnpm fixtures",

0 commit comments

Comments
 (0)