Skip to content

Commit 501ec96

Browse files
committed
Enhance setup scripts: add environment setup checks and improve error handling
1 parent baa1c33 commit 501ec96

File tree

2 files changed

+101
-8
lines changed

2 files changed

+101
-8
lines changed

scripts/setup-environment.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
3+
# setup-environment.sh - Sets up Python virtual environment and installs all dependencies
4+
5+
# Define color codes
6+
GREEN='\033[0;32m'
7+
YELLOW='\033[1;33m'
8+
RED='\033[0;31m'
9+
NC='\033[0m' # No Color
10+
11+
# Store initial directory
12+
INITIAL_DIR=$(pwd)
13+
14+
# Function to handle errors
15+
handle_error() {
16+
echo -e "${RED}Error: $1${NC}"
17+
cd "$INITIAL_DIR"
18+
exit 1
19+
}
20+
21+
echo -e "${GREEN}Setting up development environment...${NC}"
22+
23+
# Check if we're in scripts directory and navigate accordingly
24+
if [[ $(basename $(pwd)) == "scripts" ]]; then
25+
cd ..
26+
fi
27+
28+
# Verify we're in the project root
29+
if [[ ! -d "server" ]] || [[ ! -d "client" ]]; then
30+
handle_error "Not in project root directory. Please run from the project root or scripts directory."
31+
fi
32+
33+
echo -e "${YELLOW}Setting up Python virtual environment...${NC}"
34+
35+
# Check OS and use appropriate Python command
36+
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
37+
# Windows
38+
if ! py -m venv server/venv; then
39+
handle_error "Failed to create Python virtual environment"
40+
fi
41+
42+
if ! source server/venv/Scripts/activate; then
43+
handle_error "Failed to activate Python virtual environment"
44+
fi
45+
else
46+
# macOS/Linux
47+
if ! python3 -m venv server/venv; then
48+
handle_error "Failed to create Python virtual environment"
49+
fi
50+
51+
if ! source server/venv/bin/activate; then
52+
handle_error "Failed to activate Python virtual environment"
53+
fi
54+
fi
55+
56+
echo -e "${YELLOW}Installing Python dependencies...${NC}"
57+
if ! pip install -r server/requirements.txt; then
58+
handle_error "Failed to install Python dependencies"
59+
fi
60+
61+
echo -e "${YELLOW}Installing npm dependencies...${NC}"
62+
cd client || handle_error "client directory not found"
63+
64+
if ! npm install; then
65+
handle_error "Failed to install npm dependencies"
66+
fi
67+
68+
cd ..
69+
70+
echo -e "${GREEN}Environment setup completed successfully!${NC}"
71+
echo -e "${GREEN}Python virtual environment: server/venv${NC}"
72+
echo -e "${GREEN}All dependencies installed.${NC}"
73+
echo ""
74+
echo -e "${YELLOW}To activate the Python environment manually:${NC}"
75+
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
76+
echo " source server/venv/Scripts/activate"
77+
else
78+
echo " source server/venv/bin/activate"
79+
fi
80+
81+
# Return to initial directory
82+
cd "$INITIAL_DIR"

scripts/start-app.sh

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,40 @@
22

33
# Define color codes
44
GREEN='\033[0;32m'
5+
YELLOW='\033[1;33m'
56
NC='\033[0m' # No Color
67

78
# Store initial directory
89
INITIAL_DIR=$(pwd)
910

1011
# Check if we're in scripts directory and navigate accordingly
1112
if [[ $(basename $(pwd)) == "scripts" ]]; then
13+
SCRIPT_DIR=$(pwd)
1214
cd ..
15+
else
16+
SCRIPT_DIR="./scripts"
17+
fi
18+
19+
# Check if environment is already set up, if not, run setup
20+
if [[ ! -d "server/venv" ]] || [[ ! -d "client/node_modules" ]]; then
21+
echo -e "${YELLOW}Environment not set up. Running setup script...${NC}"
22+
if ! bash "$SCRIPT_DIR/setup-environment.sh"; then
23+
echo "Setup failed. Exiting."
24+
cd "$INITIAL_DIR"
25+
exit 1
26+
fi
1327
fi
1428

1529
echo "Starting API (Flask) server..."
1630

17-
# Check OS and use appropriate Python command
31+
# Activate virtual environment
1832
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
1933
# Windows
20-
py -m venv venv
21-
source venv/Scripts/activate || . venv/Scripts/activate
34+
source server/venv/Scripts/activate || . server/venv/Scripts/activate
2235
else
2336
# macOS/Linux
24-
python3 -m venv venv
25-
source venv/bin/activate || . venv/bin/activate
37+
source server/venv/bin/activate || . server/venv/bin/activate
2638
fi
27-
28-
pip install -r server/requirements.txt
2939
cd server || {
3040
echo "Error: server directory not found"
3141
cd "$INITIAL_DIR"
@@ -50,7 +60,8 @@ cd ../client || {
5060
cd "$INITIAL_DIR"
5161
exit 1
5262
}
53-
npm install
63+
64+
# npm packages should already be installed by setup script
5465
npm run dev -- --no-clearScreen &
5566

5667
# Store the SvelteKit server process ID

0 commit comments

Comments
 (0)