Skip to content

Commit e98d8a5

Browse files
committed
Offline styles and scripts;
Documentation for config; Config command list instead of harcoded; Refactoring pages and components; Changing README; Wrap command call in try-catch;
1 parent 0b78d88 commit e98d8a5

File tree

7 files changed

+118
-106610
lines changed

7 files changed

+118
-106610
lines changed

README.md

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,111 @@
88
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/infureal/artisan-gui)
99

1010

11-
Simple but yet powerful library for running some [artisan](https://laravel.com/docs/8.x/artisan) commands
11+
Simple but yet powerful library for running some [artisan](https://laravel.com/docs/8.x/artisan) commands.
1212

1313
## Requirements
1414
- **Laravel** 8.*
1515
- **php** ^7.3
16-
- **internet connection**. For what? For accessing cdns to tailwindcss and alpinejs
1716

1817
## Installation
1918
Just install package:
2019
```bash
2120
composer require infureal/artisan-gui
2221
```
2322

24-
For some "flexibility" you can publish config file `config/artisan-gui.php`:
23+
By default package has predefined config and inline styles and scripts.
24+
Since version `1.4` you can publish vendors like css and js files in `vendor/artisan-gui`:
2525
```bash
2626
php artisan vendor:publish --provider="Infureal\Providers\GuiServiceProvider"
2727
```
28+
Publish only config:
29+
```bash
30+
php artisan vendor:publish --tag="artisan-gui-config"
31+
```
32+
33+
Publish only styles and scripts:
34+
```bash
35+
php artisan vendor:publish --tag="artisan-gui-css-js"
36+
```
2837

2938
## Running command
30-
By default, you can access this page only when in local environment.
39+
By default, you can access this page only in local environment. If you wish
40+
you can change `local` key in config.
3141

3242
Simply go to `http://you-domain.com/~artisan` and here we go!
3343
Select needed command from list, fill arguments and options/flags and hit `run` button.
3444

45+
## Configuration
46+
Default config is:
47+
```php
48+
<?php
49+
50+
return [
51+
52+
/*
53+
|--------------------------------------------------------------------------
54+
| Middleware list for web routes
55+
|--------------------------------------------------------------------------
56+
|
57+
| You can pass any middleware for routes, by default it's just [web] group
58+
| of middleware.
59+
|
60+
*/
61+
'middlewares' => [
62+
'web',
63+
// 'auth'
64+
],
65+
66+
/*
67+
|--------------------------------------------------------------------------
68+
| Route prefix
69+
|--------------------------------------------------------------------------
70+
|
71+
| Prefix for advisor routes. By default url is [/~artisan-gui].
72+
| For your wish you can set it for example 'my-'. So url will be [/my-artisan-gui].
73+
|
74+
| Why tilda? It's selected for prevent route names correlation.
75+
|
76+
*/
77+
'prefix' => '~',
78+
79+
/*
80+
|--------------------------------------------------------------------------
81+
| Home url
82+
|--------------------------------------------------------------------------
83+
|
84+
| Where to go when [home] button is pressed
85+
|
86+
*/
87+
'home' => '/',
88+
89+
/*
90+
|--------------------------------------------------------------------------
91+
| Only on local
92+
|--------------------------------------------------------------------------
93+
|
94+
| Flag that preventing showing commands if environment is on production
95+
|
96+
*/
97+
'local' => true,
98+
99+
/*
100+
|--------------------------------------------------------------------------
101+
| List of commands
102+
|--------------------------------------------------------------------------
103+
|
104+
| List of all default commands that has end of execution. Commands like
105+
| [serve] not supported in case of server side behavior of php.
106+
| Keys means group. You can shuffle commands as you wish and add your own.
107+
|
108+
*/
109+
'commands' => [
110+
// ...
111+
]
112+
113+
];
114+
115+
```
116+
35117
## Issues
36118
If have any issue please [write me](https://github.com/inFureal/artisan-gui/issues).

config/artisan-gui.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
| Where to go when [home] button is pressed
3838
|
3939
*/
40-
'home' => url('/'),
40+
'home' => '/',
4141

4242
/*
4343
|--------------------------------------------------------------------------

resources/views/index.blade.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
Artisan
2929
</h1>
3030

31-
<a href="{{ config('artisan-gui.home', url('/')) }}"
31+
<a href="{{ url(config('artisan-gui.home', '/')) }}"
3232
class="{{ $__trs }} text-gray-500 hover:text-gray-800 px-4 py-2 rounded hover:bg-gray-300">
3333
./home
3434
</a>
@@ -42,7 +42,19 @@ class="{{ $__trs }} text-gray-500 hover:text-gray-800 px-4 py-2 rounded hover:bg
4242
[{{ session('command') }}] command output
4343
</div>
4444

45-
<pre>{{ trim(session('output')->fetch()) }}</pre>
45+
<pre>{{ trim(session('output')) }}</pre>
46+
</div>
47+
@endif
48+
49+
@if($errors->any())
50+
<div class="p-6 bg-red-500 text-red-100 rounded-md overflow-x-auto mb-6">
51+
<div class="grid grid-cols-1 gap-4">
52+
@foreach($errors->all() as $error)
53+
<div>
54+
{{ $error }}
55+
</div>
56+
@endforeach
57+
</div>
4658
</div>
4759
@endif
4860

src/Http/Controllers/GuiController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Illuminate\Foundation\Validation\ValidatesRequests;
1010
use Illuminate\Routing\Controller;
1111
use Illuminate\Support\Facades\Artisan;
12-
use Infureal\Providers\GuiServiceProvider;
1312
use Symfony\Component\Console\Command\Command;
1413
use Symfony\Component\Console\Output\BufferedOutput;
1514

@@ -41,7 +40,13 @@ function run($command) {
4140
}
4241

4342
$output = new BufferedOutput();
44-
$status = Artisan::call($command->getName(), $params, $output);
43+
try {
44+
$status = Artisan::call($command->getName(), $params, $output);
45+
$output = $output->fetch();
46+
} catch (\Exception $exception) {
47+
$status = $exception->getCode() ?? 500;
48+
$output = $exception->getMessage();
49+
}
4550

4651
return back()
4752
->with([

src/Providers/GuiServiceProvider.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Illuminate\Support\ServiceProvider;
99

1010

11-
class GuiServiceProvider extends ServiceProvider {
11+
class GuiServiceProvider extends ServiceProvider {
1212

1313
protected $root;
1414

@@ -19,7 +19,7 @@ public function __construct($app) {
1919

2020
protected function registerRoutes() {
2121

22-
$middleware = config('artisan-gui.middlewares');
22+
$middleware = config('artisan-gui.middlewares', []);
2323

2424
\Route::middleware($middleware)
2525
->prefix(config('artisan-gui.prefix', '~') . 'artisan')
@@ -30,23 +30,22 @@ protected function registerRoutes() {
3030
});
3131
}
3232

33-
public function register()
34-
{
33+
public function register() {
3534
$this->mergeConfigFrom(
3635
"{$this->root}/config/artisan-gui.php", 'artisan-gui'
3736
);
38-
$this->loadComponents();
39-
$this->loadViewsFrom("{$this->root}/resources/views", 'gui');
40-
}
41-
42-
public function boot() {
4337

4438
$local = $this->app->environment('local');
4539
$only = config('artisan-gui.local', true);
4640

4741
if ($local || !$only)
4842
$this->registerRoutes();
4943

44+
$this->loadComponents();
45+
$this->loadViewsFrom("{$this->root}/resources/views", 'gui');
46+
}
47+
48+
public function boot() {
5049
$this->publishVendors();
5150
\View::share('__trs', 'transition ease-in-out duration-150');
5251
\View::share('guiRoot', $this->root);

0 commit comments

Comments
 (0)