Skip to content

Commit 3ad465a

Browse files
claudiu-cristeawebflo
authored andcommitted
Support Drupal 8.3.x (#49)
1 parent 4eacf14 commit 3ad465a

File tree

3 files changed

+66
-7
lines changed

3 files changed

+66
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ Default includes are provided by the plugin:
6161
.csslintrc
6262
.editorconfig
6363
.eslintignore
64-
.eslintrc
64+
.eslintrc (Drupal <= 8.2.x)
65+
.eslintrc.json (Drupal >= 8.3.x)
6566
.gitattributes
6667
.htaccess
6768
index.php

src/Handler.php

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ public function downloadScaffold() {
109109
$dispatcher = new EventDispatcher($this->composer, $this->io);
110110
$dispatcher->dispatch(self::PRE_DRUPAL_SCAFFOLD_CMD);
111111

112-
$version = $drupalCorePackage->getPrettyVersion();
113-
if ($drupalCorePackage->getStability() == 'dev' && substr($version, -4) == '-dev') {
114-
$version = substr($version, 0, -4);
115-
}
112+
$version = $this->getDrupalCoreVersion($drupalCorePackage);
116113

117114
$remoteFs = new RemoteFilesystem($this->io);
118115

@@ -200,6 +197,22 @@ public function getDrupalCorePackage() {
200197
return $this->drupalCorePackage;
201198
}
202199

200+
/**
201+
* Returns the Drupal core version for the given package.
202+
*
203+
* @param \Composer\Package\PackageInterface $drupalCorePackage
204+
*
205+
* @return string
206+
*/
207+
protected function getDrupalCoreVersion(PackageInterface $drupalCorePackage) {
208+
$version = $drupalCorePackage->getPrettyVersion();
209+
if ($drupalCorePackage->getStability() == 'dev' && substr($version, -4) == '-dev') {
210+
$version = substr($version, 0, -4);
211+
return $version;
212+
}
213+
return $version;
214+
}
215+
203216
/**
204217
* Retrieve the path to the web root.
205218
*
@@ -301,11 +314,20 @@ protected function getExcludesDefault() {
301314
* Holds default settings files list.
302315
*/
303316
protected function getIncludesDefault() {
304-
return [
317+
$version = $this->getDrupalCoreVersion($this->getDrupalCorePackage());
318+
list($major, $minor) = explode('.', $version, 3);
319+
$version = "$major.$minor";
320+
321+
/**
322+
* Files from 8.3.x
323+
*
324+
* @see http://cgit.drupalcode.org/drupal/tree/?h=8.3.x
325+
*/
326+
$common = [
305327
'.csslintrc',
306328
'.editorconfig',
307329
'.eslintignore',
308-
'.eslintrc',
330+
'.eslintrc.json',
309331
'.gitattributes',
310332
'.htaccess',
311333
'index.php',
@@ -318,6 +340,19 @@ protected function getIncludesDefault() {
318340
'update.php',
319341
'web.config'
320342
];
343+
344+
// Version specific variations.
345+
switch ($version) {
346+
case '8.0':
347+
case '8.1':
348+
case '8.2':
349+
$common[] = '.eslintrc';
350+
$common = array_diff($common, ['.eslintrc.json']);
351+
break;
352+
}
353+
354+
sort($common);
355+
return $common;
321356
}
322357

323358
/**

tests/FetcherTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace DrupalComposer\DrupalScaffold\Tests;
99

10+
use Composer\Downloader\TransportException;
1011
use Composer\IO\NullIO;
1112
use Composer\Util\Filesystem;
1213
use Composer\Util\RemoteFilesystem;
@@ -68,6 +69,28 @@ public function testFetch() {
6869
$this->assertFileExists($this->tmpDir . '/sites/default/default.settings.php');
6970
}
7071

72+
/**
73+
* Tests version specific files.
74+
*/
75+
public function testFetchVersionSpecific() {
76+
$fetcher = new FileFetcher(new RemoteFilesystem(new NullIO()), 'http://cgit.drupalcode.org/drupal/plain/{path}?h={version}', ['.eslintrc', '.eslintrc.json']);
77+
78+
$this->setExpectedException(TransportException::class);
79+
$fetcher->fetch('8.2.x', $this->tmpDir);
80+
81+
$this->assertFileExists($this->tmpDir . '/.eslintrc');
82+
$this->assertFileNotExists($this->tmpDir . '/.eslintrc.json');
83+
84+
// Remove downloaded files to retest with 8.3.x.
85+
@unlink($this->tmpDir . '/.eslintrc');
86+
87+
$this->setExpectedException(TransportException::class);
88+
$fetcher->fetch('8.3.x', $this->tmpDir);
89+
90+
$this->assertFileExists($this->tmpDir . '/.eslintrc.json');
91+
$this->assertFileNotExists($this->tmpDir . '/.eslintrc');
92+
}
93+
7194
public function testInitialFetch() {
7295
$fetcher = new InitialFileFetcher(new RemoteFilesystem(new NullIO()), 'http://cgit.drupalcode.org/drupal/plain/{path}?h={version}', ['sites/default/default.settings.php' => 'sites/default/settings.php']);
7396
$fetcher->fetch('8.1.1', $this->tmpDir);

0 commit comments

Comments
 (0)