diff --git a/README.md b/README.md index 8fa0fc2c..2ff97887 100644 --- a/README.md +++ b/README.md @@ -36,14 +36,14 @@ Available commands: help Displays help for a command list Lists commands changelog - changelog:generate [changelog:g|cg] Generate a changelog based on GitHub issues and pull requests. + changelog:generate Generate a changelog based on GitHub issues and pull requests. drupal - drupal:component-setup [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. - drupal:site-setup [drupal:site-scaffold|drupal:ss|dss] Setup local Drupal site development copy. + drupal:drush-setup Write Drush configuration files to the specified directory. + drupal:settings-setup Write Drupal site configuration files to the specified directory. + drupal:site-install Install target site. + drupal:site-post-install Run Drupal post-install commands. + drupal:site-pre-install Run Drupal pre-install commands. setup - setup:behat [setup:b|sb] Setup Behat. - setup:phpunit [setup:p|sp] Setup PHPUnit. - setup:replace [setup:r|sr] Replace configuration tokens in a text file. + setup:behat + setup:phpunit ``` diff --git a/config/runner.yml b/config/runner.yml index 149cc0d5..158936d6 100644 --- a/config/runner.yml +++ b/config/runner.yml @@ -12,9 +12,8 @@ runner: drupal: core: "8" root: "build" - # The "root_absolute" is derived at runtime. - # @see \EC\OpenEuropa\TaskRunner\Commands\DrupalCommands::initializeDrupalRuntimeConfiguration() + # @see \EC\OpenEuropa\TaskRunner\Commands\DrupalCommands::setRuntimeConfig() root_absolute: ~ base_url: "http://127.0.0.1:8888" @@ -55,18 +54,6 @@ drupal: - "vendor" - "${drupal.root}" - # Filesystem tasks to be ran when setting up a site. - setup: - symlink: - - from: "custom/modules" - to: "modules/custom" - - from: "custom/themes" - to: "themes/custom" - - from: "custom/profiles" - to: "profiles/custom" - - from: "custom/libraries" - to: "libraries/custom" - # List of shell commands to be before and after the site installation. # You can use same syntax as the "commands:" below or simply calling a shell command. # Configuration token replacement is supported too. @@ -79,6 +66,7 @@ github: # GitHub OAuth token. token: ~ +# List of dynamically-defined commands. commands: setup:behat: - { task: "process", source: "behat.yml.dist", destination: "behat.yml" } diff --git a/src/Commands/DrupalCommands.php b/src/Commands/DrupalCommands.php index 72bb87db..bbe2d045 100644 --- a/src/Commands/DrupalCommands.php +++ b/src/Commands/DrupalCommands.php @@ -4,7 +4,6 @@ use EC\OpenEuropa\TaskRunner\Contract\ComposerAwareInterface; use EC\OpenEuropa\TaskRunner\Contract\FilesystemAwareInterface; -use Robo\Exception\TaskException; use Symfony\Component\Console\Event\ConsoleCommandEvent; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Yaml\Yaml; @@ -41,7 +40,7 @@ public function getConfigurationFile() * * @hook command-event * */ - public function initializeDrupalRuntimeConfiguration(ConsoleCommandEvent $event) + public function setRuntimeConfig(ConsoleCommandEvent $event) { $root = $this->getConfig()->get('drupal.root'); $rootFullPath = realpath($root); @@ -175,7 +174,7 @@ public function sitePreInstall() /** * Write Drush configuration files to the specified directory. * - * @command drupal:setup-drush + * @command drupal:drush-setup * * @option root Drupal root. * @@ -199,7 +198,7 @@ public function setupDrush(array $options = [ /** * Write Drupal site configuration files to the specified directory. * - * @command drupal:setup-settings + * @command drupal:settings-setup * * @option root Drupal root. * diff --git a/src/Commands/DynamicCommands.php b/src/Commands/DynamicCommands.php index d9656566..b7a73c7c 100644 --- a/src/Commands/DynamicCommands.php +++ b/src/Commands/DynamicCommands.php @@ -2,7 +2,11 @@ namespace EC\OpenEuropa\TaskRunner\Commands; -use EC\OpenEuropa\TaskRunner\Tasks\CollectionFactory\loadTasks; +use Consolidation\AnnotatedCommand\AnnotationData; +use Consolidation\AnnotatedCommand\CommandData; +use EC\OpenEuropa\TaskRunner\Tasks as TaskRunnerTasks; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Event\ConsoleCommandEvent; /** * Class DynamicCommands @@ -11,7 +15,7 @@ */ class DynamicCommands extends BaseCommands { - use loadTasks; + use TaskRunnerTasks\CollectionFactory\loadTasks; /** * @return \EC\OpenEuropa\TaskRunner\Tasks\CollectionFactory\CollectionFactory diff --git a/src/Tasks/CollectionFactory/CollectionFactory.php b/src/Tasks/CollectionFactory/CollectionFactory.php index 45bbdb17..b1e39e39 100644 --- a/src/Tasks/CollectionFactory/CollectionFactory.php +++ b/src/Tasks/CollectionFactory/CollectionFactory.php @@ -49,7 +49,7 @@ public function run() { $collection = $this->collectionBuilder(); - foreach ($this->tasks as $task) { + foreach ($this->getTasks() as $task) { $collection->addTask($this->taskFactory($task)); } @@ -61,15 +61,30 @@ public function run() */ public function simulate($context) { - foreach ($this->tasks as $task) { + foreach ($this->getTasks() as $task) { if (is_array($task)) { $task = Yaml::dump($task, 0); } - $this->printTaskInfo($task, $context); } } + /** + * @return array + */ + public function getTasks() + { + return isset($this->tasks['tasks']) ? $this->tasks['tasks'] : $this->tasks; + } + + /** + * @return string + */ + public function getHelp() + { + return isset($this->tasks['help']) ? $this->tasks['help'] : "Dynamic command defined in runner.yml"; + } + /** * @param array|string $task * @@ -128,6 +143,9 @@ protected function taskFactory($task) case "process": return $this->taskProcessConfigFile($task['source'], $task['destination']); + case "run": + return $this->taskExec($this->getConfig()->get('runner.bin_dir').'/run')->arg($task['command']); + default: throw new TaskException($this, "Task '{$task['task']}' not supported."); } diff --git a/tests/fixtures/simulation.yml b/tests/fixtures/simulation.yml index 118cbc56..3458b402 100644 --- a/tests/fixtures/simulation.yml +++ b/tests/fixtures/simulation.yml @@ -139,28 +139,53 @@ - "[Simulator] { task: symlink, from: build/modules/custom, to: ../../custom/modules }" - "[Simulator] { task: symlink, from: build/modules/custom, to: ../../custom/themes }" -- command: 'drupal:setup-drush' +- command: 'drupal:drush-setup' configuration: [] composer: '' contains: - "WriteConfiguration('build/sites/default/drushrc.php'" - "File\\Write('build/sites/default/drush.yml')" -- command: 'drupal:setup-drush --root=web' +- command: 'drupal:drush-setup --root=web' configuration: [] composer: '' contains: - "WriteConfiguration('web/sites/default/drushrc.php'" - "File\\Write('web/sites/default/drush.yml')" -- command: 'drupal:setup-settings' +- command: 'drupal:settings-setup' configuration: [] composer: '' contains: - "AppendConfiguration('build/sites/default/default.settings.php'" -- command: 'drupal:setup-settings --root=web' +- command: 'drupal:settings-setup --root=web' configuration: [] composer: '' contains: - "AppendConfiguration('web/sites/default/default.settings.php'" + +- command: 'drupal:setup-dev' + configuration: + drupal: + root: "web" + commands: + drupal:setup-dev: + - { task: "chmod", file: "${drupal.root}/sites", permissions: '0775' } + - { task: "symlink", from: "${drupal.root}/modules/custom", to: "../../custom/modules" } + - { task: "symlink", from: "${drupal.root}/themes/custom", to: "../../custom/themes" } + - { task: "symlink", from: "${drupal.root}/profiles/custom", to: "../../custom/profiles" } + - { task: "run", command: "drupal:drush-setup" } + - { task: "run", command: "drupal:settings-setup" } + - { task: "run", command: "setup:behat" } + - { task: "run", command: "setup:phpunit" } + composer: '' + contains: + - "{ task: chmod, file: web/sites, permissions: '0775' }" + - "{ task: symlink, from: web/modules/custom, to: ../../custom/modules }" + - "{ task: symlink, from: web/themes/custom, to: ../../custom/themes }" + - "{ task: symlink, from: web/profiles/custom, to: ../../custom/profiles }" + - "{ task: run, command: 'drupal:drush-setup' }" + - "{ task: run, command: 'drupal:settings-setup' }" + - "{ task: run, command: 'setup:behat' }" + - "{ task: run, command: 'setup:phpunit' }"