Skip to content

Commit

Permalink
Issue #8: Add site post install command.
Browse files Browse the repository at this point in the history
  • Loading branch information
ademarco committed Jan 5, 2018
1 parent f1dfef8 commit 84187bf
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ Available commands:
drupal
drupal:component-scaffold [drupal:cs|dcs] Scaffold Drupal component development.
drupal:site-install [drupal:si|dsi] Install target site.
drupal:site-post-install [drupal:spi|dspi] Run Drupal post-install commands.
setup
setup:behat [setup:b|sb] Setup Behat.
setup:phpunit [setup:p|sp] Setup PHPUnit.
setup:replace [setup:p|sp] Replace configuration tokens in a text file.

```
1 change: 1 addition & 0 deletions config/runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ drupal:
- "bower_components"
- "vendor"
- "${drupal.root}"
post_install: []

github:
token: ~
89 changes: 62 additions & 27 deletions src/Commands/DrupalCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function init(InputInterface $input)
*
* @param array $options
*
* @return \Robo\Task\Base\Exec
* @return \Robo\Collection\CollectionBuilder
*
* @throws \Robo\Exception\TaskException
*/
Expand All @@ -85,28 +85,65 @@ public function siteInstall(array $options = [
'database-name' => InputOption::VALUE_REQUIRED,
])
{
return $this->taskExec($this->getBin('drush'))
->option('-y')
->rawArg("--root=$(pwd)/".$options['root'])
->options([
'site-name' => $options['site-name'],
'site-mail' => $options['site-mail'],
'locale' => $options['site-locale'],
'account-mail' => $options['account-mail'],
'account-name' => $options['account-name'],
'account-pass' => $options['account-password'],
'exclude' => $options['root'],
'db-url' => sprintf(
"mysql://%s:%s@%s:%s/%s",
$options['database-user'],
$options['database-password'],
$options['database-host'],
$options['database-port'],
$options['database-name']
),
], '=')
->arg('site-install')
->arg($options['site-profile']);
$installTask = $this->taskExec($this->getBin('drush'))
->option('-y')
->rawArg("--root=$(pwd)/".$options['root'])
->options([
'site-name' => $options['site-name'],
'site-mail' => $options['site-mail'],
'locale' => $options['site-locale'],
'account-mail' => $options['account-mail'],
'account-name' => $options['account-name'],
'account-pass' => $options['account-password'],
'exclude' => $options['root'],
'db-url' => sprintf(
"mysql://%s:%s@%s:%s/%s",
$options['database-user'],
$options['database-password'],
$options['database-host'],
$options['database-port'],
$options['database-name']
),
], '=')
->arg('site-install')
->arg($options['site-profile']);

return $this->collectionBuilder()->addTaskList([
$installTask,
$this->sitePostInstall(),
]);
}

/**
* Run Drupal post-install commands.
*
* Add post install commands in your runner.yaml file under "drupal.post_install"
* as shown below:
*
* > drupal:
* > ...
* > post_install:
* > - ./vendor/bin/drush en views -y
* > - ./vendor/bin/drush cr
*
* Post install commands will be automatically executed after installing the site.
*
* @command drupal:site-post-install
*
* @aliases drupal:spi,dspi
*
* @return \Robo\Task\Base\ExecStack
*/
public function sitePostInstall()
{
$commands = $this->getConfig()->get('drupal.post_install');
$taskStack = $this->taskExecStack();

foreach ($commands as $command) {
$taskStack->exec($command);
}

return $taskStack;
}

/**
Expand Down Expand Up @@ -156,10 +193,8 @@ public function componentScaffold()
$this->taskFilesystemStack()->chmod($this->getSiteRoot().'/sites', 0775, 0000, true),
$this->taskFilesystemStack()->mkdir($this->getExtensionRoot()),
$this->taskFilesystemStack()->symlink($link, $this->getExtensionRoot().'/'.$this->getProjectName()),
$this->taskWriteConfiguration($this->getSiteRoot().'/sites/default/drushrc.php', $this->getConfig())
->setConfigKey('drupal.drush'),
$this->taskAppendConfiguration($this->getSiteRoot().'/sites/default/default.settings.php', $this->getConfig())
->setConfigKey('drupal.settings'),
$this->taskWriteConfiguration($this->getSiteRoot().'/sites/default/drushrc.php', $this->getConfig())->setConfigKey('drupal.drush'),
$this->taskAppendConfiguration($this->getSiteRoot().'/sites/default/default.settings.php', $this->getConfig())->setConfigKey('drupal.settings'),
]);

if (file_exists('behat.yml.dist') || $this->isSimulating()) {
Expand Down
23 changes: 23 additions & 0 deletions tests/fixtures/simulation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@
contains:
- "./bin/drush -y --root=$(pwd)/overridden"

- command: 'drupal:site-post-install'
configuration:
drupal:
post_install:
- "./vendor/bin/drush en views -y"
- "./vendor/bin/drush cr"
composer: ''
contains:
- "./vendor/bin/drush en views -y"
- "./vendor/bin/drush cr"

- command: 'drupal:site-install'
configuration:
drupal:
post_install:
- "./vendor/bin/drush en views -y"
- "./vendor/bin/drush cr"
composer: ''
contains:
- "[Simulator] Running ./vendor/bin/drush -y --root=$(pwd)/build --site-name='Site name' [email protected] --locale=en [email protected] --account-name=admin --account-pass=admin --exclude=build --db-url='mysql://root:[email protected]:3306/drupal' site-install standard"
- "./vendor/bin/drush en views -y"
- "./vendor/bin/drush cr"

- command: 'changelog:generate'
configuration:
github:
Expand Down

0 comments on commit 84187bf

Please sign in to comment.