Skip to content

Commit 1d05df1

Browse files
Issue drupal-composer#57: Distinguish files depending on dev environment.
1 parent 3ad465a commit 1d05df1

File tree

3 files changed

+65
-22
lines changed

3 files changed

+65
-22
lines changed

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ of your root `composer.json`.
3838
"includes": [
3939
"sites/default/example.settings.my.php"
4040
],
41+
"dev": [
42+
"my_settings_file_for_development.php"
43+
],
4144
"initial": {
4245
"sites/default/default.services.yml": "sites/default/services.yml",
4346
"sites/default/default.settings.php": "sites/default/settings.php"
@@ -58,24 +61,28 @@ default.
5861

5962
Default includes are provided by the plugin:
6063
```
61-
.csslintrc
62-
.editorconfig
63-
.eslintignore
64-
.eslintrc (Drupal <= 8.2.x)
65-
.eslintrc.json (Drupal >= 8.3.x)
66-
.gitattributes
6764
.htaccess
6865
index.php
6966
robots.txt
7067
sites/default/default.settings.php
7168
sites/default/default.services.yml
72-
sites/development.services.yml
7369
sites/example.settings.local.php
7470
sites/example.sites.php
7571
update.php
7672
web.config
7773
```
7874

75+
Default dev are provided by the plugin:
76+
```
77+
.csslintrc
78+
.editorconfig
79+
.eslintignore
80+
.eslintrc (Drupal <= 8.2.x)
81+
.eslintrc.json (Drupal >= 8.3.x)
82+
.gitattributes
83+
sites/development.services.yml
84+
```
85+
7986
When setting `omit-defaults` to `true`, neither the default excludes nor the
8087
default includes will be provided; in this instance, only those files explicitly
8188
listed in the `excludes` and `includes` options will be considered. If
@@ -86,6 +93,9 @@ The `initial` hash lists files that should be copied over only if they do not
8693
exist in the destination. The key specifies the path to the source file, and
8794
the value indicates the path to the destination file.
8895

96+
The `dev` hash lists files that should be copied over only if they do not
97+
exist in the destination and if the dev packages are installed.
98+
8999
## Limitation
90100

91101
When using Composer to install or update the Drupal development branch, the

src/Handler.php

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,30 @@ public function onPostCmdEvent(\Composer\Script\Event $event) {
8888
// Only install the scaffolding if drupal/core was installed,
8989
// AND there are no scaffolding files present.
9090
if (isset($this->drupalCorePackage)) {
91-
$this->downloadScaffold();
91+
$this->downloadScaffold($event->isDevMode());
9292
// Generate the autoload.php file after generating the scaffold files.
9393
$this->generateAutoload();
9494
}
9595
}
9696

9797
/**
9898
* Downloads drupal scaffold files for the current process.
99+
*
100+
* @param bool $dev
101+
* TRUE if dev packages are installed. FALSE otherwise.
99102
*/
100-
public function downloadScaffold() {
103+
public function downloadScaffold($dev = FALSE) {
101104
$drupalCorePackage = $this->getDrupalCorePackage();
102105
$webroot = realpath($this->getWebRoot());
103106

104-
// Collect options, excludes and settings files.
107+
// Collect options, excludes, dev and settings files.
105108
$options = $this->getOptions();
106-
$files = array_diff($this->getIncludes(), $this->getExcludes());
109+
$includes = $this->getIncludes();
110+
// Check dev files if necessary.
111+
if ($dev) {
112+
$includes = array_merge($includes, $this->getDev());
113+
}
114+
$files = array_diff($includes, $this->getExcludes());
107115

108116
// Call any pre-scaffold scripts that may be defined.
109117
$dispatcher = new EventDispatcher($this->composer, $this->io);
@@ -258,6 +266,15 @@ protected function getIncludes() {
258266
return $this->getNamedOptionList('includes', 'getIncludesDefault');
259267
}
260268

269+
/**
270+
* Retrieve list of additional dev files from optional "extra" configuration.
271+
*
272+
* @return array
273+
*/
274+
protected function getDev() {
275+
return $this->getNamedOptionList('dev', 'getDevDefault');
276+
}
277+
261278
/**
262279
* Retrieve list of initial files from optional "extra" configuration.
263280
*
@@ -297,6 +314,7 @@ protected function getOptions() {
297314
'excludes' => [],
298315
'includes' => [],
299316
'initial' => [],
317+
'dev' => [],
300318
'source' => 'http://cgit.drupalcode.org/drupal/plain/{path}?h={version}',
301319
// Github: https://raw.githubusercontent.com/drupal/drupal/{version}/{path}
302320
];
@@ -314,33 +332,48 @@ protected function getExcludesDefault() {
314332
* Holds default settings files list.
315333
*/
316334
protected function getIncludesDefault() {
317-
$version = $this->getDrupalCoreVersion($this->getDrupalCorePackage());
318-
list($major, $minor) = explode('.', $version, 3);
319-
$version = "$major.$minor";
320-
321335
/**
322336
* Files from 8.3.x
323337
*
324338
* @see http://cgit.drupalcode.org/drupal/tree/?h=8.3.x
325339
*/
326340
$common = [
327-
'.csslintrc',
328-
'.editorconfig',
329-
'.eslintignore',
330-
'.eslintrc.json',
331-
'.gitattributes',
332341
'.htaccess',
333342
'index.php',
334343
'robots.txt',
335344
'sites/default/default.settings.php',
336345
'sites/default/default.services.yml',
337-
'sites/development.services.yml',
338346
'sites/example.settings.local.php',
339347
'sites/example.sites.php',
340348
'update.php',
341349
'web.config'
342350
];
343351

352+
return $common;
353+
}
354+
355+
/**
356+
* Holds default dev files list.
357+
*/
358+
protected function getDevDefault() {
359+
$version = $this->getDrupalCoreVersion($this->getDrupalCorePackage());
360+
list($major, $minor) = explode('.', $version, 3);
361+
$version = "$major.$minor";
362+
363+
/**
364+
* Files from 8.3.x
365+
*
366+
* @see http://cgit.drupalcode.org/drupal/tree/?h=8.3.x
367+
*/
368+
$common = [
369+
'.csslintrc',
370+
'.editorconfig',
371+
'.eslintignore',
372+
'.eslintrc.json',
373+
'.gitattributes',
374+
'sites/development.services.yml'
375+
];
376+
344377
// Version specific variations.
345378
switch ($version) {
346379
case '8.0':

src/Plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function postCmd(\Composer\Script\Event $event) {
7474
*/
7575
public static function scaffold(\Composer\Script\Event $event) {
7676
$handler = new Handler($event->getComposer(), $event->getIO());
77-
$handler->downloadScaffold();
77+
$handler->downloadScaffold($event->isDevMode());
7878
// Generate the autoload.php file after generating the scaffold files.
7979
$handler->generateAutoload();
8080
}

0 commit comments

Comments
 (0)