diff --git a/build-frontend.bat b/build-frontend.bat new file mode 100644 index 00000000..b980d8dc --- /dev/null +++ b/build-frontend.bat @@ -0,0 +1,174 @@ +@echo off +REM ***************************************************************************** +REM Copyright 2025 Intel Corporation +REM +REM Licensed under the Apache License, Version 2.0 (the "License"); +REM you may not use this file except in compliance with the License. +REM You may obtain a copy of the License at +REM +REM http://www.apache.org/licenses/LICENSE-2.0 +REM +REM Unless required by applicable law or agreed to in writing, software +REM distributed under the License is distributed on an "AS IS" BASIS, +REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +REM See the License for the specific language governing permissions and +REM limitations under the License. +REM ***************************************************************************** + +setlocal enabledelayedexpansion + +echo [INFO] Oadin Control Panel Frontend Build Script (Windows) + +set "PROJECT_ROOT=%~dp0" +set "PROJECT_ROOT=%PROJECT_ROOT:~0,-1%" + +echo [INFO] Project root: %PROJECT_ROOT% + +echo [INFO] Checking if Node.js is installed... +call node --version >nul 2>&1 +if errorlevel 1 ( + echo [ERROR] Node.js not found, please install Node.js first + echo [INFO] Download from: https://nodejs.org/ + pause + exit /b 1 +) + +call npm --version >nul 2>&1 +if errorlevel 1 ( + echo [ERROR] npm not found, please reinstall Node.js + pause + exit /b 1 +) + +echo [SUCCESS] Node.js and npm are available + +echo [INFO] Checking if pnpm is installed... +call pnpm --version >nul 2>&1 +if errorlevel 1 ( + echo [ERROR] pnpm command not found, please install pnpm first + echo [INFO] You can install it with: npm install -g pnpm + pause + exit /b 1 +) + +echo [SUCCESS] pnpm check passed + +set "FRONTEND_DIR=%PROJECT_ROOT%\frontend\app\webConsole" +set "CONSOLE_DIR=%PROJECT_ROOT%\console" + +if not exist "%FRONTEND_DIR%" ( + echo [ERROR] Frontend directory not found: %FRONTEND_DIR% + pause + exit /b 1 +) + +if not exist "%CONSOLE_DIR%" ( + echo [ERROR] Console directory not found: %CONSOLE_DIR% + pause + exit /b 1 +) + +echo [SUCCESS] Directory structure check passed + +echo [INFO] Entering frontend directory: %FRONTEND_DIR% +cd /d "%FRONTEND_DIR%" + +:: ---------------------------------------------------------------------- +:: Proxy injection for pnpm +:: ---------------------------------------------------------------------- +set /p "USER_INPUT=[INFO] Do you want to set proxy values for pnpm using system environment variables? [Y/N]: " + +if /i "%USER_INPUT%"=="Y" ( + echo [INFO] Checking for system proxy environment variables... + set "HAS_PROXY_CONFIG=false" + + if defined http_proxy ( + echo [INFO] Detected http_proxy: %http_proxy% + set "HAS_PROXY_CONFIG=true" + ) + if defined https_proxy ( + echo [INFO] Detected https_proxy: %https_proxy% + set "HAS_PROXY_CONFIG=true" + ) + + if "!HAS_PROXY_CONFIG!"=="true" ( + if defined http_proxy ( + call pnpm config set httpProxy "%http_proxy%" + ) + if defined https_proxy ( + call pnpm config set httpsProxy "%https_proxy%" + ) + ) else ( + echo [INFO] No proxy environment variables found, skipping pnpm proxy config. + ) + goto AfterProxy +) + +if /i "%USER_INPUT%"=="N" ( + echo [INFO] Skipping pnpm proxy config. + goto AfterProxy +) + +echo [WARN] Invalid input. Please enter Y or N next time. + +:AfterProxy + + +echo [INFO] Installing frontend dependencies... +call pnpm i + +if errorlevel 1 ( + echo [ERROR] Failed to install dependencies + pause + exit /b 1 +) + +echo [SUCCESS] Dependencies installed successfully + +echo [INFO] Building frontend... +call pnpm run build + +if errorlevel 1 ( + echo [ERROR] Frontend build failed + pause + exit /b 1 +) + +echo [SUCCESS] Frontend build completed + +set "DIST_DIR=%FRONTEND_DIR%\dist" +if not exist "%DIST_DIR%" ( + echo [ERROR] Build output directory not found: %DIST_DIR% + pause + exit /b 1 +) + +set "CONSOLE_DIST_DIR=%CONSOLE_DIR%\dist" +if exist "%CONSOLE_DIST_DIR%" ( + echo [INFO] Cleaning existing dist directory... + rmdir /s /q "%CONSOLE_DIST_DIR%" 2>nul +) + +echo [INFO] Deploying build artifacts to console directory... +move "%DIST_DIR%" "%CONSOLE_DIST_DIR%" >nul + +if errorlevel 1 ( + echo [ERROR] Deployment failed + pause + exit /b 1 +) + +echo [SUCCESS] Deployment completed + +if exist "%CONSOLE_DIST_DIR%\index.html" ( + echo [SUCCESS] Verification passed: index.html file exists +) else ( + echo [ERROR] Verification failed: index.html file not found + pause + exit /b 1 +) + +echo [SUCCESS] Control Panel frontend build and deployment completed! +echo [INFO] You can now start Oadin service and visit http://127.0.0.1:16699/ + +pause diff --git a/build-frontend.sh b/build-frontend.sh new file mode 100644 index 00000000..54793697 --- /dev/null +++ b/build-frontend.sh @@ -0,0 +1,173 @@ +#!/bin/bash +#***************************************************************************** +# Copyright 2025 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#***************************************************************************** + + +# Oadin Control Panel Frontend Build Script +# This script automates frontend build and deployment to console directory + +set -e # Exit on error + +# 颜色定义 +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# 打印带颜色的消息 +print_info() { + echo -e "${BLUE}[INFO]${NC} $1" +} + +print_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +print_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +# Check if command exists +check_command() { + if ! command -v $1 &> /dev/null; then + print_error "$1 command not found, please install $1 first" + exit 1 + fi +} + +# 获取脚本所在目录(项目根目录) +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$SCRIPT_DIR" + +print_info "Oadin Control Panel Frontend Build Script" +print_info "Project root: $PROJECT_ROOT" + +# Check required commands +print_info "Checking required dependencies..." +check_command "pnpm" + +# Check directory structure +FRONTEND_DIR="$PROJECT_ROOT/frontend/app/webConsole" +CONSOLE_DIR="$PROJECT_ROOT/console" + +if [ ! -d "$FRONTEND_DIR" ]; then + print_error "Frontend directory not found: $FRONTEND_DIR" + exit 1 +fi + +if [ ! -d "$CONSOLE_DIR" ]; then + print_error "Console directory not found: $CONSOLE_DIR" + exit 1 +fi + +print_success "Directory structure check passed" + +# Enter frontend directory +print_info "Entering frontend directory: $FRONTEND_DIR" +cd "$FRONTEND_DIR" + +# ---------------------------------------------------------------------- +# Proxy injection for pnpm +# ---------------------------------------------------------------------- +read -p "[INFO] Do you want to set proxy values for pnpm using system environment variables? [Y/N]: " USER_INPUT +if [[ "$USER_INPUT" == "Y" || "$USER_INPUT" == "y" ]]; then + print_info "Checking for system proxy environment variables..." + HAS_PROXY_CONFIG=false + + if [ ! -z "$http_proxy" ]; then + print_info "Detected http_proxy: $http_proxy" + pnpm config set httpProxy "$http_proxy" + HAS_PROXY_CONFIG=true + fi + + if [ ! -z "$https_proxy" ]; then + print_info "Detected https_proxy: $https_proxy" + pnpm config set httpsProxy "$https_proxy" + HAS_PROXY_CONFIG=true + fi + + if [ "$HAS_PROXY_CONFIG" = false ]; then + print_info "No proxy environment variables found, skipping pnpm proxy config." + fi +elif [[ "$USER_INPUT" == "N" || "$USER_INPUT" == "n" ]]; then + print_info "Skipping pnpm proxy config." +else + print_warning "Invalid input. Please enter Y or N next time." +fi + +# Install dependencies +print_info "Installing frontend dependencies..." +pnpm install + +if [ $? -ne 0 ]; then + print_error "Failed to install dependencies" + exit 1 +fi + +print_success "Dependencies installed successfully" + +# Build frontend +print_info "Building frontend..." +pnpm build + +if [ $? -ne 0 ]; then + print_error "Frontend build failed" + exit 1 +fi + +print_success "Frontend build completed" + +# Check build artifacts +DIST_DIR="$FRONTEND_DIR/dist" +if [ ! -d "$DIST_DIR" ]; then + print_error "Build output directory not found: $DIST_DIR" + exit 1 +fi + +# Clean existing dist directory (if exists) +CONSOLE_DIST_DIR="$CONSOLE_DIR/dist" +if [ -d "$CONSOLE_DIST_DIR" ]; then + print_info "Cleaning existing dist directory..." + rm -rf "$CONSOLE_DIST_DIR" +fi + +# Move build artifacts to console directory +print_info "Deploying build artifacts to console directory..." +mv "$DIST_DIR" "$CONSOLE_DIST_DIR" + +if [ $? -ne 0 ]; then + print_error "Deployment failed" + exit 1 +fi + +print_success "Deployment completed" + +# Verify deployment result +if [ -f "$CONSOLE_DIST_DIR/index.html" ]; then + print_success "Verification passed: index.html file exists" +else + print_error "Verification failed: index.html file not found" + exit 1 +fi + +print_success "🎉 Control Panel frontend build and deployment completed!" +print_info "You can now start Oadin service and visit http://127.0.0.1:16699/" +