#!/bin/bash # # Build Scribe Security documentation from source for local development. # This ensures all internal links work correctly with the /docs base path. # # Usage: ./scripts/download-docs.sh [--force] # set -e # Get the directory where the script is located SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" PROJECT_ROOT="$( cd "${SCRIPT_DIR}/.." && pwd )" DOCS_DIR="${PROJECT_ROOT}/static/docs" DOCS_REPO="https://github.com/scribe-security/docs.git" TEMP_DIR=$(mktemp -d) FORCE=false # Cleanup function cleanup() { rm -rf "${TEMP_DIR}" } trap cleanup EXIT # Parse arguments while [[ $# -gt 0 ]]; do case $1 in -f|--force) FORCE=true shift ;; *) echo "Unknown option: $1" echo "Usage: $0 [--force]" exit 1 ;; esac done # Check if docs already exist if [ -d "${DOCS_DIR}" ] && [ -n "$(ls -A ${DOCS_DIR} 2>/dev/null)" ] && [ "${FORCE}" = false ]; then echo "Documentation already exists in ${DOCS_DIR}" echo "Use --force to rebuild" exit 0 fi # Check for required tools if ! command -v node &> /dev/null; then echo "❌ Error: Node.js is required but not installed." echo "Please install Node.js 18+ from https://nodejs.org/" exit 1 fi if ! command -v git &> /dev/null; then echo "❌ Error: Git is required but not installed." exit 1 fi echo "================================================" echo "Building Scribe Security Documentation" echo "================================================" echo "Repository: ${DOCS_REPO}" echo "Target: ${DOCS_DIR}" echo "" # Clone the docs repository echo "📥 Cloning documentation repository..." git clone --depth 1 "${DOCS_REPO}" "${TEMP_DIR}" # Build the documentation echo "🔨 Installing dependencies..." cd "${TEMP_DIR}" npm ci --silent echo "🔨 Building documentation (baseUrl=/docs)..." DOCUSAURUS_BASE_URL=/docs npm run build # Copy built docs to target directory echo "📦 Copying built documentation..." rm -rf "${DOCS_DIR}" mkdir -p "${DOCS_DIR}" cp -r "${TEMP_DIR}/build/"* "${DOCS_DIR}/" echo "" echo "✅ Documentation built successfully in ${DOCS_DIR}" echo "" echo "The docs will be available at http://localhost:5003/docs when you run the app." echo "All internal links are configured to work with the /docs base path."