4
4
5
5
use Carbon \CarbonInterface ;
6
6
use Illuminate \Console \Command ;
7
+ use Illuminate \Http \Client \ConnectionException ;
7
8
use Illuminate \Support \Facades \Http ;
8
9
use Illuminate \Support \Number ;
9
10
use Native \Laravel \Commands \Traits \CleansEnvFile ;
@@ -35,7 +36,7 @@ public function handle()
35
36
}
36
37
37
38
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 ' );
39
40
40
41
return static ::FAILURE ;
41
42
}
@@ -60,7 +61,15 @@ public function handle()
60
61
}
61
62
62
63
// 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
+ }
64
73
65
74
if ($ result ->status () === 413 ) {
66
75
$ fileSize = Number::fileSize (filesize ($ this ->zipPath ));
@@ -145,28 +154,34 @@ private function addFilesToZip(ZipArchive $zip): void
145
154
// TODO: Check the composer.json to make sure there are no symlinked
146
155
// or private packages as these will be a pain later
147
156
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
+
148
160
$ this ->line ('Creating zip archive… ' );
149
161
150
162
$ app = (new Finder )->files ()
151
163
->followLinks ()
152
164
->ignoreVCSIgnored (true )
153
165
->in (base_path ())
154
166
->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
160
173
]);
161
174
162
175
$ this ->finderToZip ($ app , $ zip );
163
176
164
177
$ vendor = (new Finder )->files ()
165
- ->exclude ([
178
+ // ->followLinks()
179
+ ->exclude (array_filter ([
166
180
'nativephp/php-bin ' ,
167
181
'nativephp/electron/resources/js ' ,
168
182
'nativephp/*/vendor ' ,
169
- ])
183
+ config ('nativephp.binary_path ' ), // User defined binary paths
184
+ ]))
170
185
->in (base_path ('vendor ' ));
171
186
172
187
$ this ->finderToZip ($ vendor , $ zip , 'vendor ' );
@@ -195,16 +210,12 @@ private function baseUrl(): string
195
210
return str (config ('nativephp-internal.zephpyr.host ' ))->finish ('/ ' );
196
211
}
197
212
198
- protected function hostname (): string
199
- {
200
- return parse_url (config ('nativephp-internal.zephpyr.host ' ), PHP_URL_HOST );
201
- }
202
-
203
213
private function sendToZephpyr ()
204
214
{
205
215
$ this ->line ('Uploading zip to Zephpyr… ' );
206
216
207
217
return Http::acceptJson ()
218
+ ->timeout (300 ) // 5 minutes
208
219
->withoutRedirecting () // Upload won't work if we follow the redirect
209
220
->withToken (config ('nativephp-internal.zephpyr.token ' ))
210
221
->attach ('archive ' , fopen ($ this ->zipPath , 'r ' ), $ this ->zipName )
@@ -247,7 +258,7 @@ private function checkForZephpyrKey()
247
258
$ this ->line (base_path ('.env ' ));
248
259
$ this ->line ('' );
249
260
$ 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 ().'' );
251
262
$ this ->line ('' );
252
263
253
264
return false ;
@@ -266,7 +277,7 @@ private function checkForZephpyrToken()
266
277
$ this ->line (base_path ('.env ' ));
267
278
$ this ->line ('' );
268
279
$ 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 ().'' );
270
281
$ this ->line ('' );
271
282
272
283
return false ;
0 commit comments