Skip to content

feat: use DRUPAL_PROJECTS_PATH for all commands. fixes #111 #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ This project provides the following DDEV container commands.
- Creates a temporary [composer.contrib.json](https://getcomposer.org/doc/03-cli.md#composer) so that `drupal/core-recommended` becomes a dev dependency. This way the composer.json from the module is untouched.
- Runs `composer install` AND `yarn install` so that dependencies are available. Additional arguments to `ddev poser` like --prefer-source are passed along to `composer install`
- Note: it is perfectly acceptable to skip this command and edit the require-dev of composer.json by hand.
- [ddev symlink-project](https://github.com/ddev/ddev-drupal-contrib/blob/main/commands/web/symlink-project). Symlinks the top level files of your project into web/modules/custom so that Drupal finds your module. This command runs automatically on every `ddev start` _as long as Composer has generated `vendor/autoload.php`_ which occurs during `composer install/update`. See codebase image below.
- [ddev symlink-project](https://github.com/ddev/ddev-drupal-contrib/blob/main/commands/web/symlink-project). Symlinks your project files into the configured location (defaults to `web/modules/custom`) so Drupal can find your module. This command runs automatically on every `ddev start` _as long as Composer has generated `vendor/autoload.php`_ which occurs during `composer install/update`. See codebase image below.

Run tests on the `web/modules/custom` directory:
Run tests on your project code (defaults to `web/modules/custom`, [configurable](#changing-the-symlink-location)):

- `ddev phpunit` Run [PHPUnit](https://github.com/sebastianbergmann/phpunit) tests.
- `ddev nightwatch` Run Nightwatch tests, requires [DDEV Selenium Standalone Chrome](https://github.com/ddev/ddev-selenium-standalone-chrome).
- `ddev phpcs` Run [PHP_CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer).
- `ddev phpcbf` Fix phpcs findings.
- `ddev phpstan`. Run [phpstan](https://phpstan.org) on the web/modules/custom directory.
- `ddev phpstan`. Run [phpstan](https://phpstan.org) on project files.
- `ddev eslint` Run [ESLint](https://github.com/eslint/eslint) on JavaScript files.
- `ddev stylelint` Run [Stylelint](https://github.com/stylelint/stylelint) on CSS files.

Expand Down Expand Up @@ -96,7 +96,11 @@ web_environment:
- DRUPAL_PROJECTS_PATH=modules
```

Then restart DDEV by running `ddev restart`.
Then run `ddev restart` to update the symlink location.

All [ddev-drupal-contrib commands](#commands) run against your project code in the configured symlink location.

To use with Drupal themes, set `DRUPAL_PROJECTS_PATH=themes/custom` in your config.

## Example of successful test

Expand Down
2 changes: 1 addition & 1 deletion commands/web/eslint
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if "$DDEV_DOCROOT/core/node_modules/.bin/eslint" --version >/dev/null ; then
test -e .prettierrc.json || ln -s $DDEV_DOCROOT/core/.prettierrc.json .
test -e .prettierignore || echo '*.yml' > .prettierignore
# Change directory to the project root folder
cd "$DDEV_DOCROOT/modules/custom/${DDEV_SITENAME//-/_}" || exit
cd "$DDEV_DOCROOT/$DRUPAL_PROJECTS_PATH/${DDEV_SITENAME//-/_}" || exit
"$DDEV_COMPOSER_ROOT/$DDEV_DOCROOT/core/node_modules/.bin/eslint" --config="../../../core/.eslintrc.passing.json" --no-error-on-unmatched-pattern --ignore-pattern="*.es6.js" --resolve-plugins-relative-to=$DDEV_COMPOSER_ROOT/$DDEV_DOCROOT/core --ext=.js,.yml . "$@"
else
echo "eslint is not available. You may need to 'ddev exec \"cd $DDEV_DOCROOT/core && yarn install\"'"
Expand Down
2 changes: 1 addition & 1 deletion commands/web/nightwatch
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
## Example: "ddev nightwatch"
## ExecRaw: true

yarn --cwd "$DDEV_DOCROOT/core" test:nightwatch "$DDEV_COMPOSER_ROOT/$DDEV_DOCROOT/modules/custom/" "$@"
yarn --cwd "$DDEV_DOCROOT/core" test:nightwatch "$DDEV_COMPOSER_ROOT/$DDEV_DOCROOT/$DRUPAL_PROJECTS_PATH/" "$@"
2 changes: 1 addition & 1 deletion commands/web/phpcbf
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ if ! command -v phpcbf >/dev/null; then
exit 1
fi
test -e phpcs.xml.dist || curl -OL https://git.drupalcode.org/project/gitlab_templates/-/raw/default-ref/assets/phpcs.xml.dist
phpcbf -s --report-full --report-summary --report-source $DDEV_DOCROOT/modules/custom "$@"
phpcbf -s --report-full --report-summary --report-source $DDEV_DOCROOT/$DRUPAL_PROJECTS_PATH "$@"
2 changes: 1 addition & 1 deletion commands/web/phpcs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ if ! command -v phpcs >/dev/null; then
exit 1
fi
test -e phpcs.xml.dist || curl -OL https://git.drupalcode.org/project/gitlab_templates/-/raw/default-ref/assets/phpcs.xml.dist
phpcs -s --report-full --report-summary --report-source $DDEV_DOCROOT/modules/custom --ignore=*/.ddev/* "$@"
phpcs -s --report-full --report-summary --report-source $DDEV_DOCROOT/$DRUPAL_PROJECTS_PATH --ignore=*/.ddev/* "$@"
2 changes: 1 addition & 1 deletion commands/web/phpstan
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ test -e phpstan.neon || curl -OL https://git.drupalcode.org/project/gitlab_templ
sed -i 's/BASELINE_PLACEHOLDER/phpstan-baseline.neon/g' phpstan.neon
# Add an empty baseline file to ensure it exists.
test -e phpstan-baseline.neon || touch phpstan-baseline.neon
phpstan analyse $DDEV_DOCROOT/modules/custom "$@"
phpstan analyse $DDEV_DOCROOT/$DRUPAL_PROJECTS_PATH "$@"
2 changes: 1 addition & 1 deletion commands/web/phpunit
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ if [ -f "phpunit.xml" ]; then
phpunit "$@"
else
# Bootstrap Drupal tests and run all custom module tests.
phpunit --bootstrap $PWD/$DDEV_DOCROOT/core/tests/bootstrap.php $DDEV_DOCROOT/modules/custom "$@"
phpunit --bootstrap $PWD/$DDEV_DOCROOT/core/tests/bootstrap.php $DDEV_DOCROOT/$DRUPAL_PROJECTS_PATH "$@"
fi
2 changes: 1 addition & 1 deletion commands/web/stylelint
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

if $DDEV_DOCROOT/core/node_modules/.bin/stylelint --version >/dev/null ; then
# Change directory to the project root folder
cd "$DDEV_DOCROOT/modules/custom/${DDEV_SITENAME//-/_}" || exit
cd "$DDEV_DOCROOT/$DRUPAL_PROJECTS_PATH/${DDEV_SITENAME//-/_}" || exit
"$DDEV_COMPOSER_ROOT/$DDEV_DOCROOT/core/node_modules/.bin/stylelint" --color --config "$DDEV_COMPOSER_ROOT/$DDEV_DOCROOT/core/.stylelintrc.json" "./**/*.css" "$@"
else
echo "stylelint is not available. You may need to 'ddev exec \"cd $DDEV_DOCROOT/core && yarn install\"'"
Expand Down
3 changes: 1 addition & 2 deletions commands/web/symlink-project
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

#ddev-generated
## Command provided by https://github.com/ddev/ddev-drupal-contrib
## Description: Symlink all root files/dirs into web.modules/custom/[PROJECT_NAME]
## Description: Symlink project files into the configured location (defaults to `web/modules/custom/[PROJECT_NAME]`)
## Usage: symlink-project [flags] [args]
## Example: "ddev symlink-project"
## ExecRaw: true

export _WEB_ROOT=$DDEV_DOCROOT
export DRUPAL_PROJECTS_PATH=${DRUPAL_PROJECTS_PATH:-modules/custom}
#todo use more dynamic ref.
cd "$DDEV_COMPOSER_ROOT" || exit
curl -OL https://git.drupalcode.org/project/gitlab_templates/-/raw/default-ref/scripts/symlink_project.php
Expand Down
5 changes: 5 additions & 0 deletions config.contrib.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#ddev-generated
## Command provided by https://github.com/ddev/ddev-drupal-contrib
## To customize this configuration, see:
## https://ddev.readthedocs.io/en/stable/users/extend/customization-extendibility/
web_environment:
# To change the Drupal core version, see the README:
# https://github.com/ddev/ddev-drupal-contrib/blob/main/README.md#changing-the-drupal-core-version
Expand All @@ -8,6 +10,9 @@ web_environment:
- SIMPLETEST_BASE_URL=http://web
- BROWSERTEST_OUTPUT_DIRECTORY=/tmp
- BROWSERTEST_OUTPUT_BASE_URL=${DDEV_PRIMARY_URL}
# To change the location of your project code, see the README:
# https://github.com/ddev/ddev-drupal-contrib/blob/main/README.md#changing-the-symlink-location
- DRUPAL_PROJECTS_PATH=modules/custom
hooks:
post-start:
- exec-host: |
Expand Down