Skip to content

Commit

Permalink
Add .ddev support
Browse files Browse the repository at this point in the history
  • Loading branch information
inpsyde-maticluznar committed Jul 19, 2024
1 parent 8bd2a3c commit d747f63
Show file tree
Hide file tree
Showing 28 changed files with 6,416 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .ddev/commands/web/orchestrate
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
## Description: Set up the development environment
## Usage: orchestrate
## Example: "ddev orchestrate"

mkdir -p "${DDEV_DOCROOT}"
pushd "${DDEV_DOCROOT}"
PLUGIN_FOLDER="${DDEV_DOCROOT}/wp-content/plugins/assets-plugin"
VALID_ARGS=$(getopt -o fp: --long force,plugin: -- "$@")
if [[ $? -ne 0 ]]; then
exit 1;
fi

eval set -- "$VALID_ARGS"
while [ : ]; do
case "$1" in
-f | --force)
echo "Removing WordPress installation"
shift
export RECREATE_ENV=1;
popd
find "${DDEV_DOCROOT}" -mindepth 1 ! -regex "^${PLUGIN_FOLDER}\(/.*\)?" -delete
pushd "${DDEV_DOCROOT}"
;;
-p | --plugin)
echo "Processing 'delta' option. Input argument is '$2'"
shift 2
;;
--) shift;
break
;;
esac
done

# Execute all fragments from orchestrate.d
if [ -d "${0}.d" ]; then
for FN in ${0}.d/*.sh ; do
echo $FN
source "${FN}"
done
fi
6 changes: 6 additions & 0 deletions .ddev/commands/web/orchestrate.d/00_download_wordpress.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

if ! wp core download --version="${WP_VERSION:-latest}"; then
echo 'WordPress is already installed.'
exit
fi
6 changes: 6 additions & 0 deletions .ddev/commands/web/orchestrate.d/01_gitignore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

cat << 'EOF' > ".gitignore"
# ignores everything in the docroot (docroot in config.yaml), this path may not be included in the standard .ddev/.gitignore.
*
EOF
22 changes: 22 additions & 0 deletions .ddev/commands/web/orchestrate.d/05_wp_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ssh#!/bin/bash

# Create wp-config.php
# the PHP snippet avoids some notices during CLI calls
# https://make.wordpress.org/cli/handbook/guides/common-issues/#php-notice-undefined-index-on-_server-superglobal
printf '
if ( defined( "WP_CLI" ) && WP_CLI && ! isset( $_SERVER["HTTP_HOST"] ) ) {
$_SERVER["HTTP_HOST"] = "%s";
}
' "${DDEV_HOSTNAME}" | wp config create \
--dbname=db \
--dbuser=db \
--dbpass=db \
--dbhost=db \
--force \
--extra-php

wp config set WP_DEBUG true --raw
wp config set WP_DEBUG_DISPLAY true --raw
wp config set WP_DEBUG_LOG true --raw
wp config set WP_SITEURL '(isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] ? "https://" : "http://") . $_SERVER["HTTP_HOST"]' --raw
wp config set WP_HOME '(isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] ? "https://" : "http://") . $_SERVER["HTTP_HOST"]' --raw
32 changes: 32 additions & 0 deletions .ddev/commands/web/orchestrate.d/10_wp_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

if [ ! -z "${RECREATE_ENV}" ]; then
echo "Deleting database before creating a new one"
wp db clean --yes
fi

if [ "${WP_MULTISITE}" = "true" ]; then
wp core multisite-install \
--title="${WP_TITLE}" \
--admin_user="${ADMIN_USER}" \
--admin_password="${ADMIN_PASS}" \
--url="${DDEV_PRIMARY_URL}" \
--admin_email="${ADMIN_EMAIL}" \
--skip-email

readarray -d , -t slugs <<< "${WP_MULTISITE_SLUGS},"; unset "slugs[-1]";
for slug in "${slugs[@]}"; do
if [ ! -z "${slug}" ]; then
wp site create --slug="${slug}"
fi
done

else
wp core install \
--title="${WP_TITLE}" \
--admin_user="${ADMIN_USER}" \
--admin_password="${ADMIN_PASS}" \
--url="${DDEV_PRIMARY_URL}" \
--admin_email="${ADMIN_EMAIL}" \
--skip-email
fi
16 changes: 16 additions & 0 deletions .ddev/commands/web/orchestrate.d/11_htaccess.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

cat << 'EOF' >> ".htaccess"
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

wp plugin is-installed akismet && wp plugin uninstall akismet
wp plugin is-installed hello && wp plugin uninstall hello
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

pushd wp-content/plugins/assets-plugin
composer install
npm install
popd
popd
10 changes: 10 additions & 0 deletions .ddev/commands/web/orchestrate.d/40_setup_and_activate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

pushd "${DDEV_DOCROOT}"

flags=""
if [ "${WP_MULTISITE}" = "true" ]; then
flags+=" --network"
fi

wp plugin activate assets-plugin $flags
4 changes: 4 additions & 0 deletions .ddev/commands/web/orchestrate.d/50_flush_rewrites.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

wp rewrite structure '/%postname%'
wp rewrite flush
Loading

0 comments on commit d747f63

Please sign in to comment.