-
Notifications
You must be signed in to change notification settings - Fork 937
WIP: Add setup wizard? #384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace DrupalProject\composer; | ||
|
||
use Composer\Json\JsonFile; | ||
use Composer\Script\Event; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
|
||
class Setup { | ||
|
||
public static function setup(Event $event) { | ||
$jsonFile = new JsonFile($event->getComposer() | ||
->getConfig() | ||
->getConfigSource() | ||
->getName()); | ||
$config = $jsonFile->read(); | ||
$fs = new Filesystem(); | ||
$drupalRoot = $event->getIO()->ask('<info>Customize Drupal root path?</info> [<comment>web</comment>]? ', '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('<info>Remove dotenv?</info> [<comment>y,N</comment>]? ', TRUE)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since default is true, it should be 'Y,n'. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, remove the .env.example and load.environment.php files (same as other scaffold files below). |
||
$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']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no phpdotenv in the require-dev section of composer.json. |
||
} | ||
if ($event->getIO()->askConfirmation('<info>Remove drush?</info> [<comment>y,N</comment>]? ', FALSE)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, also remove the drush/Commands/PolicyCommands.php, drush/README.md, drush/drush.yml and drush/sites/self.site.yml files (same as other scaffold files below). |
||
unset($config['require']['drush/drush']); | ||
unset($config['require-dev']['drush/drush']); | ||
} | ||
if ($event->getIO()->askConfirmation('<info>Remove drupal-console?</info> [<comment>y,N</comment>]? ', FALSE)) { | ||
unset($config['require']['drupal/console']); | ||
unset($config['require-dev']['drupal/console']); | ||
} | ||
if ($event->getIO()->askConfirmation('<info>Remove the installer and other scaffold files?</info> [<comment>y,N</comment>]? ', FALSE)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Project would be more user friendly if this option was TRUE by default. In which case, make the comment text 'Y,n'. |
||
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', | ||
]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove also the drupal-composer README.md file. |
||
} | ||
$jsonFile->write($config); | ||
return TRUE; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this before line 23. The logical flow would be to save the new gitignore just after the preg_replace on the gitIgnore lines, and not after the installer_paths block.