-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·148 lines (130 loc) · 6 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·148 lines (130 loc) · 6 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
#!/usr/bin/env bash
set -euo pipefail
# ── Colours ────────────────────────────────────────────────────────────────────
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'
CYAN='\033[0;36m'; BOLD='\033[1m'; RESET='\033[0m'
info() { echo -e "${CYAN}▸ $*${RESET}"; }
success() { echo -e "${GREEN}✓ $*${RESET}"; }
warn() { echo -e "${YELLOW}⚠ $*${RESET}"; }
error() { echo -e "${RED}✗ $*${RESET}" >&2; exit 1; }
step() { echo -e "\n${BOLD}── $* ──────────────────────────────────────${RESET}"; }
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WEB_DIR="$REPO_ROOT/apps/web"
EXT_DIR="$REPO_ROOT/apps/extension"
ENV_FILE="$WEB_DIR/.env"
ENV_EXAMPLE="$WEB_DIR/.env.example"
# ── 1. Prerequisites ───────────────────────────────────────────────────────────
step "Checking prerequisites"
if ! command -v node &>/dev/null; then
error "Node.js not found. Install Node.js 18+ from https://nodejs.org"
fi
NODE_MAJOR=$(node -e "process.stdout.write(process.versions.node.split('.')[0])")
if [ "$NODE_MAJOR" -lt 18 ]; then
error "Node.js 18+ required (found v$(node -v | tr -d v))"
fi
success "Node.js $(node -v)"
if ! command -v npm &>/dev/null; then
error "npm not found"
fi
success "npm $(npm -v)"
# ── 2. Install dependencies ────────────────────────────────────────────────────
step "Installing dependencies"
cd "$REPO_ROOT"
npm install
success "Dependencies installed"
# ── 3. Environment setup ───────────────────────────────────────────────────────
step "Environment configuration"
if [ -f "$ENV_FILE" ]; then
warn ".env already exists — skipping creation"
else
cp "$ENV_EXAMPLE" "$ENV_FILE"
info "Created apps/web/.env from .env.example"
fi
# Generate AUTH_SECRET if empty or placeholder
CURRENT_SECRET=$(grep -E '^AUTH_SECRET=' "$ENV_FILE" | cut -d'"' -f2 || true)
if [ -z "$CURRENT_SECRET" ]; then
if command -v openssl &>/dev/null; then
SECRET=$(openssl rand -base64 32)
else
SECRET=$(node -e "process.stdout.write(require('crypto').randomBytes(32).toString('base64'))")
fi
# Replace the AUTH_SECRET line
if [[ "$OSTYPE" == darwin* ]]; then
sed -i '' "s|^AUTH_SECRET=.*|AUTH_SECRET=\"$SECRET\"|" "$ENV_FILE"
else
sed -i "s|^AUTH_SECRET=.*|AUTH_SECRET=\"$SECRET\"|" "$ENV_FILE"
fi
success "AUTH_SECRET generated"
else
success "AUTH_SECRET already set"
fi
# Check DATABASE_URL
CURRENT_DB=$(grep -E '^DATABASE_URL=' "$ENV_FILE" | cut -d'"' -f2 || true)
DEFAULT_PLACEHOLDER="postgresql://user:password@host/dbname"
if [ -z "$CURRENT_DB" ] || [[ "$CURRENT_DB" == *"user:password@host"* ]]; then
echo ""
echo -e "${YELLOW}DATABASE_URL is not set.${RESET}"
echo "Get a free database at https://neon.tech, then paste the connection string below."
echo "(Or press Enter to skip and set it manually in apps/web/.env later.)"
echo ""
read -rp "DATABASE_URL: " INPUT_DB
if [ -n "$INPUT_DB" ]; then
if [[ "$OSTYPE" == darwin* ]]; then
sed -i '' "s|^DATABASE_URL=.*|DATABASE_URL=\"$INPUT_DB\"|" "$ENV_FILE"
else
sed -i "s|^DATABASE_URL=.*|DATABASE_URL=\"$INPUT_DB\"|" "$ENV_FILE"
fi
success "DATABASE_URL saved"
else
warn "Skipped — set DATABASE_URL in apps/web/.env before running migrations"
fi
else
success "DATABASE_URL already set"
fi
# ── 4. Database migration ──────────────────────────────────────────────────────
step "Running database migrations"
CURRENT_DB=$(grep -E '^DATABASE_URL=' "$ENV_FILE" | cut -d'"' -f2 || true)
if [ -z "$CURRENT_DB" ] || [[ "$CURRENT_DB" == *"user:password@host"* ]]; then
warn "DATABASE_URL not configured — skipping migrations"
warn "Run manually later: cd apps/web && npx prisma migrate dev"
else
cd "$WEB_DIR"
npx prisma migrate dev --name init 2>&1 | grep -v "^$" || true
success "Migrations applied"
cd "$REPO_ROOT"
fi
# ── 5. Build Chrome extension ──────────────────────────────────────────────────
step "Building Chrome extension"
npm -w apps/extension run build
success "Extension built → apps/extension/dist/"
# ── Done ───────────────────────────────────────────────────────────────────────
echo ""
echo -e "${GREEN}${BOLD}Setup complete!${RESET}"
echo ""
echo -e "${BOLD}Next steps:${RESET}"
echo ""
echo -e " ${CYAN}1. Start the web app${RESET}"
echo -e " npm -w apps/web run dev"
echo -e " → opens at http://localhost:3000"
echo ""
echo -e " ${CYAN}2. Create an account${RESET}"
echo -e " http://localhost:3000/register"
echo ""
echo -e " ${CYAN}3. Load the extension in Chrome${RESET}"
echo -e " • Go to chrome://extensions"
echo -e " • Enable Developer mode"
echo -e " • Load unpacked → select apps/extension/"
echo ""
echo -e " ${CYAN}4. Generate and copy your API token${RESET}"
echo -e " Dashboard → Settings → Generate Token"
echo ""
echo -e " ${CYAN}5. Sync your AliExpress orders${RESET}"
echo -e " • Paste token into extension popup → Connect"
echo -e " • Visit https://www.aliexpress.com/p/order/index.html"
echo -e " • Click Sync Now in the extension popup"
echo ""
read -rp "Start the web app now? [y/N] " START
if [[ "$START" =~ ^[Yy]$ ]]; then
info "Starting dev server at http://localhost:3000 ..."
npm -w apps/web run dev
fi