Skip to content

Commit

Permalink
Added tree command and changed README
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianFun123 committed Dec 10, 2022
1 parent 7aecf24 commit 8e7b228
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 12 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ php uppm.phar help
```
## Globally
```shell
wget -O uppm https://raw.githubusercontent.com/interaapps/uppm/master/target/uppm.phar
curl -o uppm https://raw.githubusercontent.com/interaapps/uppm/master/target/uppm.phar
# Installing it on linux globally
sudo mv uppm /usr/local/bin/uppm
sudo chmod +x /usr/local/bin/uppm
Expand All @@ -56,6 +56,9 @@ uppm help
# Installing dependencies
sudo apt install php8.1 php8.1-zip php8.1-json php8.1-phar

# Getting the php.ini location
php --ini

# Adding phar rule to php.ini (For building projects)
sudo echo phar.readonly = Off >> /etc/php/8.1/cli/php.ini
```
Expand Down
2 changes: 2 additions & 0 deletions src/main/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

ini_set('phar.readonly', 0);

chdir(".");
(include 'autoload.php')(mod: "main"); // Using the autoloader with the module main
array_shift($argv); // Removing useless first argument
Expand Down
9 changes: 7 additions & 2 deletions src/main/de/interaapps/uppm/UPPM.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
use de\interaapps\uppm\commands\InitCommand;
use de\interaapps\uppm\commands\InstallCommand;
use de\interaapps\uppm\commands\LockCommand;
use de\interaapps\uppm\commands\PackageTreeCommand;
use de\interaapps\uppm\commands\ProjectInfoCommand;
use de\interaapps\uppm\commands\RemoveCommand;
use de\interaapps\uppm\commands\ReplCommand;
use de\interaapps\uppm\commands\RunCommand;
use de\interaapps\uppm\commands\ServeCommand;
Expand Down Expand Up @@ -45,6 +47,8 @@ public function __construct(private array $args, string|null $dir = null) {
"init" => new InitCommand($this),
"lock" => new LockCommand($this),
"repl" => new ReplCommand($this),
"tree" => new PackageTreeCommand($this),
"remove" => new RemoveCommand($this),

"ghc" => new GHCCommand($this)
];
Expand All @@ -56,15 +60,16 @@ public function __construct(private array $args, string|null $dir = null) {

$this->commands["i"] = $this->commands["install"];
$this->commands["r"] = $this->commands["run"];
$this->commands["rm"] = $this->commands["remove"];

$config = new Configuration();
$lockFile = new LockFile();
if (file_exists($this->currentDir . "/uppm.json")) {
$config = Configuration::fromJson(file_get_contents("$this->currentDir/uppm.json"));
$config = Configuration::fromFile("$this->currentDir/uppm.json");
}
$config->repositories[] = "https://central.uppm.interaapps.de";
if (file_exists($this->currentDir . "/uppm.locks.json")) {
$lockFile = LockFile::fromJson(file_get_contents("$this->currentDir/uppm.locks.json"));
$lockFile = LockFile::fromFile("$this->currentDir/uppm.locks.json");
}
$this->currentProject = new Project(getcwd(), $config, $lockFile);
}
Expand Down
25 changes: 25 additions & 0 deletions src/main/de/interaapps/uppm/commands/PackageTreeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace de\interaapps\uppm\commands;

use de\interaapps\ulole\core\cli\Colors;
use de\interaapps\uppm\config\Configuration;

class PackageTreeCommand extends Command {
public function execute(array $args) {
$this->printOut($this->uppm->getCurrentProject()->getConfig());
}

private function printOut(Configuration $config, $indent = '', $prefix = '📁') {
$this->uppm->getLogger()->log("{$indent}{$prefix} §h{$config->name} §g{$config->version}§f");

$i = 0;
foreach ($config->modules as $module => $version) {
$i++;
$modConfig = Configuration::fromFile($this->uppm->getCurrentDir() . "/modules/$module/uppm.json");

if ($modConfig != null) {
$this->printOut($modConfig, "$indent ", '📦');
}
}
}
}
19 changes: 19 additions & 0 deletions src/main/de/interaapps/uppm/commands/RemoveCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace de\interaapps\uppm\commands;

class RemoveCommand extends Command {
public function execute(array $args) {
$this->uppm->getLogger()->loadingBar(0, "Removing package...");
$project = $this->uppm->getCurrentProject();


if (count($args) > 0) {
foreach ($args as $arg) {
$split = explode(":", $arg);

unset($project->getConfig()->modules->{$split[0]});
$project->getConfig()->save($this->uppm);
}
}
}
}
14 changes: 10 additions & 4 deletions src/main/de/interaapps/uppm/config/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct() {
$this->initScripts = [];
}

public function save($uppm): void {
public function save(UPPM $uppm): void {
if (($key = array_search("https://central.uppm.interaapps.de", $this->repositories)) !== false)
unset($this->repositories[$key]);
file_put_contents($uppm->getCurrentDir() . "/uppm.json", $this->toJson());
Expand Down Expand Up @@ -77,7 +77,7 @@ public function lock(UPPM $uppm, LockFile $lockFile, $folderPrefix = ""): void {
}

if (isset($this->initScripts))
$lockFile->initScripts = array_unique(array_merge((array)$lockFile->initScripts, (array)$this->initScripts));
$lockFile->initScripts = array_unique(array_merge((array) $lockFile->initScripts, (array)$this->initScripts));

if (isset($this->directNamespaceBindings))
$lockFile->directNamespaceBindings = (object)array_merge((array)$lockFile->directNamespaceBindings, (array)$this->directNamespaceBindings);
Expand All @@ -87,9 +87,15 @@ public function lock(UPPM $uppm, LockFile $lockFile, $folderPrefix = ""): void {
$lockFile->directNamespaceBindings = (object)array_merge((array)$lockFile->directNamespaceBindings, (array)$this->directnamespaces);

if (isset($this->namespaceBindings))
$lockFile->namespaceBindings = (object)array_merge((array)$lockFile->namespaceBindings, (array)$this->namespaceBindings);
$lockFile->namespaceBindings = (object) array_merge((array) $lockFile->namespaceBindings, (array)$this->namespaceBindings);

$lockFile->modules = (object)array_merge((array)$lockFile->modules, [$this->name => $this->version]);
$lockFile->modules = (object)array_merge((array) $lockFile->modules, [$this->name => $this->version]);
$lockFile->save($uppm);
}

public static function fromFile(string $name): Configuration|null {
if (!file_exists($name))
return null;
return self::fromJson(file_get_contents($name));
}
}
6 changes: 6 additions & 0 deletions src/main/de/interaapps/uppm/config/LockFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,10 @@ private function addRec(UPPM $uppm, $dir, $key, &$lockNameSpaces): void {
}
}
}

public static function fromFile(string $name): LockFile|null {
if (!file_exists($name))
return null;
return self::fromJson(file_get_contents($name));
}
}
1 change: 0 additions & 1 deletion src/main/de/interaapps/uppm/package/UPPMPackage.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace de\interaapps\uppm\package;

use de\interaapps\uppm\helper\Web;
Expand Down
Binary file modified target/uppm.phar
100755 → 100644
Binary file not shown.
Binary file modified target/uppm.phar.gz
Binary file not shown.
3 changes: 2 additions & 1 deletion uppm.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
},
"serve": {},
"modules": {
"interaapps\/jsonplus": "1.0.6"
"interaapps\/jsonplus": "1.0.6",
"uloleorm": "3.2.2"
},
"namespaceBindings": {
"de\\interaapps\\uppm": "src\/main\/de\/interaapps\/uppm"
Expand Down
17 changes: 14 additions & 3 deletions uppm.locks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
"Psr\\Http\\Message": "modules\/psr-http-message\/src",
"GuzzleHttp\\Psr7": "modules\/guzzlehttp-psr7\/src",
"Psr\\Http\\Client": "modules\/psr-http-client\/src",
"GuzzleHttp": "modules\/guzzlehttp-guzzle\/src"
"GuzzleHttp": "modules\/guzzlehttp-guzzle\/src",
"de\\interaapps\\ulole\\orm": "modules\/uloleorm\/de\/interaapps\/ulole\/orm",
"de\\interaapps\\ulole\\router": "modules\/deverm\/de\/interaapps\/ulole\/router",
"de\\interaapps\\ulole\\core": "modules\/ulole-core\/src\/main\/de\/interaapps\/ulole\/core"
},
"directNamespaceBindings": {
"de\\interaapps\\ulole\\orm\\Database": "modules\/uloleorm\/de\/interaapps\/ulole\/orm\/Database.php",
"de\\interaapps\\ulole\\orm\\ORMModel": "modules\/uloleorm\/de\/interaapps\/ulole\/orm\/ORMModel.php",
"de\\interaapps\\ulole\\orm\\UloleORM": "modules\/uloleorm\/de\/interaapps\/ulole\/orm\/UloleORM.php",
"de\\interaapps\\ulole\\orm\\Query": "modules\/uloleorm\/de\/interaapps\/ulole\/orm\/Query.php"
},
"directNamespaceBindings": {},
"modules": {
"interaapps\/jsonplus": "1.0.6",
"guzzlehttp\/promises": "dev-master",
Expand All @@ -17,7 +25,10 @@
"guzzlehttp\/psr7": "dev-master",
"psr\/http-client": "dev-master",
"symfony\/deprecation-contracts": "dev-main",
"guzzlehttp\/guzzle": "dev-master"
"guzzlehttp\/guzzle": "dev-master",
"uloleorm": "3.2.2",
"deverm": "5.3.0",
"ulole-core": "3.2.0"
},
"initScripts": [
"src\/functions_include.php",
Expand Down

0 comments on commit 8e7b228

Please sign in to comment.