Skip to content

Commit

Permalink
allow also to replace __DEPLOY_VERSION__ by build release
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepereiradasilva committed Jun 20, 2016
1 parent 9e596d1 commit c2407f9
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions build/bump.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function usage($command)
);

// Change copyright date exclusions.
$copyrightDateExcludeDirectories = array(
$directoryLoopExcludeDirectories = array(
'/libraries/vendor/',
'/libraries/phputf8/',
'/libraries/php-encryption/',
Expand All @@ -69,7 +69,7 @@ function usage($command)
'/libraries/fof/',
);

$copyrightDateExcludeFiles = array(
$directoryLoopExcludeFiles = array(
);

// Check arguments (exit if incorrect cli arguments).
Expand Down Expand Up @@ -259,10 +259,11 @@ function usage($command)
}

// Updates the copyright date in core files.
$changedFiles = 0;
$year = date('Y');
$directory = new \RecursiveDirectoryIterator($rootPath);
$iterator = new \RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
$changedFilesCopyrightDate = 0;
$changedFilesSinceVersion = 0;
$year = date('Y');
$directory = new \RecursiveDirectoryIterator($rootPath);
$iterator = new \RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);

foreach ($iterator as $file)
{
Expand All @@ -278,15 +279,15 @@ function usage($command)
}

// Exclude certain files.
if (in_array($relativePath, $copyrightDateExcludeFiles))
if (in_array($relativePath, $directoryLoopExcludeFiles))
{
continue;
}

// Exclude certain directories.
$continue = true;

foreach ($copyrightDateExcludeDirectories as $excludeDirectory)
foreach ($directoryLoopExcludeDirectories as $excludeDirectory)
{
if (preg_match('#^' . preg_quote($excludeDirectory) . '#', $relativePath))
{
Expand All @@ -297,21 +298,47 @@ function usage($command)

if ($continue)
{
$changeSinceVersion = false;
$changeCopyrightDate = false;

// Load the file.
$fileContents = file_get_contents($filePath);

// Check if need to change the copyright date.
if (preg_match('#2005\s+-\s+[0-9]{4}\s+Open\s+Source\s+Matters#', $fileContents) && !preg_match('#2005\s+-\s+' . $year. '\s+Open\s+Source\s+Matters#', $fileContents))
{
$changeCopyrightDate = true;
$fileContents = preg_replace('#2005\s+-\s+[0-9]{4}\s+Open\s+Source\s+Matters#', '2005 - ' . $year. ' Open Source Matters', $fileContents);
$changedFilesCopyrightDate++;
}

// Check if need to change the since version.
if ($relativePath !== '/build/bump.php' && preg_match('#__DEPLOY_VERSION__#', $fileContents))
{
$changeSinceVersion = true;
$fileContents = preg_replace('#__DEPLOY_VERSION__#', $version['release'], $fileContents);
$changedFilesSinceVersion++;
}

// Save the file.
if ($changeCopyrightDate || $changeSinceVersion)
{
file_put_contents($filePath, $fileContents);
$changedFiles++;
}
}
}
}

if ($changedFiles > 0)
if ($changedFilesCopyrightDate > 0 || $changedFilesSinceVersion > 0)
{
echo '- Copyright Date changed in ' . $changedFiles . ' files.' . PHP_EOL;
if ($changedFilesCopyrightDate > 0)
{
echo '- Copyright Date changed in ' . $changedFilesCopyrightDate . ' files.' . PHP_EOL;
}
if ($changedFilesSinceVersion > 0)
{
echo '- Since Version changed in ' . $changedFilesSinceVersion . ' files.' . PHP_EOL;
}
echo PHP_EOL;
}

Expand Down

0 comments on commit c2407f9

Please sign in to comment.