Repository navigation
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·277 lines (238 loc) · 7.88 KB
/
Copy pathinit.sh
File metadata and controls
executable file
·277 lines (238 loc) · 7.88 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/bin/bash
# GitCraft AI Studio - Initialization Script
# This script sets up the development environment and creates initial test data
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored output
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠ $1${NC}"
}
print_error() {
echo -e "${RED}✗ $1${NC}"
}
echo "GitCraft AI Studio - Initialization Script"
echo "=========================================="
echo
# Check if we're in the project root
if [ ! -f "package.json" ] || [ ! -d "apps" ]; then
print_error "Error: This script must be run from the project root directory"
exit 1
fi
# 1. Check for pnpm and install if needed
echo "Checking for pnpm..."
if ! command -v pnpm &> /dev/null; then
print_warning "pnpm not found. Installing pnpm..."
echo
echo "Please install pnpm using one of these methods:"
echo
echo "Option 1: Using npm with sudo (recommended for system-wide installation):"
echo " sudo npm install -g pnpm"
echo
echo "Option 2: Using standalone installer (no sudo required):"
echo " curl -fsSL https://get.pnpm.io/install.sh | sh -"
echo
echo "Option 3: Using Corepack (if you have Node.js 16.13+):"
echo " corepack enable"
echo " corepack prepare pnpm@latest --activate"
echo
echo "After installing pnpm, please run this script again."
exit 1
else
print_success "pnpm is already installed (version: $(pnpm --version))"
fi
# 2. Install dependencies with pnpm
echo
echo "Installing dependencies with pnpm..."
pnpm install
print_success "Dependencies installed with pnpm"
# 2. Setup environment files
echo
echo "Setting up environment files..."
# Create root .env file if it doesn't exist
if [ ! -f ".env" ]; then
if [ -f ".env.example" ]; then
cp .env.example .env
print_success "Created root .env file from .env.example"
else
cat > .env << EOF
# GitCraft AI Studio - Main Environment Configuration
# This is the primary .env file for the entire project
# ===========================================
# Database Configuration
# ===========================================
DATABASE_URL="postgresql://gitcraft:gitcraft_dev_2025@localhost:5432/gitcraft_studio?schema=public"
# ===========================================
# Authentication
# ===========================================
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-secret-key-change-this-in-production"
AUTH_SECRET="your-secret-key-change-this-in-production"
# ===========================================
# Email Configuration (for password reset)
# ===========================================
SMTP_HOST=""
SMTP_PORT=""
SMTP_SECURE=""
SMTP_USER=""
SMTP_PASS=""
FROM_EMAIL=""
# ===========================================
# OAuth Providers (Optional)
# ===========================================
GITHUB_ID=""
GITHUB_SECRET=""
GITLAB_ID=""
GITLAB_SECRET=""
# ===========================================
# AI Configuration
# ===========================================
ANTHROPIC_API_KEY="claude"
# ===========================================
# Claude CLI Configuration
# ===========================================
CLAUDE_CLI_PATH=""
CLAUDE_TOOL_EXECUTION_HOOK=""
CLAUDE_TOOL_HOOK=""
CLAUDE_HOME=""
CLAUDE_CODE_ENTRYPOINT="cli"
CLAUDECODE="1"
# ===========================================
# API Configuration
# ===========================================
PORT="4000"
NEXT_PUBLIC_API_URL="http://localhost:4000"
ALLOWED_ORIGINS="http://localhost:3000"
# ===========================================
# Storage Configuration
# ===========================================
REPOS_PATH="./git-repositories"
# S3-compatible storage (optional)
S3_ENDPOINT=""
S3_ACCESS_KEY=""
S3_SECRET_KEY=""
S3_BUCKET=""
# ===========================================
# Security
# ===========================================
ENCRYPTION_KEY="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
# ===========================================
# External Services
# ===========================================
REDIS_URL=""
CORS_PROXY_URL="https://cors.isomorphic-git.org"
# ===========================================
# Development Settings
# ===========================================
NODE_ENV="development"
CLAUDE_CODE_DANGEROUSLY_SKIP_PERMISSIONS="true"
CLAUDE_CODE_ALLOWED_PATHS="/workspace,/tmp"
# ===========================================
# Path Configuration
# ===========================================
GITCRAFT_PROJECT_ROOT=""
GITCRAFT_LOG_DIR=""
GITCRAFT_SESSION_DIR=""
EOF
print_success "Created root .env file with default settings"
fi
else
print_warning "Root .env already exists"
fi
# Create symlinks for environment files
echo "Creating environment file symlinks..."
# For API
if [ -f "apps/api/.env" ] || [ -L "apps/api/.env" ]; then
rm -f "apps/api/.env"
fi
ln -sf ../../.env "apps/api/.env"
print_success "Created symlink: apps/api/.env -> ../../.env"
# For Web (.env.local for Next.js)
if [ -f "apps/web/.env.local" ] || [ -L "apps/web/.env.local" ]; then
rm -f "apps/web/.env.local"
fi
ln -sf ../../.env "apps/web/.env.local"
print_success "Created symlink: apps/web/.env.local -> ../../.env"
# 3. Check PostgreSQL connection
echo
echo "Checking PostgreSQL connection..."
# Test PostgreSQL connection
if PGPASSWORD=gitcraft_dev_2025 psql -h localhost -U gitcraft -d gitcraft_studio -c '\l' >/dev/null 2>&1; then
print_success "PostgreSQL connection successful"
else
print_warning "Cannot connect to PostgreSQL. Please ensure:"
echo " 1. PostgreSQL is installed and running"
echo " 2. Database 'gitcraft_studio' exists"
echo " 3. User 'gitcraft' has proper permissions"
echo ""
echo "Run these commands to set up PostgreSQL:"
echo " sudo -u postgres psql"
echo " CREATE USER gitcraft WITH PASSWORD 'gitcraft_dev_2025';"
echo " CREATE DATABASE gitcraft_studio OWNER gitcraft;"
echo " GRANT ALL PRIVILEGES ON DATABASE gitcraft_studio TO gitcraft;"
echo " ALTER USER gitcraft CREATEDB;"
echo " \\q"
echo ""
read -p "Press Enter to continue anyway, or Ctrl+C to exit..."
fi
# 4. Initialize database
echo
echo "Initializing database..."
cd apps/api
# Generate Prisma client
npx prisma generate
print_success "Prisma client generated"
# Run migrations
npx prisma migrate dev --name init --skip-seed
print_success "Database migrations applied"
# Skip creating test user - users will register themselves
echo
echo "Database initialized without default users."
echo "Users can register through the application."
cd ../..
# 4. Create required directories
echo
echo "Creating required directories..."
mkdir -p apps/api/git-repositories
mkdir -p apps/api/workspace
mkdir -p workspace
print_success "Directories created"
# 5. Show summary
echo
print_success "Initialization completed successfully!"
echo
echo "Summary:"
echo "--------"
echo " • Dependencies installed"
echo " • Environment files created with PostgreSQL configuration"
echo " • Database initialized and migrations applied"
echo " • Database initialized (no default users)"
echo " • Required directories created"
echo
echo "Database Information:"
echo " • Database: gitcraft_studio"
echo " • User: gitcraft"
echo " • Password: gitcraft_dev_2025"
echo " • Host: localhost:5432"
echo
echo "Next steps:"
echo " 1. Run 'pnpm dev' to start the development servers"
echo " 2. Access the app at http://localhost:3000"
echo " 3. Register a new account through the application"
echo
echo "Optional:"
echo " • Add your Anthropic API key to apps/api/.env for production use"
echo " • Configure OAuth providers in .env files"
echo
echo "Useful commands:"
echo " • npx prisma studio - Open database GUI"
echo " • npx prisma migrate dev - Create new migrations"
echo " • ./cleanup.sh --reset-db - Reset the database"
echo
echo "Check README.md and postgresql-install-guide.md for more information"