Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  Restore state after unit test.
  Fix tests.
  Fix tests.
  Fix theme settings.
  Fix unsupported operand types.
  Code style fix.
  Fix unsupported operand types.
  Fix unsupported operand types.
  Code style fix.
  Code style fix.
  Code style fix.
  Fixes #6: Add source files folder.
  Trigger ci tools after robo-digipolis-package release.
  Fixes #3: Rename cleanMirrorDir to prepareMirrorDir.
  • Loading branch information
Jelle-S committed May 2, 2017
2 parents 5b44bef + 6ce579f commit b9742c2
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"require": {
"consolidation/robo": "~1.0",
"php": ">=5.5.0",
"digipolisgent/robo-digipolis-package": "^0.1"
"digipolisgent/robo-digipolis-package": "^0.1.1"
},
"require-dev": {
"phpunit/phpunit": "~4.4",
Expand Down
3 changes: 2 additions & 1 deletion src/PackageDrupal8.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ class PackageDrupal8 extends PackageProject
/**
* {@inheritdoc}
*/
protected function cleanMirrorDir()
protected function prepareMirrorDir()
{
$this->printTaskInfo(sprintf('Preparing directory %s.', $this->tmpDir));
// Only keep web, vendor and config folder.
$folders = new Finder();
$folders->in($this->tmpDir);
Expand Down
23 changes: 20 additions & 3 deletions src/ThemesCleanDrupal8.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ThemesCleanDrupal8 extends BaseTask implements BuilderAwareInterface
{
use \Robo\TaskAccessor;
use \DigipolisGent\Robo\Task\Package\loadTasks;
use \Robo\Task\Filesystem\loadTasks;
use Utility\ThemeFinder;

/**
Expand Down Expand Up @@ -97,17 +98,33 @@ public function finder(Finder $finder)
public function run()
{
$themesFromConfig = $this->getConfig()->get('digipolis.themes.drupal8', false);
$themeNamesFromConfig = [];
if ($themesFromConfig) {
$themesFromConfig = array_keys((array) $themesFromConfig);
$themeNamesFromConfig = array_keys((array) $themesFromConfig);
}
$themes = empty($this->themes)
? $themesFromConfig
? $themeNamesFromConfig
: $this->themes;
if (!$themes) {
return \Robo\Result::success($this);
}
$collection = $this->collectionBuilder();
foreach ($this->getThemePaths($themes) as $path) {
foreach ($this->getThemePaths($themes) as $themeName => $path) {
$themeSettings = isset($themesFromConfig[$themeName])
? $themesFromConfig[$themeName]
: [];
if (is_string($themeSettings)) {
// Backward compatibility.
$themeSettings = ['command' => $themeSettings];
}
$themeSettings = array_merge(
['command' => 'build', 'sourcedir' => 'source'],
$themeSettings
);
if ($themeSettings['sourcedir'] && is_dir($path . '/' . $themeSettings['sourcedir'])) {
$collection->addTask($this->taskDeleteDir([$path . '/' . $themeSettings['sourcedir']]));
continue;
}
$collection->addTask($this->taskThemeClean($path));
}
return $collection->run();
Expand Down
23 changes: 21 additions & 2 deletions src/ThemesCompileDrupal8.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,27 @@ public function run()
}
$collection = $this->collectionBuilder();
foreach ($this->getThemePaths(array_keys($themes)) as $themeName => $path) {
$command = $themes[$themeName];
$collection->addTask($this->taskThemeCompile($path, $command));
$themeSettings = isset($themes[$themeName])
? $themes[$themeName]
: [];
if (is_string($themeSettings)) {
// Backward compatibility.
$themeSettings = ['command' => $themeSettings];
}
$themeSettings = array_merge(
['command' => 'build', 'sourcedir' => 'source'],
$themeSettings
);
$dir = $path;
if ($themeSettings['sourcedir'] && is_dir($path . '/' . $themeSettings['sourcedir'])) {
$dir = $path . '/' . $themeSettings['sourcedir'];
}
$collection->addTask(
$this->taskThemeCompile(
$dir,
$themeSettings['command']
)
);
}
return $collection->run();
}
Expand Down
8 changes: 8 additions & 0 deletions testfiles/themes/testtheme_source/source/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports = function (grunt) {
grunt.registerTask('build', function () {
grunt.file.write('../hello_grunt.txt', 'Hello world from grunt.');
});

};
12 changes: 12 additions & 0 deletions testfiles/themes/testtheme_source/source/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "robo-digipolis-testtheme_source",
"version": "1.0.0",
"dependencies": {},
"devDependencies": {
"grunt": "~0.4.0",
"grunt-shell": "~0.3.1"
},
"engines": {
"node": ">=0.8.0"
}
}
2 changes: 2 additions & 0 deletions testfiles/themes/testtheme_source/testtheme_source.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## YAML Template.
---
13 changes: 13 additions & 0 deletions tests/ThemesCleanDrupal8Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ public function setUp()
$container = Robo::createDefaultContainer(null, new NullOutput());
$this->setContainer($container);
$this->setConfig(Robo::config());
// Backup testfiles.
$path = realpath(__DIR__ . '/..');
exec('cp -r ' . $path . '/testfiles' . ' ' . $path . '/testfiles_backup');
}

public function tearDown() {
// Restore testfiles backup.
$path = realpath(__DIR__ . '/..');
exec('rm -rf ' . $path . '/testfiles');
exec('mv ' . $path . '/testfiles_backup' . ' ' . $path . '/testfiles');
}

/**
Expand All @@ -49,6 +59,7 @@ public function testRun()
$this->getConfig()->set('digipolis.root.project', realpath(__DIR__ . '/../testfiles'));
$this->getConfig()->set('digipolis.themes.drupal8', [
'testtheme' => 'build',
'testtheme_source' => 'build',
'custom' => 'build',
]);
$compileResult = $this->taskThemesCompileDrupal8()
Expand All @@ -74,5 +85,7 @@ public function testRun()
$this->assertFileNotExists($themePath . '/node_modules');
}

// Assert cleanup of source dir.
$this->assertFileNotExists(realpath(__DIR__ . '/../testfiles/themes/testtheme_source') . '/source');
}
}
12 changes: 12 additions & 0 deletions tests/ThemesCompileDrupal8Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ThemesCompileDrupal8Test extends \PHPUnit_Framework_TestCase implements Co
use \Robo\Common\ConfigAwareTrait;

protected $themePaths;
protected $sourceThemePath;

/**
* Set up the Robo container so that we can create tasks in our tests.
Expand All @@ -34,6 +35,7 @@ public function setUp()
realpath(__DIR__ . '/../testfiles/themes/testtheme'),
realpath(__DIR__ . '/../testfiles/themes/custom/customtheme'),
];
$this->sourceThemePath = realpath(__DIR__ . '/../testfiles/themes/testtheme_source');
}

public function tearDown()
Expand All @@ -49,6 +51,9 @@ public function tearDown()
exec('rm -rf ' . $themePath . $remove);
}
}
exec('rm -rf ' . $this->sourceThemePath . '/hello_grunt.txt');
exec('rm -rf ' . $this->sourceThemePath . '/source/node_modules');
exec('rm -rf ' . $this->sourceThemePath . '/source/vendor');
}

/**
Expand All @@ -70,6 +75,7 @@ public function testRun()
$this->getConfig()->set('digipolis.root.project', realpath(__DIR__ . '/../testfiles'));
$this->getConfig()->set('digipolis.themes.drupal8', [
'testtheme' => 'build',
'testtheme_source' => 'build',
'custom' => 'build',
]);
$result = $this->taskThemesCompileDrupal8()
Expand All @@ -86,5 +92,11 @@ public function testRun()
// Assert grunt build ran.
$this->assertFileExists($themePath . '/hello_grunt.txt');
}

// Assert node ran.
$this->assertFileExists($this->sourceThemePath . '/source/node_modules');

// Assert grunt build ran.
$this->assertFileExists($this->sourceThemePath . '/hello_grunt.txt');
}
}

0 comments on commit b9742c2

Please sign in to comment.