<?php namespace LakeDrops\Ahoy; use LakeDrops\Component\Composer\BaseHandler; use Symfony\Component\Yaml\Yaml; /** * Class Handler. * * @package LakeDrops\Drupal8Scaffold */ class Handler extends BaseHandler { /** * {@inheritdoc} */ public function configId(): string { return 'ahoy'; } /** * Update ahoy scripts of all LakeDrops plugins. */ public function updateScripts(): void { $this->init(); // We only do the fancy stuff for developers. if (!$this->isDevMode()) { return; } 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) { $pluginRoot = $installationManager->getInstallPath($this->getPackage($pkg['name'])); if (file_exists($pluginRoot . '/.ahoy.l3d.yml')) { $pluginAhoy = Yaml::parseFile($pluginRoot . '/.ahoy.l3d.yml'); foreach ($pluginAhoy['commands'] as $command => $commands) { $ahoy['commands'][$command] = $commands; if (isset($commands['imports']) && is_array($commands['imports'])) { foreach ($commands['imports'] as $key => $import) { $ahoy['commands'][$command]['imports'][$key] = './vendor/' . $pkg['name'] . '/' . $import; } } } } } $file = getcwd() . '/.ahoy.yml'; file_put_contents($file, $rendered = Yaml::dump($ahoy, 9, 2)); $this->gitIgnore('.ahoy.yml'); } }