-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·180 lines (161 loc) · 6.05 KB
/
setup.sh
File metadata and controls
executable file
·180 lines (161 loc) · 6.05 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
#!/usr/bin/env bash
# Setup and build script for SimpleWish
set -e
# Parse command line arguments
BUILD_MODE=false
# Auto-detect Cloudflare Pages environment and set ROOT_DOMAIN accordingly
# Cloudflare Pages provides CF_PAGES_URL which contains the deployment URL
if [ -n "$CF_PAGES_URL" ]; then
# Running in Cloudflare Pages build environment
ROOT_DOMAIN="${ROOT_DOMAIN:-$CF_PAGES_URL}"
else
# Not in Cloudflare Pages environment or CF_PAGES_URL not available
ROOT_DOMAIN="${ROOT_DOMAIN:-INSERT-DOMAIN-NAME}"
fi
RECIPIENTS_DIR="${RECIPIENTS_DIR:-recipients}"
QR_OUT_DIR="${QR_OUT_DIR:-scripts/generated_qr}"
PUBLIC_DIR="${PUBLIC_DIR:-public}"
while [[ $# -gt 0 ]]; do
case $1 in
--build)
BUILD_MODE=true
shift
;;
--help|-h)
echo "Usage: ./setup.sh [OPTIONS]"
echo ""
echo "Options:"
echo " --build Run Cloudflare Pages build (generate HTML, QR codes, prepare public/)"
echo " --help, -h Show this help message"
echo ""
echo "Environment variables for --build mode:"
echo " ROOT_DOMAIN Domain for QR codes"
echo " Auto-detected from CF_PAGES_URL when running in Cloudflare Pages"
echo " Falls back to INSERT-DOMAIN-NAME if not set"
echo " RECIPIENTS_DIR Directory with recipient JSON files (default: recipients)"
echo " QR_OUT_DIR Output directory for QR SVGs (default: scripts/generated_qr)"
echo " PUBLIC_DIR Output directory for deployment (default: public)"
echo ""
echo "Cloudflare Pages:"
echo " When running in Cloudflare Pages, CF_PAGES_URL is automatically used as ROOT_DOMAIN"
echo " You can override this by explicitly setting ROOT_DOMAIN environment variable"
echo ""
echo "Examples:"
echo " ./setup.sh # Normal setup"
echo " ./setup.sh --build # Build (uses CF_PAGES_URL if available)"
echo " ROOT_DOMAIN=\"https://example.com\" ./setup.sh --build # Build with custom domain"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
if [ "$BUILD_MODE" = true ]; then
echo "🎄 SimpleWish - Build SSG Files"
echo "========================================"
echo ""
if [ -n "$CF_PAGES_URL" ]; then
echo "✓ Detected Cloudflare Pages environment"
echo " Using CF_PAGES_URL: $CF_PAGES_URL"
echo ""
fi
echo "Configuration:"
echo " ROOT_DOMAIN: $ROOT_DOMAIN"
echo " RECIPIENTS_DIR: $RECIPIENTS_DIR"
echo " QR_OUT_DIR: $QR_OUT_DIR"
echo " PUBLIC_DIR: $PUBLIC_DIR"
echo ""
else
echo "🎄 SimpleWish Quick Setup"
echo "========================="
echo ""
fi
# Check Python version
if ! command -v python3 &> /dev/null; then
echo "❌ Error: Python 3 is not installed"
echo " Please install Python 3.11 or later"
exit 1
fi
PYTHON_VERSION=$(python3 --version | cut -d' ' -f2)
echo "✓ Found Python $PYTHON_VERSION"
echo ""
# Create virtual environment
if [ ! -d ".venv" ]; then
echo "Creating virtual environment..."
python3 -m venv .venv
echo "✓ Virtual environment created"
else
echo "✓ Virtual environment already exists"
fi
echo ""
# Activate virtual environment and install dependencies
echo "Installing dependencies..."
source .venv/bin/activate
pip install -q --upgrade pip
pip install -q -r scripts/requirements.txt
pip install -q -r scripts/requirements-dev.txt
echo "✓ Dependencies installed"
echo ""
# Run tests and linter
# Run tests to verify everything works
echo "Running tests to verify setup..."
python3 -m pytest -q
echo "✓ Tests passed"
echo ""
# Run linter
echo "Running linter..."
python3 -m flake8
echo "✓ Linter passed"
echo ""
if [ "$BUILD_MODE" = true ]; then
# Build mode: Generate HTML, QR codes, and prepare for deployment
# Step 1: Generate HTML for all JSON recipients
echo "Step 1/4: Generating HTML files from recipient data..."
if [ -d "$RECIPIENTS_DIR" ] && compgen -G "$RECIPIENTS_DIR/*.json" > /dev/null; then
python3 scripts/generate_recipient.py --bulk --recipients-dir "$RECIPIENTS_DIR"
echo "✓ HTML files generated"
else
echo "ℹ No recipient JSON files found in $RECIPIENTS_DIR, skipping generation"
fi
echo ""
# Step 2: Generate QR SVGs
echo "Step 2/4: Generating QR codes..."
python3 scripts/generate_qr_svg.py --pattern "*.html" --out-dir "$QR_OUT_DIR" --root-domain "$ROOT_DOMAIN"
echo "✓ QR codes generated"
echo ""
# Step 3: Inject generated SVGs into HTML files
echo "Step 3/4: Injecting QR codes into HTML files..."
python3 scripts/inject_qr_svg.py --svg-dir "$QR_OUT_DIR" --pattern "*.html"
echo "✓ QR codes injected"
echo ""
# Step 4: Prepare public directory
echo "Step 4/4: Preparing output directory..."
mkdir -p "$PUBLIC_DIR"
# Move HTML files if they exist
if compgen -G "*.html" > /dev/null; then
mv -- *.html "$PUBLIC_DIR/"
echo "✓ Files moved to $PUBLIC_DIR/"
else
echo "⚠ No HTML files found to move"
fi
echo ""
echo "🎉 Build complete!"
echo ""
echo "Output directory: $PUBLIC_DIR"
echo "Ready for Static Deployment"
else
echo "🎉 Setup complete!"
echo ""
echo "Next steps:"
echo " 1. Copy index.html to create a new list (e.g., elsa.html)"
echo " 2. Edit the HTML file with gift ideas"
echo " 3. Generate QR codes:"
echo " python3 scripts/generate_qr_svg.py --root-domain YOUR_GITHUB_PAGES_URL --pattern '*.html' --out-dir scripts/generated_qr"
echo " 4. Inject QR codes into HTML files:"
echo " python3 scripts/inject_qr_svg.py --svg-dir scripts/generated_qr --pattern '*.html'"
echo ""
echo "See README.md for more details!"
fi