-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsetup-local.sh
More file actions
executable file
Β·61 lines (52 loc) Β· 1.83 KB
/
setup-local.sh
File metadata and controls
executable file
Β·61 lines (52 loc) Β· 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# BLT-Leaf Local Development Setup Script
echo "π BLT-Leaf Local Setup"
echo "========================"
# Check wrangler is installed
if ! command -v wrangler &> /dev/null; then
echo "β Wrangler not found. Install it with: npm install -g wrangler"
exit 1
fi
# Login check
echo ""
echo "π Step 1: Checking Cloudflare login..."
wrangler whoami 2>/dev/null || wrangler login
# Create or get existing D1 database
echo ""
echo "π Step 2: Setting up D1 database..."
DB_OUTPUT=$(wrangler d1 create pr_tracker 2>&1)
if echo "$DB_OUTPUT" | grep -q "already exists"; then
echo "βΉοΈ Database already exists, fetching ID..."
DB_ID=$(wrangler d1 list 2>/dev/null | grep "pr_tracker" | awk -F'β' '{gsub(/ /,"",$2); print $2}')
else
DB_ID=$(echo "$DB_OUTPUT" | grep "database_id" | awk -F'"' '{print $2}')
fi
if [ -n "$DB_ID" ]; then
echo "β
Database ID found: $DB_ID"
echo ""
echo "π Step 3: Updating wrangler.toml with database_id..."
sed -i "s/database_id = \".*\"/database_id = \"$DB_ID\"/" wrangler.toml
echo "β
wrangler.toml updated"
else
echo "β Could not find database ID. Please run 'wrangler d1 list' manually."
exit 1
fi
# Apply migrations locally
echo ""
echo "π Step 4: Applying database migrations locally..."
wrangler d1 migrations apply pr_tracker --local
echo "β
Migrations applied successfully"
# Setup .env file
echo ""
echo "π Step 5: Setting up .env file..."
if [ ! -f .env ]; then
cp env.example .env
echo "β
Created .env file from env.example"
echo "π‘ Optional: Add your GITHUB_TOKEN to .env to increase API rate limit from 60 to 5,000/hour"
else
echo "β
.env file already exists"
fi
echo ""
echo "π Setup complete!"
echo "π Run 'wrangler dev' to start the local development server"
echo "π Open http://localhost:8787 in your browser"