Skip to content

Commit aba9046

Browse files
committed
feat: add WP_BOOT_SYNC_ENABLED
1 parent 30c206e commit aba9046

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

.env.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Enable/disable WordPress sync to public directory
2+
# Set to 'true' to enable automatic sync via post-cmd.sh
3+
WP_BOOT_SYNC_ENABLED=false
4+
15
DB_HOST=
26
DB_NAME=
37
DB_USER=

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,24 @@ composer create-project wp-spaghetti/wp-boot private/wp-boot
6969
cd private/wp-boot
7070
cp .env.dist .env
7171
# Edit .env with your configuration
72+
# IMPORTANT: Set WP_BOOT_SYNC_ENABLED=true to enable WordPress sync
7273
```
7374

75+
**Note:** During `composer create-project`, WordPress core will be downloaded to `vendor/wordpress/`, but files will **not** be synced to your `public/` directory until you set `WP_BOOT_SYNC_ENABLED=true` in your `.env` file.
76+
77+
This gives you time to:
78+
1. Review and configure your `.env` file
79+
2. Verify the target `public/` directory exists and is correct
80+
3. Decide when to sync WordPress files
81+
82+
Once configured, run:
83+
84+
```bash
85+
composer install # or composer update
86+
```
87+
88+
This will trigger the sync script and copy WordPress core files to `../../public/`.
89+
7490
Then add the bootstrap block to your `wp-config.php` file (see "How It Works" section above).
7591

7692
### Directory Structure

post-cmd.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,41 @@ _check_dependencies() {
1818
fi
1919
}
2020

21+
_load_env_files() {
22+
local env_file=".env"
23+
local env_files=("${env_file}")
24+
25+
# Check for environment-specific .env files (same logic as bootstrap.php)
26+
if [[ -n "${APP_ENV:-}" ]]; then
27+
env_files+=("${env_file}.${APP_ENV}")
28+
fi
29+
30+
# Load .env files in order (later files override earlier ones)
31+
for file in "${env_files[@]}"; do
32+
if [[ -f "${file}" ]]; then
33+
echo "Loading environment from: ${file}"
34+
# Export variables while preserving quotes and handling comments
35+
set -a
36+
# shellcheck disable=SC1090
37+
source <(grep -v '^[[:space:]]*#' "${file}" | grep -v '^[[:space:]]*$')
38+
set +a
39+
fi
40+
done
41+
}
42+
2143
main() {
2244
_check_dependencies
2345

46+
# Load .env files
47+
_load_env_files
48+
49+
# Check if sync is enabled
50+
if [[ "${WP_BOOT_SYNC_ENABLED:-false}" != "true" ]]; then
51+
echo "WordPress sync is disabled (WP_BOOT_SYNC_ENABLED is not set to 'true')."
52+
echo "To enable sync, set WP_BOOT_SYNC_ENABLED=true in your .env file."
53+
exit 0
54+
fi
55+
2456
if [[ "$#" -lt 1 ]]; then
2557
echo "Missing argument 'dest'." >&2
2658
echo "Use: $0 <dest>"

0 commit comments

Comments
 (0)