- Logo: Use LOGO_TCK_small.png instead of SVG - start.sh: Fix arbitrary port handling (dev:8888 now works) - Header: Move LOGIN indicator to top-left next to logo - NavigationButtons: Make Up/Down horizontal, match title size
212 lines
6.2 KiB
Bash
Executable File
212 lines
6.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# TCK RTU - Start Script
|
|
# Interactive menu for common development commands
|
|
|
|
set -e
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
CYAN='\033[0;36m'
|
|
NC='\033[0m' # No Color
|
|
BOLD='\033[1m'
|
|
|
|
# Project directory
|
|
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/sample_interface" && pwd)"
|
|
|
|
# Default ports
|
|
DEV_PORT=5173
|
|
PREVIEW_PORT=4173
|
|
|
|
echo -e "${CYAN}${BOLD}"
|
|
echo "╔══════════════════════════════════════════════════════╗"
|
|
echo "║ TCK RTU - Development Menu ║"
|
|
echo "╚══════════════════════════════════════════════════════╝"
|
|
echo -e "${NC}"
|
|
|
|
show_menu() {
|
|
echo -e "${BOLD}Select an option:${NC}"
|
|
echo ""
|
|
echo -e " ${GREEN}1)${NC} dev Start development server (port $DEV_PORT)"
|
|
echo -e " ${GREEN}2)${NC} dev:8080 Start dev server on port 8080 (kiosk mode)"
|
|
echo -e " ${GREEN}3)${NC} dev:9090 Start dev server on port 9090 (remote mode)"
|
|
echo -e " ${GREEN}4)${NC} test Run tests"
|
|
echo -e " ${GREEN}5)${NC} test:watch Run tests in watch mode"
|
|
echo -e " ${GREEN}6)${NC} build Build for production"
|
|
echo -e " ${GREEN}7)${NC} preview Preview production (port $PREVIEW_PORT)"
|
|
echo -e " ${GREEN}8)${NC} lint Run linter"
|
|
echo -e " ${GREEN}9)${NC} clean Clean build artifacts"
|
|
echo -e " ${GREEN}10)${NC} install Install dependencies"
|
|
echo -e " ${GREEN}p)${NC} port Change default port"
|
|
echo ""
|
|
echo -e " ${RED}0)${NC} Exit"
|
|
echo ""
|
|
}
|
|
|
|
get_ip_address() {
|
|
# Try to get the primary IP address
|
|
if command -v ip &> /dev/null; then
|
|
IP=$(ip route get 1.1.1.1 2>/dev/null | grep -oP 'src \K[^ ]+' | head -1)
|
|
elif command -v ifconfig &> /dev/null; then
|
|
IP=$(ifconfig 2>/dev/null | grep -oP 'inet \K[\d.]+' | grep -v '127.0.0.1' | head -1)
|
|
fi
|
|
|
|
if [ -z "$IP" ]; then
|
|
IP="localhost"
|
|
fi
|
|
echo "$IP"
|
|
}
|
|
|
|
show_connection_info() {
|
|
local port=$1
|
|
local IP=$(get_ip_address)
|
|
echo ""
|
|
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${GREEN} Server running at:${NC}"
|
|
echo -e "${GREEN} - Local: http://localhost:$port${NC}"
|
|
echo -e "${GREEN} - Network: http://$IP:$port${NC}"
|
|
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo ""
|
|
}
|
|
|
|
run_dev_server() {
|
|
local port=${1:-$DEV_PORT}
|
|
cd "$PROJECT_DIR"
|
|
echo -e "${BLUE}Starting development server on port $port...${NC}"
|
|
echo -e "${YELLOW}(Press Ctrl+C to stop)${NC}"
|
|
echo ""
|
|
VITE_PORT=$port npm run dev -- --host &
|
|
DEV_PID=$!
|
|
show_connection_info $port
|
|
wait $DEV_PID
|
|
}
|
|
|
|
run_preview_server() {
|
|
local port=${1:-$PREVIEW_PORT}
|
|
cd "$PROJECT_DIR"
|
|
echo -e "${BLUE}Starting preview server on port $port...${NC}"
|
|
echo -e "${YELLOW}(Press Ctrl+C to stop)${NC}"
|
|
echo ""
|
|
VITE_PORT=$port npm run preview -- --host &
|
|
PREVIEW_PID=$!
|
|
show_connection_info $port
|
|
wait $PREVIEW_PID
|
|
}
|
|
|
|
change_port() {
|
|
echo -e "${BOLD}Change Default Port${NC}"
|
|
echo ""
|
|
echo -e "Current: Dev=$DEV_PORT, Preview=$PREVIEW_PORT"
|
|
echo ""
|
|
echo -n "Enter new dev port (current: $DEV_PORT): "
|
|
read -r new_dev_port
|
|
if [ -n "$new_dev_port" ]; then
|
|
DEV_PORT=$new_dev_port
|
|
fi
|
|
|
|
echo -n "Enter new preview port (current: $PREVIEW_PORT): "
|
|
read -r new_preview_port
|
|
if [ -n "$new_preview_port" ]; then
|
|
PREVIEW_PORT=$new_preview_port
|
|
fi
|
|
|
|
echo -e "${GREEN}Ports updated! Dev=$DEV_PORT, Preview=$PREVIEW_PORT${NC}"
|
|
echo ""
|
|
}
|
|
|
|
run_command() {
|
|
local option=$1
|
|
cd "$PROJECT_DIR"
|
|
|
|
case $option in
|
|
1|dev)
|
|
run_dev_server $DEV_PORT
|
|
;;
|
|
2|dev:8080)
|
|
run_dev_server 8080
|
|
;;
|
|
3|dev:9090)
|
|
run_dev_server 9090
|
|
;;
|
|
4|test)
|
|
echo -e "${BLUE}Running tests...${NC}"
|
|
npm test
|
|
;;
|
|
5|test:watch)
|
|
echo -e "${BLUE}Running tests in watch mode...${NC}"
|
|
npm run test:watch
|
|
;;
|
|
6|build)
|
|
echo -e "${BLUE}Building for production...${NC}"
|
|
npm run build
|
|
echo -e "${GREEN}Build complete!${NC}"
|
|
;;
|
|
7|preview)
|
|
run_preview_server $PREVIEW_PORT
|
|
;;
|
|
8|lint)
|
|
echo -e "${BLUE}Running linter...${NC}"
|
|
npm run lint
|
|
;;
|
|
9|clean)
|
|
echo -e "${YELLOW}Cleaning build artifacts...${NC}"
|
|
rm -rf "$PROJECT_DIR/dist"
|
|
rm -rf "$PROJECT_DIR/node_modules/.vite"
|
|
echo -e "${GREEN}Clean complete!${NC}"
|
|
;;
|
|
10|install)
|
|
echo -e "${BLUE}Installing dependencies...${NC}"
|
|
npm install
|
|
echo -e "${GREEN}Dependencies installed!${NC}"
|
|
;;
|
|
p|port)
|
|
change_port
|
|
;;
|
|
0|exit)
|
|
echo -e "${GREEN}Goodbye!${NC}"
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo -e "${RED}Invalid option. Please try again.${NC}"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# Check if dependencies are installed
|
|
if [ ! -d "$PROJECT_DIR/node_modules" ]; then
|
|
echo -e "${YELLOW}Dependencies not found. Running npm install...${NC}"
|
|
cd "$PROJECT_DIR"
|
|
npm install
|
|
fi
|
|
|
|
# Parse command line arguments
|
|
if [ $# -gt 0 ]; then
|
|
# Check for port override
|
|
if [[ "$1" == dev:* ]]; then
|
|
port="${1#dev:}"
|
|
run_dev_server "$port"
|
|
elif [[ "$1" == preview:* ]]; then
|
|
port="${1#preview:}"
|
|
run_preview_server "$port"
|
|
elif [[ "$1" =~ ^[[:digit:]]+$ ]]; then
|
|
# Direct port number
|
|
run_dev_server "$1"
|
|
else
|
|
run_command "$1"
|
|
fi
|
|
exit 0
|
|
fi
|
|
|
|
# Interactive menu
|
|
while true; do
|
|
show_menu
|
|
echo -n -e "${BOLD}Enter your choice (0-10 or p): ${NC}"
|
|
read -r choice
|
|
echo ""
|
|
run_command "$choice"
|
|
echo ""
|
|
done
|