diff --git a/src/Command/PluginCommand.php b/src/Command/PluginCommand.php index 66bf1e33..3bf567d1 100644 --- a/src/Command/PluginCommand.php +++ b/src/Command/PluginCommand.php @@ -125,7 +125,9 @@ public function bake(string $plugin, Arguments $args, ConsoleIo $io): ?bool $this->_generateFiles($plugin, $this->path, $args, $io); if (!$this->isVendor) { - $this->_modifyApplication($plugin, $io); + if (!$args->getOption('class-only')) { + $this->_modifyApplication($plugin, $io); + } $composer = $this->findComposer($args, $io); @@ -247,6 +249,12 @@ protected function _generateFiles( } } + if ($args->getOption('class-only')) { + $files = array_filter($files, function ($file) { + return $file->getFilename() === 'Plugin.php.twig'; + }); + } + $templates = array_keys($files); } } while (!$templates); @@ -370,6 +378,10 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar ->addOption('standalone-path', [ 'short' => 'p', 'help' => 'Generate a standalone plugin in the provided path.', + ])->addOption('class-only', [ + 'short' => 'c', + 'boolean' => true, + 'help' => 'Generate only the plugin class.', ]); return $parser; diff --git a/tests/TestCase/Command/PluginCommandTest.php b/tests/TestCase/Command/PluginCommandTest.php index c81b1896..03498fe2 100644 --- a/tests/TestCase/Command/PluginCommandTest.php +++ b/tests/TestCase/Command/PluginCommandTest.php @@ -233,6 +233,18 @@ public function testFindPathEmpty() $command->findPath($paths, $io); } + public function testMainClassOnlyOption() + { + $this->exec('bake plugin ClassOnly --class-only', ['y', 'n']); + $this->assertExitCode(CommandInterface::CODE_SUCCESS); + + $bakedRoot = App::path('plugins')[0]; + $pluginClass = $bakedRoot . 'ClassOnly/src/ClassOnlyPlugin.php'; + $this->assertFileContains('use Cake\Core\BasePlugin', $pluginClass); + + $this->assertFileDoesNotExist($bakedRoot . 'ClassOnly/webroot'); + } + /** * Check the baked plugin matches the expected output *