Skip to content

Commit 3692ab7

Browse files
authored
Merge pull request #29 from woocommerce/fix/fix-missing-hook-references
add logic to ensure that the hooks inside of the woocommerce/src/ are parsed
2 parents ad2a1db + 8b9f13b commit 3692ab7

File tree

4 files changed

+117
-21
lines changed

4 files changed

+117
-21
lines changed

β€Ž.gitignoreβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
*.zip
22
build/
3-
woocommerce/
3+
woocommerce
44
vendor/
55
!data/templates/woocommerce/

β€ŽREADME.mdβ€Ž

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,28 @@ git clone https://github.com/woocommerce/code-reference.git
1010

1111
## Usage
1212

13+
### Production Deployment
14+
1315
```bash
1416
cd code-reference
1517
./deploy.sh -s <VERSION>
1618
```
1719

20+
### Local Development
21+
22+
For local development and testing with your own WooCommerce installation:
23+
24+
```bash
25+
cd code-reference
26+
./run-local.sh
27+
```
28+
29+
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`).
30+
31+
After generation, the Documenation will be served from the `build/api` folder.
32+
33+
A local web server will start at `http://localhost:8000`.
34+
1835
### Options
1936

2037
| Options | Description |

β€Žgenerate-hook-docs.phpβ€Ž

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ class HookDocsGenerator
2525
*/
2626
protected const SEARCH_INDEX_PATH = 'build/api/js/searchIndex.js';
2727

28-
/**
29-
* List of files found.
30-
*
31-
* @var array
32-
*/
33-
protected static $found_files = [];
34-
3528
/**
3629
* Get files to scan.
3730
*
@@ -54,9 +47,9 @@ protected static function getFilesToScan(): array
5447
self::getFiles('*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/export/'),
5548
self::getFiles('*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/gateways/'),
5649
self::getFiles('*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/import/'),
57-
self::getFiles('*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/shipping/')
50+
self::getFiles('*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/shipping/'),
51+
self::getFiles('*.php', GLOB_MARK, self::SOURCE_PATH . 'src/')
5852
);
59-
6053
return array_filter($files);
6154
}
6255

@@ -108,18 +101,9 @@ protected static function getFiles($pattern, $flags = 0, $path = '')
108101

109102
if (is_array($paths)) {
110103
foreach ($paths as $p) {
111-
$found_files = [];
112104
$retrieved_files = (array) self::getFiles($pattern, $flags, $p . '/');
113-
foreach ($retrieved_files as $file) {
114-
if (! in_array($file, self::$found_files)) {
115-
$found_files[] = $file;
116-
}
117-
}
118-
119-
self::$found_files = array_merge(self::$found_files, $found_files);
120-
121-
if (is_array($files) && is_array($found_files)) {
122-
$files = array_merge($files, $found_files);
105+
if (is_array($files) && is_array($retrieved_files)) {
106+
$files = array_merge($files, $retrieved_files);
123107
}
124108
}
125109
}

β€Žrun-local.shβ€Ž

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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

Comments
Β (0)