|
2 | 2 |
|
3 | 3 | namespace Webteractive\Devstack\Commands; |
4 | 4 |
|
| 5 | +use Webteractive\Devstack\RuntimeDownloader; |
5 | 6 | use Webteractive\Devstack\File; |
6 | 7 | use Webteractive\Devstack\ShouldConfigure; |
7 | | -use Webteractive\Devstack\WithHttp; |
8 | | -use ZipArchive; |
9 | 8 |
|
10 | 9 | class InitStack extends Base |
11 | 10 | { |
12 | | - use ShouldConfigure, |
13 | | - WithHttp; |
| 11 | + use ShouldConfigure; |
14 | 12 |
|
15 | 13 | protected $signature = 'init |
16 | 14 | {runtime? : The runtime to load} |
17 | 15 | {--flr : Whether to fetch the latest runtimes from the runtimes repository} |
18 | 16 | {--dest= : The path where to save the runtimes, defaults to the current working directory.}'; |
19 | 17 | protected $description = 'Initialize devstack runtime to the current project'; |
20 | 18 |
|
21 | | - protected $runtimes = []; |
22 | | - |
23 | 19 | public function handle(): int |
24 | 20 | { |
25 | 21 | $this->ensureConfigurationIsSet( |
@@ -79,35 +75,7 @@ private function resolveRuntimes() |
79 | 75 | $this->warn("Unable to locate runtimes locally, downloading runtimes from {$this->config['repository']}."); |
80 | 76 | } |
81 | 77 |
|
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); |
111 | 79 | } |
112 | 80 |
|
113 | 81 | foreach ($this->devstackStorage()->directories('runtimes') as $runtimePath) { |
|
0 commit comments