-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve local development scripts (#151)
* Improve start and stop scripts * Add schema and suppress pro notice * Opt-in to browser opening
- Loading branch information
1 parent
3bc6114
commit 000e79f
Showing
10 changed files
with
141 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,130 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
root_dir=$(pwd) | ||
env_type=$1 | ||
|
||
# Cleanup after error or trapping SIGINT (Ctrl+C) and SIGTERM signals | ||
APP_MODE="$1" # "decoupled" or empty | ||
|
||
# Set WordPress port and home URL. | ||
PORT="${WP_ENV_PORT-8888}" | ||
WP_HOME="${WP_ENV_HOME_URL-http://localhost:$PORT}" | ||
|
||
if [ "$APP_MODE" = "decoupled" ]; then | ||
# When running in decoupled mode, listen on a different port to avoid | ||
# sticky cached redirects. | ||
PORT="${WP_ENV_PORT-8899}" | ||
|
||
WP_HOME="${WP_ENV_HOME_URL-http://localhost:3000}" | ||
fi | ||
|
||
FLAGS="${WP_ENV_FLAGS---xdebug}" | ||
WP_ADMIN="http://localhost:$PORT/wp-admin/" | ||
|
||
cleanup() { | ||
exit_code=0 | ||
echo "" | ||
echo "✊ Caught SIG signal. Stopping..." | ||
|
||
npm run -s dev:stop | ||
exit 0 | ||
} | ||
|
||
if [ -n "$1" ]; then | ||
exit_code=1 | ||
echo "⚠️ Error: $1" | ||
activate_plugin() { | ||
slug="$1" | ||
|
||
if (npm run -s wp-cli plugin is-active "$slug" 2>/dev/null); then | ||
echo "✏️ $slug is already active." | ||
else | ||
echo "✊ Caught SIG signal. Shutting down..." | ||
echo "✏️ Activating $slug..." | ||
npm run -s wp-cli plugin activate "$slug" | ||
fi | ||
} | ||
|
||
deactivate_plugin() { | ||
slug="$1" | ||
|
||
if [ -n "$BACKEND_PID" ]; then | ||
echo "Killing npm start process..." | ||
kill "$BACKEND_PID" 2>/dev/null || true | ||
if (npm run -s wp-cli plugin is-active "$slug" 2>/dev/null); then | ||
echo "✏️ Deactivating $slug..." | ||
npm run -s wp-cli plugin deactivate "$slug" | ||
fi | ||
} | ||
|
||
echo "Shutting down Valkey / Redis..." | ||
docker compose -f "$root_dir/docker-compose.overrides.yml" down | ||
install_and_activate_plugin() { | ||
plugin="$1" | ||
slug="$2" | ||
|
||
# This command echoes good status messages. | ||
npx wp-env stop | ||
if (npm run -s wp-cli plugin is-installed "$slug" 2>/dev/null); then | ||
echo "✏️ $slug is already installed." | ||
else | ||
echo "✏️ Installing $slug..." | ||
npm run -s wp-cli plugin install "$plugin" | ||
fi | ||
|
||
echo "" | ||
echo "⏸️ Run \`npm run start:$env_type\` to resume or \`npm run destroy\` to clean up." | ||
exit "$exit_code" | ||
activate_plugin "$slug" | ||
} | ||
|
||
setup_object_cache() { | ||
echo "Setting up object cache..." | ||
docker compose -f "$root_dir/docker-compose.overrides.yml" up -d | ||
# npx wp-env run cli -- wp redis enable | ||
configure_wordpress() { | ||
echo "✏️ Enabling Redis..." | ||
npm run -s wp-cli redis enable | ||
|
||
echo "✏️ Updating home option..." | ||
npm run -s wp-cli config set WP_HOME "$WP_HOME" | ||
|
||
if [ "$APP_MODE" = "decoupled" ]; then | ||
configure_decoupled_wordpress | ||
else | ||
deactivate_plugin "vip-decoupled-bundle" | ||
fi | ||
} | ||
|
||
composer install | ||
configure_decoupled_wordpress() { | ||
# We don't do this by default so we don't accidentally write code that | ||
# depends on a particular permalink structure. | ||
echo "✏️ Updating permalink structure..." | ||
npm run -s wp-cli rewrite structure '/%postname%/' | ||
|
||
trap 'cleanup' INT TERM | ||
install_and_activate_plugin "$DECOUPLED_PLUGIN_URL" "vip-decoupled-bundle" | ||
|
||
# Monolith via wp-env | ||
if [ "$env_type" = "monolith" ]; then | ||
# npx looks in node_modules/.bin first | ||
setup_object_cache | ||
npx wp-env start | ||
npm start | ||
exit 0 | ||
fi | ||
echo "✅ Decoupled configuration complete." | ||
} | ||
|
||
# Monolith w/xdebug via wp-env | ||
if [ "$env_type" = "monolith-xdebug" ]; then | ||
setup_object_cache | ||
npx wp-env start --xdebug=debug,develop,trace | ||
npm start | ||
exit 0 | ||
fi | ||
start_redis() { | ||
echo "🔼 Starting Redis..." | ||
docker compose -f docker-compose.overrides.yml up -d | ||
} | ||
|
||
# Decoupled via wp-env | ||
if [ "$env_type" = "decoupled" ]; then | ||
if [ ! -d "$root_dir/../wp-components" ]; then | ||
echo "⚠️ The wp-components repo does not exist. Please clone at sibling level to this repo." | ||
exit 1 | ||
fi | ||
start_wordpress() { | ||
echo "🔼 Starting WordPress..." | ||
WP_ENV_PORT="$PORT" npx wp-env start "$FLAGS" | ||
} | ||
|
||
cd ./bin/wp-env/decoupled | ||
open_browser() { | ||
echo "" | ||
echo "> 🌐 $WP_ADMIN" | ||
echo "> 🔑 Username: admin" | ||
echo "> 🔑 Password: password" | ||
echo "" | ||
|
||
setup_object_cache | ||
npx wp-env start | ||
npx wp-env run cli -- wp rewrite structure '/%postname%/' | ||
# Opening the browser is disruptive, make users opt-in. | ||
if [ -z "$WP_ENV_OPEN_BROWSER" ]; then | ||
return | ||
fi | ||
|
||
if [ $? -ne 0 ]; then | ||
cleanup "Failed to set permalink structure" | ||
UNAME="$(uname -s)" | ||
|
||
if [ "Darwin" = "$UNAME" ]; then | ||
open "$WP_ADMIN" | ||
elif [ "Linux" = "$UNAME" ]; then | ||
xdg-open "$WP_ADMIN" | ||
fi | ||
} | ||
|
||
npm start & | ||
BACKEND_PID=$! | ||
cd "$root_dir/../wp-components" && npm install && npm run build && ./.frontend-env/start react-next | ||
exit 0 | ||
fi | ||
# Cleanup after error or trapping SIGINT (Ctrl+C) and SIGTERM signals | ||
trap 'cleanup' INT TERM | ||
|
||
start_redis | ||
start_wordpress | ||
configure_wordpress | ||
open_browser | ||
|
||
echo "⚠️ Error: can't start the unknown!" | ||
exit 1 | ||
# Start hot-reloading wp-scripts start | ||
echo "🔼 Starting wp-scripts build process..." | ||
npm start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
#!/bin/sh | ||
|
||
root_dir=$(pwd) | ||
TASK="${1-stop}" | ||
|
||
echo "Shutting down Valkey / Redis..." | ||
docker compose -f "$root_dir/docker-compose.overrides.yml" down | ||
teardown_redis() { | ||
echo "🔽 Shutting down Redis..." | ||
docker compose -f docker-compose.overrides.yml down | ||
} | ||
|
||
# We don't know which environment is running, so we'll stop both and suppress output. | ||
echo "Stopping WordPress..." | ||
cd ./bin/wp-env/decoupled || exit 1 | ||
npx wp-env stop 2>/dev/null | ||
cd "$root_dir" || exit 1 | ||
npx wp-env stop 2>/dev/null | ||
teardown_wordpress() { | ||
if [ "$TASK" = "destroy" ]; then | ||
npx wp-env destroy | ||
echo "👋 Run \`npm run dev\` to recreate." | ||
else | ||
npx wp-env stop | ||
echo "⏹️ Rerun \`npm run dev\` to resume or \`npm run dev:destroy\` to clean up." | ||
fi | ||
} | ||
|
||
# Kill any lingering Node.js processes. | ||
pkill -f 'remote-data-blocks/node_modules/' | ||
|
||
echo "⏸️ Rerun \`npm run start:*\` command to resume or \`npm run destroy\` to clean up." | ||
teardown_redis | ||
teardown_wordpress |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters