Skip to content

Commit

Permalink
Discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Feb 10, 2025
1 parent 90e142e commit 2f9472d
Show file tree
Hide file tree
Showing 19 changed files with 419 additions and 259 deletions.
18 changes: 18 additions & 0 deletions .vortex/installer/src/Discovery/AbstractDiscovery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace DrevOps\Installer\Discovery;

use DrevOps\Installer\InstallerConfig;

abstract class AbstractDiscovery {

public function __construct(protected InstallerConfig $config, protected array $responses) {
}

abstract public function discover();

// @todo: Rename to getResponse().
public function getAnswer($name) {
return $this->responses[$name] ?? NULL;
}
}
21 changes: 21 additions & 0 deletions .vortex/installer/src/Discovery/CiProvoderDiscovery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace DrevOps\Installer\Discovery;

use DrevOps\Installer\Util;

class CiProvoderDiscovery extends AbstractDiscovery {

public function discover() {
if (is_readable($this->config->getDstDir() . '/.github/workflows/build-test-deploy.yml')) {
return 'GitHub Actions';
}

if (is_readable($this->config->getDstDir() . '/.circleci/config.yml')) {
return 'CircleCI';
}

return $this->isInstalled() ? 'none' : NULL;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace DrevOps\Installer\Discovery;

use DrevOps\Installer\Util;

class DatabaseDownloadSourceDiscovery extends AbstractDiscovery {

public function discover() {
return $this->getValueFromDstDotenv('VORTEX_DB_DOWNLOAD_SOURCE');
}

}
11 changes: 11 additions & 0 deletions .vortex/installer/src/Discovery/DatabaseImageDiscovery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace DrevOps\Installer\Discovery;

class DatabaseImageDiscovery extends AbstractDiscovery {

public function discover() {
return $this->getValueFromDstDotenv('VORTEX_DB_IMAGE');
}

}
11 changes: 11 additions & 0 deletions .vortex/installer/src/Discovery/DatabaseStoreTypeDiscovery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace DrevOps\Installer\Discovery;

class DatabaseStoreTypeDiscovery extends AbstractDiscovery {

public function discover() {
return $this->discoverValueDatabaseImage() ? 'container_image' : 'file';
}

}
13 changes: 13 additions & 0 deletions .vortex/installer/src/Discovery/DeployTypeDiscovery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace DrevOps\Installer\Discovery;

use DrevOps\Installer\Util;

class DeployTypeDiscovery extends AbstractDiscovery {

public function discover() {
return $this->getValueFromDstDotenv('VORTEX_DEPLOY_TYPES');
}

}
13 changes: 13 additions & 0 deletions .vortex/installer/src/Discovery/DomainDiscovery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace DrevOps\Installer\Discovery;

use DrevOps\Installer\Util;

class DomainDiscovery extends AbstractDiscovery {

public function discover() {
return $this->getValueFromDstDotenv('DRUPAL_STAGE_FILE_PROXY_ORIGIN');
}

}
19 changes: 19 additions & 0 deletions .vortex/installer/src/Discovery/MachineNameDiscovery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace DrevOps\Installer\Discovery;

use DrevOps\Installer\Util;

class MachineNameDiscovery extends AbstractDiscovery {

public function discover() {
$value = Util::getComposerJsonValue('name', $this->config->getDstDir() . DIRECTORY_SEPARATOR . 'composer.json');

if ($value && preg_match('/([^\/]+)\/(.+)/', (string) $value, $matches) && !empty($matches[2])) {
return $matches[2];
}

return NULL;
}

}
34 changes: 34 additions & 0 deletions .vortex/installer/src/Discovery/ModulePrefixDiscovery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace DrevOps\Installer\Discovery;

use DrevOps\Installer\File;
use DrevOps\Installer\PromptFields;
use DrevOps\Installer\Util;

class ModulePrefixDiscovery extends AbstractDiscovery {

public function discover() {
$webroot = $this->getAnswer(PromptFields::WEBROOT_CUSTOM);

$locations = [
$this->config->getDstDir() . sprintf('/%s/modules/custom/*_core', $webroot),
$this->config->getDstDir() . sprintf('/%s/sites/all/modules/custom/*_core', $webroot),
$this->config->getDstDir() . sprintf('/%s/profiles/*/modules/*_core', $webroot),
$this->config->getDstDir() . sprintf('/%s/profiles/*/modules/custom/*_core', $webroot),
$this->config->getDstDir() . sprintf('/%s/profiles/custom/*/modules/*_core', $webroot),
$this->config->getDstDir() . sprintf('/%s/profiles/custom/*/modules/custom/*_core', $webroot),
];

$path = File::findMatchingPath($locations);

if (empty($path)) {
return NULL;
}

$path = basename($path);

return str_replace('_core', '', $path);
}

}
19 changes: 19 additions & 0 deletions .vortex/installer/src/Discovery/NameDiscovery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace DrevOps\Installer\Discovery;

use DrevOps\Installer\Util;

class NameDiscovery extends AbstractDiscovery {

public function discover() {
$value = Util::getComposerJsonValue('description', $this->config->getDstDir() . DIRECTORY_SEPARATOR . 'composer.json');

if ($value && preg_match('/Drupal \d+ .* of ([0-9a-zA-Z\- ]+) for ([0-9a-zA-Z\- ]+)/', (string) $value, $matches) && !empty($matches[1])) {
return $matches[1];
}

return NULL;
}

}
19 changes: 19 additions & 0 deletions .vortex/installer/src/Discovery/OrgDiscovery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace DrevOps\Installer\Discovery;

use DrevOps\Installer\Util;

class OrgDiscovery extends AbstractDiscovery {

public function discover() {
$value = Util::getComposerJsonValue('description', $this->config->getDstDir() . DIRECTORY_SEPARATOR . 'composer.json');

if ($value && preg_match('/Drupal \d+ .* of ([0-9a-zA-Z\- ]+) for ([0-9a-zA-Z\- ]+)/', (string) $value, $matches) && !empty($matches[2])) {
return $matches[2];
}

return NULL;
}

}
19 changes: 19 additions & 0 deletions .vortex/installer/src/Discovery/OrgMachineNameDiscovery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace DrevOps\Installer\Discovery;

use DrevOps\Installer\Util;

class OrgMachineNameDiscovery extends AbstractDiscovery {

public function discover() {
$value = Util::getComposerJsonValue('name', $this->config->getDstDir() . DIRECTORY_SEPARATOR . 'composer.json');

if ($value && preg_match('/([^\/]+)\/(.+)/', (string) $value, $matches) && !empty($matches[1])) {
return $matches[1];
}

return NULL;
}

}
38 changes: 38 additions & 0 deletions .vortex/installer/src/Discovery/ProfileDiscovery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace DrevOps\Installer\Discovery;

use DrevOps\Installer\File;
use DrevOps\Installer\PromptFields;

class ProfileDiscovery extends AbstractDiscovery {

public function discover() {
$webroot = $this->getAnswer(PromptFields::WEBROOT_CUSTOM);

if ($this->isInstalled()) {
$name = $this->getValueFromDstDotenv('DRUPAL_PROFILE');
if (!empty($name)) {
return $name;
}
}

$locations = [
$this->config->getDstDir() . sprintf('/%s/profiles/*/*.info', $webroot),
$this->config->getDstDir() . sprintf('/%s/profiles/*/*.info.yml', $webroot),
$this->config->getDstDir() . sprintf('/%s/profiles/custom/*/*.info', $webroot),
$this->config->getDstDir() . sprintf('/%s/profiles/custom/*/*.info.yml', $webroot),
];

$name = File::findMatchingPath($locations, 'Drupal 11 profile implementation of');

if (empty($name)) {
return NULL;
}

$name = basename($name);

return str_replace(['.info.yml', '.info'], '', $name);
}

}
13 changes: 13 additions & 0 deletions .vortex/installer/src/Discovery/ProvisionUseProfileDiscovery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace DrevOps\Installer\Discovery;

use DrevOps\Installer\Util;

class ProvisionUseProfileDiscovery extends AbstractDiscovery {

public function discover() {
return (bool) $this->getValueFromDstDotenv('VORTEX_PROVISION_USE_PROFILE');
}

}
74 changes: 74 additions & 0 deletions .vortex/installer/src/Discovery/ThemeDiscovery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace DrevOps\Installer\Discovery;

use DrevOps\Installer\File;
use DrevOps\Installer\PromptFields;

class ThemeDiscovery extends AbstractDiscovery {

public function discover() {
$webroot = $this->getAnswer(PromptFields::WEBROOT_CUSTOM);

$name_from_env = NULL;
if ($this->isInstalled()) {
$name_from_env = $this->getValueFromDstDotenv('DRUPAL_THEME');
}

$file = $this->findThemeFile($this->config->getDstDir(), $webroot);

if (empty($file)) {
// If theme file was not found, but the theme is set in the .env file -
// return the theme name from the .env file.
return $name_from_env ?: NULL;
}

$name_from_info = str_replace(['.info.yml', '.info'], '', basename($file));

// Check that this is a theme coming originally from the Vortex template.
$dir = dirname($file);

if (!$this->isVortexTheme($dir)) {
// If the theme is not coming from the Vortex template - return the theme
// name from the .env file.
return $name_from_env ?: NULL;
}

if ($name_from_env) {
if ($name_from_info !== $name_from_env) {
// If the theme name from the .env file does not match the theme name
// from the theme file - return the theme name from the info file
// to update the .env file.
return $name_from_info;
}

return $name_from_env;
}

return NULL;
}

protected function findThemeFile(string $dir, string $webroot): ?string {
$locations = [
sprintf('%s/%s/themes/custom/*/*.info', $dir, $webroot),
sprintf('%s/%s/themes/custom/*/*.info.yml', $dir, $webroot),
sprintf('%s/%s/sites/all/themes/custom/*/*.info', $dir, $webroot),
sprintf('%s/%s/sites/all/themes/custom/*/*.info.yml', $dir, $webroot),
sprintf('%s/%s/profiles/*/themes/custom/*/*.info', $dir, $webroot),
sprintf('%s/%s/profiles/*/themes/custom/*/*.info.yml', $dir, $webroot),
sprintf('%s/%s/profiles/custom/*/themes/custom/*/*.info', $dir, $webroot),
sprintf('%s/%s/profiles/custom/*/themes/custom/*/*.info.yml', $dir, $webroot),
];

return File::findMatchingPath($locations);
}

protected function isVortexTheme(string $dir): bool {
$c1 = file_exists($dir . '/scss/_variables.scss');
$c2 = file_exists($dir . '/Gruntfile.js');
$c3 = file_exists($dir . '/package.json');
$c4 = File::fileContains('build-dev', $dir . '/package.json');

return $c1 && $c2 && $c3 && $c4;
}
}
23 changes: 23 additions & 0 deletions .vortex/installer/src/Discovery/WebrootDiscovery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace DrevOps\Installer\Discovery;

use DrevOps\Installer\Util;

class WebrootDiscovery extends AbstractDiscovery {

public function discover() {
$webroot = $this->getValueFromDstDotenv('WEBROOT');

if (empty($webroot) && $this->isInstalled()) {
// Try from composer.json.
$extra = Util::getComposerJsonValue('extra', $this->config->getDstDir() . DIRECTORY_SEPARATOR . 'composer.json');
if (!empty($extra)) {
$webroot = $extra['drupal-scaffold']['drupal-scaffold']['locations']['web-root'] ?? NULL;
}
}

return $webroot;
}

}
Loading

1 comment on commit 2f9472d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.