Skip to content

Commit 8e7b228

Browse files
committed
Added tree command and changed README
1 parent 7aecf24 commit 8e7b228

File tree

12 files changed

+89
-12
lines changed

12 files changed

+89
-12
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ php uppm.phar help
4040
```
4141
## Globally
4242
```shell
43-
wget -O uppm https://raw.githubusercontent.com/interaapps/uppm/master/target/uppm.phar
43+
curl -o uppm https://raw.githubusercontent.com/interaapps/uppm/master/target/uppm.phar
4444
# Installing it on linux globally
4545
sudo mv uppm /usr/local/bin/uppm
4646
sudo chmod +x /usr/local/bin/uppm
@@ -56,6 +56,9 @@ uppm help
5656
# Installing dependencies
5757
sudo apt install php8.1 php8.1-zip php8.1-json php8.1-phar
5858

59+
# Getting the php.ini location
60+
php --ini
61+
5962
# Adding phar rule to php.ini (For building projects)
6063
sudo echo phar.readonly = Off >> /etc/php/8.1/cli/php.ini
6164
```

src/main/bootstrap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
ini_set('display_startup_errors', 1);
55
error_reporting(E_ALL);
66

7+
ini_set('phar.readonly', 0);
8+
79
chdir(".");
810
(include 'autoload.php')(mod: "main"); // Using the autoloader with the module main
911
array_shift($argv); // Removing useless first argument

src/main/de/interaapps/uppm/UPPM.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
use de\interaapps\uppm\commands\InitCommand;
1313
use de\interaapps\uppm\commands\InstallCommand;
1414
use de\interaapps\uppm\commands\LockCommand;
15+
use de\interaapps\uppm\commands\PackageTreeCommand;
1516
use de\interaapps\uppm\commands\ProjectInfoCommand;
17+
use de\interaapps\uppm\commands\RemoveCommand;
1618
use de\interaapps\uppm\commands\ReplCommand;
1719
use de\interaapps\uppm\commands\RunCommand;
1820
use de\interaapps\uppm\commands\ServeCommand;
@@ -45,6 +47,8 @@ public function __construct(private array $args, string|null $dir = null) {
4547
"init" => new InitCommand($this),
4648
"lock" => new LockCommand($this),
4749
"repl" => new ReplCommand($this),
50+
"tree" => new PackageTreeCommand($this),
51+
"remove" => new RemoveCommand($this),
4852

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

5761
$this->commands["i"] = $this->commands["install"];
5862
$this->commands["r"] = $this->commands["run"];
63+
$this->commands["rm"] = $this->commands["remove"];
5964

6065
$config = new Configuration();
6166
$lockFile = new LockFile();
6267
if (file_exists($this->currentDir . "/uppm.json")) {
63-
$config = Configuration::fromJson(file_get_contents("$this->currentDir/uppm.json"));
68+
$config = Configuration::fromFile("$this->currentDir/uppm.json");
6469
}
6570
$config->repositories[] = "https://central.uppm.interaapps.de";
6671
if (file_exists($this->currentDir . "/uppm.locks.json")) {
67-
$lockFile = LockFile::fromJson(file_get_contents("$this->currentDir/uppm.locks.json"));
72+
$lockFile = LockFile::fromFile("$this->currentDir/uppm.locks.json");
6873
}
6974
$this->currentProject = new Project(getcwd(), $config, $lockFile);
7075
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
namespace de\interaapps\uppm\commands;
3+
4+
use de\interaapps\ulole\core\cli\Colors;
5+
use de\interaapps\uppm\config\Configuration;
6+
7+
class PackageTreeCommand extends Command {
8+
public function execute(array $args) {
9+
$this->printOut($this->uppm->getCurrentProject()->getConfig());
10+
}
11+
12+
private function printOut(Configuration $config, $indent = '', $prefix = '📁') {
13+
$this->uppm->getLogger()->log("{$indent}{$prefix} §h{$config->name} §g{$config->version}§f");
14+
15+
$i = 0;
16+
foreach ($config->modules as $module => $version) {
17+
$i++;
18+
$modConfig = Configuration::fromFile($this->uppm->getCurrentDir() . "/modules/$module/uppm.json");
19+
20+
if ($modConfig != null) {
21+
$this->printOut($modConfig, "$indent ", '📦');
22+
}
23+
}
24+
}
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
namespace de\interaapps\uppm\commands;
3+
4+
class RemoveCommand extends Command {
5+
public function execute(array $args) {
6+
$this->uppm->getLogger()->loadingBar(0, "Removing package...");
7+
$project = $this->uppm->getCurrentProject();
8+
9+
10+
if (count($args) > 0) {
11+
foreach ($args as $arg) {
12+
$split = explode(":", $arg);
13+
14+
unset($project->getConfig()->modules->{$split[0]});
15+
$project->getConfig()->save($this->uppm);
16+
}
17+
}
18+
}
19+
}

src/main/de/interaapps/uppm/config/Configuration.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct() {
4040
$this->initScripts = [];
4141
}
4242

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

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

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

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

92-
$lockFile->modules = (object)array_merge((array)$lockFile->modules, [$this->name => $this->version]);
92+
$lockFile->modules = (object)array_merge((array) $lockFile->modules, [$this->name => $this->version]);
9393
$lockFile->save($uppm);
9494
}
95+
96+
public static function fromFile(string $name): Configuration|null {
97+
if (!file_exists($name))
98+
return null;
99+
return self::fromJson(file_get_contents($name));
100+
}
95101
}

src/main/de/interaapps/uppm/config/LockFile.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,10 @@ private function addRec(UPPM $uppm, $dir, $key, &$lockNameSpaces): void {
6262
}
6363
}
6464
}
65+
66+
public static function fromFile(string $name): LockFile|null {
67+
if (!file_exists($name))
68+
return null;
69+
return self::fromJson(file_get_contents($name));
70+
}
6571
}

src/main/de/interaapps/uppm/package/UPPMPackage.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
namespace de\interaapps\uppm\package;
43

54
use de\interaapps\uppm\helper\Web;

target/uppm.phar

100755100644
213 KB
Binary file not shown.

target/uppm.phar.gz

41.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)