diff --git a/.ahoy.yml b/.ahoy.yml index eb127f5..f51cdc1 100644 --- a/.ahoy.yml +++ b/.ahoy.yml @@ -8,35 +8,43 @@ commands: build: usage: Build or rebuild the project. cmd: | - ahoy build-codebase - ahoy start-server + ahoy assemble + ahoy start ahoy provision - build-codebase: - usage: Build the codebase. - cmd: ./.devtools/build-codebase.sh + assemble: + usage: Assemble a codebase using project code and all required dependencies. + cmd: ./.devtools/assemble.sh - start-server: - usage: Start built-in PHP-server. - cmd: ./.devtools/start-server.sh + start: + usage: Start development environment. + cmd: ./.devtools/start.sh provision: - usage: Provision a website. + usage: Provision application within assembled codebase. cmd: ./.devtools/provision.sh + drush: + usage: Run Drush command. + cmd: build/vendor/bin/drush -l http://${WEBSERVER_HOST:-localhost}:${WEBSERVER_PORT:-8000} $* + + login: + usage: Login to a website. + cmd: ahoy drush uli + lint: - usage: Lint code. + usage: Check coding standards for violations. cmd: | pushd "build" >/dev/null || exit 1 vendor/bin/phpcs vendor/bin/phpstan vendor/bin/rector --clear-cache --dry-run vendor/bin/phpmd . text phpmd.xml - vendor/bin/twigcs + vendor/bin/twig-cs-fixer popd >/dev/null || exit 1 lint-fix: - usage: Fix coding standards. + usage: Fix violations in coding standards. cmd: | pushd "build" >/dev/null || exit 1 vendor/bin/rector --clear-cache @@ -44,7 +52,7 @@ commands: popd >/dev/null || exit 1 test: - usage: Run all tests. + usage: Run tests. cmd: | pushd "build" >/dev/null || exit 1 vendor/bin/phpunit @@ -71,6 +79,14 @@ commands: vendor/bin/phpunit --testsuite functional popd >/dev/null || exit 1 + reset: + usage: Reset project to the default state. + cmd: | + killall -9 php >/dev/null 2>&1 || true + chmod -Rf 777 build > /dev/null + rm -Rf build > /dev/null || true + rm -Rf .logs > /dev/null || true + # Override entrypoint to alter default behaviour of Ahoy. entrypoint: - bash diff --git a/.circleci/config.yml b/.circleci/config.yml index 79e099a..b98d945 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -21,11 +21,11 @@ job-test: &job-test - run: name: Build the codebase - command: .devtools/build-codebase.sh + command: .devtools/assemble.sh - run: name: Start built-in PHP server - command: .devtools/start-server.sh + command: .devtools/start.sh - run: name: Provision site @@ -52,8 +52,8 @@ job-test: &job-test working_directory: build - run: - name: Lint code with Twigcs - command: vendor/bin/twigcs || [ "${CI_TWIGCS_IGNORE_FAILURE:-0}" -eq 1 ] + name: Lint code with Twig CS Fixer + command: vendor/bin/twig-cs-fixer || [ "${CI_TWIGCSFIXER_IGNORE_FAILURE:-0}" -eq 1 ] working_directory: build - run: @@ -88,8 +88,7 @@ jobs: docker: - image: cimg/php:8.2-browsers environment: - DRUPAL_VERSION: 9.5 - DRUPAL_PROJECT_SHA: 9.x + DRUPAL_VERSION: 10.1 <<: *job-test test-php-8.2-next: diff --git a/.devtools/README.nd b/.devtools/README.nd new file mode 100644 index 0000000..59e2745 --- /dev/null +++ b/.devtools/README.nd @@ -0,0 +1,3 @@ +This directory contains scripts used for development. + +These can be used locally and in the CI environment. diff --git a/.devtools/README.txt b/.devtools/README.txt deleted file mode 100644 index cdda9a5..0000000 --- a/.devtools/README.txt +++ /dev/null @@ -1,3 +0,0 @@ -This directory contains development tools to help with building and testing. - -These can be used locally and in the CI environment. diff --git a/.devtools/build-codebase.sh b/.devtools/assemble.sh similarity index 92% rename from .devtools/build-codebase.sh rename to .devtools/assemble.sh index 54a6b26..8944e92 100755 --- a/.devtools/build-codebase.sh +++ b/.devtools/assemble.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash ## -# Build the codebase. +# Assemble a codebase using project code and all required dependencies. # # Allows to use the latest Drupal core as well as specified versions (for # testing backward compatibility). @@ -37,9 +37,10 @@ DRUPAL_PROJECT_REPO="${DRUPAL_PROJECT_REPO:-https://github.com/drupal-composer/d #------------------------------------------------------------------------------- -echo "-------------------------------" -echo " Build codebase " -echo "-------------------------------" +echo "===============================" +echo " 🏗️ ASSEMBLE " +echo "===============================" +echo # Make sure Composer doesn't run out of memory. export COMPOSER_MEMORY_LIMIT=-1 @@ -107,7 +108,7 @@ for composer_suggest in $composer_suggests; do done echo "> Copy tools configuration files." -cp phpcs.xml phpstan.neon phpmd.xml rector.php .twig_cs.php phpunit.xml "build/" +cp phpcs.xml phpstan.neon phpmd.xml rector.php .twig-cs-fixer.php phpunit.xml "build/" echo "> Symlink extension's code." rm -rf "build/web/${type}/custom" >/dev/null && mkdir -p "build/web/${type}/custom/${extension}" @@ -126,11 +127,11 @@ if [ -f "build/web/${type}/custom/${extension}/package-lock.json" ]; then fi echo -echo "-------------------------------" -echo " Codebase built 🚀 " -echo "-------------------------------" +echo "===============================" +echo " 🏗 ASSEMBLE COMPLETE " +echo "===============================" echo echo "> Next steps:" -echo " .devtools/start-server.sh # Start the webserver" +echo " .devtools/start.sh # Start the webserver" echo " .devtools/provision.sh # Provision the website" echo diff --git a/.devtools/deploy.sh b/.devtools/deploy.sh index f059abc..40b8a8b 100755 --- a/.devtools/deploy.sh +++ b/.devtools/deploy.sh @@ -76,9 +76,10 @@ if [ -n "${DEPLOY_SSH_KEY_FINGERPRINT}" ]; then ssh-add -l fi -echo "-------------------------------" -echo " Deploy code " -echo "-------------------------------" +echo "===============================" +echo " 🚚 DEPLOY " +echo "===============================" +echo [ -z "${DEPLOY_USER_NAME}" ] && echo "ERROR: Missing required value for DEPLOY_USER_NAME" && exit 1 [ -z "${DEPLOY_USER_EMAIL}" ] && echo "ERROR: Missing required value for DEPLOY_USER_EMAIL" && exit 1 @@ -106,9 +107,9 @@ git push --force deployremote HEAD:"${DEPLOY_BRANCH}" echo "> Push tags." git push --force --tags deployremote || true -echo "-------------------------------" -echo " Deployed code " -echo "-------------------------------" +echo "===============================" +echo " 🚚 DEPLOY COMPLETE " +echo "===============================" echo echo "Remote URL : ${DEPLOY_REMOTE}" echo "Remote branch : ${DEPLOY_BRANCH}" diff --git a/.devtools/provision.sh b/.devtools/provision.sh index dc8336f..8cc57a3 100755 --- a/.devtools/provision.sh +++ b/.devtools/provision.sh @@ -26,9 +26,10 @@ DRUPAL_PROFILE="${DRUPAL_PROFILE:-standard}" #------------------------------------------------------------------------------- -echo "----------------------------------" -echo " Install Drupal and extensions " -echo "----------------------------------" +echo "===============================" +echo " 🚀 PROVISION " +echo "===============================" +echo drush() { "build/vendor/bin/drush" -r "$(pwd)/build/web" -y "$@"; } @@ -65,9 +66,9 @@ done curl -s "http://${WEBSERVER_HOST}:${WEBSERVER_PORT}" >/dev/null echo -echo "-------------------------------" -echo " Install finished 🚀🚀🚀 " -echo "-------------------------------" +echo "===============================" +echo " 🚀 PROVISION COMPLETE " +echo "===============================" echo echo "Site URL: http://${WEBSERVER_HOST}:${WEBSERVER_PORT}" echo -n "One-time login link: " diff --git a/.devtools/start-server.sh b/.devtools/start.sh similarity index 86% rename from .devtools/start-server.sh rename to .devtools/start.sh index 5f0b128..f4b5685 100755 --- a/.devtools/start-server.sh +++ b/.devtools/start.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash ## -# Start built-in PHP-server. +# Start development environment. # # shellcheck disable=SC2015,SC2094,SC2002 @@ -22,9 +22,10 @@ WEBSERVER_WAIT_TIMEOUT="${WEBSERVER_WAIT_TIMEOUT:-5}" #------------------------------------------------------------------------------- -echo "-------------------------------" -echo " Start built-in PHP server " -echo "-------------------------------" +echo "===============================" +echo " 💻 START ENVIRONMENT " +echo "===============================" +echo echo "> Stop previously started services, if any." killall -9 php >/dev/null 2>&1 || true @@ -44,9 +45,9 @@ echo "> Check that the server can serve content." curl -s -o /dev/null -w "%{http_code}" -L -I "http://${WEBSERVER_HOST}:${WEBSERVER_PORT}" | grep -q 200 || (echo "ERROR: Server is started, but site cannot be served" && exit 1) echo -echo "-----------------------------------" -echo " Started built-in PHP server 🚀🚀 " -echo "-----------------------------------" +echo "===============================" +echo " 💻 ENVIRONMENT READY " +echo "===============================" echo echo "Directory : $(pwd)/build/web" echo "URL : http://${WEBSERVER_HOST}:${WEBSERVER_PORT}" diff --git a/.gitattributes b/.gitattributes index a0d3dee..d4ebe5b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,21 +1,21 @@ # Ignore files for distribution archives. # Uncomment the lines below in your project. -# .ahoy.yml export-ignore -# .circleci export-ignore -# .devtools export-ignore -# .editorconfig export-ignore -# .gitattributes export-ignore -# .github export-ignore -# .gitignore export-ignore -# .twig_cs.php export-ignore -# composer.dev.json export-ignore -# phpcs.xml export-ignore -# phpmd.xml export-ignore -# phpstan.neon export-ignore -# rector.php export-ignore -# renovate.json export-ignore -# tests export-ignore +# .ahoy.yml export-ignore +# .circleci export-ignore +# .devtools export-ignore +# .editorconfig export-ignore +# .gitattributes export-ignore +# .github export-ignore +# .gitignore export-ignore +# .twig-cs-fixer.php export-ignore +# composer.dev.json export-ignore +# phpcs.xml export-ignore +# phpmd.xml export-ignore +# phpstan.neon export-ignore +# rector.php export-ignore +# renovate.json export-ignore +# tests export-ignore # Remove the lines below in your project. .github/FUNDING.yml export-ignore diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 343e789..a3e3bbf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,8 +24,8 @@ jobs: - name: test-php-8.2-legacy php-version: 8.2 - drupal-version: 9.5 - drupal-project-sha: 9.x + drupal-version: 10.1 + drupal-project-sha: 10.x drupal-version-alias: legacy - name: test-php-8.2-next @@ -65,10 +65,10 @@ jobs: php-version: ${{ matrix.php-version }} - name: Build the codebase - run: .devtools/build-codebase.sh + run: .devtools/assemble.sh - name: Start built-in PHP server - run: .devtools/start-server.sh + run: .devtools/start.sh - name: Provision site run: .devtools/provision.sh @@ -89,9 +89,9 @@ jobs: working-directory: build run: vendor/bin/phpmd . text phpmd.xml || [ "${CI_PHPMD_IGNORE_FAILURE:-0}" -eq 1 ] - - name: Lint code with Twigcs + - name: Lint code with Twig CS Fixer working-directory: build - run: vendor/bin/twigcs || [ "${CI_TWIGCS_IGNORE_FAILURE:-0}" -eq 1 ] + run: vendor/bin/twig-cs-fixer || [ "${CI_TWIGCSFIXER_IGNORE_FAILURE:-0}" -eq 1 ] - name: Run tests working-directory: build diff --git a/.scaffold/tests/bats/_assert_init.bash b/.scaffold/tests/bats/_assert_init.bash index 4f8a222..3e0f48e 100644 --- a/.scaffold/tests/bats/_assert_init.bash +++ b/.scaffold/tests/bats/_assert_init.bash @@ -120,29 +120,10 @@ assert_workflow() { pushd "${dir}" >/dev/null || exit 1 - ./.devtools/build-codebase.sh - ./.devtools/start-server.sh - ./.devtools/provision.sh - - # Lint. - pushd "build" >/dev/null || exit 1 - - vendor/bin/phpcs - vendor/bin/phpstan - vendor/bin/rector --clear-cache --dry-run - vendor/bin/phpmd . text phpmd.xml - vendor/bin/twigcs - - popd >/dev/null || exit 1 - - # Test. - ./.devtools/test.sh - - # Change mode to make bats have enough permission to clean tmp test directory. - chmod -R 777 "build/web/sites/default" - - # Allow bats finish this assert, we need kill php process because it run in background in start server step. - killall -9 php >/dev/null 2>&1 || true + ahoy build + ahoy lint + ahoy test + ahoy reset popd >/dev/null || exit 1 } diff --git a/.twig-cs-fixer.php b/.twig-cs-fixer.php new file mode 100644 index 0000000..7db2293 --- /dev/null +++ b/.twig-cs-fixer.php @@ -0,0 +1,16 @@ +addStandard(new TwigCsFixer\Standard\Twig()); + +$finder = new TwigCsFixer\File\Finder(); +$finder->in(__DIR__ . '/web/modules/custom'); +$finder->in(__DIR__ . '/web/themes/custom'); + +$config = new TwigCsFixer\Config\Config(); +$config->setRuleset($ruleset); +$config->setFinder($finder); + +return $config; diff --git a/.twig_cs.php b/.twig_cs.php deleted file mode 100644 index a44f6be..0000000 --- a/.twig_cs.php +++ /dev/null @@ -1,15 +0,0 @@ -setName('custom-config') - ->setSeverity('error') - ->setReporter('console') - ->setRuleSet(Twigcs\Ruleset\Official::class) - ->addFinder(Twigcs\Finder\TemplateFinder::create()->in([ - __DIR__ . '/web/modules/custom', - __DIR__ . '/web/themes/custom', - ])); diff --git a/README.dist.md b/README.dist.md index c40f438..f37471a 100644 --- a/README.dist.md +++ b/README.dist.md @@ -39,7 +39,7 @@ the provided scripts. ### Build -Run `.devtools/build-codebase.sh` (or `ahoy build-codebase` +Run `.devtools/assemble.sh` (or `ahoy assemble` if [Ahoy](https://github.com/ahoy-cli/ahoy) is installed) to start inbuilt PHP server locally and run the same commands as in CI, plus installing a site and your extension automatically. @@ -58,14 +58,14 @@ vendor/bin/phpcs vendor/bin/phpstan vendor/bin/rector --clear-cache --dry-run vendor/bin/phpmd . text phpmd.xml -vendor/bin/twigcs +vendor/bin/twig-cs-fixer ``` - PHPCS config: [`phpcs.xml`](phpcs.xml) - PHPStan config: [`phpstan.neon`](phpstan.neon) - PHPMD config: [`phpmd.xml`](phpmd.xml) - Rector config: [`rector.php`](rector.php) -- TwigCS config: [`.twig_cs.php`](.twig_cs.php) +- Twig CS Fixer config: [`.twig-cs-fixer.php`](.twig-cs-fixer.php) ### Tests diff --git a/README.md b/README.md index 8953912..e1258c4 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ to [drupal.org](https://drupal.org). with PHPStan (including [PHPStan Drupal](https://github.com/mglaman/phpstan-drupal)). - PHP deprecated code analysis with [Drupal Rector](https://github.com/palantirnet/drupal-rector). - - Twig code analysis with [TwigCS](https://github.com/friendsoftwig/twigcs). + - Twig code analysis with [Twig CS Fixer](https://github.com/VincentLanglet/Twig-CS-Fixer). ![Lint process](https://user-images.githubusercontent.com/378794/253732548-9403e4cc-db03-4696-b114-32517ab0a571.gif) - Drupal's Simpletest testing support - runs tests in the same way as [drupal.org](https://drupal.org)'s Drupal CI diff --git a/composer.dev.json b/composer.dev.json index 6a7f151..84ae244 100644 --- a/composer.dev.json +++ b/composer.dev.json @@ -1,14 +1,14 @@ { "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^1.0", - "friendsoftwig/twigcs": "^6.2", "jangregor/phpstan-prophecy": "^1.0", "mglaman/phpstan-drupal": "^1.2", "palantirnet/drupal-rector": "^0.18", "phpcompatibility/php-compatibility": "^9.3", "phpmd/phpmd": "^2.15", "phpspec/prophecy-phpunit": "^2", - "phpstan/extension-installer": "^1.3" + "phpstan/extension-installer": "^1.3", + "vincentlanglet/twig-cs-fixer": "^2.8" }, "config": { "allow-plugins": { diff --git a/init.sh b/init.sh index dd7b0d7..d68dbdd 100755 --- a/init.sh +++ b/init.sh @@ -60,10 +60,6 @@ replace_string_content() { set -e } -to_lowercase() { - echo "${1}" | tr '[:upper:]' '[:lower:]' -} - remove_string_content() { local token="${1}" local sed_opts @@ -71,14 +67,6 @@ remove_string_content() { grep -rI --exclude-dir=".git" --exclude-dir=".idea" --exclude-dir="vendor" --exclude-dir="node_modules" -l "${token}" "$(pwd)" | LC_ALL=C.UTF-8 xargs sed "${sed_opts[@]}" -e "/^${token}/d" || true } -remove_string_content_line() { - local token="${1}" - local target="${2:-.}" - local sed_opts - sed_opts=(-i) && [ "$(uname)" == "Darwin" ] && sed_opts=(-i '') - grep -rI --exclude-dir=".git" --exclude-dir=".idea" --exclude-dir="vendor" --exclude-dir="node_modules" -l "${token}" "$(pwd)/${target}" | LC_ALL=C.UTF-8 xargs sed "${sed_opts[@]}" -e "/${token}/d" || true -} - remove_tokens_with_content() { local token="${1}" local sed_opts @@ -187,7 +175,7 @@ process_internal() { uncomment_line ".gitattributes" ".gitattributes" uncomment_line ".gitattributes" ".github" uncomment_line ".gitattributes" ".gitignore" - uncomment_line ".gitattributes" ".twig_cs.php" + uncomment_line ".gitattributes" ".twig-cs-fixer.php" uncomment_line ".gitattributes" "composer.dev.json" uncomment_line ".gitattributes" "phpcs.xml" uncomment_line ".gitattributes" "phpmd.xml" @@ -239,9 +227,12 @@ main() { echo [ -z "${extension_name}" ] && extension_name="$(ask "Name")" - [ -z "${extension_machine_name}" ] && extension_machine_name="$(ask "Machine name")" - [ -z "${extension_type}" ] && extension_type="$(ask "Type: module or theme")" - [ -z "${ci_provider}" ] && ci_provider="$(ask "CI Provider: GitHub Actions or CircleCI")" + extension_machine_name_default="$(convert_string "${extension_name}" "file_name")" + [ -z "${extension_machine_name}" ] && extension_machine_name="$(ask "Machine name" "${extension_machine_name_default}")" + extension_type_default="module" + [ -z "${extension_type}" ] && extension_type="$(ask "Type: module or theme" "${extension_type_default}")" + ci_provider_default="GitHub Actions" + [ -z "${ci_provider}" ] && ci_provider="$(ask "CI Provider: GitHub Actions or CircleCI" "${ci_provider_default}")" remove_self="$(ask_yesno "Remove this script")" diff --git a/your_extension.info.yml b/your_extension.info.yml index 760f6de..9084ee5 100644 --- a/your_extension.info.yml +++ b/your_extension.info.yml @@ -2,7 +2,7 @@ name: Drupal extension scaffold type: module description: Drupal extension scaffold example. package: Testing -core_version_requirement: ^9 || ^10 +core_version_requirement: ^10 dependencies: - drupal:config