If you want to contribute to Drupal modules and themes, this starterkit is for you. It provides all the necessary tools to get started with contributing to Drupal and ensures that you follow the Drupal coding standards. By using this starterkit, you'll have a running Drupal site with all the required tools for development. All you need to do is copy this repository and run a few commands. You can change the project's name in the .ddev/config.yaml
file and update the Drupal version by changing the drupal/core-recommended
version in the composer.json
file and running the ddev composer install
command. Available Drupal versions are listed on this page: https://github.com/drupal/core-recommended/tags. With this starterkit, you can start contributing to Drupal projects without worrying about setting up a development environment from scratch.
- Clone this repository
git clone https://github.com/msankhala/drupal-contrib-starterkit.git
- Run
ddev start
- Run
ddev composer install
- Run
ddev nvm install stable
- Run
ddev npm install
- Run
ddev drush site:install --account-name=admin --account-pass=admin -y
This starterkit provides the precommit hooks that will run each time you try to commit in this repository. The precommit hooks will run the following commands based on the file extensions.
- secretlint
- prettier --write
- eslint --fix
- stylelint --fix
- twig-cs-fixer --fix
- phpcbf
- phpcs
For any module or theme that you want to contribute to, you can use the precommit hooks provided by this starterkit.
- First clone the module or theme in the
docroot/modules/custom
ordocroot/themes/custom
directory. - Then run
git config core.hooksPath ../../../../.husky
command in the module or theme directory. This will set the custom module or theme to use the precommit hooks provided by this starterkit.
cd docroot/modules/custom/<module-name> or docroot/themes/custom/<theme-name>
git config core.hooksPath ../../../../.husky
- Husky
- Lint-staged
- PHP Code Sniffer
- PHP Code Beautifier
- EsLint
- StyleLint
- SecretLint
- Prettier
- Twig-cs-fixer
Ddev has pre-installed nvm. You can use nvm to install any node version you want. For example, if you want to install node version 18.13.0, you can run the following command:
Install node version 18.13.0
ddev nvm install 18.13.0
List the installed node versions
ddev nvm ls
Use the installed node version
ddev nvm use 18.13.0
You can simply change the drupal core version in the composer.json
file and run the ddev composer install
command. This starterkit is using drupal/core-recommended package. You can find the available drupal core versions here:
https://github.com/drupal/core-recommended/tags
Sometimes you may want to bypass the precommit hooks, Because it is throwing some linting error that you may want to fix letter or it is not part of the scope of the issue that you try to fix. You can do that by using the --no-verify
flag with the git commit
command.
git commit -m "Commit message" --no-verify
There are two files for each linting tool. One is the rule file and the other is the ignore file. You can find these files in the repo root. You can update these files as per your need but it is NOT recommended to update the rule file. You can update the ignore file if you want to ignore any file or directory from linting. Below are the files for each linting tool.
- .eslintrc.js
- .eslintignore
- .stylelintrc.js
- .stylelintignore
- .prettierrc.js
- .prettierignore
- .secretlintrc.js
- .secretlintignore
Note: The linting rule files are supported in different formats like .json, .yaml, .cjs, .mjs, rc files, etc
. But we are sticking with .js
files because it is easy to use and maintain and you can add comments and use variables in .js
files.
There is .validate-branch-namerc.js
file that contains the rule for validating the branch name. You can update this file as per your need.
There is jira-prepare-commit-msg.config.js
file that will automatically add the issue number to the commit message. You can update this file as per your need.
By default this starterkit will install the drupal 9. You can change the drupal version by following the below steps.
- Update the drupal/core-recommended version in the
composer.json
file. - Run the
ddev composer update
command, This will update the dependencies.