Skip to content

Commit 6318616

Browse files
committed
Improve fresh local setup flow
1 parent eacef7a commit 6318616

4 files changed

Lines changed: 88 additions & 22 deletions

File tree

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,27 @@ Or run `npx echo-start my-app` to choose interactively.
121121

122122
# Development
123123

124-
Fill out `packages/app/control/.env` and `packages/app/server/.env`. Then...
124+
Prerequisites:
125125

126-
- `pnpm i`
127-
- `pnpm dev`
126+
- Node.js 18 or newer
127+
- pnpm 10.11.0 or newer
128+
- Docker with Docker Compose
129+
130+
From a fresh clone:
131+
132+
```bash
133+
pnpm i
134+
pnpm dev
135+
```
136+
137+
`pnpm dev` runs the local setup step automatically. It creates
138+
`packages/app/control/.env` from `.env.example` when needed, generates a local
139+
`AUTH_SECRET`, sets the local PostgreSQL `DATABASE_URL`, starts the Docker
140+
PostgreSQL container, applies Prisma migrations, and starts the control app plus
141+
router server.
142+
143+
If `pnpm` is not available yet, install the pinned version first:
144+
145+
```bash
146+
npm install -g pnpm@10.11.0
147+
```

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"private": true,
66
"packageManager": "pnpm@10.11.0",
77
"scripts": {
8+
"predev": "pnpm run local-setup",
89
"dev": "turbo run dev --filter=echo-control --filter=echo-server",
910
"local-setup": "turbo run local-setup --filter=echo-control",
1011
"build": "turbo run build --env-mode=loose",
Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,65 @@
11
#!/bin/bash
22

3-
# Check if .env file exists and if AUTH_SECRET is already set
4-
if [ -f .env ] && grep -q "^AUTH_SECRET=" .env; then
5-
echo "AUTH_SECRET already exists in .env file. Skipping generation."
6-
else
7-
echo "Generating AUTH_SECRET..."
8-
AUTH_SECRET=$(node -e "console.log('AUTH_SECRET=' + require('crypto').randomBytes(32).toString('base64'))")
9-
echo $AUTH_SECRET
10-
echo $AUTH_SECRET >> .env
11-
fi
12-
13-
# Check if DATABASE_URL is already set
14-
if [ -f .env ] && grep -q "^DATABASE_URL=" .env; then
15-
echo "DATABASE_URL already exists in .env file. Skipping."
16-
else
17-
echo "DATABASE_URL='postgresql://echo_user:echo_password@localhost:5469/echo_control_v2?schema=public'" >> .env
18-
fi
19-
20-
echo "Setup complete! You can now run 'pnpm dev' to start the development server."
3+
set -euo pipefail
4+
5+
ENV_FILE=".env"
6+
DATABASE_URL_VALUE='"postgresql://echo_user:echo_password@localhost:5469/echo_control_v2?schema=public"'
7+
8+
ensure_env_file() {
9+
if [ -f "$ENV_FILE" ]; then
10+
return
11+
fi
12+
13+
if [ -f ".env.example" ]; then
14+
cp ".env.example" "$ENV_FILE"
15+
echo "Created $ENV_FILE from .env.example."
16+
else
17+
touch "$ENV_FILE"
18+
echo "Created empty $ENV_FILE."
19+
fi
20+
}
21+
22+
env_value() {
23+
local key="$1"
24+
grep -E "^${key}=" "$ENV_FILE" | tail -n 1 | cut -d= -f2- | tr -d "\"'"
25+
}
26+
27+
set_env_value() {
28+
local key="$1"
29+
local value="$2"
30+
local current
31+
32+
current="$(env_value "$key" || true)"
33+
if [ -n "$current" ]; then
34+
echo "$key already exists in $ENV_FILE. Skipping."
35+
return
36+
fi
37+
38+
if grep -qE "^${key}=" "$ENV_FILE"; then
39+
local temp_file
40+
temp_file="$(mktemp)"
41+
awk -v key="$key" -v replacement="${key}=${value}" '
42+
BEGIN { replaced = 0 }
43+
$0 ~ "^" key "=" && replaced == 0 {
44+
print replacement
45+
replaced = 1
46+
next
47+
}
48+
{ print }
49+
' "$ENV_FILE" > "$temp_file"
50+
mv "$temp_file" "$ENV_FILE"
51+
else
52+
printf "%s=%s\n" "$key" "$value" >> "$ENV_FILE"
53+
fi
54+
55+
echo "Set $key in $ENV_FILE."
56+
}
57+
58+
ensure_env_file
59+
60+
AUTH_SECRET_VALUE="\"$(node -e "process.stdout.write(require('crypto').randomBytes(32).toString('base64'))")\""
61+
62+
set_env_value "AUTH_SECRET" "$AUTH_SECRET_VALUE"
63+
set_env_value "DATABASE_URL" "$DATABASE_URL_VALUE"
64+
65+
echo "Setup complete. You can now run 'pnpm dev' to start the development server."

packages/sdk/examples/next-402-chat/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"build": "next build --turbopack",
88
"start": "next start",
99
"lint": "biome check --write",
10-
"postinstall": "npm dedupe || true"
10+
"postinstall": "node -e \"if (!(process.env.npm_config_user_agent || '').includes('pnpm')) require('child_process').execSync('npm dedupe', { stdio: 'inherit' })\" || true"
1111
},
1212
"dependencies": {
1313
"@ai-sdk/openai": "2.0.16",

0 commit comments

Comments
 (0)