Skip to content

Commit

Permalink
Issue drupal-composer#57: Distinguish files depending on dev environm…
Browse files Browse the repository at this point in the history
…ent.
  • Loading branch information
FlorentTorregrosa committed Dec 9, 2017
1 parent 745f0a2 commit f8730b2
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 22 deletions.
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ of your root `composer.json`.
"includes": [
"sites/default/example.settings.my.php"
],
"dev": [
"my_settings_file_for_development.php"
],
"initial": {
"sites/default/default.services.yml": "sites/default/services.yml",
"sites/default/default.settings.php": "sites/default/settings.php"
Expand All @@ -58,25 +61,29 @@ default.

Default includes are provided by the plugin:
```
.csslintrc
.editorconfig
.eslintignore
.eslintrc (Drupal <= 8.2.x)
.eslintrc.json (Drupal >= 8.3.x)
.gitattributes
.ht.router.php (Drupal >= 8.5.x)
.htaccess
index.php
robots.txt
sites/default/default.settings.php
sites/default/default.services.yml
sites/development.services.yml
sites/example.settings.local.php
sites/example.sites.php
update.php
web.config
```

Default dev are provided by the plugin:
```
.csslintrc
.editorconfig
.eslintignore
.eslintrc (Drupal <= 8.2.x)
.eslintrc.json (Drupal >= 8.3.x)
.gitattributes
.ht.router.php (Drupal >= 8.5.x)
sites/development.services.yml
```

When setting `omit-defaults` to `true`, neither the default excludes nor the
default includes will be provided; in this instance, only those files explicitly
listed in the `excludes` and `includes` options will be considered. If
Expand All @@ -87,6 +94,9 @@ The `initial` hash lists files that should be copied over only if they do not
exist in the destination. The key specifies the path to the source file, and
the value indicates the path to the destination file.

The `dev` hash lists files that should be copied over only if they do not
exist in the destination and if the dev packages are installed.

## Limitation

When using Composer to install or update the Drupal development branch, the
Expand Down
60 changes: 47 additions & 13 deletions src/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,30 @@ public function onPostCmdEvent(\Composer\Script\Event $event) {
// Only install the scaffolding if drupal/core was installed,
// AND there are no scaffolding files present.
if (isset($this->drupalCorePackage)) {
$this->downloadScaffold();
$this->downloadScaffold($event->isDevMode());
// Generate the autoload.php file after generating the scaffold files.
$this->generateAutoload();
}
}

/**
* Downloads drupal scaffold files for the current process.
*
* @param bool $dev
* TRUE if dev packages are installed. FALSE otherwise.
*/
public function downloadScaffold() {
public function downloadScaffold($dev = FALSE) {
$drupalCorePackage = $this->getDrupalCorePackage();
$webroot = realpath($this->getWebRoot());

// Collect options, excludes and settings files.
// Collect options, excludes, dev and settings files.
$options = $this->getOptions();
$files = array_diff($this->getIncludes(), $this->getExcludes());
$includes = $this->getIncludes();
// Check dev files if necessary.
if ($dev) {
$includes = array_merge($includes, $this->getDev());
}
$files = array_diff($includes, $this->getExcludes());

// Call any pre-scaffold scripts that may be defined.
$dispatcher = new EventDispatcher($this->composer, $this->io);
Expand Down Expand Up @@ -259,6 +267,15 @@ protected function getIncludes() {
return $this->getNamedOptionList('includes', 'getIncludesDefault');
}

/**
* Retrieve list of additional dev files from optional "extra" configuration.
*
* @return array
*/
protected function getDev() {
return $this->getNamedOptionList('dev', 'getDevDefault');
}

/**
* Retrieve list of initial files from optional "extra" configuration.
*
Expand Down Expand Up @@ -298,6 +315,7 @@ protected function getOptions() {
'excludes' => [],
'includes' => [],
'initial' => [],
'dev' => [],
'source' => 'http://cgit.drupalcode.org/drupal/plain/{path}?h={version}',
// Github: https://raw.githubusercontent.com/drupal/drupal/{version}/{path}
];
Expand All @@ -315,32 +333,48 @@ protected function getExcludesDefault() {
* Holds default settings files list.
*/
protected function getIncludesDefault() {
$version = $this->getDrupalCoreVersion($this->getDrupalCorePackage());
list($major, $minor) = explode('.', $version, 3);
$version = "$major.$minor";

/**
* Files from 8.3.x
*
* @see http://cgit.drupalcode.org/drupal/tree/?h=8.3.x
*/
$common = [
'.csslintrc',
'.editorconfig',
'.eslintignore',
'.gitattributes',
'.htaccess',
'index.php',
'robots.txt',
'sites/default/default.settings.php',
'sites/default/default.services.yml',
'sites/development.services.yml',
'sites/example.settings.local.php',
'sites/example.sites.php',
'update.php',
'web.config'
];

return $common;
}

/**
* Holds default dev files list.
*/
protected function getDevDefault() {
$version = $this->getDrupalCoreVersion($this->getDrupalCorePackage());
list($major, $minor) = explode('.', $version, 3);
$version = "$major.$minor";

/**
* Files from 8.3.x
*
* @see http://cgit.drupalcode.org/drupal/tree/?h=8.3.x
*/
$common = [
'.csslintrc',
'.editorconfig',
'.eslintignore',
'.eslintrc.json',
'.gitattributes',
'sites/development.services.yml',
];

// Version specific variations.
if (Semver::satisfies($version, '<8.3')) {
$common[] = '.eslintrc';
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function postCmd(\Composer\Script\Event $event) {
*/
public static function scaffold(\Composer\Script\Event $event) {
$handler = new Handler($event->getComposer(), $event->getIO());
$handler->downloadScaffold();
$handler->downloadScaffold($event->isDevMode());
// Generate the autoload.php file after generating the scaffold files.
$handler->generateAutoload();
}
Expand Down

0 comments on commit f8730b2

Please sign in to comment.