Skip to content

Commit 5bcb261

Browse files
authored
Merge pull request #1053 from cakephp/plugin-class-only
Add option to PluginCommand to only generate the plugin class.
2 parents 8d5e199 + 54440f1 commit 5bcb261

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Command/PluginCommand.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ public function bake(string $plugin, Arguments $args, ConsoleIo $io): ?bool
125125
$this->_generateFiles($plugin, $this->path, $args, $io);
126126

127127
if (!$this->isVendor) {
128-
$this->_modifyApplication($plugin, $io);
128+
if (!$args->getOption('class-only')) {
129+
$this->_modifyApplication($plugin, $io);
130+
}
129131

130132
$composer = $this->findComposer($args, $io);
131133

@@ -247,6 +249,12 @@ protected function _generateFiles(
247249
}
248250
}
249251

252+
if ($args->getOption('class-only')) {
253+
$files = array_filter($files, function ($file) {
254+
return $file->getFilename() === 'Plugin.php.twig';
255+
});
256+
}
257+
250258
$templates = array_keys($files);
251259
}
252260
} while (!$templates);
@@ -370,6 +378,10 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
370378
->addOption('standalone-path', [
371379
'short' => 'p',
372380
'help' => 'Generate a standalone plugin in the provided path.',
381+
])->addOption('class-only', [
382+
'short' => 'c',
383+
'boolean' => true,
384+
'help' => 'Generate only the plugin class.',
373385
]);
374386

375387
return $parser;

tests/TestCase/Command/PluginCommandTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ public function testFindPathEmpty()
233233
$command->findPath($paths, $io);
234234
}
235235

236+
public function testMainClassOnlyOption()
237+
{
238+
$this->exec('bake plugin ClassOnly --class-only', ['y', 'n']);
239+
$this->assertExitCode(CommandInterface::CODE_SUCCESS);
240+
241+
$bakedRoot = App::path('plugins')[0];
242+
$pluginClass = $bakedRoot . 'ClassOnly/src/ClassOnlyPlugin.php';
243+
$this->assertFileContains('use Cake\Core\BasePlugin', $pluginClass);
244+
245+
$this->assertFileDoesNotExist($bakedRoot . 'ClassOnly/webroot');
246+
}
247+
236248
/**
237249
* Check the baked plugin matches the expected output
238250
*

0 commit comments

Comments
 (0)