├── .gitignore ├── LICENSE ├── README.md ├── _config.yml ├── composer.json ├── config └── nova-command-runner.php ├── dist ├── css │ └── tool.css ├── js │ └── tool.js └── mix-manifest.json ├── package.json ├── resources ├── js │ ├── components │ │ └── Tool.vue │ └── tool.js ├── sass │ └── tool.scss └── views │ └── navigation.blade.php ├── routes └── api.php ├── src ├── CommandRunner.php ├── Http │ ├── Controllers │ │ ├── CommandsController.php │ │ └── HistoryController.php │ └── Middleware │ │ └── Authorize.php └── ToolServiceProvider.php └── webpack.mix.js /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /vendor 3 | /node_modules 4 | package-lock.json 5 | composer.phar 6 | composer.lock 7 | phpunit.xml 8 | .phpunit.result.cache 9 | .DS_Store 10 | Thumbs.db 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 guratr 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Nova tool for running Artisan commands. 2 | [![Latest Version on Github](https://img.shields.io/packagist/v/guratr/nova-command-runner.svg?style=flat)](https://packagist.org/packages/guratr/nova-command-runner) 3 | [![Total Downloads](https://img.shields.io/packagist/dt/guratr/nova-command-runner.svg?style=flat)](https://packagist.org/packages/guratr/nova-command-runner) 4 | 5 | This [Nova](https://nova.laravel.com) tool lets you: 6 | - run & queue artisan commands 7 | - specify options for commands 8 | - get command result 9 | - view commands history 10 | 11 | ![screenshot of the command runner tool](https://user-images.githubusercontent.com/1502853/50797697-16c4f100-12ef-11e9-99b0-2bf9736236f1.png) 12 | 13 | ## Installation 14 | 15 | You can install the nova tool in to a Laravel app that uses [Nova](https://nova.laravel.com) via composer: 16 | 17 | ```bash 18 | composer require guratr/nova-command-runner 19 | ``` 20 | 21 | Next up, you must register the tool with Nova. This is typically done in the `tools` method of the `NovaServiceProvider`. 22 | 23 | ```php 24 | // in app/Providers/NovaServiceProvder.php 25 | 26 | // ... 27 | 28 | public function tools() 29 | { 30 | return [ 31 | // ... 32 | new \Guratr\CommandRunner\CommandRunner, 33 | ]; 34 | } 35 | ``` 36 | 37 | Publish the config file: 38 | 39 | ``` bash 40 | php artisan vendor:publish --provider="Guratr\CommandRunner\ToolServiceProvider" 41 | ``` 42 | 43 | Add your commands to config/nova-command-runner.php 44 | 45 | Available options: 46 | - run : command to run (e.g. `route:cache`) 47 | - options : array of options for command (e.g. `['--allow' => ['127.0.0.1']]`) 48 | - queue : boolean (will use default settings when true) or array (e.g. `['connection' => 'database', 'queue' => 'default']`) 49 | - type : button class (primary, secondary, success, danger, warning, info, light, dark, link) 50 | - group: Group name (optional) 51 | 52 | ## Usage 53 | 54 | Click on the "Command Runner" menu item in your Nova app to see the tool. 55 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guratr/nova-command-runner", 3 | "description": "Laravel Nova tool for running Artisan commands.", 4 | "keywords": [ 5 | "laravel", 6 | "nova", 7 | "Artisan", 8 | "commands" 9 | ], 10 | "license": "MIT", 11 | "require": { 12 | "php": ">=7.1.0" 13 | }, 14 | "autoload": { 15 | "psr-4": { 16 | "Guratr\\CommandRunner\\": "src/" 17 | } 18 | }, 19 | "extra": { 20 | "laravel": { 21 | "providers": [ 22 | "Guratr\\CommandRunner\\ToolServiceProvider" 23 | ] 24 | } 25 | }, 26 | "config": { 27 | "sort-packages": true 28 | }, 29 | "minimum-stability": "stable", 30 | "prefer-stable": true 31 | } 32 | -------------------------------------------------------------------------------- /config/nova-command-runner.php: -------------------------------------------------------------------------------- 1 | [ 5 | /* 6 | 7 | 'Route cache' => ['run' => 'route:cache', 'type' => 'info', 'group' => 'Cache'], 8 | 'Config cache' => ['run' => 'config:cache', 'type' => 'info', 'group' => 'Cache'], 9 | 'View cache' => ['run' => 'view:cache', 'type' => 'info', 'group' => 'Cache'], 10 | 11 | 'Route clear' => ['run' => 'route:clear', 'type' => 'warning', 'group' => 'Clear Cache'], 12 | 'Config clear' => ['run' => 'config:clear', 'type' => 'warning', 'group' => 'Clear Cache'], 13 | 'View clear' => ['run' => 'view:clear', 'type' => 'warning', 'group' => 'Clear Cache'], 14 | 15 | 'Up' => ['run' => 'up', 'type' => 'success', 'group' => 'Maintenance'], 16 | 'Down' => ['run' => 'down', 'options' => ['--allow' => ['127.0.0.1']], 'type' => 'dark', 'group' => 'Maintenance'], 17 | 18 | 'Queue default' => ['run' => 'custom:default', 'queue' => true, 'type' => 'info', 'group' => 'Queue'], 19 | 'Queue custom' => ['run' => 'custom:something', 'queue' => ['connection' => 'database', 'queue' => 'default'], 'type' => 'info', 'group' => 'Queue'], 20 | 21 | */ 22 | ], 23 | 'history' => 10, 24 | ]; -------------------------------------------------------------------------------- /dist/css/tool.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guratr/nova-command-runner/5e5668cc954736527fca834ce71c32e98a67baf8/dist/css/tool.css -------------------------------------------------------------------------------- /dist/js/tool.js: -------------------------------------------------------------------------------- 1 | !function(t){var o={};function e(n){if(o[n])return o[n].exports;var r=o[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,e),r.l=!0,r.exports}e.m=t,e.c=o,e.d=function(t,o,n){e.o(t,o)||Object.defineProperty(t,o,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var o=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(o,"a",o),o},e.o=function(t,o){return Object.prototype.hasOwnProperty.call(t,o)},e.p="",e(e.s=0)}([function(t,o,e){e(1),t.exports=e(11)},function(t,o,e){Nova.booting(function(t,o){o.addRoutes([{name:"command-runner",path:"/command-runner",component:e(2)}])})},function(t,o,e){var n=e(8)(e(9),e(10),!1,function(t){e(3)},null,null);t.exports=n.exports},function(t,o,e){var n=e(4);"string"==typeof n&&(n=[[t.i,n,""]]),n.locals&&(t.exports=n.locals);e(6)("98d2fa3c",n,!0,{})},function(t,o,e){(t.exports=e(5)(!1)).push([t.i,".history-table{text-align:left}.btn-secondary{color:#fff;background-color:#6c757d;border-color:#6c757d}.btn-secondary:hover{color:#fff;background-color:#5a6268;border-color:#545b62}.btn-secondary.focus,.btn-secondary:focus{-webkit-box-shadow:0 0 0 .2rem hsla(208,6%,54%,.5);box-shadow:0 0 0 .2rem hsla(208,6%,54%,.5)}.btn-secondary.disabled,.btn-secondary:disabled{color:#fff;background-color:#6c757d;border-color:#6c757d}.btn-secondary:not(:disabled):not(.disabled).active,.btn-secondary:not(:disabled):not(.disabled):active,.show>.btn-secondary.dropdown-toggle{color:#fff;background-color:#545b62;border-color:#4e555b}.btn-secondary:not(:disabled):not(.disabled).active:focus,.btn-secondary:not(:disabled):not(.disabled):active:focus,.show>.btn-secondary.dropdown-toggle:focus{-webkit-box-shadow:0 0 0 .2rem hsla(208,6%,54%,.5);box-shadow:0 0 0 .2rem hsla(208,6%,54%,.5)}.btn-success{color:#fff;background-color:#28a745;border-color:#28a745}.btn-success:hover{color:#fff;background-color:#218838;border-color:#1e7e34}.btn-success.focus,.btn-success:focus{-webkit-box-shadow:0 0 0 .2rem rgba(72,180,97,.5);box-shadow:0 0 0 .2rem rgba(72,180,97,.5)}.btn-success.disabled,.btn-success:disabled{color:#fff;background-color:#28a745;border-color:#28a745}.btn-success:not(:disabled):not(.disabled).active,.btn-success:not(:disabled):not(.disabled):active,.show>.btn-success.dropdown-toggle{color:#fff;background-color:#1e7e34;border-color:#1c7430}.btn-success:not(:disabled):not(.disabled).active:focus,.btn-success:not(:disabled):not(.disabled):active:focus,.show>.btn-success.dropdown-toggle:focus{-webkit-box-shadow:0 0 0 .2rem rgba(72,180,97,.5);box-shadow:0 0 0 .2rem rgba(72,180,97,.5)}.btn-info{color:#fff;background-color:#17a2b8;border-color:#17a2b8}.btn-info:hover{color:#fff;background-color:#138496;border-color:#117a8b}.btn-info.focus,.btn-info:focus{-webkit-box-shadow:0 0 0 .2rem rgba(58,176,195,.5);box-shadow:0 0 0 .2rem rgba(58,176,195,.5)}.btn-info.disabled,.btn-info:disabled{color:#fff;background-color:#17a2b8;border-color:#17a2b8}.btn-info:not(:disabled):not(.disabled).active,.btn-info:not(:disabled):not(.disabled):active,.show>.btn-info.dropdown-toggle{color:#fff;background-color:#117a8b;border-color:#10707f}.btn-info:not(:disabled):not(.disabled).active:focus,.btn-info:not(:disabled):not(.disabled):active:focus,.show>.btn-info.dropdown-toggle:focus{-webkit-box-shadow:0 0 0 .2rem rgba(58,176,195,.5);box-shadow:0 0 0 .2rem rgba(58,176,195,.5)}.btn-warning{color:#212529;background-color:#ffc107;border-color:#ffc107}.btn-warning:hover{color:#212529;background-color:#e0a800;border-color:#d39e00}.btn-warning.focus,.btn-warning:focus{-webkit-box-shadow:0 0 0 .2rem rgba(222,170,12,.5);box-shadow:0 0 0 .2rem rgba(222,170,12,.5)}.btn-warning.disabled,.btn-warning:disabled{color:#212529;background-color:#ffc107;border-color:#ffc107}.btn-warning:not(:disabled):not(.disabled).active,.btn-warning:not(:disabled):not(.disabled):active,.show>.btn-warning.dropdown-toggle{color:#212529;background-color:#d39e00;border-color:#c69500}.btn-warning:not(:disabled):not(.disabled).active:focus,.btn-warning:not(:disabled):not(.disabled):active:focus,.show>.btn-warning.dropdown-toggle:focus{-webkit-box-shadow:0 0 0 .2rem rgba(222,170,12,.5);box-shadow:0 0 0 .2rem rgba(222,170,12,.5)}.btn-light{color:#212529;background-color:#f8f9fa;border-color:#f8f9fa}.btn-light:hover{color:#212529;background-color:#e2e6ea;border-color:#dae0e5}.btn-light.focus,.btn-light:focus{-webkit-box-shadow:0 0 0 .2rem hsla(220,4%,85%,.5);box-shadow:0 0 0 .2rem hsla(220,4%,85%,.5)}.btn-light.disabled,.btn-light:disabled{color:#212529;background-color:#f8f9fa;border-color:#f8f9fa}.btn-light:not(:disabled):not(.disabled).active,.btn-light:not(:disabled):not(.disabled):active,.show>.btn-light.dropdown-toggle{color:#212529;background-color:#dae0e5;border-color:#d3d9df}.btn-light:not(:disabled):not(.disabled).active:focus,.btn-light:not(:disabled):not(.disabled):active:focus,.show>.btn-light.dropdown-toggle:focus{-webkit-box-shadow:0 0 0 .2rem hsla(220,4%,85%,.5);box-shadow:0 0 0 .2rem hsla(220,4%,85%,.5)}.btn-dark{color:#fff;background-color:#343a40;border-color:#343a40}.btn-dark:hover{color:#fff;background-color:#23272b;border-color:#1d2124}.btn-dark.focus,.btn-dark:focus{-webkit-box-shadow:0 0 0 .2rem rgba(82,88,93,.5);box-shadow:0 0 0 .2rem rgba(82,88,93,.5)}.btn-dark.disabled,.btn-dark:disabled{color:#fff;background-color:#343a40;border-color:#343a40}.btn-dark:not(:disabled):not(.disabled).active,.btn-dark:not(:disabled):not(.disabled):active,.show>.btn-dark.dropdown-toggle{color:#fff;background-color:#1d2124;border-color:#171a1d}.btn-dark:not(:disabled):not(.disabled).active:focus,.btn-dark:not(:disabled):not(.disabled):active:focus,.show>.btn-dark.dropdown-toggle:focus{-webkit-box-shadow:0 0 0 .2rem rgba(82,88,93,.5);box-shadow:0 0 0 .2rem rgba(82,88,93,.5)}.badge{display:inline-block;padding:.25em .4em;font-size:75%;font-weight:700;line-height:1;text-align:center;white-space:nowrap;vertical-align:baseline;border-radius:.25rem}.badge-success{color:#fff;background-color:#28a745}.badge-error{color:#fff;background-color:#dc3545}",""])},function(t,o){t.exports=function(t){var o=[];return o.toString=function(){return this.map(function(o){var e=function(t,o){var e=t[1]||"",n=t[3];if(!n)return e;if(o&&"function"==typeof btoa){var r=(s=n,"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(s))))+" */"),a=n.sources.map(function(t){return"/*# sourceURL="+n.sourceRoot+t+" */"});return[e].concat(a).concat([r]).join("\n")}var s;return[e].join("\n")}(o,t);return o[2]?"@media "+o[2]+"{"+e+"}":e}).join("")},o.i=function(t,e){"string"==typeof t&&(t=[[null,t,""]]);for(var n={},r=0;re.parts.length&&(n.parts.length=e.parts.length)}else{var s=[];for(r=0;r 2 |
3 | 4 | 5 | 11 |
12 |
13 |

{{commandIndex}}

14 |

15 | Are you sure you want to run this command ? 16 |

17 |
18 | 19 |
20 |
21 | 22 | 23 | 44 |
45 |
46 |
47 |
48 |
49 |
50 | 51 | Command Runner 52 | 53 | 54 |

55 | Available commands 56 |

57 | 58 |
59 |
60 |

61 | {{group ? group : 'Unnamed group'}} 62 |

63 | 73 |
74 |
75 | 76 | 77 |
78 | 79 | History 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 |
CommandOptionsStatusResultDurationHappened
{{value.run}}{{value.options}}{{value.status}}{{value.result}}{{value.duration}} sec.{{value.time}}
104 |
105 |
106 | 107 | 108 | 172 | 173 | 405 | -------------------------------------------------------------------------------- /resources/js/tool.js: -------------------------------------------------------------------------------- 1 | Nova.booting((Vue, router) => { 2 | router.addRoutes([ 3 | { 4 | name: 'command-runner', 5 | path: '/command-runner', 6 | component: require('./components/Tool'), 7 | }, 8 | ]) 9 | }) 10 | -------------------------------------------------------------------------------- /resources/sass/tool.scss: -------------------------------------------------------------------------------- 1 | // Nova Tool CSS 2 | -------------------------------------------------------------------------------- /resources/views/navigation.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {{----}} 6 | 7 | 8 | Command Runner 9 | 10 | 11 | -------------------------------------------------------------------------------- /routes/api.php: -------------------------------------------------------------------------------- 1 | false, 'result' => 'Command not found!']; 19 | } 20 | 21 | $start = microtime(true); 22 | 23 | try { 24 | $result = $this->execute($command); 25 | $status = true; 26 | } catch (\Exception $exception) { 27 | $result = $exception->getMessage(); 28 | $status = false; 29 | } 30 | 31 | $duration = microtime(true) - $start; 32 | 33 | if ($historyLength = config('nova-command-runner.history')) { 34 | $history = \Cache::get('nova-command-runner-history', []); 35 | $history = array_slice($history, 0, $historyLength - 1); 36 | array_unshift($history, [ 37 | 'run' => $command['run'], 38 | 'options' => $command['options'] ?? [], 39 | 'status' => $status ? 'success' : 'error', 40 | 'result' => $result, 41 | 'time' => now()->timestamp, 42 | 'duration' => round($duration, 4), 43 | ]); 44 | \Cache::forever('nova-command-runner-history', $history); 45 | } 46 | 47 | return ['status' => $status, 'result' => $result]; 48 | } 49 | 50 | protected function execute($command) 51 | { 52 | $buffer = new \Symfony\Component\Console\Output\BufferedOutput(); 53 | 54 | if(!($command['queue'] ?? false)) { 55 | \Artisan::call($command['run'], $command['options'] ?? [], $buffer); 56 | return $buffer->fetch(); 57 | } 58 | 59 | ['connection' => $connection, 'queue' => $queue] = array_merge( 60 | ['connection' => config('queue.default'), 'queue' => 'default'], 61 | is_array($command['queue']) ? $command['queue'] : [] 62 | ); 63 | 64 | \Artisan::queue($command['run'], $command['options'] ?? [], $buffer) 65 | ->onConnection($connection) 66 | ->onQueue($queue); 67 | 68 | return $buffer->fetch(); 69 | } 70 | } -------------------------------------------------------------------------------- /src/Http/Controllers/HistoryController.php: -------------------------------------------------------------------------------- 1 | diffForHumans(); 12 | }); 13 | 14 | return $history; 15 | } 16 | } -------------------------------------------------------------------------------- /src/Http/Middleware/Authorize.php: -------------------------------------------------------------------------------- 1 | authorize($request) ? $next($request) : abort(403); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/ToolServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 21 | __DIR__.'/../config/nova-command-runner.php' => config_path('nova-command-runner.php'), 22 | ], 'config'); 23 | 24 | $this->loadViewsFrom(__DIR__.'/../resources/views', 'command-runner'); 25 | 26 | $this->app->booted(function () { 27 | $this->routes(); 28 | }); 29 | 30 | Nova::serving(function (ServingNova $event) { 31 | // 32 | }); 33 | } 34 | 35 | /** 36 | * Register the tool's routes. 37 | * 38 | * @return void 39 | */ 40 | protected function routes() 41 | { 42 | if ($this->app->routesAreCached()) { 43 | return; 44 | } 45 | 46 | Route::middleware(['nova', Authorize::class]) 47 | ->prefix('nova-vendor/guratr/command-runner') 48 | ->group(__DIR__.'/../routes/api.php'); 49 | } 50 | 51 | /** 52 | * Register any application services. 53 | * 54 | * @return void 55 | */ 56 | public function register() 57 | { 58 | // 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /webpack.mix.js: -------------------------------------------------------------------------------- 1 | let mix = require('laravel-mix') 2 | 3 | mix.setPublicPath('dist') 4 | .js('resources/js/tool.js', 'js') 5 | .sass('resources/sass/tool.scss', 'css') 6 | --------------------------------------------------------------------------------