mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-20 02:11:36 +00:00
* Add node support using nvm * Add icon * Rename to NodeJS * Rename to NodeJS * update php and node logo * only services which have units can be started,restarted,stopped,disabled and enabled * add tests --------- Co-authored-by: Saeed Vaziry <mr.saeedvaziry@gmail.com> Co-authored-by: Saeed Vaziry <61919774+saeedvaziry@users.noreply.github.com>
46 lines
1.2 KiB
PHP
Executable File
46 lines
1.2 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Actions\NodeJS;
|
|
|
|
use App\Enums\NodeJS;
|
|
use App\Enums\ServiceStatus;
|
|
use App\Models\Server;
|
|
use App\Models\Service;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class InstallNewNodeJsVersion
|
|
{
|
|
public function install(Server $server, array $input): void
|
|
{
|
|
$nodejs = new Service([
|
|
'server_id' => $server->id,
|
|
'type' => 'nodejs',
|
|
'type_data' => [],
|
|
'name' => 'nodejs',
|
|
'version' => $input['version'],
|
|
'status' => ServiceStatus::INSTALLING,
|
|
'is_default' => false,
|
|
]);
|
|
$nodejs->save();
|
|
|
|
dispatch(function () use ($nodejs) {
|
|
$nodejs->handler()->install();
|
|
$nodejs->status = ServiceStatus::READY;
|
|
$nodejs->save();
|
|
})->catch(function () use ($nodejs) {
|
|
$nodejs->delete();
|
|
})->onConnection('ssh');
|
|
}
|
|
|
|
public static function rules(Server $server): array
|
|
{
|
|
return [
|
|
'version' => [
|
|
'required',
|
|
Rule::in(config('core.nodejs_versions')),
|
|
Rule::notIn(array_merge($server->installedNodejsVersions(), [NodeJS::NONE])),
|
|
],
|
|
];
|
|
}
|
|
}
|