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

Commit

Permalink
Merge pull request #12 from Muetze42/development
Browse files Browse the repository at this point in the history
feat: add addDependency method
  • Loading branch information
Muetze42 authored Oct 17, 2023
2 parents c83e1c8 + cce8664 commit a58cab7
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"illuminate/events": "^9.0|^10.0",
"illuminate/filesystem": "^9.43|^10.0",
"league/flysystem": "^3.11",
"norman-huth/helpers-collection-php": "^1.0"
"norman-huth/helpers-collection-php": "^1.3"
},
"bin": [
"bin/lura"
Expand Down
66 changes: 66 additions & 0 deletions src/LuraInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace NormanHuth\ConsoleApp;

use NormanHuth\Helpers\Str;

abstract class LuraInstaller
{
/**
Expand All @@ -10,4 +12,68 @@ abstract class LuraInstaller
* @param mixed|\NormanHuth\ConsoleApp\LuraCommand $command
*/
abstract public function runLura(mixed $command);

/**
* Collected dependencies version from https://github.com/Muetze42/data.
*
* @var array{composer: array<array-key, string>, npm: array<array-key, string>}|null
*/
protected static ?array $dependenciesVersions = null;

/**
* Add a dependencies to json.
*
* @param array $dependencies
* @param string $package
* @param string $version
* @param bool $updateVersion
*
* @return void
*/
protected static function addDependency(
array &$dependencies,
string $package,
string $version,
bool $updateVersion = true
): void {
if ($updateVersion) {
$versions = static::getDependenciesVersions();

$version = data_get(
$versions,
'composer.' . $package,
data_get(
$versions,
'npm.' . $package,
$version
)
);
}

$dependencies = array_merge($dependencies, [$package => $version]);
ksort($dependencies, SORT_NATURAL | SORT_FLAG_CASE);
}

/**
* @return array
*/
protected static function getDependenciesVersions(): array
{
if (is_null(static::$dependenciesVersions)) {
if (
$contents = file_get_contents(
'https://raw.githubusercontent.com/Muetze42/data/main/storage/versions.json'
)
) {
if (Str::isJson($contents)) {
static::$dependenciesVersions = json_decode($contents, true);
}
}
}
if (is_null(static::$dependenciesVersions)) {
static::$dependenciesVersions = [];
}

return static::$dependenciesVersions;
}
}

0 comments on commit a58cab7

Please sign in to comment.