Scaffolding Composer plugin for Drupal modules and themes.
Drupal Component Scaffold is a Composer plugin that helps Drupal 8
project maintainers enjoy leaner development workflow: working on modules and themes will be like working on any other
modern PHP component.
Once installed the plugin allows to:
require-dev
, like Drupal core, modules, themes or any neededcomposer install
.The plugin leverages the excellent Drupal Scaffold project and
fires only after (and if) its main scaffolding tasks are ran.
Require it via Composer as follow:
$ composer require nuvoleweb/drupal-component-scaffold --dev
List all your dependencies (core version, modules, etc.) and run:
$ composer update
For example, take the following composer.json
:
{
"name": "drupal/my_module",
"type": "drupal-module",
"require": {
"drupal/ds": "~3"
},
"require-dev": {
"nuvoleweb/drupal-component-scaffold": "*",
"drush/drush": "~8.0",
"drupal/core": "~8",
"drupal/panels": "~4",
},
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
}
],
"extra": {
"installer-paths": {
"web/core": ["type:drupal-core"],
"web/modules/contrib/{$name}": ["type:drupal-module"]
}
}
}
Running composer install
will result in:
.
├── web
│ ├── autoload.php
│ ├── core
│ ├── modules
│ │ ├── contrib
│ │ │ └── panels
│ │ └── custom
│ │ └── my_module (symlink to project root)
│ └── sites
│ ├── default
│ │ ├── default.services.yml
│ │ ├── default.settings.php
│ │ ├── drushrc.php
│ │ └── settings.local.php
│ ├── development.services.yml
│ ├── example.settings.local.php
│ └── example.sites.php
├── vendor
├── composer.json
├── composer.lock
├── my_module.info.yml
└── my_module.module
Build directory will be derived by the installer-paths
, make sure you specify there where you wish to install
your core, modules etc:
{
"extra": {
"installer-paths": {
"web/core": ["type:drupal-core"],
"web/modules/contrib/{$name}": ["type:drupal-module"]
}
}
}
Also, all options for Drupal Scaffold still apply, check the
project’s documentation for more.
Component scaffolding can be triggered at any time by running:
$ composer drupal-component-scaffold
To setup PHPUnit use the following phpunit.xml.dist
template:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php" backupGlobals="true" colors="true" >
<php>
<ini name="error_reporting" value="32767"></ini>
<var name="namespaces" value=""></var>
<ini name="memory_limit" value="-1"></ini>
<env name="SIMPLETEST_DB" value="mysql://user:pass@host/database"></env>
</php>
<testsuites>
<testsuite>
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
This will ensure that both Unit and Kernel tests
tests will ran correctly. See an example here.
When fired the plugin will:
After Drupal Scaffold is done the plugin will:
./web/modules/custom
../web/sites/default
writable../web/modules/custom/my_module
(or at ./web/themes/custom/my_theme
)../web/sites/default/drushrc.php
../web/sites/development.services.yml
../web/sites/default/settings.local.php
.Note: the local development settings file above is disabled by default, to enable it un-comment the related lines
in your settings.php
file and clear the cache.