Skip to content

Commit 190ef1e

Browse files
committed
🎨 restructured leaf cli
1 parent b26ceff commit 190ef1e

File tree

4 files changed

+50
-12
lines changed

4 files changed

+50
-12
lines changed

bin/leaf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $app = new Symfony\Component\Console\Application("Leaf CLI", $currentVersion);
1414
$app->add(new Leaf\Console\CreateCommand);
1515
$app->add(new Leaf\Console\UpdateCommand);
1616
$app->add(new Leaf\Console\InstallCommand);
17-
$app->add(new Leaf\Console\App\ServeCommand);
18-
$app->add(new Leaf\Console\App\InteractCommand);
17+
$app->add(new Leaf\Console\ServeCommand);
18+
$app->add(new Leaf\Console\InteractCommand);
1919

2020
$app->run();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22

3-
namespace Leaf\Console\App;
3+
namespace Leaf\Console;
44

55
use Symfony\Component\Console\Command\Command;
66
use Symfony\Component\Console\Input\InputInterface;
77
use Symfony\Component\Console\Output\OutputInterface;
88
use Psy\Shell;
99

1010
class InteractCommand extends Command {
11-
protected static $defaultName = "app:interact";
11+
protected static $defaultName = "interact";
1212

1313
protected function configure() {
1414
$this
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Leaf\Console\App;
3+
namespace Leaf\Console;
44

55
use Symfony\Component\Console\Command\Command;
66
use Symfony\Component\Console\Input\InputOption;
@@ -9,7 +9,7 @@
99

1010
class ServeCommand extends Command
1111
{
12-
protected static $defaultName = 'app:serve';
12+
protected static $defaultName = 'serve';
1313

1414
protected function configure()
1515
{

src/Utils/Package.php

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,56 @@
99
*/
1010
class Package
1111
{
12+
/**
13+
* Check current version
14+
*/
15+
public static function info()
16+
{
17+
return json_decode(file_get_contents(
18+
dirname(dirname(__DIR__)) . "/composer.json"
19+
));
20+
}
21+
22+
/**
23+
* Check current version
24+
*/
25+
public static function version()
26+
{
27+
$meta = static::info();
28+
29+
return $meta->version;
30+
}
31+
32+
/**
33+
* Find latest stable version
34+
*/
35+
public static function ltsInfo()
36+
{
37+
$package = json_decode(
38+
file_get_contents("https://repo.packagist.org/p2/leafs/cli.json")
39+
);
40+
41+
return $package->packages->{"leafs/cli"}[0];
42+
}
43+
44+
/**
45+
* Find latest stable version
46+
*/
47+
public static function ltsVersion()
48+
{
49+
$package = static::ltsInfo();
50+
51+
return $package->version;
52+
}
53+
1254
/**
1355
* Check if there is an update available
1456
*/
1557
public static function updateAvailable()
1658
{
17-
$leafCli = json_decode(file_get_contents(dirname(dirname(__DIR__)) . "/composer.json"));
18-
$latestLeafCli = json_decode(file_get_contents("https://repo.packagist.org/p2/leafs/cli.json"));
19-
20-
$currentVersion = $leafCli->version;
21-
$latestVersion = $latestLeafCli->packages->{"leafs/cli"}[0]->version;
59+
$currentVersion = static::version();
60+
$latestVersion = static::ltsVersion();
2261

2362
return ($currentVersion !== $latestVersion);
2463
}
2564
}
26-

0 commit comments

Comments
 (0)