-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild-panel-devmode.sh
More file actions
executable file
·131 lines (113 loc) · 4.12 KB
/
build-panel-devmode.sh
File metadata and controls
executable file
·131 lines (113 loc) · 4.12 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
#!/usr/bin/env bash
set -e
# Always operate from the script's folder (repo root)
cd "$(dirname "$0")"
# --- Config ---
REPO_URL="https://github.com/HORNET-Storage/HORNETS-Relay-Panel.git"
PANEL_DIR="panel-source"
BACKEND_EXE="./hornet-storage"
CONFIG_FILE="config.yaml"
export NODE_OPTIONS="--openssl-legacy-provider --max-old-space-size=4096"
# -------------
echo
echo "==============================="
echo "HORNETS-Relay-Panel Dev Runner"
echo "==============================="
echo
# Check if config.yaml exists and read port early
CONFIG_EXISTS=0
BASE_PORT=""
if [ -f "$CONFIG_FILE" ]; then
CONFIG_EXISTS=1
PARSED_PORT=$(grep "port:" "$CONFIG_FILE" | grep -v "http" | head -1 | sed 's/.*port:\s*//' | tr -d '[:space:]')
if [ -n "$PARSED_PORT" ]; then
BASE_PORT="$PARSED_PORT"
WEB_PORT=$((BASE_PORT + 2))
DEV_PORT=$((BASE_PORT + 3))
echo "Config found - Base port: $BASE_PORT - API port: $WEB_PORT - Dev server port: $DEV_PORT"
fi
fi
if [ "$CONFIG_EXISTS" -eq 0 ]; then
echo "No config.yaml found - relay will generate it on first run."
fi
# 1) Clone panel if missing (no pull/update if it already exists)
if [ ! -d "$PANEL_DIR" ]; then
if ! command -v git >/dev/null 2>&1; then
echo "ERROR: git not found in PATH."
exit 1
fi
echo "Cloning panel to $PANEL_DIR ..."
git clone "$REPO_URL" "$PANEL_DIR" || { echo "ERROR: clone failed."; exit 1; }
fi
# Sanity check the panel project exists
if [ ! -f "$PANEL_DIR/package.json" ]; then
echo "ERROR: $PANEL_DIR/package.json not found."
exit 1
fi
# 2) Build the RELAY using root build.sh
if [ ! -f "build.sh" ]; then
echo "ERROR: Root build.sh not found."
exit 1
fi
echo "Running root build.sh (relay)..."
./build.sh
# 3) Run the backend exe from the root
if [ ! -f "$BACKEND_EXE" ]; then
echo "ERROR: $BACKEND_EXE not found in repo root after build."
echo "Tip: confirm build.sh outputs the binary to the root, or adjust BACKEND_EXE path."
exit 1
fi
echo "Starting backend: $BACKEND_EXE"
$BACKEND_EXE &
# 4) If config didn't exist before, wait for relay to generate it and read port
if [ "$CONFIG_EXISTS" -eq 0 ]; then
echo "Waiting for relay to generate config.yaml..."
sleep 3
if [ -f "$CONFIG_FILE" ]; then
PARSED_PORT=$(grep "port:" "$CONFIG_FILE" | grep -v "http" | head -1 | sed 's/.*port:\s*//' | tr -d '[:space:]')
if [ -n "$PARSED_PORT" ]; then
BASE_PORT="$PARSED_PORT"
fi
fi
if [ -z "$BASE_PORT" ]; then
echo "WARNING: Could not read port from config.yaml, using default 11000"
BASE_PORT="11000"
fi
WEB_PORT=$((BASE_PORT + 2))
DEV_PORT=$((BASE_PORT + 3))
echo "Config generated - Base port: $BASE_PORT - API port: $WEB_PORT - Dev server port: $DEV_PORT"
fi
# 5) Update .env.development with the correct web port
echo "Updating .env.development with port $WEB_PORT..."
if [ -f "$PANEL_DIR/.env.development" ]; then
if grep -q "REACT_APP_BASE_URL=" "$PANEL_DIR/.env.development"; then
sed -i "s|REACT_APP_BASE_URL=http://localhost:[0-9]*|REACT_APP_BASE_URL=http://localhost:$WEB_PORT|g" "$PANEL_DIR/.env.development"
else
echo "REACT_APP_BASE_URL=http://localhost:$WEB_PORT" >> "$PANEL_DIR/.env.development"
fi
fi
# 6) Start the panel in dev mode (current process)
echo
echo "Starting panel dev server (dev mode)..."
cd "$PANEL_DIR"
# Install deps (Yarn preferred, fallback to npm)
if command -v yarn >/dev/null 2>&1; then
yarn install || echo "WARNING: yarn install reported issues."
else
npm install || echo "WARNING: npm install reported issues."
fi
# Create themes directory if it doesn't exist and build themes
echo "Building themes for development..."
mkdir -p "public/themes"
node_modules/.bin/lessc --js --clean-css="--s1 --advanced" src/styles/themes/main.less public/themes/main.css || {
echo "WARNING: Theme building failed. Styles may not load properly."
}
# Prefer CRACO if present; else yarn start; else npm start
echo "Starting React dev server on port $DEV_PORT..."
if [ -f "node_modules/.bin/craco" ]; then
PORT=$DEV_PORT exec npx craco start
elif command -v yarn >/dev/null 2>&1; then
PORT=$DEV_PORT NODE_ENV=development exec yarn start
else
PORT=$DEV_PORT NODE_ENV=development exec npm run start
fi