diff --git a/src/Module/Console/ModuleOptimizeCommand.php b/src/Module/Console/ModuleOptimizeCommand.php new file mode 100644 index 00000000..adb4343d --- /dev/null +++ b/src/Module/Console/ModuleOptimizeCommand.php @@ -0,0 +1,35 @@ +info('Generating optimized module cache'); + + $this->nova['modules']->optimize(); + } +} diff --git a/src/Module/Providers/ConsoleServiceProvider.php b/src/Module/Providers/ConsoleServiceProvider.php index c19b6d6d..7776f75b 100644 --- a/src/Module/Providers/ConsoleServiceProvider.php +++ b/src/Module/Providers/ConsoleServiceProvider.php @@ -3,6 +3,7 @@ namespace Nova\Module\Providers; use Nova\Module\Console\ModuleListCommand; +use Nova\Module\Console\ModuleOptimizeCommand; use Nova\Support\ServiceProvider; @@ -16,7 +17,7 @@ class ConsoleServiceProvider extends ServiceProvider */ protected $defer = true; - + /** * Bootstrap the application services. */ @@ -32,6 +33,7 @@ public function register() { $commands = array( 'List', + 'Optimize' ); foreach ($commands as $command) { @@ -50,4 +52,16 @@ protected function registerListCommand() $this->commands('command.module.list'); } + + /** + * Register the module:list command. + */ + protected function registerOptimizeCommand() + { + $this->app->singleton('command.module.optimize', function ($app) { + return new ModuleOptimizeCommand($app['modules']); + }); + + $this->commands('command.module.optimize'); + } } diff --git a/src/Module/Repository.php b/src/Module/Repository.php index ed5e22ce..966bd999 100644 --- a/src/Module/Repository.php +++ b/src/Module/Repository.php @@ -227,6 +227,18 @@ public function getNamespace() | */ + /** + * Update cached repository of module information. + * + * @return bool + */ + public function optimize() + { + $modules = $this->getAllModules(); + + $this->writeCache($modules); + } + /** * Get the contents of the cache file. *