Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-kuendig committed Jul 29, 2020
2 parents 5f30b5a + 5a3ea80 commit fadc19e
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 24 deletions.
2 changes: 1 addition & 1 deletion october
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env php
<?php
define('DS', DIRECTORY_SEPARATOR);
define('VERSION', '0.8.0');
define('VERSION', '0.8.6');

if (file_exists(__DIR__.'/../../autoload.php')) {
require __DIR__.'/../../autoload.php';
Expand Down
8 changes: 4 additions & 4 deletions src/Config/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ public function env($createBackup = true, $restoreBackup = false)
'',
'MAIL_DRIVER' => $this->config->mail['driver'],
'MAIL_HOST' => '"' . $this->config->mail['host'] . '"',
'MAIL_PORT' => '587',
'MAIL_ENCRYPTION' => 'tls',
'MAIL_USERNAME' => null,
'MAIL_PASSWORD' => null,
'MAIL_PORT' => $this->config->mail['port'] ?? 587,
'MAIL_ENCRYPTION' => $this->config->mail['encryption'] ?? 'tls',
'MAIL_USERNAME' => $this->config->mail['username'] ?? null,
'MAIL_PASSWORD' => $this->config->mail['password'] ?? null,
'MAIL_NAME' => '"' . $this->config->mail['name'] . '"',
'MAIL_ADDRESS' => $this->config->mail['address'],
'',
Expand Down
10 changes: 5 additions & 5 deletions src/Console/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ private function setLandoConfig(string $targetOctoberYaml, string $project)
}, $contents);

$contents = preg_replace_callback('/^mail:\n(?:^[ ].*\n?)*$/m', function () use ($project) {
$mail = <<<EOF
return <<<EOF
mail:
host: mail.%s.lndo.site
host: mailhog
name: Sender Name
address: [email protected]
driver: sendmail
driver: smtp
port: 1025
encryption: ''
EOF;

return sprintf($mail, $project);
}, $contents);

file_put_contents($targetOctoberYaml, $contents);
Expand Down
44 changes: 38 additions & 6 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
use LogicException;
use OFFLINE\Bootstrapper\October\Config\Setup;
use OFFLINE\Bootstrapper\October\Deployment\DeploymentFactory;
use OFFLINE\Bootstrapper\October\DevEnvironment\DevEnvFactory;
use OFFLINE\Bootstrapper\October\Downloader\OctoberCms;
use OFFLINE\Bootstrapper\October\Exceptions\DeploymentExistsException;
use OFFLINE\Bootstrapper\October\Exceptions\DevEnvExistsException;
use OFFLINE\Bootstrapper\October\Exceptions\ThemeExistsException;
use OFFLINE\Bootstrapper\October\Manager\PluginManager;
use OFFLINE\Bootstrapper\October\Manager\ThemeManager;
Expand Down Expand Up @@ -80,9 +78,9 @@ class InstallCommand extends Command
public function __construct($name = null)
{
$this->pluginManager = new PluginManager();
$this->themeManager = new ThemeManager();
$this->artisan = new Artisan();
$this->composer = new Composer();
$this->themeManager = new ThemeManager();
$this->artisan = new Artisan();
$this->composer = new Composer();

$this->setPhp();

Expand Down Expand Up @@ -135,6 +133,13 @@ protected function configure()
InputOption::VALUE_OPTIONAL,
'Specify the path to a custom PHP binary',
'php'
)
->addOption(
'templates-from',
null,
InputOption::VALUE_OPTIONAL,
'Specify from where to fetch template files (git remote)',
''
);
}

Expand Down Expand Up @@ -163,6 +168,11 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->firstRun = ! $this->dirExists($this->path('bootstrap')) || $this->force;

if ($input->getOption('templates-from')) {
$remote = $input->getOption('templates-from');
$this->fetchTemplateFiles($remote);
}

$this->makeConfig();

if ( ! empty($php = $input->getOption('php'))) {
Expand Down Expand Up @@ -261,6 +271,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->write('Removing demo data...');
$this->artisan->call('october:fresh');

// Make sure the demo data is gone! (october:fresh is unreliable)
$this->rrmdir('themes/demo');
$this->rrmdir('plugins/demo');

$this->write('Creating README...');
$this->copyReadme();

Expand Down Expand Up @@ -288,7 +302,7 @@ public function installPlugins($pluginsDeclarations)
{
foreach ($pluginsDeclarations as $pluginDeclaration) {
$pluginInstalled = $this->pluginManager->isInstalled($pluginDeclaration);
$installPlugin = ! $pluginInstalled;
$installPlugin = ! $pluginInstalled;

list($update, $vendor, $plugin, $remote, $branch) = $this->pluginManager->parseDeclaration($pluginDeclaration);

Expand Down Expand Up @@ -437,4 +451,22 @@ protected function patchComposerJson()
$this->write('Failed to write new composer.json', 'error');
}
}

private function rrmdir(string $dir)
{
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object !== "." && $object !== "..") {
if (filetype($dir . "/" . $object) === "dir") {
$this->rrmdir($dir . "/" . $object);
} else {
unlink($dir . "/" . $object);
}
}
}
reset($objects);
rmdir($dir);
}
}
}
11 changes: 11 additions & 0 deletions src/Deployment/DeploymentBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace OFFLINE\Bootstrapper\October\Deployment;

