Skip to content

Commit 6957ce6

Browse files
committed
better errors
1 parent 1c389f2 commit 6957ce6

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

config/nativephp-internal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
'api_url' => env('NATIVEPHP_API_URL', 'http://localhost:4000/api/'),
3232

3333
'zephpyr' => [
34-
'host' => env('ZEPHPYR_HOST', 'zephpyr.com'),
34+
'host' => env('ZEPHPYR_HOST', 'https://zephpyr.com'),
3535
'token' => env('ZEPHPYR_TOKEN'),
3636
'key' => env('ZEPHPYR_KEY'),
3737
],

config/nativephp.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,9 @@
125125
'timeout' => 60,
126126
],
127127
],
128+
129+
/**
130+
* Custom PHP binary path.
131+
*/
132+
'binary_path' => env('NATIVEPHP_BINARY_PATH', null),
128133
];

src/Commands/BundleCommand.php

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Carbon\CarbonInterface;
66
use Illuminate\Console\Command;
7+
use Illuminate\Http\Client\ConnectionException;
78
use Illuminate\Support\Facades\Http;
89
use Illuminate\Support\Number;
910
use Native\Laravel\Commands\Traits\CleansEnvFile;
@@ -35,7 +36,7 @@ public function handle()
3536
}
3637

3738
if (! $this->checkAuthenticated()) {
38-
$this->error('Invalid API token: check your ZEPHPYR_TOKEN on https://'.$this->hostname().'/user/api-tokens');
39+
$this->error('Invalid API token: check your ZEPHPYR_TOKEN on '.$this->baseUrl().'user/api-tokens');
3940

4041
return static::FAILURE;
4142
}
@@ -60,7 +61,15 @@ public function handle()
6061
}
6162

6263
// Send the zip file
63-
$result = $this->sendToZephpyr();
64+
try {
65+
$result = $this->sendToZephpyr();
66+
} catch (ConnectionException $e) {
67+
// Timeout, etc.
68+
$this->error('Failed to send to Zephpyr: '.$e->getMessage());
69+
$this->cleanUp();
70+
71+
return static::FAILURE;
72+
}
6473

6574
if ($result->status() === 413) {
6675
$fileSize = Number::fileSize(filesize($this->zipPath));
@@ -145,28 +154,34 @@ private function addFilesToZip(ZipArchive $zip): void
145154
// TODO: Check the composer.json to make sure there are no symlinked
146155
// or private packages as these will be a pain later
147156

157+
// TODO: Fail if there is symlinked packages
158+
// TODO: For private packages: make an endpoint to check if user gave us their credentials
159+
148160
$this->line('Creating zip archive…');
149161

150162
$app = (new Finder)->files()
151163
->followLinks()
152164
->ignoreVCSIgnored(true)
153165
->in(base_path())
154166
->exclude([
155-
'vendor',
156-
'dist',
157-
'build',
158-
'tests',
159-
...config('nativephp.cleanup_exclude_files', []),
167+
'vendor', // We add this later
168+
'node_modules', // We add this later
169+
'dist', // Compiled nativephp assets
170+
'build', // Compiled box assets
171+
'tests', // Tests
172+
...config('nativephp.cleanup_exclude_files', []), // User defined
160173
]);
161174

162175
$this->finderToZip($app, $zip);
163176

164177
$vendor = (new Finder)->files()
165-
->exclude([
178+
// ->followLinks()
179+
->exclude(array_filter([
166180
'nativephp/php-bin',
167181
'nativephp/electron/resources/js',
168182
'nativephp/*/vendor',
169-
])
183+
config('nativephp.binary_path'), // User defined binary paths
184+
]))
170185
->in(base_path('vendor'));
171186

172187
$this->finderToZip($vendor, $zip, 'vendor');
@@ -195,16 +210,12 @@ private function baseUrl(): string
195210
return str(config('nativephp-internal.zephpyr.host'))->finish('/');
196211
}
197212

198-
protected function hostname(): string
199-
{
200-
return parse_url(config('nativephp-internal.zephpyr.host'), PHP_URL_HOST);
201-
}
202-
203213
private function sendToZephpyr()
204214
{
205215
$this->line('Uploading zip to Zephpyr…');
206216

207217
return Http::acceptJson()
218+
->timeout(300) // 5 minutes
208219
->withoutRedirecting() // Upload won't work if we follow the redirect
209220
->withToken(config('nativephp-internal.zephpyr.token'))
210221
->attach('archive', fopen($this->zipPath, 'r'), $this->zipName)
@@ -247,7 +258,7 @@ private function checkForZephpyrKey()
247258
$this->line(base_path('.env'));
248259
$this->line('');
249260
$this->info('Not set up with Zephpyr yet? Secure your NativePHP app builds and more!');
250-
$this->info('Check out https://'.$this->hostname().'');
261+
$this->info('Check out '.$this->baseUrl().'');
251262
$this->line('');
252263

253264
return false;
@@ -266,7 +277,7 @@ private function checkForZephpyrToken()
266277
$this->line(base_path('.env'));
267278
$this->line('');
268279
$this->info('Not set up with Zephpyr yet? Secure your NativePHP app builds and more!');
269-
$this->info('Check out https://'.$this->hostname().'');
280+
$this->info('Check out '.$this->baseUrl().'');
270281
$this->line('');
271282

272283
return false;

0 commit comments

Comments
 (0)