#!/bin/bash # CI/CD Site/Documentation Builder # This script builds and deploys VitePress documentation with version management. # Usage: ./scripts/ci_site.sh [OPTIONS] - Specify options for the script execution. set -euo pipefail # Constants # Resolve the folder containing this script so relative paths work SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" DOCS_DIR="${PROJECT_ROOT}/docs" readonly SCRIPT_DIR readonly PROJECT_ROOT readonly DOCS_DIR # Load shared configuration if [[ -f "${SCRIPT_DIR}/ci_00_config.sh" ]]; then source "${SCRIPT_DIR}/ci_00_config.sh" else echo "ERROR: ci_00_config.sh not found" >&2 exit 1 fi # Final output directory for the site readonly SITE_OUTPUT_DIR="${PROJECT_ROOT}/${SITE_DIR}" # Default values MODE="prod" # Set the default mode to production CURL_INSECURE=false # Allow curl to skip TLS verification (use only when needed) CLEAN=false # Clean generated/site before build LEGACY_OPENSSL=false # Use --openssl-legacy-provider for older Node.js versions # Function to check required tools check_requirements() { log_info "Checking required tools..." local missing_tools=() if ! command -v node >/dev/null 2>&1; then missing_tools+=("node") # Node.js is required else local node_version node_version=$(node --version) log_info "✓ Node.js ${node_version} found" fi if ! command -v npm >/dev/null 2>&1; then missing_tools+=("npm") # npm is required else local npm_version npm_version=$(npm --version) log_info "✓ npm ${npm_version} found" fi if ! command -v openssl >/dev/null 2>&1; then missing_tools+=("openssl") # OpenSSL is required else local openssl_version openssl_version=$(openssl version | grep -oP '\d+\.\d+\.\d+' || echo "unknown") log_info "✓ OpenSSL ${openssl_version} found" fi if [[ ${#missing_tools[@]} -gt 0 ]]; then log_error "Missing required tools: ${missing_tools[*]}" return 1 fi log_info "All required tools are available" return 0 } # Function to install dependencies install_dependencies() { log_info "Installing dependencies..." # Install Node dependencies log_info "Installing Node.js dependencies..." cd "${PROJECT_ROOT}" npm install --quiet || { log_error "Failed to install Node.js dependencies" return 1 } log_info "Dependencies installed successfully" } # Function to download common config download_common_config() { log_info "Downloading common configuration..." local config_url="https://www.theengs.io/commonConfig.js" local config_dest="${DOCS_DIR}/.vitepress/public/commonConfig.js" local curl_opts="-sSf" # Optionally disable TLS verification if explicitly requested if [[ "${CURL_INSECURE}" == "true" ]]; then curl_opts+="k" log_warn "curl is running with --insecure; TLS verification is disabled" fi mkdir -p "$(dirname "$config_dest")" if curl ${curl_opts} -o "$config_dest" "$config_url"; then log_info "✓ Common config downloaded" else log_warn "Failed to download common config, continuing anyway..." fi } create_configuration_files() { local url_prefix="$1" local version="$2" local mode="$3" # Note: dest is always "generated/site" (from defaults.json). # The dev subdirectory is handled by destination_dir in the GitHub Actions deploy step. # download common config download_common_config ## Create a meta.json file on config folder local meta_file="${DOCS_DIR}/.vitepress/meta.json" cat > "$meta_file" <