Skip to content

Commit 554467b

Browse files
Update code due to the new drupal:scaffold command. Follow logic of Composer to add require-dev by default.
1 parent 2f1053e commit 554467b

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

src/DrupalScaffoldCommand.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Composer\Command\BaseCommand;
66
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Input\InputOption;
78
use Symfony\Component\Console\Output\OutputInterface;
89

910
/**
@@ -20,15 +21,18 @@ protected function configure() {
2021
parent::configure();
2122
$this
2223
->setName('drupal:scaffold')
23-
->setDescription('Update the Drupal scaffold files.');
24+
->setDescription('Update the Drupal scaffold files.')
25+
->setDefinition(array(
26+
new InputOption('no-dev', NULL, InputOption::VALUE_NONE, 'Disables download of include-dev files.'),
27+
));
2428
}
2529

2630
/**
2731
* {@inheritdoc}
2832
*/
2933
protected function execute(InputInterface $input, OutputInterface $output) {
3034
$handler = new Handler($this->getComposer(), $this->getIO());
31-
$handler->downloadScaffold();
35+
$handler->downloadScaffold(!$input->getOption('no-dev'));
3236
// Generate the autoload.php file after generating the scaffold files.
3337
$handler->generateAutoload();
3438
}

src/Handler.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function onPostCmdEvent(Event $event) {
133133
// Only install the scaffolding if drupal/core was installed,
134134
// AND there are no scaffolding files present.
135135
if (isset($this->drupalCorePackage)) {
136-
$this->downloadScaffold($event);
136+
$this->downloadScaffold($event->isDevMode());
137137
// Generate the autoload.php file after generating the scaffold files.
138138
$this->generateAutoload();
139139
}
@@ -142,18 +142,18 @@ public function onPostCmdEvent(Event $event) {
142142
/**
143143
* Downloads drupal scaffold files for the current process.
144144
*
145-
* @param \Composer\Script\Event $event
146-
* The Composer event.
145+
* @param bool $dev
146+
* TRUE if dev packages are installed. FALSE otherwise.
147147
*/
148-
public function downloadScaffold($event) {
148+
public function downloadScaffold($dev = TRUE) {
149149
$drupalCorePackage = $this->getDrupalCorePackage();
150150
$webroot = realpath($this->getWebRoot());
151151

152152
// Collect options, excludes, dev and settings files.
153153
$options = $this->getOptions();
154154
$includes = $this->getIncludes();
155155
// Check dev files if necessary.
156-
if ($event->isDevMode()) {
156+
if ($dev) {
157157
$includes = array_merge($includes, $this->getIncludesDev());
158158
}
159159
$files = array_diff($includes, $this->getExcludes());

src/Plugin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function postCmd(Event $event) {
9595
public static function scaffold(Event $event) {
9696
@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);
9797
$handler = new Handler($event->getComposer(), $event->getIO());
98-
$handler->downloadScaffold($event);
98+
$handler->downloadScaffold($event->isDevMode());
9999
// Generate the autoload.php file after generating the scaffold files.
100100
$handler->generateAutoload();
101101
}

tests/HandlerTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testDevFiles() {
2323
$this->composer('install --no-dev');
2424
$this->assertFileExists($exampleScaffoldFile, 'Scaffold file should exist.');
2525
$this->assertFileNotExists($developmentScaffoldFile, 'Development scaffold file should not exist.');
26-
$this->composer('drupal-scaffold');
26+
$this->composer('drupal:scaffold');
2727
$this->assertFileExists($exampleScaffoldFile, 'Scaffold file should exist.');
2828
$this->assertFileExists($developmentScaffoldFile, 'Development scaffold file should exist.');
2929
}
@@ -35,7 +35,7 @@ public function testDevFiles() {
3535
*/
3636
protected function composerJSONDefaults() {
3737
$composerJsonDefault = parent::composerJSONDefaults();
38-
$composerJsonDefault['prefer-stable'] = true;
38+
$composerJsonDefault['prefer-stable'] = TRUE;
3939
return $composerJsonDefault;
4040
}
4141

0 commit comments

Comments
 (0)