Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .no-header.php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
__DIR__ . '/app',
__DIR__ . '/public',
])
->notName('#Logger\.php$#');
->notName('#Logger\.php$#')
->append([
__DIR__ . '/admin/starter/builds',
]);

$overrides = [
// @TODO Remove once these are live in coding-standard
Expand Down
224 changes: 93 additions & 131 deletions admin/starter/builds
Original file line number Diff line number Diff line change
Expand Up @@ -15,149 +15,111 @@ define('GITHUB_URL', 'https://github.com/codeigniter4/codeigniter4');
*/

// Determine the requested stability
if (empty($argv[1]) || ! in_array($argv[1], ['release', 'development']))
{
echo 'Usage: php builds [release|development]' . PHP_EOL;
exit;
if (empty($argv[1]) || ! in_array($argv[1], ['release', 'development'], true)) {
echo 'Usage: php builds [release|development]' . PHP_EOL;

exit;
}

$dev = $argv[1] == 'development';
$dev = $argv[1] === 'development';

$modified = [];

/* Locate each file and update it for the requested stability */
// Locate each file and update it for the requested stability

// Composer.json
$file = __DIR__ . DIRECTORY_SEPARATOR . 'composer.json';

if (is_file($file))
{
// Make sure we can read it
if ($contents = file_get_contents($file))
{
if ($array = json_decode($contents, true))
{
// Development
if ($dev)
{
// Set 'minimum-stability'
$array['minimum-stability'] = 'dev';
$array['prefer-stable'] = true;

// Make sure the repo is configured
if (! isset($array['repositories']))
{
$array['repositories'] = [];
}

// Check for the CodeIgniter repo
$found = false;
foreach ($array['repositories'] as $repository)
{
if ($repository['url'] == GITHUB_URL)
{
$found = true;
break;
}
}

// Add the repo if it was not found
if (! $found)
{
$array['repositories'][] = [
'type' => 'vcs',
'url' => GITHUB_URL,
];
}

// Define the "require"
$array['require']['codeigniter4/codeigniter4'] = 'dev-develop';
unset($array['require']['codeigniter4/framework']);
}

// Release
else
{
// Clear 'minimum-stability'
unset($array['minimum-stability']);

// If the repo is configured then clear it
if (isset($array['repositories']))
{
// Check for the CodeIgniter repo
foreach ($array['repositories'] as $i => $repository)
{
if ($repository['url'] == GITHUB_URL)
{
unset($array['repositories'][$i]);
break;
}
}
if (empty($array['repositories']))
{
unset($array['repositories']);
}
}

// Define the "require"
$array['require']['codeigniter4/framework'] = LATEST_RELEASE;
unset($array['require']['codeigniter4/codeigniter4']);
}

// Write out a new composer.json
file_put_contents($file, json_encode($array, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES) . PHP_EOL);
$modified[] = $file;
}
else
{
echo 'Warning: Unable to decode composer.json! Skipping...' . PHP_EOL;
}
}
else
{
echo 'Warning: Unable to read composer.json! Skipping...' . PHP_EOL;
}
if (is_file($file)) {
$contents = file_get_contents($file);

if ((string) $contents !== '') {
$array = json_decode($contents, true);

if (is_array($array)) {
if ($dev) {
$array['minimum-stability'] = 'dev';
$array['prefer-stable'] = true;
$array['repositories'] = $array['repositories'] ?? [];

$found = false;

foreach ($array['repositories'] as $repository) {
if ($repository['url'] === GITHUB_URL) {
$found = true;
break;
}
}

if (! $found) {
$array['repositories'][] = [
'type' => 'vcs',
'url' => GITHUB_URL,
];
}

$array['require']['codeigniter4/codeigniter4'] = 'dev-develop';
unset($array['require']['codeigniter4/framework']);
} else {
unset($array['minimum-stability']);

if (isset($array['repositories'])) {
foreach ($array['repositories'] as $i => $repository) {
if ($repository['url'] === GITHUB_URL) {
unset($array['repositories'][$i]);
break;
}
}

if (empty($array['repositories'])) {
unset($array['repositories']);
}
}

$array['require']['codeigniter4/framework'] = LATEST_RELEASE;
unset($array['require']['codeigniter4/codeigniter4']);
}

file_put_contents($file, json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL);

$modified[] = $file;
} else {
echo 'Warning: Unable to decode composer.json! Skipping...' . PHP_EOL;
}
} else {
echo 'Warning: Unable to read composer.json! Skipping...' . PHP_EOL;
}
}

// Paths config and PHPUnit XMLs
$files = [
__DIR__ . DIRECTORY_SEPARATOR . 'app/Config/Paths.php',
__DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml.dist',
__DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml',
__DIR__ . DIRECTORY_SEPARATOR . 'app/Config/Paths.php',
__DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml.dist',
__DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml',
];

foreach ($files as $file)
{
if (is_file($file))
{
$contents = file_get_contents($file);

// Development
if ($dev)
{
$contents = str_replace('vendor/codeigniter4/framework', 'vendor/codeigniter4/codeigniter4', $contents);
}

// Release
else
{
$contents = str_replace('vendor/codeigniter4/codeigniter4', 'vendor/codeigniter4/framework', $contents);
}

file_put_contents($file, $contents);
$modified[] = $file;
}
}
foreach ($files as $file) {
if (is_file($file)) {
$contents = file_get_contents($file);

if ($dev) {
$contents = str_replace('vendor/codeigniter4/framework', 'vendor/codeigniter4/codeigniter4', $contents);
} else {
$contents = str_replace('vendor/codeigniter4/codeigniter4', 'vendor/codeigniter4/framework', $contents);
}

if (empty($modified))
{
echo 'No files modified' . PHP_EOL;
file_put_contents($file, $contents);

$modified[] = $file;
}
}
else
{
echo 'The following files were modified:' . PHP_EOL;
foreach ($modified as $file)
{
echo " * {$file}" . PHP_EOL;
}
echo 'Run `composer update` to sync changes with your vendor folder' . PHP_EOL;

if ($modified === []) {
echo 'No files modified.' . PHP_EOL;
} else {
echo 'The following files were modified:' . PHP_EOL;

foreach ($modified as $file) {
echo " * {$file}" . PHP_EOL;
}

echo 'Run `composer update` to sync changes with your vendor folder.' . PHP_EOL;
}