Skip to content

Commit 8086c54

Browse files
committed
Refactor runtime downloader. Add download command to download latest runtimes
1 parent f02c39e commit 8086c54

File tree

3 files changed

+6
-35
lines changed

3 files changed

+6
-35
lines changed

devstack

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ if (file_exists($autoload = __DIR__ . '/vendor/autoload.php')) {
99

1010
use Symfony\Component\Console\Application;
1111
use Webteractive\Devstack\Commands\Config;
12+
use Webteractive\Devstack\Commands\DownloadRuntimes;
1213
use Webteractive\Devstack\Commands\InitStack;
1314

1415
$app = new Application;
1516
$app->add(new InitStack);
1617
$app->add(new Config);
18+
$app->add(new DownloadRuntimes);
1719
$app->run();

src/Commands/InitStack.php

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,20 @@
22

33
namespace Webteractive\Devstack\Commands;
44

5+
use Webteractive\Devstack\RuntimeDownloader;
56
use Webteractive\Devstack\File;
67
use Webteractive\Devstack\ShouldConfigure;
7-
use Webteractive\Devstack\WithHttp;
8-
use ZipArchive;
98

109
class InitStack extends Base
1110
{
12-
use ShouldConfigure,
13-
WithHttp;
11+
use ShouldConfigure;
1412

1513
protected $signature = 'init
1614
{runtime? : The runtime to load}
1715
{--flr : Whether to fetch the latest runtimes from the runtimes repository}
1816
{--dest= : The path where to save the runtimes, defaults to the current working directory.}';
1917
protected $description = 'Initialize devstack runtime to the current project';
2018

21-
protected $runtimes = [];
22-
2319
public function handle(): int
2420
{
2521
$this->ensureConfigurationIsSet(
@@ -79,35 +75,7 @@ private function resolveRuntimes()
7975
$this->warn("Unable to locate runtimes locally, downloading runtimes from {$this->config['repository']}.");
8076
}
8177

82-
if ($shouldGetTheLatestRuntimes) {
83-
$this->devstackStorage()->deleteDirectory('runtimes');
84-
$this->info("Downloading fresh runtimes from {$this->config['repository']}.");
85-
}
86-
87-
$archive = $this->homePath('runtimes.zip');
88-
$downloadUrl = join('/', [$this->config['repository'], 'zipball', $this->config['branch']]);
89-
$response = $this->http()->get($downloadUrl, [
90-
'headers' => [
91-
'Authorization' => 'token ' . $this->config['token'],
92-
],
93-
'sink' => $archive
94-
]);
95-
96-
if ($response->getStatusCode() == 200) {
97-
$zip = new ZipArchive;
98-
if ($zip->open($archive)) {
99-
$zip->extractTo($this->homePath('tmp'));
100-
$zip->close();
101-
$this->devstackStorage()->delete('runtimes.zip');
102-
$runtimes = $this->devstackStorage()->directories($this->devstackStorage()->directories('tmp')[0]);
103-
foreach ($runtimes as $runtime) {
104-
$runtimeName = pathinfo($runtime, PATHINFO_BASENAME);
105-
$this->runtimes[$runtimeName] = $runtime;
106-
$this->devstackStorage()->move($runtime, 'runtimes/' . $runtimeName);
107-
}
108-
$this->devstackStorage()->deleteDirectory('tmp');
109-
}
110-
}
78+
(new RuntimeDownloader($this, $this->config))->download($shouldGetTheLatestRuntimes);
11179
}
11280

11381
foreach ($this->devstackStorage()->directories('runtimes') as $runtimePath) {

src/ShouldConfigure.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ trait ShouldConfigure
1111
protected $branch;
1212
protected $token;
1313
protected $config;
14+
protected $runtimes = [];
1415

1516
public function ensureConfigurationIsSet($runtime = null)
1617
{

0 commit comments

Comments
 (0)