Skip to content

Commit

Permalink
feat: add composer-update
Browse files Browse the repository at this point in the history
  • Loading branch information
jevantang committed Nov 26, 2022
1 parent 02e62fc commit 48c619c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
31 changes: 31 additions & 0 deletions src/Commands/PluginComposerUpdateCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* Fresns (https://fresns.org)
* Copyright (C) 2021-Present Jarvis Tang
* Released under the Apache-2.0 License.
*/

namespace Fresns\PluginManager\Commands;

use Illuminate\Console\Command;
use Fresns\PluginManager\Support\Process;

class PluginComposerUpdateCommand extends Command
{
protected $signature = 'plugin:composer-update';

protected $description = 'Update all plugins composer package';

public function handle()
{
$process = Process::run('composer update', $this->output);
if (!$process->isSuccessful()) {
$this->error('Failed to install packages, calc composer.json hash value fail');

return Command::FAILURE;
}

return 0;
}
}
13 changes: 6 additions & 7 deletions src/Commands/PluginInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use Fresns\PluginManager\Plugin;
use Fresns\PluginManager\Support\Json;
use Fresns\PluginManager\Support\Process;
use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
Expand Down Expand Up @@ -45,14 +44,14 @@ public function handle()
if (! $unikey) {
info('Failed to unzip, couldn\'t get the plugin unikey');

return -1;
return Command::FAILURE;
}

$plugin = new Plugin($unikey);
if (! $plugin->isValidPlugin()) {
$this->error('plugin is invalid');

return -1;
return Command::FAILURE;
}

$plugin->manualAddNamespace();
Expand All @@ -68,11 +67,11 @@ public function handle()
// Triggers top-level computation of composer.json hash values and installation of extension packages
// @see https://getcomposer.org/doc/03-cli.md#process-exit-codes
if (count($require) || count($requireDev)) {
$process = Process::run('composer update', $this->output);
if (! $process->isSuccessful()) {
$this->error('Failed to install packages, calc composer.json hash value fail');
$exitCode = $this->call('plugin:composer-update');
if ($exitCode) {
$this->error("Failed to update plugin dependency");

return -1;
return Command::FAILURE;
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/Commands/PluginUninstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use Fresns\PluginManager\Plugin;
use Fresns\PluginManager\Support\Json;
use Fresns\PluginManager\Support\Process;
use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\File;
Expand Down Expand Up @@ -59,11 +58,11 @@ public function handle()

// Triggers top-level computation of composer.json hash values and installation of extension packages
if (count($require) || count($requireDev)) {
$process = Process::run('composer update', $this->output);
if (! $process->isSuccessful()) {
$this->error('Failed to uninstall packages, calc composer.json hash value fail');
$exitCode = $this->call('plugin:composer-update');
if ($exitCode) {
$this->error("Failed to update plugin dependency");

return -1;
return Command::FAILURE;
}
}

Expand Down

0 comments on commit 48c619c

Please sign in to comment.