Skip to content

add logic to ensure that the hooks inside of the woocommerce/src/ are parsed #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*.zip
build/
woocommerce/
woocommerce
vendor/
!data/templates/woocommerce/
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,28 @@ git clone https://github.com/woocommerce/code-reference.git

## Usage

### Production Deployment

```bash
cd code-reference
./deploy.sh -s <VERSION>
```

### 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 |
Expand Down
24 changes: 4 additions & 20 deletions generate-hook-docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}
}
}
Expand Down
95 changes: 95 additions & 0 deletions run-local.sh
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +70 to +73
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you prefer this to the symbolic link you tried first?

If the symlink-based approach worked correctly, that'd be faster and less error prone than copying directories as we wouldn't need to keep this script in sync with paths inside the plugin. Everything could be handled from the phpcs.xml file as today.

Copy link
Author

@piinthecloud piinthecloud Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the files were symlinked, not all the files were being parsed. So the site would build, but there would large gaps of content missing, for examples Namespaces were completely empty. cp is slower, but it's the only way I could get it to build out the whole site.

Screenshot 2025-07-25 at 11 34 32

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@piinthecloud I tested the new, non-symlinked approach and it's working for me 👍

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