Skip to content

Commit

Permalink
Add support for themes and profiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmash committed Feb 1, 2018
1 parent 308432d commit 203d3ce
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ composer composerize-drupal --composer-root=. --drupal-root=.
The `composerize-drupal` command will perform the following operations:

* Remove all vestigial `composer.json` and `composer.lock` files
* Generate a new `composer.json` in the `[composer-root]` directory based on [template.composer.json](composer.template.json)
* Populate `require` with an entry for `drupal/core`
* Populate `require` with an entry for each module is `[drupal-root]/modules/contrib`
10 changes: 7 additions & 3 deletions src/Composer/ComposerizeDrupalCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,13 @@ protected function determineDrupalCoreVersion()
*/
protected function requireModules($root_composer_json)
{
$modules = DrupalInspector::findModules($this->drupalRoot);
foreach ($modules as $module => $version) {
$package_name = "drupal/$module";
$modules = DrupalInspector::findContribProjects($this->drupalRoot, "modules/contrib");
$themes = DrupalInspector::findContribProjects($this->drupalRoot, "themes/contrib");
$profiles = DrupalInspector::findContribProjects($this->drupalRoot, "profiles/contrib");

$projects = array_merge($modules, $themes, $profiles);
foreach ($projects as $project => $version) {
$package_name = "drupal/$project";
$version_constraint = $this->getVersionConstraint($version);
$root_composer_json->require->{$package_name} = $version_constraint;
$this->getIO()->write("<info>Added $package_name $version_constraint to requirements.</info>");
Expand Down
14 changes: 7 additions & 7 deletions src/Utility/DrupalInspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@
class DrupalInspector
{

public static function findModules($drupal_root)
public static function findContribProjects($drupal_root, $subdir)
{
if (!file_exists($drupal_root . "/modules/contrib")) {
if (!file_exists($drupal_root . "/" . $subdir)) {
return [];
}

$finder = new Finder();
$finder->in([$drupal_root . "/modules/contrib"])
$finder->in([$drupal_root . "/" . $subdir])
->name('*.info.yml')
->depth('== 1')
->files();

$modules = [];
$projects = [];
foreach ($finder as $fileInfo) {
$path = $fileInfo->getPathname();
$filename_parts = explode('.', $fileInfo->getFilename());
$module_machine_name = $filename_parts[0];
$machine_name = $filename_parts[0];
$module_info = Yaml::parseFile($path);
$semantic_verision = self::getSemanticVersion($module_info['version']);
$modules[$module_machine_name] = $semantic_verision;
$projects[$machine_name] = $semantic_verision;
}

return $modules;
return $projects;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/DrupalInspectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class DrupalInspectorTest extends TestBase
{

/**
* Tests DrupalInspector::findModules().
* Tests DrupalInspector::findContribProjects().
*/
public function testFindModules()
{
$this->sandbox = $this->sandboxManager->makeSandbox();
$modules = DrupalInspector::findModules($this->sandbox . "/docroot");
$modules = DrupalInspector::findContribProjects($this->sandbox . "/docroot", "modules/contrib");
$this->assertArrayHasKey('ctools', $modules);
$this->assertContains('3.0.0', $modules);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/phpunit/src/SandboxManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public function makeSandbox()
return $sandbox;
}

protected function downloadProjectFromDrupalOrg($project_string) {
protected function downloadProjectFromDrupalOrg($project_string)
{
$targz_filename = "$project_string.tar.gz";
$targz_filepath = "{$this->tmp}/$targz_filename";
$tar_filepath = str_replace('.gz', '', $targz_filepath);
Expand Down

0 comments on commit 203d3ce

Please sign in to comment.