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

Added bump version task for replacing the DEPLOY_VERSION placeholder #31

Merged
merged 1 commit into from Jan 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions RoboFile.php
Expand Up @@ -76,4 +76,16 @@ public function headers()
{
(new \Joomla\Jorobo\Tasks\CopyrightHeader)->run();
}

/**
* Bump Version placeholder __DEPLOY_VERSION__ in this project. (Set the version up in the jorobo.ini)
*
* @return void
*
* @since 1.0.0
*/
public function bump()
{
(new \Joomla\Jorobo\Tasks\BumpVersion())->run();
}
}
104 changes: 104 additions & 0 deletions src/Tasks/BumpVersion.php
@@ -0,0 +1,104 @@
<?php
/**
* @package JoRobo
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Jorobo\Tasks;

use Robo\Result;
use Robo\Task\BaseTask;
use Robo\Contract\TaskInterface;
use Robo\Exception\TaskException;

/**
* Bump the version of an Joomla extension
*
* @package Joomla\Jorobo\Tasks\Component
*/
class BumpVersion extends JTask implements TaskInterface
{
use \Robo\Task\Development\loadTasks;
use \Robo\Common\TaskIO;

/**
* Constructor
*
* @since 1.0
*/
public function __construct()
{
parent::__construct();
}

/**
* Maps all parts of an extension into a Joomla! installation
*
* @return bool
*
* @since 1.0
*/
public function run()
{
$this->say('Updating ' . $this->getJConfig()->extension . " to " . $this->getJConfig()->version);

// Reusing the header config here
$exclude = explode(",", trim($this->getJConfig()->header->exclude));

$path = realpath($this->getJConfig()->source);
$fileTypes = explode(",", trim($this->getJConfig()->header->files));

$changedFiles = 0;

foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)) as $filename)
{
if (substr($filename, 0, 1) == '.')
{
continue;
}

$file = new \SplFileInfo($filename);

if (!in_array($file->getExtension(), $fileTypes))
{
continue;
}

// Skip directories in exclude list
if (isset($exclude) && count($exclude))
{
$relative = str_replace(realpath($path), "", $file->getPath());

// It is possible to have multiple exclude directories
foreach ($exclude as $e)
{
if (stripos($relative, $e) !== false)
{
$this->say("Excluding " . $filename);
continue 2;
}
}
}

// Load the file
$fileContents = file_get_contents($file->getRealPath());

if (preg_match('#__DEPLOY_VERSION__#', $fileContents))
{
$fileContents = preg_replace('#__DEPLOY_VERSION__#', $this->getJConfig()->version, $fileContents);

$this->say('Updating file: ' . $file->getRealPath());

file_put_contents($file->getRealPath(), $fileContents);

$changedFiles++;
}
}

$this->say('Updated ' . $changedFiles . ' files');

return true;
}
}
5 changes: 0 additions & 5 deletions src/Tasks/JTask.php
Expand Up @@ -69,11 +69,6 @@ public function __construct($params = array())
$this->loadConfiguration($params);
$this->determineOperatingSystem();
$this->determineSourceFolder();

// Registers the application to run Robo commands
$runner = new Runner;
$app = new Application('Joomla\Jorobo\Tasks\JTask', '1.0.0');
$runner->registerCommandClass($app, $this);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I sent a fix for this in #30 since it needs to be set before the configuration. I'll fix that PR to get it merged asap.

/**
Expand Down
12 changes: 12 additions & 0 deletions src/Tasks/loadTasks.php
Expand Up @@ -65,4 +65,16 @@ protected function taskCopyrightHeaders($params)
{
return new CopyrightHeader($params);
}

/**
* Bump the __DEPLOY_VERSION__ task
*
* @return BumpVersion
*
* @since 1.0
*/
protected function taskBumbVersion()
{
return new BumpVersion();
}
}