|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +SITE_WEB="$SITE_ROOT/web" |
| 4 | +SITE_APP="$SITE_ROOT/app" |
| 5 | + |
| 6 | +# Colors. |
| 7 | +RED=$'\E[1;31m' |
| 8 | +GREEN=$'\E[1;32m' |
| 9 | +BLUE=$'\E[1;34m' |
| 10 | + |
| 11 | +# Message status. |
| 12 | +COLOR_RESET=$'\E[0m' |
| 13 | +MSG_ERROR="${RED}[ERROR]${COLOR_RESET}" |
| 14 | +MSG_OK="${GREEN}[OK]${COLOR_RESET}" |
| 15 | +MSG_INFO="${BLUE}[INFO]${COLOR_RESET}" |
| 16 | + |
| 17 | +## |
| 18 | +# Check if the "app" folder exists. |
| 19 | +# |
| 20 | +if [ ! -d "$SITE_APP" ]; then |
| 21 | + echo "${MSG_ERROR} 'app' folder does not exist" |
| 22 | + exit 1 |
| 23 | +else |
| 24 | + echo "${MSG_OK} 'app' folder exists" |
| 25 | +fi |
| 26 | + |
| 27 | +## |
| 28 | +# Check if the "web" folder exists. |
| 29 | +# |
| 30 | +if [ ! -d "$SITE_WEB" ]; then |
| 31 | + echo "${MSG_ERROR} 'web' folder does not exist" |
| 32 | + exit 1 |
| 33 | +else |
| 34 | + echo "${MSG_OK} 'web' folder exists" |
| 35 | +fi |
| 36 | + |
| 37 | +## |
| 38 | +# Check if the stub files exist. |
| 39 | +# See \DrupalComposer\DrupalParanoia $frontControllers |
| 40 | +# |
| 41 | +STUB_FILES=( |
| 42 | +"web/index.php" |
| 43 | +"web/core/install.php" |
| 44 | +"web/core/rebuild.php" |
| 45 | +"web/core/modules/statistics/statistics.php" |
| 46 | +) |
| 47 | + |
| 48 | +for STUB_FILE_PATH in ${STUB_FILES[*]}; do |
| 49 | + if [ ! -f "$STUB_FILE_PATH" ]; then |
| 50 | + echo "${MSG_ERROR} stub file '$STUB_FILE_PATH' does not exist" |
| 51 | + exit 1 |
| 52 | + else |
| 53 | + echo "${MSG_OK} stub file '$STUB_FILE_PATH' exists" |
| 54 | + fi |
| 55 | + |
| 56 | + # Check if the stub file has the correct code. |
| 57 | + STUB_FILE=$( basename "$STUB_FILE_PATH" ) |
| 58 | + if [ $( grep -c "require './$STUB_FILE';" "$STUB_FILE_PATH" ) -eq 0 ]; then |
| 59 | + echo "${MSG_ERROR} stub file '$STUB_FILE_PATH' does not contain the correct content" |
| 60 | + exit 1 |
| 61 | + else |
| 62 | + echo "${MSG_OK} stub file '$STUB_FILE_PATH' contains the correct content" |
| 63 | + fi |
| 64 | +done |
| 65 | + |
| 66 | +## |
| 67 | +# Check if there are no PHP files in the "web" folder. |
| 68 | +# It is ignoring the stub files. |
| 69 | +# |
| 70 | +if [ $( grep -Rl "<?php" "$SITE_WEB" | awk '{print $0" "}' | tr -d '\n' | grep -vc "$SITE_WEB/index.php $SITE_WEB/core/install.php $SITE_WEB/core/rebuild.php $SITE_WEB/core/modules/statistics/statistics.php" ) -eq 1 ]; then |
| 71 | + grep -Rl "<?php" "$SITE_WEB" |
| 72 | + echo "${MSG_ERROR} there are PHP files (non-stub files) in the web directory" |
| 73 | + exit 1 |
| 74 | +else |
| 75 | + echo "${MSG_OK} there are no PHP files (non-stub files) in the web directory" |
| 76 | +fi |
| 77 | + |
| 78 | +## |
| 79 | +# Install a Drupal package using Composer and check if the package's assets have been symlinked. |
| 80 | +# |
| 81 | +echo "${MSG_INFO} installing 'drupal/bootstrap' to check if the theme assets will be symlinked to web directory" |
| 82 | +cd "$SITE_ROOT" |
| 83 | +composer require --update-no-dev drupal/bootstrap || exit 1 |
| 84 | + |
| 85 | +BOOTSTRAP_SYMLINK="$SITE_WEB/themes/contrib/bootstrap/screenshot.png" |
| 86 | +if [ ! -L "$BOOTSTRAP_SYMLINK" ]; then |
| 87 | + echo "${MSG_ERROR} '$BOOTSTRAP_SYMLINK' does not exist or it is not a symlink" |
| 88 | + exit 1 |
| 89 | +else |
| 90 | + echo "${MSG_OK} $BOOTSTRAP_SYMLINK has been symlinked" |
| 91 | +fi |
| 92 | + |
| 93 | +## |
| 94 | +# Remove the Drupal package using "composer remove" and check if the package's assets have been removed from the "web" directory. |
| 95 | +# |
| 96 | +echo "${MSG_INFO} removing 'drupal/bootstrap' to check if the theme's assets will be removed from the web directory" |
| 97 | + |
| 98 | +composer remove drupal/bootstrap || exit 1 |
| 99 | + |
| 100 | +if [ -d "$SITE_WEB/themes/contrib/bootstrap" ]; then |
| 101 | + echo "${MSG_ERROR} the 'drupal/bootstrap' assets still exist in the web directory after the package has been removed" |
| 102 | + exit 1 |
| 103 | +else |
| 104 | + echo "${MSG_OK} 'drupal/bootstrap' assets have been removed from the web directory" |
| 105 | +fi |
| 106 | + |
| 107 | +## |
| 108 | +# Create a theme image, run the command 'composer drupal:paranoia' and check if the image has been symlinked. |
| 109 | +# |
| 110 | +touch "$SITE_APP/themes/travis-test-image.jpg" |
| 111 | + |
| 112 | +# Rebuild web directory. |
| 113 | +composer drupal:paranoia || exit 1 |
| 114 | + |
| 115 | +if [ ! -L "$SITE_WEB/themes/travis-test-image.jpg" ]; then |
| 116 | + echo "${MSG_ERROR} 'composer drupal:paranoia' command did not re-create the web directory with new symlinks" |
| 117 | + exit 1 |
| 118 | +else |
| 119 | + echo "${MSG_OK} 'composer drupal:paranoia' command re-created the web directory with new symlinks" |
| 120 | +fi |
0 commit comments