Skip to content

Commit

Permalink
Update code due to the new drupal:scaffold command. Follow logic of C…
Browse files Browse the repository at this point in the history
…omposer to add require-dev by default.
  • Loading branch information
FlorentTorregrosa committed Apr 21, 2018
1 parent d0d450f commit bbf9fa6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/DrupalScaffoldCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Composer\Command\BaseCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand All @@ -20,15 +21,18 @@ protected function configure() {
parent::configure();
$this
->setName('drupal:scaffold')
->setDescription('Update the Drupal scaffold files.');
->setDescription('Update the Drupal scaffold files.')
->setDefinition(array(
new InputOption('no-dev', NULL, InputOption::VALUE_NONE, 'Disables download of include-dev files.'),
));
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output) {
$handler = new Handler($this->getComposer(), $this->getIO());
$handler->downloadScaffold();
$handler->downloadScaffold(!$input->getOption('no-dev'));
// Generate the autoload.php file after generating the scaffold files.
$handler->generateAutoload();
}
Expand Down
10 changes: 5 additions & 5 deletions src/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function onPostCmdEvent(Event $event) {
// Only install the scaffolding if drupal/core was installed,
// AND there are no scaffolding files present.
if (isset($this->drupalCorePackage)) {
$this->downloadScaffold($event);
$this->downloadScaffold($event->isDevMode());
// Generate the autoload.php file after generating the scaffold files.
$this->generateAutoload();
}
Expand All @@ -121,18 +121,18 @@ public function onPostCmdEvent(Event $event) {
/**
* Downloads drupal scaffold files for the current process.
*
* @param \Composer\Script\Event $event
* The Composer event.
* @param bool $dev
* TRUE if dev packages are installed. FALSE otherwise.
*/
public function downloadScaffold($event) {
public function downloadScaffold($dev = TRUE) {
$drupalCorePackage = $this->getDrupalCorePackage();
$webroot = realpath($this->getWebRoot());

// Collect options, excludes, dev and settings files.
$options = $this->getOptions();
$includes = $this->getIncludes();
// Check dev files if necessary.
if ($event->isDevMode()) {
if ($dev) {
$includes = array_merge($includes, $this->getIncludesDev());
}
$files = array_diff($includes, $this->getExcludes());
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function postCmd(Event $event) {
public static function scaffold(Event $event) {
@trigger_error('\DrupalComposer\DrupalScaffold\Plugin::scaffold is deprecated since version 2.5.0 and will be removed in 3.0. Use "composer drupal:scaffold" instead.', E_USER_DEPRECATED);
$handler = new Handler($event->getComposer(), $event->getIO());
$handler->downloadScaffold($event);
$handler->downloadScaffold($event->isDevMode());
// Generate the autoload.php file after generating the scaffold files.
$handler->generateAutoload();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testDevFiles() {
$this->composer('install --no-dev');
$this->assertFileExists($exampleScaffoldFile, 'Scaffold file should exist.');
$this->assertFileNotExists($developmentScaffoldFile, 'Development scaffold file should not exist.');
$this->composer('drupal-scaffold');
$this->composer('drupal:scaffold');
$this->assertFileExists($exampleScaffoldFile, 'Scaffold file should exist.');
$this->assertFileExists($developmentScaffoldFile, 'Development scaffold file should exist.');
}
Expand All @@ -35,7 +35,7 @@ public function testDevFiles() {
*/
protected function composerJSONDefaults() {
$composerJsonDefault = parent::composerJSONDefaults();
$composerJsonDefault['prefer-stable'] = true;
$composerJsonDefault['prefer-stable'] = TRUE;
return $composerJsonDefault;
}

Expand Down

0 comments on commit bbf9fa6

Please sign in to comment.