-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathdev-setup.sh
More file actions
executable file
·229 lines (195 loc) · 6.25 KB
/
dev-setup.sh
File metadata and controls
executable file
·229 lines (195 loc) · 6.25 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
#!/usr/bin/env bash
set -e # Exit on error
echo "======================================"
echo "DailyNotes Development Setup"
echo "======================================"
echo ""
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Check if Python is installed
echo "Checking for Python..."
if ! command -v python3 &> /dev/null && ! command -v python &> /dev/null; then
echo -e "${RED}Error: Python is not installed.${NC}"
echo "Please install Python 3.8+ from https://www.python.org/downloads/"
exit 1
fi
# Determine which Python command to use
if command -v python3 &> /dev/null; then
PYTHON_CMD="python3"
PIP_CMD="pip3"
else
PYTHON_CMD="python"
PIP_CMD="pip"
fi
PYTHON_VERSION=$($PYTHON_CMD --version 2>&1 | awk '{print $2}')
echo -e "${GREEN}✓ Found Python $PYTHON_VERSION${NC}"
# Check if pip is installed
echo "Checking for pip..."
if ! command -v $PIP_CMD &> /dev/null; then
echo -e "${RED}Error: pip is not installed.${NC}"
echo "Please install pip: https://pip.pypa.io/en/stable/installation/"
exit 1
fi
echo -e "${GREEN}✓ Found pip${NC}"
# Check if Node.js is installed
echo "Checking for Node.js..."
if ! command -v node &> /dev/null; then
echo -e "${RED}Error: Node.js is not installed.${NC}"
echo "Please install Node.js >= 12 from https://nodejs.org/"
exit 1
fi
NODE_VERSION=$(node --version)
echo -e "${GREEN}✓ Found Node.js $NODE_VERSION${NC}"
# Check if npm is installed
echo "Checking for npm..."
if ! command -v npm &> /dev/null; then
echo -e "${RED}Error: npm is not installed.${NC}"
echo "npm should come with Node.js. Please reinstall Node.js."
exit 1
fi
NPM_VERSION=$(npm --version)
echo -e "${GREEN}✓ Found npm $NPM_VERSION${NC}"
echo ""
echo "======================================"
echo "Setting up Python Virtual Environment"
echo "======================================"
echo ""
# Create virtual environment if it doesn't exist
VENV_DIR="venv"
if [ -d "$VENV_DIR" ]; then
echo -e "${YELLOW}Virtual environment already exists at $VENV_DIR${NC}"
else
echo "Creating Python virtual environment..."
if $PYTHON_CMD -m venv $VENV_DIR; then
echo -e "${GREEN}✓ Virtual environment created${NC}"
else
echo -e "${RED}Error: Failed to create virtual environment${NC}"
exit 1
fi
fi
# Activate virtual environment
echo "Activating virtual environment..."
source $VENV_DIR/bin/activate
if [ -z "$VIRTUAL_ENV" ]; then
echo -e "${RED}Error: Failed to activate virtual environment${NC}"
exit 1
fi
echo -e "${GREEN}✓ Virtual environment activated${NC}"
echo ""
echo "======================================"
echo "Installing Dependencies"
echo "======================================"
echo ""
# Install Python dependencies
echo "Installing Python dependencies from requirements.txt..."
if pip install -r requirements.txt; then
echo -e "${GREEN}✓ Python dependencies installed successfully${NC}"
else
echo -e "${RED}Error: Failed to install Python dependencies${NC}"
exit 1
fi
echo ""
# Deactivate venv before installing Node dependencies to avoid Python path conflicts
deactivate
# Load nvm if available
if [ -s "$NVM_DIR/nvm.sh" ]; then
source "$NVM_DIR/nvm.sh"
elif [ -s "$HOME/.nvm/nvm.sh" ]; then
export NVM_DIR="$HOME/.nvm"
source "$NVM_DIR/nvm.sh"
fi
# Install Node dependencies
echo "Installing Node.js dependencies in client directory..."
if [ ! -d "client" ]; then
echo -e "${RED}Error: client directory not found${NC}"
exit 1
fi
cd client
# Use Node 16 via nvm if available
if command -v nvm &> /dev/null && [ -f ".nvmrc" ]; then
echo "Using Node.js version from .nvmrc..."
nvm use || nvm install
NODE_VERSION=$(node --version)
echo -e "${GREEN}✓ Switched to Node.js $NODE_VERSION${NC}"
fi
# Remove old package-lock.json to force a fresh install with updated dependencies
if [ -f "package-lock.json" ]; then
echo "Removing old package-lock.json..."
rm package-lock.json
fi
# Remove node_modules if it exists to ensure clean install
if [ -d "node_modules" ]; then
echo "Removing old node_modules..."
rm -rf node_modules
fi
if npm install; then
echo -e "${GREEN}✓ Node.js dependencies installed successfully${NC}"
else
echo -e "${RED}Error: Failed to install Node.js dependencies${NC}"
exit 1
fi
cd ..
# Reactivate venv for the environment setup step
echo "Reactivating virtual environment..."
source $VENV_DIR/bin/activate
echo ""
echo "======================================"
echo "Setting up Environment"
echo "======================================"
echo ""
# Run verify_env.py to create environment variables
echo "Generating environment configuration..."
if $PYTHON_CMD verify_env.py; then
echo -e "${GREEN}✓ Environment configuration created${NC}"
if [ -f "config/.env" ]; then
echo -e "${YELLOW}Note: Environment variables saved to config/.env${NC}"
fi
else
echo -e "${RED}Error: Failed to create environment configuration${NC}"
exit 1
fi
echo ""
echo "======================================"
echo "Building Frontend"
echo "======================================"
echo ""
cd client
# Use Node 16 via nvm if available
if command -v nvm &> /dev/null && [ -f ".nvmrc" ]; then
nvm use > /dev/null 2>&1
fi
echo "Building Vue.js production bundle..."
if npm run build; then
echo -e "${GREEN}✓ Frontend built successfully${NC}"
echo "Built files available in dist/"
else
echo -e "${YELLOW}Warning: Frontend build failed${NC}"
echo "You can still run the development server with 'npm run serve'"
fi
cd ..
echo ""
echo "======================================"
echo -e "${GREEN}Setup Complete!${NC}"
echo "======================================"
echo ""
echo "You can now run the application:"
echo ""
echo -e "${BLUE}Option 1: Production Mode (Backend only, serves built frontend)${NC}"
echo " ./run.sh"
echo " Then visit: http://localhost:5001"
echo ""
echo -e "${BLUE}Option 2: Development Mode (Hot reload for frontend)${NC}"
echo " Terminal 1 - Backend:"
echo " ./run.sh"
echo ""
echo " Terminal 2 - Frontend:"
echo " cd client"
echo " npm run serve"
echo " Then visit: http://localhost:8080"
echo ""
echo -e "${YELLOW}Note: In development mode, run both servers simultaneously.${NC}"
echo ""