Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Command/PluginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions tests/TestCase/Command/PluginCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down