Skip to content

Commit

Permalink
Offline styles and scripts;
Browse files Browse the repository at this point in the history
Documentation for config;
Config command list instead of harcoded;
Refactoring pages and components;
Changing README;
Wrap command call in try-catch;
  • Loading branch information
infureal committed Nov 19, 2020
1 parent 0b78d88 commit e98d8a5
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 106,610 deletions.
90 changes: 86 additions & 4 deletions README.md
Expand Up @@ -8,29 +8,111 @@
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/infureal/artisan-gui)


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

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

## Installation
Just install package:
```bash
composer require infureal/artisan-gui
```

For some "flexibility" you can publish config file `config/artisan-gui.php`:
By default package has predefined config and inline styles and scripts.
Since version `1.4` you can publish vendors like css and js files in `vendor/artisan-gui`:
```bash
php artisan vendor:publish --provider="Infureal\Providers\GuiServiceProvider"
```
Publish only config:
```bash
php artisan vendor:publish --tag="artisan-gui-config"
```

Publish only styles and scripts:
```bash
php artisan vendor:publish --tag="artisan-gui-css-js"
```

## Running command
By default, you can access this page only when in local environment.
By default, you can access this page only in local environment. If you wish
you can change `local` key in config.

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

## Configuration
Default config is:
```php
<?php

return [

/*
|--------------------------------------------------------------------------
| Middleware list for web routes
|--------------------------------------------------------------------------
|
| You can pass any middleware for routes, by default it's just [web] group
| of middleware.
|
*/
'middlewares' => [
'web',
// 'auth'
],

/*
|--------------------------------------------------------------------------
| Route prefix
|--------------------------------------------------------------------------
|
| Prefix for advisor routes. By default url is [/~artisan-gui].
| For your wish you can set it for example 'my-'. So url will be [/my-artisan-gui].
|
| Why tilda? It's selected for prevent route names correlation.
|
*/
'prefix' => '~',

/*
|--------------------------------------------------------------------------
| Home url
|--------------------------------------------------------------------------
|
| Where to go when [home] button is pressed
|
*/
'home' => '/',

/*
|--------------------------------------------------------------------------
| Only on local
|--------------------------------------------------------------------------
|
| Flag that preventing showing commands if environment is on production
|
*/
'local' => true,

/*
|--------------------------------------------------------------------------
| List of commands
|--------------------------------------------------------------------------
|
| List of all default commands that has end of execution. Commands like
| [serve] not supported in case of server side behavior of php.
| Keys means group. You can shuffle commands as you wish and add your own.
|
*/
'commands' => [
// ...
]

];

```

## Issues
If have any issue please [write me](https://github.com/inFureal/artisan-gui/issues).
2 changes: 1 addition & 1 deletion config/artisan-gui.php
Expand Up @@ -37,7 +37,7 @@
| Where to go when [home] button is pressed
|
*/
'home' => url('/'),
'home' => '/',

/*
|--------------------------------------------------------------------------
Expand Down
16 changes: 14 additions & 2 deletions resources/views/index.blade.php
Expand Up @@ -28,7 +28,7 @@
Artisan
</h1>

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

<pre>{{ trim(session('output')->fetch()) }}</pre>
<pre>{{ trim(session('output')) }}</pre>
</div>
@endif

@if($errors->any())
<div class="p-6 bg-red-500 text-red-100 rounded-md overflow-x-auto mb-6">
<div class="grid grid-cols-1 gap-4">
@foreach($errors->all() as $error)
<div>
{{ $error }}
</div>
@endforeach
</div>
</div>
@endif

Expand Down
9 changes: 7 additions & 2 deletions src/Http/Controllers/GuiController.php
Expand Up @@ -9,7 +9,6 @@
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Artisan;
use Infureal\Providers\GuiServiceProvider;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\BufferedOutput;

Expand Down Expand Up @@ -41,7 +40,13 @@ function run($command) {
}

$output = new BufferedOutput();
$status = Artisan::call($command->getName(), $params, $output);
try {
$status = Artisan::call($command->getName(), $params, $output);
$output = $output->fetch();
} catch (\Exception $exception) {
$status = $exception->getCode() ?? 500;
$output = $exception->getMessage();
}

return back()
->with([
Expand Down
17 changes: 8 additions & 9 deletions src/Providers/GuiServiceProvider.php
Expand Up @@ -8,7 +8,7 @@
use Illuminate\Support\ServiceProvider;


class GuiServiceProvider extends ServiceProvider {
class GuiServiceProvider extends ServiceProvider {

protected $root;

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

protected function registerRoutes() {

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

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

public function register()
{
public function register() {
$this->mergeConfigFrom(
"{$this->root}/config/artisan-gui.php", 'artisan-gui'
);
$this->loadComponents();
$this->loadViewsFrom("{$this->root}/resources/views", 'gui');
}

public function boot() {

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

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

$this->loadComponents();
$this->loadViewsFrom("{$this->root}/resources/views", 'gui');
}

public function boot() {
$this->publishVendors();
\View::share('__trs', 'transition ease-in-out duration-150');
\View::share('guiRoot', $this->root);
Expand Down

0 comments on commit e98d8a5

Please sign in to comment.