diff --git a/composer.json b/composer.json
index a787820c28..261585caac 100644
--- a/composer.json
+++ b/composer.json
@@ -39,12 +39,14 @@
},
"autoload": {
"classmap": [
- "scripts/composer/ScriptHandler.php"
+ "scripts/composer/ScriptHandler.php",
+ "scripts/composer/Setup.php"
],
"files": ["load.environment.php"]
},
"scripts": {
"drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold",
+ "setup": "DrupalProject\\composer\\Setup::setup",
"pre-install-cmd": [
"DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
],
@@ -56,6 +58,9 @@
],
"post-update-cmd": [
"DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
+ ],
+ "post-root-package-install": [
+ "@setup"
]
},
"extra": {
diff --git a/scripts/composer/Setup.php b/scripts/composer/Setup.php
new file mode 100644
index 0000000000..9cfcf6995c
--- /dev/null
+++ b/scripts/composer/Setup.php
@@ -0,0 +1,69 @@
+getComposer()
+ ->getConfig()
+ ->getConfigSource()
+ ->getName());
+ $config = $jsonFile->read();
+ $fs = new Filesystem();
+ $drupalRoot = $event->getIO()->ask('Customize Drupal root path? [web]? ', 'web');
+ if ($drupalRoot !== 'web') {
+ $drupalRoot = rtrim($drupalRoot, '/');
+ $gitIgnore = file_get_contents('.gitignore');
+ $gitIgnore = preg_replace('/' . preg_quote('web/', '/') . '/', $drupalRoot . '/', $gitIgnore);
+ if (isset($config['extra']['installer-paths'])) {
+ $installer_paths = [];
+ foreach ($config['extra']['installer-paths'] as $path => $spec) {
+ $newPath = preg_replace('/' . preg_quote('web/', '/') . '/', $drupalRoot . '/', $path);
+ $installer_paths[$newPath] = $spec;
+ }
+ $config['extra']['installer-paths'] = $installer_paths;
+ }
+ $fs->dumpFile('.gitignore', $gitIgnore);
+ }
+ if ($event->getIO()->askConfirmation('Remove dotenv? [y,N]? ', TRUE)) {
+ $fs->remove(['.env.example', 'load.environment.php']);
+ if (!empty($config['autoload']['files'])) {
+ $config['autoload']['files'] = array_diff($config['autoload']['files'], ['load.environment.php']);
+ if (empty($config['autoload']['files'])) {
+ unset($config['autoload']['files']);
+ }
+ }
+ unset($config['require']['vlucas/phpdotenv']);
+ unset($config['require-dev']['vlucas/phpdotenv']);
+ }
+ if ($event->getIO()->askConfirmation('Remove drush? [y,N]? ', FALSE)) {
+ unset($config['require']['drush/drush']);
+ unset($config['require-dev']['drush/drush']);
+ }
+ if ($event->getIO()->askConfirmation('Remove drupal-console? [y,N]? ', FALSE)) {
+ unset($config['require']['drupal/console']);
+ unset($config['require-dev']['drupal/console']);
+ }
+ if ($event->getIO()->askConfirmation('Remove the installer and other scaffold files? [y,N]? ', FALSE)) {
+ unset($config['scripts']['setup']);
+ $config['autoload']['classmap'] = array_diff($config['autoload']['classmap'], ['scripts/composer/Setup.php']);
+ $config['scripts']['post-root-package-install'] = array_diff($config['scripts']['post-root-package-install'], ['@setup']);
+ if (empty($config['scripts']['post-root-package-install'])) {
+ unset($config['scripts']['post-root-package-install']);
+ }
+ $fs->remove([
+ '.travis.yml',
+ 'phpunit.xml.dist',
+ 'scripts/composer/Setup.php',
+ ]);
+ }
+ $jsonFile->write($config);
+ return TRUE;
+ }
+
+}