Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composer 2 support #51

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ RUN mkdir /composer

WORKDIR /composer

RUN composer global require --prefer-dist hirak/prestissimo --no-interaction
RUN composer require --prefer-dist laravel/envoy offline/oc-bootstrapper --no-interaction

RUN ln -s /composer/vendor/bin/october /usr/bin/october
Expand Down
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.9.1');
define('VERSION', '1.0.0');

if (file_exists(__DIR__.'/../../autoload.php')) {
require __DIR__.'/../../autoload.php';
Expand Down
11 changes: 6 additions & 5 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->gitignore = new Gitignore($this->getGitignore());

$this->write('Downloading latest October CMS...');
$this->write('Installing latest October CMS...');
try {
(new OctoberCms())->download($this->force);
(new OctoberCms($this->composer))->install($this->force);
} catch (\LogicException $e) {
$this->write($e->getMessage(), 'comment');
} catch (Throwable $e) {
Expand All @@ -195,9 +195,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->write('Patching composer.json...');
$this->patchComposerJson();

$this->write('Installing composer dependencies...');
$this->composer->install();

$this->write('Setting up config files...');
$this->writeConfig($this->force);

Expand Down Expand Up @@ -243,6 +240,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->installPlugins($pluginsDeclarations);
}

// Plugins may have composer dependencies, so install them now...
$this->write('Installing composer dependencies...');
$this->composer->install();

$deployment = false;
try {
$deployment = $this->config->git['deployment'];
Expand Down
111 changes: 21 additions & 90 deletions src/Downloader/OctoberCms.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,134 +2,75 @@

namespace OFFLINE\Bootstrapper\October\Downloader;


use GuzzleHttp\Client;
use OFFLINE\Bootstrapper\October\Util\Composer;
use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\Exception\RuntimeException;
use Symfony\Component\Process\Process;
use ZipArchive;

class OctoberCms
{
protected $zipFile;
/**
* @var Composer
*/
protected $composer;

/**
* Downloads and extracts October CMS.
* Downloads and installs October CMS.
*
*/
public function __construct()
public function __construct(Composer $composer)
{
$this->zipFile = $this->makeFilename();
$this->composer = $composer;
}

/**
* Download latest October CMS.
* Install latest October CMS.
*
* @param bool $force
*
* @return $this
* @throws RuntimeException
* @throws LogicException
*/
public function download($force = false)
public function install($force = false)
{
if ($this->alreadyInstalled($force)) {
throw new \LogicException('-> October is already installed. Use --force to reinstall.');
}

$this->fetchZip()
->extract()
->fetchHtaccess()
->cleanUp()
->setMaster();

return $this;
}

/**
* Download the temporary Zip to the given file.
*
* @return $this
* @throws RuntimeException
* @throws LogicException
*/
protected function fetchZip()
{
$response = (new Client)->get('https://github.com/octobercms/october/archive/1.0.zip');
file_put_contents($this->zipFile, $response->getBody());

return $this;
}

/**
* Extract the zip file into the given directory.
*
* @return $this
*/
protected function extract()
{
$archive = new ZipArchive;
$archive->open($this->zipFile);
$archive->extractTo(getcwd());
$archive->close();

return $this;
}

/**
* Download the latest .htaccess file from GitHub separately
* since ZipArchive does not support extracting hidden files.
*
* @return $this
*/
protected function fetchHtaccess()
{
$contents = file_get_contents('https://raw.githubusercontent.com/octobercms/october/1.0/.htaccess');
file_put_contents(getcwd() . DS . '.htaccess', $contents);
$this->createProject()
->cleanUp();

return $this;
}


/**
* Since we don't want any unstable updates we fix
* the libraries to the master branch.
*
* Create a new October CMS project using composer
*
* @return $this
*/
protected function setMaster()
protected function createProject()
{
$json = getcwd() . DS . 'composer.json';

$contents = file_get_contents($json);

$contents = preg_replace_callback(
'/october\/(?:rain|system|backend|cms)":\s"([^"]+)"/m',
function ($treffer) {
return str_replace($treffer[1], '~1.0', $treffer[0]);
},
$contents
$this->composer->createProject(
'october/october',
'october-1.1',
'1.1.*'
);

file_put_contents($json, $contents);

return $this;
}

/**
* Remove the Zip file, move folder contents one level up.
* Move folder contents one level up, remove temporary folder
*
* @return $this
* @throws RuntimeException
* @throws LogicException
*/
protected function cleanUp()
{
@chmod($this->zipFile, 0777);
@unlink($this->zipFile);

$directory = getcwd();
$source = $directory . DS . 'october-1.0';
$source = $directory . DS . 'october-1.1';

(new Process(sprintf('mv %s %s', $source . '/*', $directory)))->run();
(new Process(sprintf('rm -rf %s', $source)))->run();
Expand All @@ -141,16 +82,6 @@ protected function cleanUp()
return $this;
}

/**
* Generate a random temporary filename.
*
* @return string
*/
protected function makeFilename()
{
return getcwd() . DS . 'october_' . md5(time() . uniqid('oc-', true)) . '.zip';
}

/**
* @param $force
*
Expand Down
21 changes: 21 additions & 0 deletions src/Util/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,25 @@ public function requireVersion($package, $version)
3600
);
}

/**
* Composer create-project <project> <path> <version>
*
* @return void
* @throws LogicException
* @throws RuntimeException
* @throws InvalidArgumentException
*/
public function createProject($project, $path, $version)
{
$project = escapeshellarg($project);
$path = escapeshellarg($path);
$version = escapeshellarg($version);

$this->runProcess(
$this->composer . ' create-project ' . $project . ' ' . $path . ' ' . $version . ' --no-interaction',
'Failed to create the composer project',
3600
);
}
}