From 18d1ca729f4655d16bf66a03c9ba075d9d02a099 Mon Sep 17 00:00:00 2001 From: Travis Carden <42520-TravisCarden@users.noreply.drupalcode.org> Date: Thu, 10 Nov 2022 08:35:42 -0500 Subject: [PATCH] Issue #3318933 by TravisCarden: Create a script to re/install the module into an existing local development environment --- scripts/install_module.sh | 86 ++++++++++++++++++++++++++++++++++++++ scripts/phpcbf.sh | 2 + scripts/phpcs.sh | 2 + scripts/phpunit.sh | 2 + scripts/setup_local_dev.sh | 3 ++ 5 files changed, 95 insertions(+) create mode 100755 scripts/install_module.sh diff --git a/scripts/install_module.sh b/scripts/install_module.sh new file mode 100755 index 0000000000..7533c1a0cc --- /dev/null +++ b/scripts/install_module.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash + +# NAME +# install_module.sh - Re/install the module in a local dev environment. +# +# SYNOPSIS +# bash scripts/install_module.sh +# +# DESCRIPTION +# Install this module physically (i.e., code only, no database changes) into +# an existing local development environment, e.g., one created with +# scripts/setup_local_dev.sh. Only files committed to Git will be affected. +# Excluded files such as settings.php will not be changed or deleted. + +# cSpell:disable + +cd "$(dirname "$0")/../" || exit; + +MODULE_DIRECTORY=$(pwd) + +# Find the site root directory. Check up to three directories above. +DIR=$(pwd) +for i in {0..3}; do + DIR=$(dirname "$DIR") + if test -f "$DIR/core/composer.json"; then + SITE_DIRECTORY="$DIR" + break + fi +done + +# Exit if the site can't be found. +if test -z "$SITE_DIRECTORY"; then + echo "Could not find the local development environment. Are you inside a Drupal site's 'modules' directory?" + exit 1 +fi + +cd "$SITE_DIRECTORY" || exit 1 + +# Eliminate any changes to the environment because they will need to be +# overwritten--especially Composer files. +git reset --hard + +# Tell Composer to look for the package in the local clone. This is done rather +# than MERELY cloning the module so that the composer.json of the code under +# development is actually exercised and dependencies don't have to be added +# manually. +composer config \ + repositories.automatic_updates \ + path \ + "$MODULE_DIRECTORY" + +# Prevent Composer from symlinking path repositories. +export COMPOSER_MIRROR_PATH_REPOS=1 + +# Update the Composer platform PHP emulation. +composer config platform.php 7.4.0 + +# Prevent Composer from installing symlinks from common packages known to +# contain them. +# @see https://www.drupal.org/docs/develop/using-composer/using-drupals-vendor-hardening-composer-plugin +composer config --json extra.drupal-core-vendor-hardening.drush/drush '["docs"]' +composer config --json extra.drupal-core-vendor-hardening.grasmash/yaml-expander '["scenarios"]' + +# Require the module using the checked out dev branch. +composer require \ + --no-ansi \ + drupal/automatic_updates:*@dev + +# Revert needless changes to Core Composer metapackages. +git checkout -- "$SITE_DIRECTORY/composer/Metapackage" + +cat << DONE + +$(printf "\e[1;34m")================================================================================ +$(printf "\e[1;33m") + oooooooooo. .oooooo. ooooo ooo oooooooooooo .o. + '888' 'Y8b d8P' 'Y8b '888b. '8' '888' '8 888 + 888 888 888 888 8 '88b. 8 888 888 + 888 888 888 888 8 '88b. 8 888oooo8 Y8P + 888 888 888 888 8 '88b.8 888 ' '8' + 888 d88' '88b d88' 8 '888 888 o .o. + o888bood8P' 'Y8bood8P' o8o '8 o888ooooood8 Y8P + +$(printf "\e[1;34m")================================================================================ + +DONE diff --git a/scripts/phpcbf.sh b/scripts/phpcbf.sh index 0575ea6aef..04a06c8d5c 100755 --- a/scripts/phpcbf.sh +++ b/scripts/phpcbf.sh @@ -13,6 +13,8 @@ # It is assumed that this module is inside a Drupal core installation, in # modules or modules/contrib. See setup_local_dev.sh. +# cSpell:disable + cd "$(dirname "$0")" || exit 0; # Find PHPCBF in Drupal core. Check up to three directories up. diff --git a/scripts/phpcs.sh b/scripts/phpcs.sh index 8ffb58ffec..f6fc8cca7c 100755 --- a/scripts/phpcs.sh +++ b/scripts/phpcs.sh @@ -13,6 +13,8 @@ # It is assumed that this module is inside a Drupal core installation, in # modules or modules/contrib. See setup_local_dev.sh. +# cSpell:disable + cd "$(dirname "$0")" || exit 0; # Find PHPCS in Drupal core. Check up to three directories up. diff --git a/scripts/phpunit.sh b/scripts/phpunit.sh index 4a58223074..7ef23b583b 100755 --- a/scripts/phpunit.sh +++ b/scripts/phpunit.sh @@ -12,6 +12,8 @@ # It is assumed that this module is inside a Drupal core installation, in # modules or modules/contrib. See setup_local_dev.sh. +# cSpell:disable + cd "$(dirname "$0")" || exit 0; # Find PHPUnit in Drupal core. Check up to three directories up. diff --git a/scripts/setup_local_dev.sh b/scripts/setup_local_dev.sh index 34d696c9a1..06fb68b25f 100755 --- a/scripts/setup_local_dev.sh +++ b/scripts/setup_local_dev.sh @@ -12,6 +12,8 @@ # installing the module and its dependencies. It does NOT set up a web # server or install Drupal in a database. +# cSpell:disable + # GNU realpath can't be depended upon to always be available. Simulate it. # https://stackoverflow.com/questions/3572030/bash-script-absolute-path-with-os-x safe_realpath() { @@ -108,6 +110,7 @@ modules profiles themes # Drupal site configuration +default sites # Composer libraries vendor -- GitLab