Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Add CLI command to check if there's some version to be built #5

Merged
merged 1 commit into from
Jan 10, 2018
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
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,10 @@
"name": "Michael Krasnow",
"email": "mnkras@gmail.com"
}
]
],
"scripts": {
"new-versions-available": [
"Concrete5\\Api\\Composer\\Script\\NewVersionsAvailable::run"
]
}
}
46 changes: 46 additions & 0 deletions src/Composer/Script/NewVersionsAvailable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Concrete5\Api\Composer\Script;

use Composer\Script\Event;
use RuntimeException;

class NewVersionsAvailable
{
/**
* @param Event $event
*
* @throws RuntimeException
*
* @return int
*/
public static function run(Event $event): int
{
$missingVersions = static::getMissingVersions();
if (count($missingVersions) === 0) {
throw new RuntimeException('No version need to be built.');
}
$event->getIO()->write('# Missing versions');
foreach ($missingVersions as $missingVersion) {
$event->getIO()->write($missingVersion);
}
return 0;
}

/**
* @return string[]
*/
protected static function getMissingVersions(): array
{
$result = [];
$config = require dirname(__DIR__, 3) . '/sami_config.php';
$buildDir = $config['build_dir'];
$project = $config['project'];
foreach ($project->getVersions() as $version) {
if (!is_dir(str_replace('%version%', $version->getName(), $buildDir))) {
$result[] = $version->getName();
}
}
return $result;
}
}