From 75ac6d53e5a9edc494dc13a74f05a8843e131b47 Mon Sep 17 00:00:00 2001 From: cbl Date: Wed, 24 Jun 2020 18:10:38 +0200 Subject: [PATCH] clear cache --- README.md | 8 ++++ src/Commands/ScriptClearCommand.php | 66 +++++++++++++++++++++++++++++ src/ServiceProvider.php | 18 +++++++- 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/Commands/ScriptClearCommand.php diff --git a/README.md b/README.md index 7a89697..8bdec30 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,14 @@ myFunction() { ``` +## Clear Cache + +You may use the `script:clear` command to clear the script cache: + +```shell +php artisan script:clear +``` + ## Write Transpiler You can easily add transpilers to the compiler, the following example explains diff --git a/src/Commands/ScriptClearCommand.php b/src/Commands/ScriptClearCommand.php new file mode 100644 index 0000000..c3933a9 --- /dev/null +++ b/src/Commands/ScriptClearCommand.php @@ -0,0 +1,66 @@ +files = $files; + } + + /** + * Execute the console command. + * + * @return void + * + * @throws \RuntimeException + */ + public function handle() + { + $path = $this->laravel['config']['script.compiled']; + + if (!$path) { + throw new RuntimeException('Script path not found.'); + } + + foreach ($this->files->glob("{$path}/*") as $script) { + $this->files->delete($script); + } + + $this->info('Compiled scripts cleared!'); + } +} diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 8c35293..cc561a8 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -9,8 +9,8 @@ use BladeScript\Compiler\ScriptCompiler; use BladeScript\Minifier\MullieMinifier; use BladeScript\Components\ScriptComponent; +use BladeScript\Commands\ScriptClearCommand; use BladeScript\Components\ScriptsComponent; -use BladeScript\Contracts\ScriptEngine; use Illuminate\Support\ServiceProvider as LaravelServiceProvider; class ServiceProvider extends LaravelServiceProvider @@ -32,6 +32,8 @@ public function register() $this->registerScriptCompiler(); + $this->registerScriptClearCommand(); + $this->registerFactory(); $this->registerBladeComponents(); @@ -116,6 +118,20 @@ protected function registerCompilerEngine() }); } + /** + * Register the command. + * + * @return void + */ + protected function registerScriptClearCommand() + { + $this->app->singleton('command.script.clear', function ($app) { + return new ScriptClearCommand($app['files']); + }); + + $this->commands(['command.script.clear']); + } + /** * Register publishes. *