diff --git a/.ahoy.yml b/.ahoy.yml new file mode 100644 index 0000000000000000000000000000000000000000..146b5b80d49d4396a407b1e11d8223d40e0bce9f --- /dev/null +++ b/.ahoy.yml @@ -0,0 +1,6 @@ +ahoyapi: v2 +commands: + me: + cmd: + - ahoy.yml + usage: Ahoy plugin commands diff --git a/composer.json b/composer.json index 500a90568945985741d36a4960592ffe393597e4..019caa9fc2794640eb223529142b36e9c5ef50ef 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "require": { "php": ">=7.2", "composer-plugin-api": "^1||^2", - "lakedrops/composer-json-utils": "^1.4.0", + "lakedrops/composer-json-utils": "^1.7||dev-master", "symfony/yaml": "^3.4||^4.4||^5.0" }, "require-dev": { @@ -47,14 +47,6 @@ } }, "extra": { - "class": "LakeDrops\\Ahoy\\Plugin", - "lakedrops": { - "ahoy": { - "me": { - "usage": "Ahoy plugin commands", - "imports": ["ahoy.yml"] - } - } - } + "class": "LakeDrops\\Ahoy\\Plugin" } } diff --git a/src/Handler.php b/src/Handler.php index 08d05eea64f6e63c84d89e09a2edfd4e376c599d..80112d840d9fb630cb78fd413c9acb075724c08a 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -13,34 +13,44 @@ use Symfony\Component\Yaml\Yaml; */ class Handler extends BaseHandler { + /** + * {@inheritdoc} + */ + public function configId(): string { + return 'ahoy'; + } + /** * Update ahoy scripts of all LakeDrops plugins. */ public function updateScripts() { + $this->init(); // We only do the fancy stuff for developers. if (!$this->isDevMode()) { return; } - $ahoy = [ - 'ahoyapi' => 'v2', - 'commands' => [], - ]; - - $settings = new Utils($this->composer); - foreach ($settings->getSubSubSection('extra', 'lakedrops', 'ahoy') as $command => $commands) { - $ahoy['commands'][$command] = $commands; + if (file_exists('.ahoy.yml')) { + $ahoy = Yaml::parseFile('.ahoy.yml'); + } + else { + $ahoy = [ + 'ahoyapi' => 'v2', + 'commands' => [], + ]; } $installationManager = $this->composer->getInstallationManager(); - foreach ($this->composer->getRepositoryManager()->getLocalRepository()->search('lakedrops/*') as $pkg) { + foreach ($this->composer->getRepositoryManager()->getLocalRepository()->search('*') as $pkg) { $pluginRoot = $installationManager->getInstallPath($this->getPackage($pkg['name'])); - $pluginSettings = new Utils($this->composer, $pluginRoot); - foreach ($pluginSettings->getSubSubSection('extra', 'lakedrops', 'ahoy') as $command => $commands) { - $ahoy['commands'][$command] = $commands; - foreach ($commands['imports'] as $key => $import) { - $ahoy['commands'][$command]['imports'][$key] = './vendor/' . $pkg['name'] . '/' . $import; + if (file_exists($pluginRoot . '/.ahoy.yml')) { + $pluginAhoy = Yaml::parseFile($pluginRoot . '/.ahoy.yml'); + foreach ($pluginAhoy['commands'] as $command => $commands) { + $ahoy['commands'][$command] = $commands; + foreach ($commands['imports'] as $key => $import) { + $ahoy['commands'][$command]['imports'][$key] = './vendor/' . $pkg['name'] . '/' . $import; + } } } } diff --git a/src/Plugin.php b/src/Plugin.php index 20d88cd69adbc384d69f3232db693d8eb605e1b7..004bd21505bd114e72a3cce902c46f35c83424cf 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -14,7 +14,7 @@ class Plugin extends BasePlugin { /** * {@inheritdoc} */ - public function getHandlerClass() { + public function getHandlerClass(): string { return Handler::class; } @@ -44,7 +44,7 @@ class Plugin extends BasePlugin { * @param \Composer\Script\Event $event * The event that triggered the plugin. */ - public function updateScripts(Event $event) { + public function updateScripts(Event $event): void { /** @var Handler $handler */ $handler = $this->handler; $handler diff --git a/src/UpdateCommand.php b/src/UpdateCommand.php index dfcb1c401521654d6da54b8fa94c326f386b118c..cf1b07c4b3d92b97efce62425f8fe1b73b0fe6f8 100644 --- a/src/UpdateCommand.php +++ b/src/UpdateCommand.php @@ -11,7 +11,7 @@ class UpdateCommand extends BaseCommand { /** * {@inheritdoc} */ - protected function configure() { + protected function configure(): void { parent::configure(); $this ->setName('lakedrops:ahoy') @@ -21,18 +21,19 @@ class UpdateCommand extends BaseCommand { /** * {@inheritdoc} */ - public function getHandlerClass() { + public function getHandlerClass(): string { return Handler::class; } /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { parent::execute($input, $output); /** @var Handler $handler */ $handler = $this->handler; $handler->updateScripts(); + return 0; } }