diff --git a/composer.json b/composer.json index 9911973aba5e08b17351b67a9861bb57e49557ab..e886b62ba3d132cd8a2c6da7dab45901c46763b8 100644 --- a/composer.json +++ b/composer.json @@ -7,13 +7,8 @@ "prefer-stable": true, "authors": [ { - "name": "Mohammed J. Razem", - "homepage": "https://github.com/moerazem", - "role": "Maintainer" - }, - { - "name": "Rajab Natshah", - "homepage": "https://github.com/Natshah", + "name": "Vardot", + "homepage": "https://www.drupal.org/vardot", "role": "Maintainer" } ], @@ -172,30 +167,38 @@ ] }, "scripts": { - "post-install-cmd": [ - "@composer drupal-scaffold", - "./bin/phing push" - ], - "post-update-cmd": [ - "./bin/phing push" - ], - "post-drupal-scaffold-cmd": [ - "Varbase\\composer\\ScriptHandler::postDrupalScaffoldProcedure" - ], - "drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold" + "drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold", + "post-drupal-scaffold-cmd": ["Varbase\\composer\\ScriptHandler::postDrupalScaffoldProcedure"], + "pre-install-cmd": ["Varbase\\composer\\ScriptHandler::checkComposerVersion"], + "pre-update-cmd": ["Varbase\\composer\\ScriptHandler:checkComposerVersion"], + "post-install-cmd": ["Varbase\\composer\\ScriptHandler::createRequiredFiles"], + "post-update-cmd": ["Varbase\\composer\\ScriptHandlerr::createRequiredFiles"], + "post-package-install": ["Varbase\\composer\\ScriptHandler::postInstallProcedure"], + "post-package-update": ["Varbase\\composer\\ScriptHandler::postUpdateProcedure"], + "create-new-vartheme": "scripts/create-new-vartheme.sh", + "varbase-check-tests": "scripts/varbase-check-tests.sh", + "varbase-init-tests": "scripts/varbase-init-tests.sh", + "varbase-apply-tests": "scripts/varbase-apply-tests.sh", + "varbase-cleanup-tests": "scripts/varbase-cleanup-tests.sh", + "varbase-full-tests": "scripts/varbase-full-tests.sh", + "varbase-full-local-tests": "scripts/varbase-full-tests.sh", + "varbase-full-development-tests": "scripts/varbase-full-development-tests.sh", + "varbase-full-staging-tests": "scripts/varbase-full-staging-tests.sh", + "varbase-full-production-tests": "scripts/varbase-full-production-tests.sh" }, "extra": { + "branch-alias": { + "dev-8.x-4.x": "8.4.x-dev" + }, "installer-paths": { "docroot/core": ["drupal/core"], "docroot/profiles/{$name}": ["type:drupal-profile"], "docroot/modules/contrib/{$name}": ["type:drupal-module"], "docroot/themes/contrib/{$name}": ["type:drupal-theme"], - "docroot/libraries/{$name}": ["type:drupal-library"] - }, - "branch-alias": { - "dev-8.x-4.x": "8.4.x-dev" + "docroot/libraries/{$name}": ["type:drupal-library"], + "drush/contrib/{$name}": ["type:drupal-drush"] }, - "drupal-libraries": { + "drupal-libraries": { "library-directory": "docroot/libraries", "libraries": [ {"name": "dropzone","package": "vardot/dropzone"}, @@ -204,6 +207,7 @@ {"name": "ace", "package": "vardot/ace-builds"} ] }, + "enable-patching": true, "patches": { "drupal/core": { "Issue #1356276: Allow profiles to provide a base_parent profile and load them in the correct order": diff --git a/scripts/create-new-vartheme.sh b/scripts/create-new-vartheme.sh new file mode 100644 index 0000000000000000000000000000000000000000..195ccbd8da3f81354a1cea731e119744c000ffdc --- /dev/null +++ b/scripts/create-new-vartheme.sh @@ -0,0 +1,176 @@ +#!/bin/bash + +# Create new vartheme subtheme. + +bootstrap_library_version="3.3.7"; +bootstrap_rtl_library_version="3.4.0"; + +# Default theme name +theme_name="mytheme"; + +# Grape the theme name argument. +if [ "$1" != "" ]; then + if [[ $1 =~ ^[A-Za-z][A-Za-z0-9_]*$ ]]; then + theme_name=$1; + else + echo "---------------------------------------------------------------------------"; + echo " Theme name is not a valid theme name! "; + echo "---------------------------------------------------------------------------"; + exit 1; + fi +else + echo "---------------------------------------------------------------------------"; + echo " Please add the name of your theme! "; + echo "---------------------------------------------------------------------------"; + exit 1; +fi + + + +# Default direction of language. +direction="ltr"; + +# Grape the direction argument. only if we have arg #2. +if [ "$2" != "" ]; then + if [[ $2 == "rtl" || $2 == "RTL" ]]; then + direction=$2; + elif [[ $2 == "ltr" || $2 == "LTR" ]]; then + direction=$2; + else + echo "---------------------------------------------------------------------------"; + echo " Direction of language is not valid! "; + echo " ltr - for (left to right) languages. "; + echo " rtl - for (right to left) languages. "; + echo "---------------------------------------------------------------------------"; + exit 1; + fi +fi + +# Default themes creation path. +theme_path="docroot/themes/custom"; + +# Grape the theme path argument. only if we have arg #3. +if [ "$3" != "" ]; then + if [[ $3 =~ ^[A-Za-z][A-Za-z0-9_-/]*$ ]]; then + arg3=$3; + if [[ "${arg3: -1}" == "/" ]]; then + arg3="${arg3::-1}"; + fi + + if [[ ! -d "$arg3" ]]; then + theme_path=$arg3; + mkdir -p $theme_path; + fi + else + echo "---------------------------------------------------------------------------"; + echo " Theme path must be in the right format! "; + echo "---------------------------------------------------------------------------"; + exit 1; + fi +else + if [[ ! -d "$theme_path" ]]; then + mkdir -p $theme_path; + fi +fi + + +# Create the new Vartheme subtheme if we do not have a folder with that name yet. +if [[ ! -d "$theme_path/$theme_name" ]]; then + # 1. Copy the VARTHEME_SUBTHEME folder to your custom theme location. + cp -r docroot/profiles/varbase/themes/vartheme/VARTHEME_SUBTHEME ${theme_path}/${theme_name} ; + + # 2. Rename VARTHEME_SUBTHEME.starterkit.yml your_subtheme_name.info.yml + mv ${theme_path}/${theme_name}/VARTHEME_SUBTHEME.starterkit.yml ${theme_path}/${theme_name}/VARTHEME_SUBTHEME.info.yml ; + mv ${theme_path}/${theme_name}/VARTHEME_SUBTHEME.info.yml ${theme_path}/${theme_name}/${theme_name}.info.yml ; + + # 3. Rename VARTHEME_SUBTHEME.libraries.yml your_subtheme_name.libraries.yml + mv ${theme_path}/${theme_name}/VARTHEME_SUBTHEME.libraries.yml ${theme_path}/${theme_name}/${theme_name}.libraries.yml ; + + # 4. Rename VARTHEME_SUBTHEME.theme your_subtheme_name.theme + mv ${theme_path}/${theme_name}/VARTHEME_SUBTHEME.theme ${theme_path}/${theme_name}/${theme_name}.theme ; + + # 5. Rename VARTHEME_SUBTHEME.settings.yml + mv ${theme_path}/${theme_name}/config/install/VARTHEME_SUBTHEME.settings.yml ${theme_path}/${theme_name}/config/install/${theme_name}.settings.yml ; + + # 6. Rename VARTHEME_SUBTHEME.schema.yml + mv ${theme_path}/${theme_name}/config/schema/VARTHEME_SUBTHEME.schema.yml ${theme_path}/${theme_name}/config/schema/${theme_name}.schema.yml ; + + # 7. Rename VARTHEME_SUBTHEME optional blocks. + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_SUBTHEME_branding.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_branding.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_SUBTHEME_breadcrumbs.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_breadcrumbs.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_SUBTHEME_content.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_content.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_SUBTHEME_footer.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_footer.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_SUBTHEME_help.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_help.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_SUBTHEME_local_actions.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_local_actions.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_SUBTHEME_local_tasks.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_local_tasks.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_SUBTHEME_main_menu.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_main_menu.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_SUBTHEME_messages.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_messages.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_SUBTHEME_page_title.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_page_title.yml + + # 8. Rename VARTHEME_SUBTHEME.base.css files. + mv ${theme_path}/${theme_name}/css/base/VARTHEME_SUBTHEME.base.css ${theme_path}/${theme_name}/css/base/${theme_name}.base.css + mv ${theme_path}/${theme_name}/css/base/VARTHEME_SUBTHEME.base.css.map ${theme_path}/${theme_name}/css/base/${theme_name}.base.css.map + + # 9. Rename VARTHEME_SUBTHEME-rtl.base.css files. + mv ${theme_path}/${theme_name}/css/rtl/base/VARTHEME_SUBTHEME-rtl.base.css ${theme_path}/${theme_name}/css/rtl/base/${theme_name}-rtl.base.css + mv ${theme_path}/${theme_name}/css/rtl/base/VARTHEME_SUBTHEME-rtl.base.css.map ${theme_path}/${theme_name}/css/rtl/base/${theme_name}-rtl.base.css.map + + # 10. Rename VARTHEME_SUBTHEME.base.less file. + mv ${theme_path}/${theme_name}/less/base/VARTHEME_SUBTHEME.base.less ${theme_path}/${theme_name}/less/base/${theme_name}.base.less + + # 11. Rename VARTHEME_SUBTHEME-rtl.base.less file. + mv ${theme_path}/${theme_name}/less/rtl/base/VARTHEME_SUBTHEME-rtl.base.less ${theme_path}/${theme_name}/less/rtl/base/${theme_name}-rtl.base.less + + # 12. Replace all VARTHEME_SUBTHEME with the machine name of your theme. + grep -rl 'VARTHEME_SUBTHEME' ${theme_path}/${theme_name} | xargs sed -i "s/VARTHEME_SUBTHEME/${theme_name}/g" ; + + # 13. Replace the name: 'Vartheme Sub-Theme (LESS)' to the name of your theme. + grep -rl 'Vartheme Sub-Theme (LESS)' ${theme_path}/${theme_name} | xargs sed -i "s/Vartheme Sub-Theme (LESS)/${theme_name}/g" ; + + + # 14. If we want to use the RTL (right to left) bootstrap. + # 15.1 Delete the template folder bootstrap. + rm -rf ${theme_path}/${theme_name}/bootstrap ; + + # 15.2 Download the bootstrap library. change the version as you need. + wget -P ${theme_path}/${theme_name} https://github.com/twbs/bootstrap/archive/v${bootstrap_library_version}.tar.gz -vvv + + # 15.3 Extract the bootstrap library. + mkdir ${theme_path}/${theme_name}/bootstrap + tar -xzvf ${theme_path}/${theme_name}/v${bootstrap_library_version}.tar.gz --strip-components=1 -C ${theme_path}/${theme_name}/bootstrap -vvv + + # 15.4 Delete the archived bootstrap library. + rm ${theme_path}/${theme_name}/v${bootstrap_library_version}.tar.gz + + + # 16. If we want to use the RTL (right to left) bootstrap. + if [[ $direction == "rtl" || $direction == "RTL" ]]; then + # 16.1. Delete the template folder bootstrap-rtl. + rm -rf ${theme_path}/${theme_name}/bootstrap-rtl ; + + # 16.2. Download the bootstrap library. change the version as you need. + wget -P ${theme_path}/${theme_name} https://github.com/morteza/bootstrap-rtl/archive/v${bootstrap_rtl_library_version}.tar.gz -vvv + + # 16.3. Extract the bootstrap library. + mkdir ${theme_path}/${theme_name}/bootstrap-rtl + tar -xzvf ${theme_path}/${theme_name}/v${bootstrap_rtl_library_version}.tar.gz --strip-components=1 -C ${theme_path}/${theme_name}/bootstrap-rtl -vvv + + # 16.4. Delete the archived bootstrap library. + rm ${theme_path}/${theme_name}/v${bootstrap_rtl_library_version}.tar.gz + fi + + generated_datetime="$(date '+%Y/%m/%d - %H:%M:%S')"; + generated_log=" Generated by -- composer create-new-vartheme ${theme_name} ${direction} ${theme_path} -- on ${generated_datetime}"; + echo "${generated_log}" >> ${theme_path}/${theme_name}/README.md; + + echo "---------------------------------------------------------------------------"; + echo " The new Vartheme subtheme were created at \"${theme_path}/${theme_name} :)\" "; + echo "---------------------------------------------------------------------------"; + exit 0; + +else + echo "---------------------------------------------------------------------------"; + echo " The folder \"${theme_path}/${theme_name}\" is already in the site!"; + echo "---------------------------------------------------------------------------"; + exit 1; +fi diff --git a/scripts/varbase-apply-tests.sh b/scripts/varbase-apply-tests.sh new file mode 100644 index 0000000000000000000000000000000000000000..d27917694d7c938117f3881ad94811df605deada --- /dev/null +++ b/scripts/varbase-apply-tests.sh @@ -0,0 +1,4 @@ +#!/bin/bash +echo "Varbase Apply tests"; +cd docroot/profiles/varbase; +../../../bin/behat tests/features/varbase/step2-apply-tests --format pretty --out std --format html --out tests/reports/varbase-apply-tests-report-$( date '+%Y-%m-%d_%H-%M-%S' ); diff --git a/scripts/varbase-check-tests.sh b/scripts/varbase-check-tests.sh new file mode 100644 index 0000000000000000000000000000000000000000..1f507dd8ddf945b946ee955f69bad7190ab1418d --- /dev/null +++ b/scripts/varbase-check-tests.sh @@ -0,0 +1,4 @@ +#!/bin/bash +echo "Varbase check tests"; +cd docroot/profiles/varbase; +../../../bin/behat tests/features/varbase --tags '@check' --format pretty --out std --format html --out tests/reports/varbase-check-tests-report-$( date '+%Y-%m-%d_%H-%M-%S' ); diff --git a/scripts/varbase-cleanup-tests.sh b/scripts/varbase-cleanup-tests.sh new file mode 100644 index 0000000000000000000000000000000000000000..182acaf2c38e915b067288be994159ad6c712736 --- /dev/null +++ b/scripts/varbase-cleanup-tests.sh @@ -0,0 +1,4 @@ +#!/bin/bash +echo "Varbase Cleanup tests"; +cd docroot/profiles/varbase; +../../../bin/behat tests/features/varbase/step3-cleanup-tests --format pretty --out std --format html --out tests/reports/varbase-cleanup-tests-report-$( date '+%Y-%m-%d_%H-%M-%S' ); diff --git a/scripts/varbase-full-development-tests.sh b/scripts/varbase-full-development-tests.sh new file mode 100644 index 0000000000000000000000000000000000000000..8cf0d4fe3d97951051493271ed7245c3f09ced6f --- /dev/null +++ b/scripts/varbase-full-development-tests.sh @@ -0,0 +1,4 @@ +#!/bin/bash +echo "Varbase Full Development tests"; +cd docroot/profiles/varbase; +../../../bin/behat tests/features/varbase --tags '@development' --format pretty --out std --format html --out tests/reports/varbase-full-development-tests-report-$( date '+%Y-%m-%d_%H-%M-%S' ); diff --git a/scripts/varbase-full-local-tests.sh b/scripts/varbase-full-local-tests.sh new file mode 100644 index 0000000000000000000000000000000000000000..8309a3e5a333301be42a65cf4957d6b60772d0ef --- /dev/null +++ b/scripts/varbase-full-local-tests.sh @@ -0,0 +1,4 @@ +#!/bin/bash +echo "Varbase Full local tests"; +cd docroot/profiles/varbase; +../../../bin/behat tests/features/varbase --tags '@local' --format pretty --out std --format html --out tests/reports/varbase-full-local-tests-report-$( date '+%Y-%m-%d_%H-%M-%S' ); diff --git a/scripts/varbase-full-production-tests.sh b/scripts/varbase-full-production-tests.sh new file mode 100644 index 0000000000000000000000000000000000000000..2a32aecf5cc482f6ed75551c549d317ab9c3aee1 --- /dev/null +++ b/scripts/varbase-full-production-tests.sh @@ -0,0 +1,4 @@ +#!/bin/bash +echo "Varbase Full Production tests"; +cd docroot/profiles/varbase; +../../../bin/behat tests/features/varbase --tags '@production' --format pretty --out std --format html --out tests/reports/varbase-full-production-tests-report-$( date '+%Y-%m-%d_%H-%M-%S' ); diff --git a/scripts/varbase-full-staging-tests.sh b/scripts/varbase-full-staging-tests.sh new file mode 100644 index 0000000000000000000000000000000000000000..08a2ae23f7b1f1ce89e3cdd95512bbdb2b89ff33 --- /dev/null +++ b/scripts/varbase-full-staging-tests.sh @@ -0,0 +1,4 @@ +#!/bin/bash +echo "Varbase Full Staging tests"; +cd docroot/profiles/varbase; +../../../bin/behat tests/features/varbase --tags '@staging' --format pretty --out std --format html --out tests/reports/varbase-full-staging-tests-report-$( date '+%Y-%m-%d_%H-%M-%S' ); diff --git a/scripts/varbase-full-tests.sh b/scripts/varbase-full-tests.sh new file mode 100644 index 0000000000000000000000000000000000000000..4ce8459d4cfc32d56dd1d6f5859f0490a3462449 --- /dev/null +++ b/scripts/varbase-full-tests.sh @@ -0,0 +1,4 @@ +#!/bin/bash +echo "Varbase Full tests"; +cd docroot/profiles/varbase; +../../../bin/behat tests/features/varbase --format pretty --out std --format html --out tests/reports/varbase-full-tests-report-$( date '+%Y-%m-%d_%H-%M-%S' ); diff --git a/scripts/varbase-init-tests.sh b/scripts/varbase-init-tests.sh new file mode 100644 index 0000000000000000000000000000000000000000..11bcc2d0a606b517d115641083245c52318e7a89 --- /dev/null +++ b/scripts/varbase-init-tests.sh @@ -0,0 +1,4 @@ +#!/bin/bash +echo "Varbase init tests"; +cd docroot/profiles/varbase; +../../../bin/behat tests/features/varbase/step1-init-tests --format pretty --out std --format html --out tests/reports/varbase-init-tests-report-$( date '+%Y-%m-%d_%H-%M-%S' ); diff --git a/src/composer/ScriptHandler.php b/src/composer/ScriptHandler.php index dc6c25e5c006be788c00fbc4c3442079c351dc1d..b9055952ac6fbcdb0ec3f75e4dd3c328a53c338a 100644 --- a/src/composer/ScriptHandler.php +++ b/src/composer/ScriptHandler.php @@ -22,6 +22,82 @@ class ScriptHandler { protected static function getDrupalRoot($project_root) { return $project_root . '/docroot'; } + + /** + * Create required files. + * + * @param Event $event + */ + public static function createRequiredFiles(Event $event) { + $fs = new Filesystem(); + $root = static::getDrupalRoot(getcwd()); + $dirs = [ + 'modules', + 'profiles', + 'themes', + 'libraries', + ]; + // Required for unit testing + foreach ($dirs as $dir) { + if (!$fs->exists($root . '/'. $dir)) { + $fs->mkdir($root . '/'. $dir); + $fs->touch($root . '/'. $dir . '/.gitkeep'); + } + } + // Prepare the settings file for installation + if (!$fs->exists($root . '/sites/default/settings.php') and $fs->exists($root . '/sites/default/default.settings.php')) { + $fs->copy($root . '/sites/default/default.settings.php', $root . '/sites/default/settings.php'); + $fs->chmod($root . '/sites/default/settings.php', 0666); + $event->getIO()->write("Create a sites/default/settings.php file with chmod 0666"); + } + // Prepare the services file for installation + if (!$fs->exists($root . '/sites/default/services.yml') and $fs->exists($root . '/sites/default/default.services.yml')) { + $fs->copy($root . '/sites/default/default.services.yml', $root . '/sites/default/services.yml'); + $fs->chmod($root . '/sites/default/services.yml', 0666); + $event->getIO()->write("Create a sites/default/services.yml file with chmod 0666"); + } + // Create the files directory with chmod 0777 + if (!$fs->exists($root . '/sites/default/files')) { + $oldmask = umask(0); + $fs->mkdir($root . '/sites/default/files', 0777); + umask($oldmask); + $event->getIO()->write("Create a sites/default/files directory with chmod 0777"); + } + } + + /** + * Checks if the installed version of Composer is compatible. + * + * Composer 1.0.0 and higher consider a `composer install` without having a + * lock file present as equal to `composer update`. We do not ship with a lock + * file to avoid merge conflicts downstream, meaning that if a project is + * installed with an older version of Composer the scaffolding of Drupal will + * not be triggered. We check this here instead of in drupal-scaffold to be + * able to give immediate feedback to the end user, rather than failing the + * installation after going through the lengthy process of compiling and + * downloading the Composer dependencies. + * + * @see https://github.com/composer/composer/pull/5035 + */ + public static function checkComposerVersion(Event $event) { + $composer = $event->getComposer(); + $io = $event->getIO(); + $version = $composer::VERSION; + // The dev-channel of composer uses the git revision as version number, + // try to the branch alias instead. + if (preg_match('/^[0-9a-f]{40}$/i', $version)) { + $version = $composer::BRANCH_ALIAS_VERSION; + } + // If Composer is installed through git we have no easy way to determine if + // it is new enough, just display a warning. + if ($version === '@package_version@' || $version === '@package_branch_alias_version@') { + $io->writeError('<warning>You are running a development version of Composer. If you experience problems, please update Composer to the latest stable version.</warning>'); + } + elseif (Comparator::lessThan($version, '1.0.0')) { + $io->writeError('<error>Drupal-project requires Composer version 1.0.0 or higher. Please update your Composer before continuing</error>.'); + exit(1); + } + } /** * Post Drupal Scaffold Procedure.