diff --git a/src/Handler.php b/src/Handler.php index fdba9b2f81a1aab2a25a375572434d59513089d0..9788b25b7720c4ebccdffa43441d8be519ee838c 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -56,8 +56,28 @@ class Handler extends BaseHandler { } } } + + // Cleanup configuration: remove non-existant includes. + foreach ($ahoy['commands'] as $command => $commands) { + if (isset($commands['imports']) && is_array($commands['imports'])) { + $deleteKeys = []; + foreach ($commands['imports'] as $key => $import) { + if (!file_exists($import)) { + $deleteKeys[] = $key; + } + } + arsort($deleteKeys); + foreach ($deleteKeys as $deleteKey) { + unset($ahoy['commands'][$command]['imports'][$deleteKey]); + } + if (empty($ahoy['commands'][$command]['imports'])) { + unset($ahoy['commands'][$command]); + } + } + } + $file = $rootDir . '/.ahoy.yml'; - file_put_contents($file, $rendered = Yaml::dump($ahoy, 9, 2)); + file_put_contents($file, Yaml::dump($ahoy, 9, 2)); $this->gitIgnore('.ahoy.yml'); }