Skip to content

Commit

Permalink
Merge pull request #43 from craftcms/feature/pt-1716-update-the-exten…
Browse files Browse the repository at this point in the history
…sion-to-have-build-command

Feature/pt 1716 update the extension to have build command
  • Loading branch information
timkelty authored May 30, 2024
2 parents bdb7390 + 2ae8e54 commit 8d1a90d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cli/controllers/AssetBundlesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function init(): void

public function beforeAction($action): bool
{
// Don't allow if ephemeral, as the publish command won't create any files
if (App::isEphemeral()) {
throw new Exception('Asset bundle publishing is not supported in ephemeral environments.');
}
Expand Down
37 changes: 37 additions & 0 deletions src/cli/controllers/BuildController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace craft\cloud\cli\controllers;

use Craft;
use craft\console\Controller;
use Illuminate\Support\Collection;
use samdark\log\PsrMessage;
use yii\console\ExitCode;

class BuildController extends Controller
{
public function actionIndex(string $json): int
{
$options = json_decode($json, true);
$exitCode = ExitCode::OK;

Collection::make([
'cloud/validate/project-type',
'cloud/asset-bundles/publish',
])->each(function(string $command) use ($options, &$exitCode) {
$params = $options[$command] ?? [];
$exitCode = $this->run("/$command", $params);

if ($exitCode !== ExitCode::OK) {
Craft::error(new PsrMessage('Command failed.', [
'command' => $command,
'params' => $params,
]));

return false;
}
});

return $exitCode;
}
}

0 comments on commit 8d1a90d

Please sign in to comment.