Skip to content

Commit

Permalink
clear cache
Browse files Browse the repository at this point in the history
  • Loading branch information
cbl committed Jun 24, 2020
1 parent 04b60b2 commit 75ac6d5
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ myFunction() {
</x-script>
```

## 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
Expand Down
66 changes: 66 additions & 0 deletions src/Commands/ScriptClearCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace BladeScript\Commands;

use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use RuntimeException;

class ScriptClearCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'script:clear';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Clear all compiled script files';

/**
* The filesystem instance.
*
* @var \Illuminate\Filesystem\Filesystem
*/
protected $files;

/**
* Create a new config clear command instance.
*
* @param \Illuminate\Filesystem\Filesystem $files
* @return void
*/
public function __construct(Filesystem $files)
{
parent::__construct();

$this->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!');
}
}
18 changes: 17 additions & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,6 +32,8 @@ public function register()

$this->registerScriptCompiler();

$this->registerScriptClearCommand();

$this->registerFactory();

$this->registerBladeComponents();
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 75ac6d5

Please sign in to comment.