diff --git a/.gitignore b/.gitignore index cfd4ba8f3..166d7ded9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ *.zip build/ -woocommerce/ +woocommerce vendor/ !data/templates/woocommerce/ diff --git a/README.md b/README.md index 15c505cc0..d748b5f8f 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,28 @@ git clone https://github.com/woocommerce/code-reference.git ## Usage +### Production Deployment + ```bash cd code-reference ./deploy.sh -s ``` +### Local Development + +For local development and testing with your own WooCommerce installation: + +```bash +cd code-reference +./run-local.sh +``` + +The script will prompt you for the path to your WooCommerce plugin directory. This should be the directory containing the main WooCommerce plugin files (e.g., `Users/YourUserName/woocommerce/plugins/woocommerce`). + +After generation, the Documenation will be served from the `build/api` folder. + +A local web server will start at `http://localhost:8000`. + ### Options | Options | Description | diff --git a/generate-hook-docs.php b/generate-hook-docs.php index ceccc068e..20f7c9467 100644 --- a/generate-hook-docs.php +++ b/generate-hook-docs.php @@ -25,13 +25,6 @@ class HookDocsGenerator */ protected const SEARCH_INDEX_PATH = 'build/api/js/searchIndex.js'; - /** - * List of files found. - * - * @var array - */ - protected static $found_files = []; - /** * Get files to scan. * @@ -54,9 +47,9 @@ protected static function getFilesToScan(): array self::getFiles('*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/export/'), self::getFiles('*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/gateways/'), self::getFiles('*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/import/'), - self::getFiles('*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/shipping/') + self::getFiles('*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/shipping/'), + self::getFiles('*.php', GLOB_MARK, self::SOURCE_PATH . 'src/') ); - return array_filter($files); } @@ -108,18 +101,9 @@ protected static function getFiles($pattern, $flags = 0, $path = '') if (is_array($paths)) { foreach ($paths as $p) { - $found_files = []; $retrieved_files = (array) self::getFiles($pattern, $flags, $p . '/'); - foreach ($retrieved_files as $file) { - if (! in_array($file, self::$found_files)) { - $found_files[] = $file; - } - } - - self::$found_files = array_merge(self::$found_files, $found_files); - - if (is_array($files) && is_array($found_files)) { - $files = array_merge($files, $found_files); + if (is_array($files) && is_array($retrieved_files)) { + $files = array_merge($files, $retrieved_files); } } } diff --git a/run-local.sh b/run-local.sh new file mode 100755 index 000000000..272b3ff3a --- /dev/null +++ b/run-local.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env bash +set -o errexit # Abort if any command fails + +# Change to the script's directory for safety +cd "$(dirname "$0")" + +echo "🚀 WooCommerce Code Reference Generator - Local Development" +echo "==========================================================" +echo "" +echo "Usage: ./run-local.sh [source-directory]" +echo " - If source-directory is provided, use that as WooCommerce source" +echo " - If no argument provided, use ./woocommerce if it exists, otherwise prompt" +echo "" + +# Check if PHP is available +if ! command -v php &> /dev/null; then + echo "❌ PHP is not installed or not in PATH" + exit 1 +fi + +# Check if Composer is available +if ! command -v composer &> /dev/null; then + echo "❌ Composer is not installed or not in PATH" + exit 1 +fi + +# Install dependencies if vendor directory doesn't exist +if [ ! -d "vendor" ]; then + echo "📦 Installing dependencies..." + composer install +fi + +# Determine WooCommerce directory +if [ $# -eq 1 ]; then + # Use provided source directory + WOOCOMMERCE_DIR="$1" + echo "📁 Using provided source directory: $WOOCOMMERCE_DIR" +elif [ -d "woocommerce" ]; then + # Use existing woocommerce directory in current project + WOOCOMMERCE_DIR="woocommerce" + echo "📁 Found existing woocommerce directory in current project." +else + # Prompt user for WooCommerce directory + echo "📁 Please provide the path to your WooCommerce directory." + echo "Example: /Users/YourUserName/woocommerce/plugins/woocommerce" + echo "" + read -p "Enter WooCommerce directory path: " WOOCOMMERCE_DIR +fi + +# Check if directory exists +if [ ! -d "$WOOCOMMERCE_DIR" ]; then + echo "❌ WooCommerce plugin directory not found at: $WOOCOMMERCE_DIR" + echo " Please check the path and try again." + exit 1 +fi + +echo "📁 Using WooCommerce plugin directory: $WOOCOMMERCE_DIR" + +# Copy files if we're using an external path (not the existing woocommerce directory) +if [ "$WOOCOMMERCE_DIR" != "woocommerce" ]; then + # Always remove existing woocommerce directory when using external source + if [ -d "woocommerce" ]; then + echo "🗑️ Removing existing woocommerce directory..." + rm -rf woocommerce + fi + + echo "📁 Copying WooCommerce files..." + mkdir -p woocommerce + + # Copy only the directories we want for documentation + cp -r "$WOOCOMMERCE_DIR"/includes woocommerce/ 2>/dev/null || true + cp -r "$WOOCOMMERCE_DIR"/src woocommerce/ 2>/dev/null || true + cp -r "$WOOCOMMERCE_DIR"/templates woocommerce/ 2>/dev/null || true +else + echo "📁 Using existing woocommerce directory in project." +fi + +# Generate documentation +echo "🔧 Generating documentation from local WooCommerce source..." +echo "" +./deploy.sh --no-download --build-only --source-version 0.0.0 + +echo "" +echo "✅ Documentation generated successfully!" +echo "📁 Output location: ./build/api/" +echo "" +echo "🌐 Starting local web server for WooCommerce Code Reference..." +echo "📁 Serving from: ./build/api" +echo "🌍 URL: http://localhost:8000" +echo "" +echo "Press Ctrl+C to stop the server" +echo "" + +# Start PHP development server +php -S localhost:8000 -t build/api