|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -o errexit # Abort if any command fails |
| 3 | + |
| 4 | +# Change to the script's directory for safety |
| 5 | +cd "$(dirname "$0")" |
| 6 | + |
| 7 | +echo "π WooCommerce Code Reference Generator - Local Development" |
| 8 | +echo "==========================================================" |
| 9 | +echo "" |
| 10 | +echo "Usage: ./run-local.sh [source-directory]" |
| 11 | +echo " - If source-directory is provided, use that as WooCommerce source" |
| 12 | +echo " - If no argument provided, use ./woocommerce if it exists, otherwise prompt" |
| 13 | +echo "" |
| 14 | + |
| 15 | +# Check if PHP is available |
| 16 | +if ! command -v php &> /dev/null; then |
| 17 | + echo "β PHP is not installed or not in PATH" |
| 18 | + exit 1 |
| 19 | +fi |
| 20 | + |
| 21 | +# Check if Composer is available |
| 22 | +if ! command -v composer &> /dev/null; then |
| 23 | + echo "β Composer is not installed or not in PATH" |
| 24 | + exit 1 |
| 25 | +fi |
| 26 | + |
| 27 | +# Install dependencies if vendor directory doesn't exist |
| 28 | +if [ ! -d "vendor" ]; then |
| 29 | + echo "π¦ Installing dependencies..." |
| 30 | + composer install |
| 31 | +fi |
| 32 | + |
| 33 | +# Determine WooCommerce directory |
| 34 | +if [ $# -eq 1 ]; then |
| 35 | + # Use provided source directory |
| 36 | + WOOCOMMERCE_DIR="$1" |
| 37 | + echo "π Using provided source directory: $WOOCOMMERCE_DIR" |
| 38 | +elif [ -d "woocommerce" ]; then |
| 39 | + # Use existing woocommerce directory in current project |
| 40 | + WOOCOMMERCE_DIR="woocommerce" |
| 41 | + echo "π Found existing woocommerce directory in current project." |
| 42 | +else |
| 43 | + # Prompt user for WooCommerce directory |
| 44 | + echo "π Please provide the path to your WooCommerce directory." |
| 45 | + echo "Example: /Users/YourUserName/woocommerce/plugins/woocommerce" |
| 46 | + echo "" |
| 47 | + read -p "Enter WooCommerce directory path: " WOOCOMMERCE_DIR |
| 48 | +fi |
| 49 | + |
| 50 | +# Check if directory exists |
| 51 | +if [ ! -d "$WOOCOMMERCE_DIR" ]; then |
| 52 | + echo "β WooCommerce plugin directory not found at: $WOOCOMMERCE_DIR" |
| 53 | + echo " Please check the path and try again." |
| 54 | + exit 1 |
| 55 | +fi |
| 56 | + |
| 57 | +echo "π Using WooCommerce plugin directory: $WOOCOMMERCE_DIR" |
| 58 | + |
| 59 | +# Copy files if we're using an external path (not the existing woocommerce directory) |
| 60 | +if [ "$WOOCOMMERCE_DIR" != "woocommerce" ]; then |
| 61 | + # Always remove existing woocommerce directory when using external source |
| 62 | + if [ -d "woocommerce" ]; then |
| 63 | + echo "ποΈ Removing existing woocommerce directory..." |
| 64 | + rm -rf woocommerce |
| 65 | + fi |
| 66 | + |
| 67 | + echo "π Copying WooCommerce files..." |
| 68 | + mkdir -p woocommerce |
| 69 | + |
| 70 | + # Copy only the directories we want for documentation |
| 71 | + cp -r "$WOOCOMMERCE_DIR"/includes woocommerce/ 2>/dev/null || true |
| 72 | + cp -r "$WOOCOMMERCE_DIR"/src woocommerce/ 2>/dev/null || true |
| 73 | + cp -r "$WOOCOMMERCE_DIR"/templates woocommerce/ 2>/dev/null || true |
| 74 | +else |
| 75 | + echo "π Using existing woocommerce directory in project." |
| 76 | +fi |
| 77 | + |
| 78 | +# Generate documentation |
| 79 | +echo "π§ Generating documentation from local WooCommerce source..." |
| 80 | +echo "" |
| 81 | +./deploy.sh --no-download --build-only --source-version 0.0.0 |
| 82 | + |
| 83 | +echo "" |
| 84 | +echo "β
Documentation generated successfully!" |
| 85 | +echo "π Output location: ./build/api/" |
| 86 | +echo "" |
| 87 | +echo "π Starting local web server for WooCommerce Code Reference..." |
| 88 | +echo "π Serving from: ./build/api" |
| 89 | +echo "π URL: http://localhost:8000" |
| 90 | +echo "" |
| 91 | +echo "Press Ctrl+C to stop the server" |
| 92 | +echo "" |
| 93 | + |
| 94 | +# Start PHP development server |
| 95 | +php -S localhost:8000 -t build/api |
0 commit comments