-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
90e142e
commit 2f9472d
Showing
19 changed files
with
419 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
.vortex/installer/src/Discovery/DatabaseDownloadSourceDiscovery.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
.vortex/installer/src/Discovery/DatabaseImageDiscovery.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
.vortex/installer/src/Discovery/DatabaseStoreTypeDiscovery.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
.vortex/installer/src/Discovery/OrgMachineNameDiscovery.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
.vortex/installer/src/Discovery/ProvisionUseProfileDiscovery.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
Oops, something went wrong.
2f9472d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Deployed on https://67ae7998a228422d05caabd4--vortex-docs.netlify.app