From f7b03f426391da4500ab16737703630ba337f046 Mon Sep 17 00:00:00 2001 From: Florent Torregrosa Date: Sat, 11 Feb 2017 22:19:19 +0100 Subject: [PATCH] Issue #57: Distinguish files depending on dev environment. --- README.md | 26 ++++++++++++++------- src/Handler.php | 60 ++++++++++++++++++++++++++++++++++++++----------- src/Plugin.php | 2 +- 3 files changed, 66 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 03e1493..823cd39 100644 --- a/README.md +++ b/README.md @@ -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" @@ -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 @@ -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 diff --git a/src/Handler.php b/src/Handler.php index 1bdefe0..304980f 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -133,7 +133,7 @@ public function onPostCmdEvent(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(); } @@ -141,14 +141,22 @@ public function onPostCmdEvent(Event $event) { /** * 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); @@ -304,6 +312,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. * @@ -343,6 +360,7 @@ protected function getOptions() { 'excludes' => [], 'includes' => [], 'initial' => [], + 'dev' => [], 'source' => 'https://cgit.drupalcode.org/drupal/plain/{path}?h={version}', // Github: https://raw.githubusercontent.com/drupal/drupal/{version}/{path} ]; @@ -360,32 +378,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 https://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'; diff --git a/src/Plugin.php b/src/Plugin.php index 7833903..318c3ad 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -95,7 +95,7 @@ public function postCmd(Event $event) { public static function scaffold(Event $event) { @trigger_error('\DrupalComposer\DrupalScaffold\Plugin::scaffold is deprecated since version 2.5.0 and will be removed in 3.0. Use "composer drupal:scaffold" instead.', E_USER_DEPRECATED); $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(); }