use OFFLINE\Bootstrapper\October\Config\Yaml;
use OFFLINE\Bootstrapper\October\Util\ManageDirectory;
use OFFLINE\Bootstrapper\October\Util\UsesTemplate;

Expand All @@ -11,4 +12,14 @@
abstract class DeploymentBase
{
use UsesTemplate, ManageDirectory;

/**
* @var Yaml
*/
protected $config;

public function __construct(Yaml $config)
{
$this->config = $config;
}
}
5 changes: 2 additions & 3 deletions src/Deployment/Gitlab.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace OFFLINE\Bootstrapper\October\Deployment;

use OFFLINE\Bootstrapper\October\DevEnvironment\DevEnvBase;
use OFFLINE\Bootstrapper\October\Exceptions\DeploymentExistsException;

/**
* GitLab deployment
*/
class Gitlab extends DevEnvBase implements DeploymentInterface
class Gitlab extends DeploymentBase implements DeploymentInterface
{
/**
* @inheritDoc
Expand All @@ -22,7 +21,7 @@ public function install($force = false)
$this->copy($this->getTemplate('gitlab-ci.yml'), '.gitlab-ci.yml');
$this->copy($this->getTemplate('Envoy.blade.php'), 'Envoy.blade.php');

$this->replaceVars('gitlab-ci.yml', $this->config->toArray());
$this->replaceVars('.gitlab-ci.yml', $this->config->toArray());
$this->replaceVars('Envoy.blade.php', $this->config->toArray());
}
}
14 changes: 14 additions & 0 deletions src/Util/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ public function addDependency($package)
);
}

/**
* Returns Composer's home directory.
*
*/
public function getHome()
{
$result = $this->runProcessWithOutput(
$this->composer . ' config --global data-dir',
'Failed to get composer data-dir',
3600
);
return trim($result);
}

/**
* Composer require <package> <version>
*
Expand Down
12 changes: 11 additions & 1 deletion src/Util/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
class Git
{
public static function repo($path)
{
return Repository::open($path, self::getBinary());
}

public static function clone(string $url, string $to)
{
Repository::createFromRemote($url, $to, self::getBinary());
}

protected static function getBinary()
{
$binary = null;
if (stripos(PHP_OS, 'WIN') === 0) {
Expand All @@ -19,6 +29,6 @@ public static function repo($path)
$binary = 'git';
}

return Repository::open($path, $binary);
return $binary;
}
}
14 changes: 14 additions & 0 deletions src/Util/RunsProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,26 @@ protected function runProcess($command, $errorMessage, $timeout = 30)
return $this->checkProcessResult($exitCode, $errorMessage, $process->getOutput());
}

protected function runProcessWithOutput($command, $errorMessage, $timeout = 30)
{
$process = new Process($command);
$process->setTimeout($timeout);
$process->enableOutput();
$exitCode = $process->run();

$this->checkProcessResult($exitCode, $errorMessage, $process->getOutput());

return $process->getOutput();
}

/**
* Checks the result of a process.
*
* @param $exitCode
* @param $message
*
* @param $output
*
* @return bool
*/
protected function checkProcessResult($exitCode, $message, $output)
Expand Down
22 changes: 21 additions & 1 deletion src/Util/UsesTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ public function updateTemplateFiles()
}
}

public function fetchTemplateFiles(string $remote)
{
$overridePath = $this->getTemplateOverridePath();
if ( is_dir($overridePath . DS . '.git')) {
return $this->updateTemplateFiles();
}

if ( ! mkdir($overridePath) && ! is_dir($overridePath)) {
throw new \RuntimeException(sprintf('Failed to create template directory "%s"', $overridePath));
}

try {
Git::clone($remote, $overridePath);
} catch (\Throwable $e) {
throw new RuntimeException('Error while fetching template files: ' . $e->getMessage());
}
}

/**
* Return the path to the local composer .config path where
* the template files are stored.
Expand All @@ -48,6 +66,8 @@ public function updateTemplateFiles()
*/
protected function getTemplateOverridePath($file = null)
{
return __DIR__ . DS . implode(DS, ['..', '..', '..', '..', '..', 'october', $file]);
$composerHome = (new Composer())->getHome();

return implode(DS, [$composerHome, 'october', $file]);
}
}
5 changes: 2 additions & 3 deletions templates/lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ config:
services:
appserver:
composer:
offline/oc-bootstrapper: ^0.7.5
offline/oc-bootstrapper: ^0.8.0
overrides:
depends_on: [database]
build:
- october install
-
- october install # --templates-from=git@yourhost:october-cms/oc-bootstrapper-templates.git
mailhog:
type: mailhog
portforward: true
Expand Down

0 comments on commit fadc19e

Please sign in to comment.