-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·223 lines (183 loc) · 6.77 KB
/
setup.sh
File metadata and controls
executable file
·223 lines (183 loc) · 6.77 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
#!/bin/bash
# Pluggist Quick Setup Script
# Run this to get Pluggist running locally or deploy to production
set -e
echo "
╔═══════════════════════════════════════════════════════════╗
║ PLUGGIST SETUP ⚡ ║
║ AI-Powered EV Charging Marketplace ║
╚═══════════════════════════════════════════════════════════╝
"
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to print colored output
print_success() {
echo -e "\033[0;32m✓ $1\033[0m"
}
print_error() {
echo -e "\033[0;31m✗ $1\033[0m"
}
print_info() {
echo -e "\033[0;34mℹ $1\033[0m"
}
# Check prerequisites
echo "📋 Checking prerequisites..."
if ! command_exists node; then
print_error "Node.js is not installed. Please install Node.js 18+ from https://nodejs.org"
exit 1
else
print_success "Node.js found: $(node --version)"
fi
if ! command_exists npm; then
print_error "npm is not installed"
exit 1
else
print_success "npm found: $(npm --version)"
fi
# Check for Cloudflare CLI (optional)
if command_exists wrangler; then
print_success "Wrangler CLI found: $(wrangler --version)"
else
print_info "Wrangler CLI not found. Installing..."
npm install -g wrangler
fi
# Setup selection
echo ""
echo "🚀 What would you like to do?"
echo "1) Local Development Setup"
echo "2) Deploy to Cloudflare (Production)"
echo "3) Deploy to Cloudflare (Preview)"
echo "4) Setup Partner Demo"
echo "5) Run Tests"
echo "6) Update Dependencies"
echo ""
read -p "Enter your choice (1-6): " choice
case $choice in
1)
echo ""
echo "🔧 Setting up local development environment..."
# Install dependencies
print_info "Installing dependencies..."
npm install
# Setup environment variables
if [ ! -f .env.local ]; then
print_info "Creating .env.local from template..."
cp .env.example .env.local
print_success "Created .env.local - Please update with your API keys"
else
print_success ".env.local already exists"
fi
# Setup MCP server
if [ -d "mcp-server" ]; then
print_info "Setting up MCP server..."
cd mcp-server
npm install
cd ..
print_success "MCP server ready"
fi
# Initialize database
print_info "Would you like to initialize the local database? (y/n)"
read -p "> " init_db
if [ "$init_db" = "y" ]; then
if command_exists wrangler; then
wrangler d1 create pluggist-db --local || true
wrangler d1 execute pluggist-db --local --file=migrations/0001_initial.sql
wrangler d1 execute pluggist-db --local --file=migrations/0002_complete_schema.sql
print_success "Database initialized"
else
print_error "Wrangler not found. Please install it first."
fi
fi
# Start development server
print_info "Starting development server..."
echo ""
echo "════════════════════════════════════════════════════════════"
echo " 🎉 Setup complete! Starting Pluggist..."
echo " 📱 Local: http://localhost:3000"
echo " 🤖 ChargePal Demo: http://localhost:3000/charging"
echo " 💼 Partner Portal: http://localhost:3000/for-business"
echo "════════════════════════════════════════════════════════════"
echo ""
npm run dev
;;
2)
echo ""
echo "🚀 Deploying to Cloudflare (Production)..."
# Check for required environment variables
if [ -z "$CLOUDFLARE_API_TOKEN" ]; then
print_error "CLOUDFLARE_API_TOKEN not set"
echo "Please set your Cloudflare API token:"
echo "export CLOUDFLARE_API_TOKEN=your-token-here"
exit 1
fi
# Build and deploy
print_info "Building application..."
npm run build
print_info "Building for Cloudflare Workers..."
npm run build:worker
print_info "Deploying to production..."
wrangler deploy --env production
print_success "Deployment complete!"
echo ""
echo "🌐 Your app is live at:"
echo " https://pluggist.com"
echo " https://pluggist.workers.dev"
;;
3)
echo ""
echo "👁️ Deploying to Cloudflare (Preview)..."
# Build and deploy to preview
print_info "Building application..."
npm run build
print_info "Deploying to preview environment..."
wrangler deploy --env preview
print_success "Preview deployment complete!"
echo "Preview URL: https://preview.pluggist.workers.dev"
;;
4)
echo ""
echo "🏪 Setting up Partner Demo..."
# Create demo partner account
print_info "Creating demo partner account..."
# Start server with demo mode
export MOCK_CHARGING_SESSIONS=true
export FEATURE_AI_CHAT=true
export FEATURE_DEALS=true
print_success "Demo mode enabled"
echo ""
echo "📝 Demo Credentials:"
echo " Partner Email: demo@subway.com"
echo " Password: demo123"
echo ""
echo "🔗 Demo Links:"
echo " Partner Dashboard: http://localhost:3000/partner/dashboard"
echo " Charging Demo: http://localhost:3000/charging?demo=true"
echo ""
npm run dev
;;
5)
echo ""
echo "🧪 Running tests..."
# Run tests
print_info "Running unit tests..."
npm test
print_info "Running linting..."
npm run lint
print_success "All tests passed!"
;;
6)
echo ""
echo "📦 Updating dependencies..."
print_info "Updating npm packages..."
npm update
print_info "Checking for vulnerabilities..."
npm audit fix
print_success "Dependencies updated!"
;;
*)
print_error "Invalid choice"
exit 1
;;
esac