docs(quick-1): Create start.sh with development menu

- Interactive menu for dev, test, build, preview, lint, clean, install
- Auto-installs dependencies if missing
- Supports direct command-line arguments
This commit is contained in:
2026-03-13 11:01:25 +08:00
parent 9e3cc99bed
commit b474f7067a
4 changed files with 200 additions and 1 deletions

114
start.sh Executable file
View File

@@ -0,0 +1,114 @@
#!/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)"
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"
echo -e " ${GREEN}2)${NC} test Run tests"
echo -e " ${GREEN}3)${NC} test:watch Run tests in watch mode"
echo -e " ${GREEN}4)${NC} build Build for production"
echo -e " ${GREEN}5)${NC} preview Preview production build"
echo -e " ${GREEN}6)${NC} lint Run linter"
echo -e " ${GREEN}7)${NC} clean Clean build artifacts"
echo -e " ${GREEN}8)${NC} install Install dependencies"
echo ""
echo -e " ${RED}0)${NC} Exit"
echo ""
}
run_command() {
local option=$1
cd "$PROJECT_DIR"
case $option in
1|dev)
echo -e "${BLUE}Starting development server...${NC}"
npm run dev
;;
2|test)
echo -e "${BLUE}Running tests...${NC}"
npm test
;;
3|test:watch)
echo -e "${BLUE}Running tests in watch mode...${NC}"
npm run test:watch
;;
4|build)
echo -e "${BLUE}Building for production...${NC}"
npm run build
echo -e "${GREEN}Build complete!${NC}"
;;
5|preview)
echo -e "${BLUE}Previewing production build...${NC}"
npm run preview
;;
6|lint)
echo -e "${BLUE}Running linter...${NC}"
npm run lint
;;
7|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}"
;;
8|install)
echo -e "${BLUE}Installing dependencies...${NC}"
npm install
echo -e "${GREEN}Dependencies installed!${NC}"
;;
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
# If arguments provided, run directly
if [ $# -gt 0 ]; then
run_command "$1"
exit 0
fi
# Interactive menu
while true; do
show_menu
echo -n -e "${BOLD}Enter your choice (0-8): ${NC}"
read -r choice
echo ""
run_command "$choice"
echo ""
done