forked from drupal-composer/drupal-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup.php
69 lines (64 loc) · 2.85 KB
/
Setup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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)) {
$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('<info>Remove drush?</info> [<comment>y,N</comment>]? ', FALSE)) {
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)) {
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;
}
}